Skip to content

Commit d826290

Browse files
committed
Use std::string_view in vulkan op-test codegen
torchgen emits c10::string_view for string args; normalize to std::string_view at codegen time. Also drop the unused c10/util/Optional.h include in exir/verification/bindings.cpp.
1 parent aceeb40 commit d826290

4 files changed

Lines changed: 6 additions & 8 deletions

File tree

backends/vulkan/test/op_tests/utils/aten_types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
OPT_MEMORY_FORMAT = "::std::optional<at::MemoryFormat>"
2727
OPT_SCALAR_TYPE = "::std::optional<at::ScalarType>"
2828
STRING = "std::string_view"
29-
OLD_STRING = "c10::string_view"
3029
TWO_TENSOR_TUPLE = "::std::tuple<at::Tensor,at::Tensor>"
3130
THREE_TENSOR_TUPLE = "::std::tuple<at::Tensor,at::Tensor,at::Tensor>"
3231
TENSOR_VECTOR = "::std::vector<at::Tensor>"

backends/vulkan/test/op_tests/utils/gen_computegraph.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
BOOL,
1717
DOUBLE,
1818
INT,
19-
OLD_STRING,
2019
OPT_AT_DOUBLE_ARRAY_REF,
2120
OPT_AT_INT_ARRAY_REF,
2221
OPT_AT_TENSOR,
@@ -122,7 +121,9 @@ def __init__(
122121
ctype = cpp.argumenttype_type(
123122
arg.type, mutable=arg.is_write, binds=arg.name
124123
)
125-
cpp_type = ctype.cpp_type(strip_ref=True)
124+
cpp_type = ctype.cpp_type(strip_ref=True).replace(
125+
"c10::string_view", STRING
126+
)
126127

127128
self.args.append(
128129
ATenArg(name=arg.name, cpp_type=cpp_type, default=arg.default)
@@ -494,7 +495,7 @@ def create_value_for( # noqa: C901
494495
or ref.src_cpp_type == OPT_MEMORY_FORMAT
495496
):
496497
ret_str += "add_none(); \n"
497-
elif ref.src_cpp_type == STRING or ref.src_cpp_type == OLD_STRING:
498+
elif ref.src_cpp_type == STRING:
498499
ret_str += f"add_string(std::string({ref.src_cpp_name})); \n"
499500
elif ref.src_cpp_type == TWO_TENSOR_TUPLE:
500501
ret_str += f"add_value_list({{{ref.name}_first, {ref.name}_second}}); \n"

backends/vulkan/test/op_tests/utils/gen_correctness_base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
BOOL,
1616
DOUBLE,
1717
INT,
18-
OLD_STRING,
1918
OPT_AT_DOUBLE_ARRAY_REF,
2019
OPT_AT_INT_ARRAY_REF,
2120
OPT_AT_TENSOR,
@@ -156,7 +155,7 @@ def call_data_gen_fn(self, arg: Argument, data: Any, terminate: bool = True) ->
156155

157156
def create_input_data(self, arg: Argument, data: Any) -> str: # noqa: C901
158157
ctype = cpp.argumenttype_type(arg.type, mutable=arg.is_write, binds=arg.name)
159-
cpp_type = ctype.cpp_type(strip_ref=True)
158+
cpp_type = ctype.cpp_type(strip_ref=True).replace("c10::string_view", STRING)
160159

161160
# Short cut exit for TENSORLIST, because it needs multiple lines of
162161
# construction, deviates from the rest.
@@ -218,7 +217,7 @@ def create_input_data(self, arg: Argument, data: Any) -> str: # noqa: C901
218217
ret_str += "std::nullopt;"
219218
else:
220219
ret_str += f"{str(data)};"
221-
elif cpp_type == STRING or cpp_type == OLD_STRING:
220+
elif cpp_type == STRING:
222221
ret_str += f'std::string_view("{data}");'
223222
elif (
224223
cpp_type == OPT_SCALAR_TYPE

exir/verification/bindings.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <c10/core/ScalarType.h>
1414
#include <c10/macros/Macros.h>
1515
#include <c10/util/C++17.h>
16-
#include <c10/util/Optional.h>
1716
#include <pybind11/pybind11.h>
1817
#include <pybind11/stl.h>
1918
#include <torch/extension.h> // @manual=//caffe2:torch_extension

0 commit comments

Comments
 (0)