@@ -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)" ,
@@ -61,6 +68,10 @@ def et_operator_library(
61
68
genrule_cmd .append (
62
69
"--include_all_operators" ,
63
70
)
71
+
72
+ # TODO(larryliu0820): Remove usages of this flag.
73
+ if "define_static_targets" in kwargs :
74
+ kwargs .pop ("define_static_targets" )
64
75
runtime .genrule (
65
76
name = name ,
66
77
macros_only = False ,
@@ -70,18 +81,22 @@ def et_operator_library(
70
81
** kwargs
71
82
)
72
83
73
- def _get_headers (genrule_name , prefix = "" , custom_op = None ):
84
+ def _get_headers (genrule_name , prefix = "" , custom_op = None , manual_registration = False ):
85
+ headers = OPERATOR_HEADERS + (CUSTOM_OPS_NATIVE_FUNCTION_HEADER if custom_op else [])
74
86
return {
75
87
prefix + f : ":{}[{}]" .format (genrule_name , f )
76
- for f in OPERATOR_HEADERS + (CUSTOM_OPS_NATIVE_FUNCTION_HEADER if custom_op else [])
88
+ for f in (MANUAL_REGISTRATION_HEADERS if manual_registration else [])
89
+ }, {
90
+ prefix + f : ":{}[{}]" .format (genrule_name , f )
91
+ for f in headers
77
92
}
78
93
79
94
def _prepare_genrule_and_lib (
80
95
name ,
81
96
functions_yaml_path = None ,
82
97
custom_ops_yaml_path = None ,
83
- custom_ops_aten_kernel_deps = [],
84
98
custom_ops_requires_runtime_registration = True ,
99
+ manual_registration = False ,
85
100
aten_mode = False ):
86
101
"""
87
102
This function returns two dicts `genrules` and `libs`, derived from the arguments being passed
@@ -122,15 +137,18 @@ def _prepare_genrule_and_lib(
122
137
# actually-generated files matches GENERATED_FILES.
123
138
]
124
139
140
+ # Sources for generated kernel registration lib
141
+ sources = MANUAL_REGISTRATION_SOURCES if manual_registration else GENERATED_SOURCES
142
+
125
143
# 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 [])
144
+ genrule_outs = sources + OPERATOR_HEADERS + (CUSTOM_OPS_NATIVE_FUNCTION_HEADER if custom_ops_yaml_path else []) + MANUAL_REGISTRATION_HEADERS
127
145
128
146
genrules = {}
129
147
libs = {}
130
148
131
149
# if aten_mode is true, we don't need functions_yaml_path
132
150
genrule_name = name + "_combined"
133
- headers = _get_headers (genrule_name = genrule_name , custom_op = custom_ops_yaml_path )
151
+ exported_headers , headers = _get_headers (genrule_name = genrule_name , custom_op = custom_ops_yaml_path , manual_registration = manual_registration )
134
152
135
153
# need to register ATen ops into Executorch runtime:
136
154
need_reg_aten_ops = aten_mode or functions_yaml_path
@@ -149,6 +167,10 @@ def _prepare_genrule_and_lib(
149
167
]
150
168
if aten_mode :
151
169
genrule_cmd = genrule_cmd + ["--use_aten_lib" ]
170
+ if manual_registration :
171
+ genrule_cmd = genrule_cmd + [
172
+ "--manual_registration" ,
173
+ ]
152
174
if custom_ops_yaml_path :
153
175
genrule_cmd = genrule_cmd + [
154
176
"--custom_ops_yaml_path=" + custom_ops_yaml_path ,
@@ -160,13 +182,15 @@ def _prepare_genrule_and_lib(
160
182
161
183
if need_reg_ops :
162
184
libs [name ] = {
185
+ "exported_headers" : exported_headers ,
163
186
"genrule" : genrule_name ,
164
187
"headers" : headers ,
165
- "srcs" : GENERATED_SOURCES ,
188
+ "srcs" : sources ,
166
189
}
167
190
168
191
header_lib = name + "_headers"
169
192
libs [header_lib ] = {
193
+ "exported_headers" : exported_headers ,
170
194
"headers" : headers ,
171
195
}
172
196
return genrules , libs
@@ -303,6 +327,7 @@ def executorch_generated_lib(
303
327
custom_ops_requires_runtime_registration = True ,
304
328
visibility = [],
305
329
aten_mode = False ,
330
+ manual_registration = False ,
306
331
use_default_aten_ops_lib = True ,
307
332
deps = [],
308
333
xplat_deps = [],
@@ -350,6 +375,7 @@ def executorch_generated_lib(
350
375
visibility: Visibility of the C++ library targets.
351
376
deps: Additinal deps of the main C++ library. Needs to be in either `//executorch` or `//caffe2` module.
352
377
platforms: platforms args to runtime.cxx_library (only used when in xplat)
378
+ manual_registration: if true, generate RegisterKernels.cpp and RegisterKernels.h.
353
379
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
380
xplat_deps: Additional xplat deps, can be used to provide custom operator library.
355
381
fbcode_deps: Additional fbcode deps, can be used to provide custom operator library.
@@ -391,9 +417,9 @@ def executorch_generated_lib(
391
417
name = name ,
392
418
functions_yaml_path = functions_yaml_path ,
393
419
custom_ops_yaml_path = custom_ops_yaml_path ,
394
- 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