Skip to content

Commit 50f97de

Browse files
lucylqfacebook-github-bot
authored andcommitted
Rename selected_mobile_ops --> selected_op_dtypes (pytorch#1098)
Summary: Pull Request resolved: pytorch#1098 ^ Header naming can be more accurate; describing the dtypes for each operator, rather than mobile operators. Reviewed By: larryliu0820 Differential Revision: D50677452 fbshipit-source-id: 5178ad06220494b2f8d22dcacb76e57eef4d1669
1 parent 2a7bd9a commit 50f97de

File tree

8 files changed

+37
-38
lines changed

8 files changed

+37
-38
lines changed

codegen/tools/gen_selected_mobile_ops.py renamed to codegen/tools/gen_selected_op_variants.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
from torchgen.code_template import CodeTemplate
1616

1717

18-
ops_and_dtypes_template_str = """((string_view(operator_name).compare("$operator_name") == 0)\n && ($dtype_checks))"""
18+
ops_and_dtypes_template_str = """((exec_aten::string_view(operator_name).compare("$operator_name") == 0)\n && ($dtype_checks))"""
1919
ops_and_dtypes_template = CodeTemplate(ops_and_dtypes_template_str)
2020

2121
selected_kernel_dtypes_h_template_str = """#pragma once
2222
/**
23-
* Generated by executorch/codegen/tools/gen_selected_mobile_ops_header.py
23+
* Generated by executorch/codegen/tools/gen_selected_op_variants.py
2424
*/
2525
2626
inline constexpr bool should_include_kernel_dtype(
@@ -60,7 +60,7 @@
6060
}
6161

6262

63-
def write_selected_mobile_ops(yaml_file_path: str, output_dir: str) -> None:
63+
def write_selected_op_variants(yaml_file_path: str, output_dir: str) -> None:
6464
with open(yaml_file_path, "r") as selected_operators_file:
6565
# Collect et_kernel_metadata from selected_operators.yaml and extract dtypes
6666
# Example format: v1/6;0,1|6;0,1|6;0,1|6;0,1 # Float, 0, 1
@@ -92,8 +92,8 @@ def write_selected_mobile_ops(yaml_file_path: str, output_dir: str) -> None:
9292
)
9393
body = "\n || ".join(body_parts)
9494
header_contents = selected_kernel_dtypes_h_template.substitute(body=body)
95-
selected_mobile_ops_path = os.path.join(output_dir, "selected_mobile_ops.h")
96-
with open(selected_mobile_ops_path, "wb") as out_file:
95+
selected_op_variants_path = os.path.join(output_dir, "selected_op_variants.h")
96+
with open(selected_op_variants_path, "wb") as out_file:
9797
out_file.write(header_contents.encode("utf-8"))
9898

9999

@@ -109,14 +109,14 @@ def main(argv: List[Any]) -> None:
109109
"--output-dir",
110110
"--output_dir",
111111
help=(
112-
"The directory to store the output yaml files (selected_mobile_ops.h, "
112+
"The directory to store the output yaml files (selected_op_variants.h, "
113113
+ "selected_kernel_dtypes.h, selected_operators.yaml)"
114114
),
115115
required=True,
116116
)
117117

118118
options = parser.parse_args(argv)
119-
write_selected_mobile_ops(options.yaml_file_path, options.output_dir)
119+
write_selected_op_variants(options.yaml_file_path, options.output_dir)
120120

121121

122122
if __name__ == "__main__":

codegen/tools/targets.bzl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def define_common_targets(is_fbcode = False):
119119
)
120120

121121
runtime.python_library(
122-
name = "gen_selected_mobile_ops_lib",
123-
srcs = ["gen_selected_mobile_ops.py"],
122+
name = "gen_selected_op_variants_lib",
123+
srcs = ["gen_selected_op_variants.py"],
124124
base_module = "executorch.codegen.tools",
125125
visibility = ["//executorch/..."],
126126
external_deps = [
@@ -129,29 +129,29 @@ def define_common_targets(is_fbcode = False):
129129
)
130130

131131
runtime.python_binary(
132-
name = "gen_selected_mobile_ops",
133-
main_module = "executorch.codegen.tools.gen_selected_mobile_ops",
132+
name = "gen_selected_op_variants",
133+
main_module = "executorch.codegen.tools.gen_selected_op_variants",
134134
package_style = "inplace",
135135
visibility = [
136136
"PUBLIC",
137137
],
138138
deps = [
139-
":gen_selected_mobile_ops_lib",
139+
":gen_selected_op_variants_lib",
140140
],
141141
_is_external_target = True,
142142
)
143143

144144
runtime.python_test(
145-
name = "test_gen_selected_mobile_ops",
145+
name = "test_gen_selected_op_variants",
146146
srcs = [
147-
"test/test_gen_selected_mobile_ops.py",
147+
"test/test_gen_selected_op_variants.py",
148148
],
149149
package_style = "inplace",
150150
visibility = [
151151
"PUBLIC",
152152
],
153153
deps = [
154-
":gen_selected_mobile_ops_lib",
154+
":gen_selected_op_variants_lib",
155155
"fbsource//third-party/pypi/expecttest:expecttest",
156156
],
157157
_is_external_target = True,

codegen/tools/test/test_gen_selected_mobile_ops.py renamed to codegen/tools/test/test_gen_selected_op_variants.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
import tempfile
1010

11-
import executorch.codegen.tools.gen_selected_mobile_ops as gen_selected_mobile_ops
11+
import executorch.codegen.tools.gen_selected_op_variants as gen_selected_op_variants
1212
import expecttest
1313

1414

@@ -55,29 +55,29 @@ def tearDown(self):
5555
self.temp_dir.cleanup()
5656

5757
def test_generates_correct_header(self) -> None:
58-
gen_selected_mobile_ops.write_selected_mobile_ops(
58+
gen_selected_op_variants.write_selected_op_variants(
5959
os.path.join(self.temp_dir.name, "selected_operators.yaml"),
6060
self.temp_dir.name,
6161
)
6262
with open(
63-
os.path.join(self.temp_dir.name, "selected_mobile_ops.h"), "r"
63+
os.path.join(self.temp_dir.name, "selected_op_variants.h"), "r"
6464
) as result:
6565
self.assertExpectedInline(
6666
result.read(),
6767
"""#pragma once
6868
/**
69-
* Generated by executorch/codegen/tools/gen_selected_mobile_ops_header.py
69+
* Generated by executorch/codegen/tools/gen_selected_op_variants.py
7070
*/
7171
7272
inline constexpr bool should_include_kernel_dtype(
7373
const char *operator_name,
7474
exec_aten::ScalarType scalar_type
7575
) {
76-
return ((string_view(operator_name).compare("add.out") == 0)
76+
return ((exec_aten::string_view(operator_name).compare("add.out") == 0)
7777
&& (scalar_type == exec_aten::ScalarType::Float || scalar_type == exec_aten::ScalarType::Int))
78-
|| ((string_view(operator_name).compare("mul.out") == 0)
78+
|| ((exec_aten::string_view(operator_name).compare("mul.out") == 0)
7979
&& (scalar_type == exec_aten::ScalarType::Float))
80-
|| ((string_view(operator_name).compare("sub.out") == 0)
80+
|| ((exec_aten::string_view(operator_name).compare("sub.out") == 0)
8181
&& (true));
8282
}
8383
""",
@@ -108,18 +108,18 @@ def tearDown(self):
108108
self.temp_dir.cleanup()
109109

110110
def test_generates_correct_header(self) -> None:
111-
gen_selected_mobile_ops.write_selected_mobile_ops(
111+
gen_selected_op_variants.write_selected_op_variants(
112112
os.path.join(self.temp_dir.name, "selected_operators.yaml"),
113113
self.temp_dir.name,
114114
)
115115
with open(
116-
os.path.join(self.temp_dir.name, "selected_mobile_ops.h"), "r"
116+
os.path.join(self.temp_dir.name, "selected_op_variants.h"), "r"
117117
) as result:
118118
self.assertExpectedInline(
119119
result.read(),
120120
"""#pragma once
121121
/**
122-
* Generated by executorch/codegen/tools/gen_selected_mobile_ops_header.py
122+
* Generated by executorch/codegen/tools/gen_selected_op_variants.py
123123
*/
124124
125125
inline constexpr bool should_include_kernel_dtype(

runtime/core/exec_aten/util/scalar_type_util.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@ using string_view = torch::executor::string_view;
4747
} // namespace exec_aten
4848
#endif
4949

50-
namespace torch {
51-
namespace executor {
52-
5350
#ifdef EXECUTORCH_SELECTIVE_BUILD_DTYPE
54-
#include <executorch/runtime/core/exec_aten/util/selected_mobile_ops.h>
51+
#include <executorch/runtime/core/exec_aten/util/selected_op_variants.h>
5552
#else
5653
inline constexpr bool should_include_kernel_dtype(
5754
const char* /*operator_name*/,
@@ -61,6 +58,8 @@ inline constexpr bool should_include_kernel_dtype(
6158
}
6259
#endif
6360

61+
namespace torch {
62+
namespace executor {
6463
#define ET_INTERNAL_CHECK_SELECTIVE_BUILD(enum_type) \
6564
do { \
6665
if (!should_include_kernel_dtype(et_switch_name, enum_type)) { \

runtime/core/exec_aten/util/targets.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ def define_common_targets():
4242

4343
dtype_selective_build_lib = native.read_config("executorch", "dtype_selective_build_lib", None)
4444
if dtype_selective_build_lib != None:
45-
# retrieve selected_mobile_ops.h from codegen
46-
genrule_name = dtype_selective_build_lib + "_et_op_dtype_gen[selected_mobile_ops]"
45+
# retrieve selected_op_variants.h from codegen
46+
genrule_name = dtype_selective_build_lib + "_et_op_dtype_gen[selected_op_variants]"
4747
runtime.cxx_library(
4848
name = "dtype_headers",
4949
srcs = [],
5050
exported_headers = {
51-
"selected_mobile_ops.h": genrule_name,
51+
"selected_op_variants.h": genrule_name,
5252
},
5353
visibility = [
5454
"//executorch/...",

runtime/core/exec_aten/util/test/targets.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def define_common_targets():
1717
)
1818

1919
runtime.cxx_test(
20-
name = "selected_mobile_ops_header_test",
21-
srcs = ["selected_mobile_ops_header_test.cpp"],
20+
name = "selected_op_variants_test",
21+
srcs = ["selected_op_variants_test.cpp"],
2222
deps = [
2323
"//executorch/runtime/core/exec_aten/util:scalar_type_util_TEST_ONLY",
2424
"//executorch/runtime/core/portable_type:portable_type",

shim/xplat/executorch/codegen/codegen.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,15 @@ def executorch_generated_lib(
437437
platforms = platforms,
438438
)
439439

440-
# genrule to generate selected_mobile_ops.h from selected_operators.yaml above
440+
# genrule to generate selected_op_variants.h from selected_operators.yaml above
441441
oplist_header_name = name + "_et_op_dtype_gen"
442442
runtime.genrule(
443443
name = oplist_header_name,
444444
macros_only = False,
445-
cmd = ("$(exe //executorch/codegen/tools:gen_selected_mobile_ops) " +
445+
cmd = ("$(exe //executorch/codegen/tools:gen_selected_op_variants) " +
446446
"--yaml_file_path $(location :{}[selected_operators.yaml]) " +
447447
"--output_dir $OUT").format(oplist_dir_name),
448-
outs = {"selected_mobile_ops": ["selected_mobile_ops.h"]},
448+
outs = {"selected_op_variants": ["selected_op_variants.h"]},
449449
default_outs = ["."],
450450
platforms = platforms,
451451
visibility = visibility,
@@ -471,7 +471,7 @@ def executorch_generated_lib(
471471
# along with headers declaring custom ops `Functions.h`, `NativeFunctions.h` and `UnboxingFunctions.h`.
472472
header_lib = name + "_headers"
473473
if header_lib in libs:
474-
libs[header_lib]["headers"]["selected_mobile_ops.h"] = ":{}[selected_mobile_ops]".format(oplist_header_name)
474+
libs[header_lib]["headers"]["selected_op_variants.h"] = ":{}[selected_op_variants]".format(oplist_header_name)
475475
runtime.cxx_library(
476476
name = header_lib,
477477
srcs = [],

0 commit comments

Comments
 (0)