@@ -146,14 +146,10 @@ def TypedDict(name, attrs, total=True): # type: ignore
146
146
147
147
// ${schema_string}
148
148
${return_type} Tensor::${api_name}(${method_formals}) const {
149
- #ifdef USE_STATIC_DISPATCH
150
- ${static_dispatch_method_body}
151
- #else
152
149
static auto op = c10::Dispatcher::singleton()
153
150
.findSchemaOrThrow("aten::${operator_name}", "${overload_name}")
154
151
.typed<${tensor_method_cpp_signature}>();
155
152
return op.call(${tensor_method_actuals});
156
- #endif
157
153
}
158
154
""" )
159
155
@@ -172,45 +168,13 @@ def TypedDict(name, attrs, total=True): # type: ignore
172
168
173
169
// ${schema_string}
174
170
${return_type} ${api_name}(${formals}) {
175
- #ifdef USE_STATIC_DISPATCH
176
- ${static_dispatch_function_body}
177
- #else
178
171
static auto op = c10::Dispatcher::singleton()
179
172
.findSchemaOrThrow("aten::${operator_name}", "${overload_name}")
180
173
.typed<${function_cpp_signature}>();
181
174
return op.call(${function_actuals});
182
- #endif
183
- }
184
- """ )
185
-
186
- # In order to rely on the linker to strip unused ops, it requires us to dispatch statically
187
- # in Functions.h and TensorMethods.cpp.
188
- #
189
- # NB: The default body also needs to apply a variable guard, as in some
190
- # situations what we think is a default body actually does have an
191
- # explicit derivative, and thereby would have gotten unwrapped by
192
- # the time you get to the implementation.
193
- STATIC_DISPATCH_FUNCTION_DEFAULT_BODY = CodeTemplate ("""\
194
- at::AutoNonVariableTypeMode _var_guard(true);
195
- ${return_call} TypeDefault::${type_wrapper_name}(${actuals});
196
- """ )
197
-
198
- STATIC_DISPATCH_FUNCTION_SWITCH_BODY = CodeTemplate ("""\
199
- at::AutoNonVariableTypeMode _var_guard(true);
200
- ${dispatch_key_init}
201
- switch (dispatchKeyToBackend(${dispatch_key_var_name})) {
202
- ${static_dispatch_function_cases}
203
- default:
204
- AT_ERROR("${api_name} not implemented for ", at::toString(${dispatch_key_var_name}));
205
175
}
206
176
""" )
207
177
208
- STATIC_DISPATCH_FUNCTION_SWITCH_CASE = CodeTemplate ("""\
209
- case Backend::${backend}:
210
- ${return_call} ${backend}Type::${type_wrapper_name}(${actuals});
211
- break;
212
- """ )
213
-
214
178
IFDEF_BLOCK = CodeTemplate ("""\
215
179
#ifdef ${ifdef_guard}
216
180
${content}
@@ -246,10 +210,6 @@ def TypedDict(name, attrs, total=True): # type: ignore
246
210
('ComplexDouble' , 'ComplexDouble' , 'ComplexDouble' , False ),
247
211
]
248
212
249
- static_dispatch_backends = ['CPU' , 'QuantizedCPU' , 'Vulkan' ]
250
- static_dispatch_backends_ifdef_guard = {'Vulkan' : 'USE_VULKAN' }
251
-
252
-
253
213
class NYIError (Exception ):
254
214
"""Indicates we don't support this declaration yet"""
255
215
@@ -1136,44 +1096,6 @@ def swizzle_self(f): # blegh
1136
1096
1137
1097
method_actuals = maybe_unwrap_optional_tensors (option , formals , option ['method_actuals' ])
1138
1098
1139
- if isinstance (type_method_dispatch , dict ):
1140
- static_dispatch_function_cases = []
1141
- # NB: As this code is currently written, there will NEVER be
1142
- # a backend generated for variable dispatch. There is nothing
1143
- # stopping us from actually implementing this, however, if you
1144
- # really wanted variable on mobile, there's nothing stopping
1145
- # you from implementing this (however, you would have an
1146
- # annoying phase problem, since code generation for variable
1147
- # happens in tools/ which happens later than here.)
1148
- #
1149
- # If you pass in a variable to the dispatch, and variable is
1150
- # enabled, this switch will fail. This is intentional: you
1151
- # probably need to disable variable globally in the mobile
1152
- # calling code.
1153
- for backend in static_dispatch_backends :
1154
- if backend in type_method_dispatch :
1155
- static_dispatch_function_case = STATIC_DISPATCH_FUNCTION_SWITCH_CASE .substitute (
1156
- option ,
1157
- backend = backend ,
1158
- backend_function = type_method_dispatch [backend ],
1159
- actuals = method_actuals )
1160
- if (backend in static_dispatch_backends_ifdef_guard ):
1161
- static_dispatch_function_cases .append (IFDEF_BLOCK .substitute (
1162
- option ,
1163
- ifdef_guard = static_dispatch_backends_ifdef_guard [backend ],
1164
- content = static_dispatch_function_case ))
1165
- else :
1166
- static_dispatch_function_cases .append (static_dispatch_function_case )
1167
-
1168
- static_dispatch_method_body = STATIC_DISPATCH_FUNCTION_SWITCH_BODY .substitute (
1169
- option ,
1170
- dispatch_key_var_name = dispatch_key_var_name ,
1171
- dispatch_key_init = dispatch_key_init ,
1172
- static_dispatch_function_cases = static_dispatch_function_cases )
1173
- else :
1174
- static_dispatch_method_body = STATIC_DISPATCH_FUNCTION_DEFAULT_BODY .substitute (
1175
- option , actuals = method_actuals )
1176
-
1177
1099
# See NOTE[UnboxedOnly]
1178
1100
if option ['use_c10_dispatcher' ] == 'full' :
1179
1101
tensor_method_actuals = option ['schema_order_method_actuals' ]
@@ -1184,13 +1106,12 @@ def swizzle_self(f): # blegh
1184
1106
tensor_method_cpp_signature = option ['cpp_signature' ]
1185
1107
1186
1108
method_definition = TENSOR_METHOD_DEFINITION .substitute (
1187
- option , static_dispatch_method_body = static_dispatch_method_body ,
1109
+ option ,
1188
1110
tensor_method_actuals = tensor_method_actuals ,
1189
1111
tensor_method_cpp_signature = tensor_method_cpp_signature
1190
1112
)
1191
1113
return FunctionCode (
1192
- declaration = TENSOR_METHOD_DECLARATION .substitute (
1193
- option , static_dispatch_method_body = static_dispatch_method_body ),
1114
+ declaration = TENSOR_METHOD_DECLARATION .substitute (option ),
1194
1115
definition = method_definition )
1195
1116
1196
1117
def gen_namespace_function (option , multidispatch_formals ):
@@ -1204,31 +1125,6 @@ def gen_namespace_function(option, multidispatch_formals):
1204
1125
1205
1126
actuals = maybe_unwrap_optional_tensors (option , formals , option ['actuals' ])
1206
1127
1207
- if isinstance (type_method_dispatch , dict ):
1208
- static_dispatch_function_cases = []
1209
- for backend in static_dispatch_backends :
1210
- if backend in type_method_dispatch :
1211
- static_dispatch_function_case = STATIC_DISPATCH_FUNCTION_SWITCH_CASE .substitute (
1212
- option ,
1213
- backend = backend ,
1214
- backend_function = type_method_dispatch [backend ],
1215
- actuals = actuals )
1216
- if (backend in static_dispatch_backends_ifdef_guard ):
1217
- static_dispatch_function_cases .append (IFDEF_BLOCK .substitute (
1218
- option ,
1219
- ifdef_guard = static_dispatch_backends_ifdef_guard [backend ],
1220
- content = static_dispatch_function_case ))
1221
- else :
1222
- static_dispatch_function_cases .append (static_dispatch_function_case )
1223
- static_dispatch_function_body = STATIC_DISPATCH_FUNCTION_SWITCH_BODY .substitute (
1224
- option ,
1225
- dispatch_key_var_name = dispatch_key_var_name ,
1226
- dispatch_key_init = dispatch_key_init ,
1227
- static_dispatch_function_cases = static_dispatch_function_cases )
1228
- else :
1229
- static_dispatch_function_body = STATIC_DISPATCH_FUNCTION_DEFAULT_BODY .substitute (
1230
- option , actuals = actuals )
1231
-
1232
1128
# See NOTE[UnboxedOnly]
1233
1129
if option ['use_c10_dispatcher' ] == 'full' :
1234
1130
function_actuals = option ['schema_order_actuals' ]
@@ -1239,7 +1135,7 @@ def gen_namespace_function(option, multidispatch_formals):
1239
1135
function_cpp_signature = option ['cpp_signature' ]
1240
1136
1241
1137
fn_definition = FUNCTION_DEFINITION .substitute (
1242
- option , static_dispatch_function_body = static_dispatch_function_body ,
1138
+ option ,
1243
1139
function_actuals = function_actuals ,
1244
1140
function_cpp_signature = function_cpp_signature )
1245
1141
0 commit comments