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