MCPcopy Create free account
hub / github.com/pytorch/executorch / __call__

Method __call__

codegen/gen.py:149–192  ·  view source on GitHub ↗
(self, f: NativeFunction)

Source from the content-addressed store, hash-verified

147
148 @method_with_native_function
149 def __call__(self, f: NativeFunction) -> str | None:
150 is_method_variant = False
151 if not self.selector.is_root_operator(f"{f.namespace}::{f.func.name}"):
152 return None
153
154 if Variant.function not in f.variants and Variant.method not in f.variants:
155 raise Exception( # noqa: TRY002
156 f"Expected one of function or method to be in variants for {f.func.name}"
157 )
158
159 if Variant.function not in f.variants and Variant.method in f.variants:
160 is_method_variant = True
161
162 sig: CppSignature | ExecutorchCppSignature = (
163 CppSignatureGroup.from_native_function(
164 f, method=False, fallback_binding=f.manual_cpp_binding
165 ).most_faithful_signature()
166 if self.use_aten_lib
167 else ExecutorchCppSignature.from_native_function(f)
168 )
169 if self.use_aten_lib and not self.is_custom_op(f):
170 comma = ", "
171
172 if is_method_variant:
173 return f"""
174// {f.namespace}::{f.func}
175TORCH_API inline {_sig_decl_wrapper(sig)} {{
176 return {sig.arguments()[0].name}.{sig.name()}({comma.join(e.name for e in sig.arguments()[1:])});
177}}
178"""
179 else:
180 return f"""
181// {f.namespace}::{f.func}
182TORCH_API inline {_sig_decl_wrapper(sig)} {{
183 return at::{sig.name()}({comma.join(e.name for e in sig.arguments())});
184}}
185"""
186
187 else:
188 return static_dispatch(
189 sig,
190 f,
191 backend_indices=self.static_dispatch_backend_indices,
192 )
193
194
195# Generates RegisterCodegenUnboxedKernels.cpp.

Callers

nothing calls this directly

Calls 5

_sig_decl_wrapperFunction · 0.85
static_dispatchFunction · 0.85
from_native_functionMethod · 0.80
argumentsMethod · 0.80
nameMethod · 0.80

Tested by

no test coverage detected