From d82629034fc3fa1a53cf015340325f29da3f57b1 Mon Sep 17 00:00:00 2001 From: cyy Date: Sat, 11 Jul 2026 09:52:20 +0800 Subject: [PATCH] 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. --- backends/vulkan/test/op_tests/utils/aten_types.py | 1 - backends/vulkan/test/op_tests/utils/gen_computegraph.py | 7 ++++--- .../vulkan/test/op_tests/utils/gen_correctness_base.py | 5 ++--- exir/verification/bindings.cpp | 1 - 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/backends/vulkan/test/op_tests/utils/aten_types.py b/backends/vulkan/test/op_tests/utils/aten_types.py index a78263987a1..52da866ae01 100644 --- a/backends/vulkan/test/op_tests/utils/aten_types.py +++ b/backends/vulkan/test/op_tests/utils/aten_types.py @@ -26,7 +26,6 @@ OPT_MEMORY_FORMAT = "::std::optional" OPT_SCALAR_TYPE = "::std::optional" STRING = "std::string_view" -OLD_STRING = "c10::string_view" TWO_TENSOR_TUPLE = "::std::tuple" THREE_TENSOR_TUPLE = "::std::tuple" TENSOR_VECTOR = "::std::vector" diff --git a/backends/vulkan/test/op_tests/utils/gen_computegraph.py b/backends/vulkan/test/op_tests/utils/gen_computegraph.py index b6374a890e5..657cbfdd926 100644 --- a/backends/vulkan/test/op_tests/utils/gen_computegraph.py +++ b/backends/vulkan/test/op_tests/utils/gen_computegraph.py @@ -16,7 +16,6 @@ BOOL, DOUBLE, INT, - OLD_STRING, OPT_AT_DOUBLE_ARRAY_REF, OPT_AT_INT_ARRAY_REF, OPT_AT_TENSOR, @@ -122,7 +121,9 @@ def __init__( ctype = cpp.argumenttype_type( arg.type, mutable=arg.is_write, binds=arg.name ) - cpp_type = ctype.cpp_type(strip_ref=True) + cpp_type = ctype.cpp_type(strip_ref=True).replace( + "c10::string_view", STRING + ) self.args.append( ATenArg(name=arg.name, cpp_type=cpp_type, default=arg.default) @@ -494,7 +495,7 @@ def create_value_for( # noqa: C901 or ref.src_cpp_type == OPT_MEMORY_FORMAT ): ret_str += "add_none(); \n" - elif ref.src_cpp_type == STRING or ref.src_cpp_type == OLD_STRING: + elif ref.src_cpp_type == STRING: ret_str += f"add_string(std::string({ref.src_cpp_name})); \n" elif ref.src_cpp_type == TWO_TENSOR_TUPLE: ret_str += f"add_value_list({{{ref.name}_first, {ref.name}_second}}); \n" diff --git a/backends/vulkan/test/op_tests/utils/gen_correctness_base.py b/backends/vulkan/test/op_tests/utils/gen_correctness_base.py index efd073a0cfb..25784e41559 100644 --- a/backends/vulkan/test/op_tests/utils/gen_correctness_base.py +++ b/backends/vulkan/test/op_tests/utils/gen_correctness_base.py @@ -15,7 +15,6 @@ BOOL, DOUBLE, INT, - OLD_STRING, OPT_AT_DOUBLE_ARRAY_REF, OPT_AT_INT_ARRAY_REF, OPT_AT_TENSOR, @@ -156,7 +155,7 @@ def call_data_gen_fn(self, arg: Argument, data: Any, terminate: bool = True) -> def create_input_data(self, arg: Argument, data: Any) -> str: # noqa: C901 ctype = cpp.argumenttype_type(arg.type, mutable=arg.is_write, binds=arg.name) - cpp_type = ctype.cpp_type(strip_ref=True) + cpp_type = ctype.cpp_type(strip_ref=True).replace("c10::string_view", STRING) # Short cut exit for TENSORLIST, because it needs multiple lines of # construction, deviates from the rest. @@ -218,7 +217,7 @@ def create_input_data(self, arg: Argument, data: Any) -> str: # noqa: C901 ret_str += "std::nullopt;" else: ret_str += f"{str(data)};" - elif cpp_type == STRING or cpp_type == OLD_STRING: + elif cpp_type == STRING: ret_str += f'std::string_view("{data}");' elif ( cpp_type == OPT_SCALAR_TYPE diff --git a/exir/verification/bindings.cpp b/exir/verification/bindings.cpp index e435a43a490..689375da727 100644 --- a/exir/verification/bindings.cpp +++ b/exir/verification/bindings.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include // @manual=//caffe2:torch_extension