@@ -20,6 +20,15 @@ GENERATED_SOURCES = [
20
20
"RegisterCodegenUnboxedKernelsEverything.cpp" ,
21
21
]
22
22
23
+ MANUAL_REGISTRATION_SOURCES = [
24
+ # buildifier: keep sorted
25
+ "RegisterKernelsEverything.cpp" ,
26
+ ]
27
+
28
+ MANUAL_REGISTRATION_HEADERS = [
29
+ "RegisterKernels.h" ,
30
+ ]
31
+
23
32
# Fake kernels only return `out` or any other tensor from arguments
24
33
CUSTOM_OPS_DUMMY_KERNEL_SOURCES = ["Register{}Stub.cpp" .format (backend ) for backend in STATIC_DISPATCH_BACKENDS ]
25
34
@@ -35,11 +44,9 @@ CUSTOM_OPS_SCHEMA_REGISTRATION_SOURCES = [
35
44
def et_operator_library (
36
45
name ,
37
46
ops = [],
38
- exported_deps = [],
39
47
model = None ,
40
48
include_all_operators = False ,
41
49
ops_schema_yaml_target = None ,
42
- define_static_targets = False ,
43
50
** kwargs ):
44
51
genrule_cmd = [
45
52
"$(exe //executorch/codegen/tools:gen_oplist)" ,
@@ -70,18 +77,22 @@ def et_operator_library(
70
77
** kwargs
71
78
)
72
79
73
- def _get_headers (genrule_name , prefix = "" , custom_op = None ):
80
+ def _get_headers (genrule_name , prefix = "" , custom_op = None , manual_registration = False ):
81
+ headers = OPERATOR_HEADERS + (CUSTOM_OPS_NATIVE_FUNCTION_HEADER if custom_op else [])
74
82
return {
75
83
prefix + f : ":{}[{}]" .format (genrule_name , f )
76
- for f in OPERATOR_HEADERS + (CUSTOM_OPS_NATIVE_FUNCTION_HEADER if custom_op else [])
84
+ for f in (MANUAL_REGISTRATION_HEADERS if manual_registration else [])
85
+ }, {
86
+ prefix + f : ":{}[{}]" .format (genrule_name , f )
87
+ for f in headers
77
88
}
78
89
79
90
def _prepare_genrule_and_lib (
80
91
name ,
81
92
functions_yaml_path = None ,
82
93
custom_ops_yaml_path = None ,
83
- custom_ops_aten_kernel_deps = [],
84
94
custom_ops_requires_runtime_registration = True ,
95
+ manual_registration = False ,
85
96
aten_mode = False ):
86
97
"""
87
98
This function returns two dicts `genrules` and `libs`, derived from the arguments being passed
@@ -122,15 +133,18 @@ def _prepare_genrule_and_lib(
122
133
# actually-generated files matches GENERATED_FILES.
123
134
]
124
135
136
+ # Sources for generated kernel registration lib
137
+ sources = MANUAL_REGISTRATION_SOURCES if manual_registration else GENERATED_SOURCES
138
+
125
139
# The command will always generate these files.
126
- genrule_outs = GENERATED_SOURCES + OPERATOR_HEADERS + (CUSTOM_OPS_NATIVE_FUNCTION_HEADER if custom_ops_yaml_path else [])
140
+ genrule_outs = sources + OPERATOR_HEADERS + (CUSTOM_OPS_NATIVE_FUNCTION_HEADER if custom_ops_yaml_path else []) + MANUAL_REGISTRATION_HEADERS
127
141
128
142
genrules = {}
129
143
libs = {}
130
144
131
145
# if aten_mode is true, we don't need functions_yaml_path
132
146
genrule_name = name + "_combined"
133
- headers = _get_headers (genrule_name = genrule_name , custom_op = custom_ops_yaml_path )
147
+ exported_headers , headers = _get_headers (genrule_name = genrule_name , custom_op = custom_ops_yaml_path , manual_registration = manual_registration )
134
148
135
149
# need to register ATen ops into Executorch runtime:
136
150
need_reg_aten_ops = aten_mode or functions_yaml_path
@@ -149,6 +163,10 @@ def _prepare_genrule_and_lib(
149
163
]
150
164
if aten_mode :
151
165
genrule_cmd = genrule_cmd + ["--use_aten_lib" ]
166
+ if manual_registration :
167
+ genrule_cmd = genrule_cmd + [
168
+ "--manual_registration" ,
169
+ ]
152
170
if custom_ops_yaml_path :
153
171
genrule_cmd = genrule_cmd + [
154
172
"--custom_ops_yaml_path=" + custom_ops_yaml_path ,
@@ -160,13 +178,15 @@ def _prepare_genrule_and_lib(
160
178
161
179
if need_reg_ops :
162
180
libs [name ] = {
181
+ "exported_headers" : exported_headers ,
163
182
"genrule" : genrule_name ,
164
183
"headers" : headers ,
165
- "srcs" : GENERATED_SOURCES ,
184
+ "srcs" : sources ,
166
185
}
167
186
168
187
header_lib = name + "_headers"
169
188
libs [header_lib ] = {
189
+ "exported_headers" : exported_headers ,
170
190
"headers" : headers ,
171
191
}
172
192
return genrules , libs
@@ -303,6 +323,7 @@ def executorch_generated_lib(
303
323
custom_ops_requires_runtime_registration = True ,
304
324
visibility = [],
305
325
aten_mode = False ,
326
+ manual_registration = False ,
306
327
use_default_aten_ops_lib = True ,
307
328
deps = [],
308
329
xplat_deps = [],
@@ -350,6 +371,7 @@ def executorch_generated_lib(
350
371
visibility: Visibility of the C++ library targets.
351
372
deps: Additinal deps of the main C++ library. Needs to be in either `//executorch` or `//caffe2` module.
352
373
platforms: platforms args to runtime.cxx_library (only used when in xplat)
374
+ manual_registration: if true, generate RegisterKernels.cpp and RegisterKernels.h.
353
375
use_default_aten_ops_lib: If `aten_mode` is True AND this flag is True, use `torch_mobile_all_ops` for ATen operator library.
354
376
xplat_deps: Additional xplat deps, can be used to provide custom operator library.
355
377
fbcode_deps: Additional fbcode deps, can be used to provide custom operator library.
@@ -391,9 +413,9 @@ def executorch_generated_lib(
391
413
name = name ,
392
414
functions_yaml_path = functions_yaml_path ,
393
415
custom_ops_yaml_path = custom_ops_yaml_path ,
394
- custom_ops_aten_kernel_deps = custom_ops_aten_kernel_deps ,
395
416
custom_ops_requires_runtime_registration = custom_ops_requires_runtime_registration ,
396
417
aten_mode = aten_mode ,
418
+ manual_registration = manual_registration ,
397
419
)
398
420
399
421
# genrule for selective build from static operator list
@@ -457,6 +479,7 @@ def executorch_generated_lib(
457
479
# target, and are not meant to be used by targets outside of this
458
480
# directory.
459
481
headers = libs [lib_name ]["headers" ],
482
+ exported_headers = libs [lib_name ]["exported_headers" ],
460
483
exported_preprocessor_flags = ["-DUSE_ATEN_LIB" ] if aten_mode else [],
461
484
# link_whole is necessary because the operators register themselves via
462
485
# static initializers that run at program startup.
0 commit comments