Skip to content

Commit 3b0533f

Browse files
larryliu0820facebook-github-bot
authored andcommitted
Add back selective build to custom ops AOT lib
Summary: In D47976256 I split AOT lib logic out from the previously intertwined logic. However this AOT lib should also go through selective build and I neglected it. This diff adds it back. Reviewed By: JacobSzwejbka Differential Revision: D48283315 fbshipit-source-id: 3a6f081f0b2c0973eb6d3d25627a2c4e54e50813
1 parent 5f8aa6d commit 3b0533f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

shim/xplat/executorch/codegen/codegen.bzl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def _prepare_genrule_and_lib(
174174
def _prepare_custom_ops_genrule_and_lib(
175175
name,
176176
custom_ops_yaml_path = None,
177+
deps = [],
177178
kernels = []):
178179
"""Similar to _prepare_genrule_and_lib but for custom ops."""
179180
genrules = {}
@@ -183,13 +184,28 @@ def _prepare_custom_ops_genrule_and_lib(
183184
genrule_name = name + "_gen"
184185

185186
if custom_ops_yaml_path:
187+
# genrule for selective build from static operator list
188+
oplist_dir_name = name + "_oplist"
189+
runtime.genrule(
190+
name = oplist_dir_name,
191+
macros_only = False,
192+
cmd = ("$(exe fbsource//xplat/executorch/codegen/tools:gen_all_oplist) " +
193+
"--model_file_list_path $(@query_outputs 'attrfilter(labels, et_operator_library, deps(set({deps})))') " +
194+
"--allow_include_all_overloads " +
195+
"--output_dir $OUT ").format(deps = " ".join(["\"{}\"".format(d) for d in deps])),
196+
outs = {"selected_operators.yaml": ["selected_operators.yaml"]},
197+
default_outs = ["."],
198+
)
199+
200+
# genrule for generating operator kernel bindings
186201
genrule_cmd = [
187202
"$(exe {})".format(target),
188203
"--source-path=$(location //executorch/codegen:templates)",
189204
"--tags-path $(location {})/aten/src/ATen/native/tags.yaml".format(aten_src_path),
190205
"--aten_yaml_path $(location {})/aten/src/ATen/native/native_functions.yaml".format(aten_src_path),
191206
"--custom_ops_yaml_path=" + custom_ops_yaml_path,
192207
"--install_dir=${OUT}",
208+
"--op_selection_yaml_path=$(location :{}[selected_operators.yaml])".format(oplist_dir_name),
193209
]
194210

195211
# Determine what sources custom_ops_<name> target should include
@@ -234,7 +250,12 @@ def exir_custom_ops_aot_lib(
234250
kernels: C++ kernels for these custom ops. They need to be implemented using ATen/c10 basics.
235251
deps: dependencies of the generated library.
236252
"""
237-
genrules, libs = _prepare_custom_ops_genrule_and_lib(name = name, custom_ops_yaml_path = "$(location {})".format(yaml_target), kernels = kernels)
253+
genrules, libs = _prepare_custom_ops_genrule_and_lib(
254+
name = name,
255+
custom_ops_yaml_path = "$(location {})".format(yaml_target),
256+
kernels = kernels,
257+
deps = deps,
258+
)
238259
for genrule in genrules:
239260
runtime.genrule(
240261
name = genrule,

0 commit comments

Comments
 (0)