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

Function gen_custom_ops

codegen/gen.py:581–639  ·  view source on GitHub ↗
(
    *,
    native_functions: Sequence[NativeFunction],
    selector: SelectiveBuilder,
    kernel_index: ETKernelIndex,
    cpu_fm: FileManager,
    rocm: bool,
)

Source from the content-addressed store, hash-verified

579
580
581def gen_custom_ops(
582 *,
583 native_functions: Sequence[NativeFunction],
584 selector: SelectiveBuilder,
585 kernel_index: ETKernelIndex,
586 cpu_fm: FileManager,
587 rocm: bool,
588) -> None:
589 dispatch_key = DispatchKey.CPU
590 (
591 anonymous_definition,
592 static_init_dispatch_registrations,
593 ) = gen_custom_ops_registration(
594 native_functions=native_functions,
595 selector=selector,
596 kernel_index=kernel_index,
597 rocm=rocm,
598 )
599 cpu_fm.write_with_template(
600 f"Register{dispatch_key}CustomOps.cpp",
601 "RegisterDispatchKeyCustomOps.cpp",
602 lambda: {
603 "ops_headers": '#include "CustomOpsNativeFunctions.h"',
604 "DispatchKey": dispatch_key,
605 "dispatch_namespace": dispatch_key.lower(),
606 "dispatch_namespaced_definitions": "",
607 "dispatch_anonymous_definitions": anonymous_definition,
608 "static_init_dispatch_registrations": static_init_dispatch_registrations,
609 },
610 )
611 cpu_fm.write_with_template(
612 f"Register{dispatch_key}Stub.cpp",
613 "RegisterDispatchKeyCustomOps.cpp",
614 lambda: {
615 "ops_headers": "",
616 "DispatchKey": dispatch_key,
617 "dispatch_namespace": dispatch_key.lower(),
618 "dispatch_namespaced_definitions": "",
619 "dispatch_anonymous_definitions": list(
620 mapMaybe(ComputeNativeFunctionStub(), native_functions)
621 ),
622 "static_init_dispatch_registrations": static_init_dispatch_registrations,
623 },
624 )
625
626 (
627 aten_schema_registrations,
628 schema_registrations,
629 ) = get_native_function_schema_registrations(
630 native_functions=native_functions,
631 schema_selector=selector,
632 )
633 cpu_fm.write(
634 "RegisterSchema.cpp",
635 lambda: {
636 "schema_registrations": schema_registrations,
637 "aten_schema_registrations": aten_schema_registrations,
638 },

Callers 1

mainFunction · 0.85

Calls 3

writeMethod · 0.80

Tested by

no test coverage detected