@@ -174,6 +174,7 @@ def _prepare_genrule_and_lib(
174
174
def _prepare_custom_ops_genrule_and_lib (
175
175
name ,
176
176
custom_ops_yaml_path = None ,
177
+ deps = [],
177
178
kernels = []):
178
179
"""Similar to _prepare_genrule_and_lib but for custom ops."""
179
180
genrules = {}
@@ -183,13 +184,28 @@ def _prepare_custom_ops_genrule_and_lib(
183
184
genrule_name = name + "_gen"
184
185
185
186
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
186
201
genrule_cmd = [
187
202
"$(exe {})" .format (target ),
188
203
"--source-path=$(location //executorch/codegen:templates)" ,
189
204
"--tags-path $(location {})/aten/src/ATen/native/tags.yaml" .format (aten_src_path ),
190
205
"--aten_yaml_path $(location {})/aten/src/ATen/native/native_functions.yaml" .format (aten_src_path ),
191
206
"--custom_ops_yaml_path=" + custom_ops_yaml_path ,
192
207
"--install_dir=${OUT}" ,
208
+ "--op_selection_yaml_path=$(location :{}[selected_operators.yaml])" .format (oplist_dir_name ),
193
209
]
194
210
195
211
# Determine what sources custom_ops_<name> target should include
@@ -234,7 +250,12 @@ def exir_custom_ops_aot_lib(
234
250
kernels: C++ kernels for these custom ops. They need to be implemented using ATen/c10 basics.
235
251
deps: dependencies of the generated library.
236
252
"""
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
+ )
238
259
for genrule in genrules :
239
260
runtime .genrule (
240
261
name = genrule ,
0 commit comments