@@ -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
@@ -70,10 +79,14 @@ def et_operator_library(
70
79
** kwargs
71
80
)
72
81
73
- def _get_headers (genrule_name , prefix = "" , custom_op = None ):
82
+ def _get_headers (genrule_name , prefix = "" , custom_op = None , manual_registration = False ):
83
+ headers = OPERATOR_HEADERS + (CUSTOM_OPS_NATIVE_FUNCTION_HEADER if custom_op else [])
74
84
return {
75
85
prefix + f : ":{}[{}]" .format (genrule_name , f )
76
- for f in OPERATOR_HEADERS + (CUSTOM_OPS_NATIVE_FUNCTION_HEADER if custom_op else [])
86
+ for f in (MANUAL_REGISTRATION_HEADERS if manual_registration else [])
87
+ }, {
88
+ prefix + f : ":{}[{}]" .format (genrule_name , f )
89
+ for f in headers
77
90
}
78
91
79
92
def _prepare_genrule_and_lib (
@@ -82,6 +95,7 @@ def _prepare_genrule_and_lib(
82
95
custom_ops_yaml_path = None ,
83
96
custom_ops_aten_kernel_deps = [],
84
97
custom_ops_requires_runtime_registration = True ,
98
+ manual_registration = False ,
85
99
aten_mode = False ):
86
100
"""
87
101
This function returns two dicts `genrules` and `libs`, derived from the arguments being passed
@@ -122,15 +136,18 @@ def _prepare_genrule_and_lib(
122
136
# actually-generated files matches GENERATED_FILES.
123
137
]
124
138
139
+ # Sources for generated kernel registration lib
140
+ sources = MANUAL_REGISTRATION_SOURCES if manual_registration else GENERATED_SOURCES
141
+
125
142
# 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 [])
143
+ genrule_outs = sources + OPERATOR_HEADERS + (CUSTOM_OPS_NATIVE_FUNCTION_HEADER if custom_ops_yaml_path else []) + MANUAL_REGISTRATION_HEADERS
127
144
128
145
genrules = {}
129
146
libs = {}
130
147
131
148
# if aten_mode is true, we don't need functions_yaml_path
132
149
genrule_name = name + "_combined"
133
- headers = _get_headers (genrule_name = genrule_name , custom_op = custom_ops_yaml_path )
150
+ exported_headers , headers = _get_headers (genrule_name = genrule_name , custom_op = custom_ops_yaml_path , manual_registration = manual_registration )
134
151
135
152
# need to register ATen ops into Executorch runtime:
136
153
need_reg_aten_ops = aten_mode or functions_yaml_path
@@ -149,6 +166,10 @@ def _prepare_genrule_and_lib(
149
166
]
150
167
if aten_mode :
151
168
genrule_cmd = genrule_cmd + ["--use_aten_lib" ]
169
+ if manual_registration :
170
+ genrule_cmd = genrule_cmd + [
171
+ "--manual_registration" ,
172
+ ]
152
173
if custom_ops_yaml_path :
153
174
genrule_cmd = genrule_cmd + [
154
175
"--custom_ops_yaml_path=" + custom_ops_yaml_path ,
@@ -160,13 +181,15 @@ def _prepare_genrule_and_lib(
160
181
161
182
if need_reg_ops :
162
183
libs [name ] = {
184
+ "exported_headers" : exported_headers ,
163
185
"genrule" : genrule_name ,
164
186
"headers" : headers ,
165
- "srcs" : GENERATED_SOURCES ,
187
+ "srcs" : sources ,
166
188
}
167
189
168
190
header_lib = name + "_headers"
169
191
libs [header_lib ] = {
192
+ "exported_headers" : exported_headers ,
170
193
"headers" : headers ,
171
194
}
172
195
return genrules , libs
@@ -303,6 +326,7 @@ def executorch_generated_lib(
303
326
custom_ops_requires_runtime_registration = True ,
304
327
visibility = [],
305
328
aten_mode = False ,
329
+ manual_registration = False ,
306
330
use_default_aten_ops_lib = True ,
307
331
deps = [],
308
332
xplat_deps = [],
@@ -350,6 +374,7 @@ def executorch_generated_lib(
350
374
visibility: Visibility of the C++ library targets.
351
375
deps: Additinal deps of the main C++ library. Needs to be in either `//executorch` or `//caffe2` module.
352
376
platforms: platforms args to runtime.cxx_library (only used when in xplat)
377
+ manual_registration: if true, generate RegisterKernels.cpp and RegisterKernels.h.
353
378
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
379
xplat_deps: Additional xplat deps, can be used to provide custom operator library.
355
380
fbcode_deps: Additional fbcode deps, can be used to provide custom operator library.
@@ -394,6 +419,7 @@ def executorch_generated_lib(
394
419
custom_ops_aten_kernel_deps = custom_ops_aten_kernel_deps ,
395
420
custom_ops_requires_runtime_registration = custom_ops_requires_runtime_registration ,
396
421
aten_mode = aten_mode ,
422
+ manual_registration = manual_registration ,
397
423
)
398
424
399
425
# genrule for selective build from static operator list
@@ -457,6 +483,7 @@ def executorch_generated_lib(
457
483
# target, and are not meant to be used by targets outside of this
458
484
# directory.
459
485
headers = libs [lib_name ]["headers" ],
486
+ exported_headers = libs [lib_name ]["exported_headers" ],
460
487
exported_preprocessor_flags = ["-DUSE_ATEN_LIB" ] if aten_mode else [],
461
488
# link_whole is necessary because the operators register themselves via
462
489
# static initializers that run at program startup.
0 commit comments