(
*,
native_functions: Sequence[NativeFunction],
cpu_fm: FileManager,
selector: SelectiveBuilder,
use_aten_lib: bool,
kernel_index: ETKernelIndex,
manual_registration: bool,
add_exception_boundary: bool = False,
)
| 322 | |
| 323 | |
| 324 | def gen_unboxing( |
| 325 | *, |
| 326 | native_functions: Sequence[NativeFunction], |
| 327 | cpu_fm: FileManager, |
| 328 | selector: SelectiveBuilder, |
| 329 | use_aten_lib: bool, |
| 330 | kernel_index: ETKernelIndex, |
| 331 | manual_registration: bool, |
| 332 | add_exception_boundary: bool = False, |
| 333 | ) -> None: |
| 334 | # Iterable type for write_sharded is a Tuple of (native_function, (kernel_key, metadata)) |
| 335 | def key_func( |
| 336 | item: tuple[NativeFunction, tuple[ETKernelKey, BackendMetadata]], |
| 337 | ) -> str: |
| 338 | return item[0].root_name + ":" + item[1][0].to_native_string() |
| 339 | |
| 340 | items: list[tuple[NativeFunction, tuple[ETKernelKey, BackendMetadata]]] = [ |
| 341 | (native_function, (kernel_key, metadata)) |
| 342 | for native_function in native_functions |
| 343 | for kernel_key, metadata in kernel_index.get_kernels(native_function).items() |
| 344 | ] |
| 345 | |
| 346 | header = ["Functions.h" if use_aten_lib else "NativeFunctions.h"] |
| 347 | filename = ( |
| 348 | "RegisterKernels.cpp" |
| 349 | if manual_registration |
| 350 | else "RegisterCodegenUnboxedKernels.cpp" |
| 351 | ) |
| 352 | cpu_fm.write_sharded( |
| 353 | filename, |
| 354 | items, |
| 355 | key_fn=key_func, |
| 356 | env_callable=lambda unbox_kernel_entry: { |
| 357 | "unboxed_kernels": [ |
| 358 | ComputeCodegenUnboxedKernels( |
| 359 | selector, use_aten_lib, add_exception_boundary |
| 360 | )(unbox_kernel_entry) |
| 361 | ], |
| 362 | "fn_header": ( |
| 363 | header if unbox_kernel_entry == items[0] else [] |
| 364 | ), # Only write header once |
| 365 | }, |
| 366 | num_shards=1, |
| 367 | sharded_keys={"unboxed_kernels", "fn_header"}, |
| 368 | ) |
| 369 | |
| 370 | |
| 371 | @with_native_function_and_index # type: ignore[arg-type] |
no test coverage detected