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

Function gen_headers

codegen/gen.py:478–578  ·  view source on GitHub ↗

Generate headers. Args: native_functions (Sequence[NativeFunction]): a collection of NativeFunction for ATen ops. gen_custom_ops_header (bool): whether we should generate CustomOpsNativeFunctions.h custom_ops_native_functions (Sequence[NativeFunction]): a collection of N

(
    *,
    native_functions: Sequence[NativeFunction],
    gen_custom_ops_header: bool,
    custom_ops_native_functions: Sequence[NativeFunction],
    selector: SelectiveBuilder,
    kernel_index: ETKernelIndex,
    cpu_fm: FileManager,
    use_aten_lib: bool,
)

Source from the content-addressed store, hash-verified

476
477
478def gen_headers(
479 *,
480 native_functions: Sequence[NativeFunction],
481 gen_custom_ops_header: bool,
482 custom_ops_native_functions: Sequence[NativeFunction],
483 selector: SelectiveBuilder,
484 kernel_index: ETKernelIndex,
485 cpu_fm: FileManager,
486 use_aten_lib: bool,
487) -> None:
488 """Generate headers.
489
490 Args:
491 native_functions (Sequence[NativeFunction]): a collection of NativeFunction for ATen ops.
492 gen_custom_ops_header (bool): whether we should generate CustomOpsNativeFunctions.h
493 custom_ops_native_functions (Sequence[NativeFunction]): a collection of NativeFunction for custom ops.
494 kernel_index (ETKernelIndex): kernel collection
495 cpu_fm (FileManager): file manager manages output stream
496 use_aten_lib (bool): whether we are generating for PyTorch types or Executorch types.
497 """
498 aten_headers = ["#include <ATen/Functions.h>"]
499 backend_indices = {DispatchKey.CPU: kernel_index._to_backend_index()}
500 if gen_custom_ops_header:
501 cpu_fm.write_with_template(
502 "CustomOpsNativeFunctions.h",
503 "NativeFunctions.h",
504 lambda: {
505 "nativeFunctions_declarations": get_native_function_declarations(
506 grouped_native_functions=custom_ops_native_functions,
507 backend_indices=backend_indices,
508 # pyre-ignore: Incompatible parameter type [6]
509 native_function_decl_gen=dest.compute_native_function_declaration,
510 ),
511 "headers": [
512 "#include <ATen/ATen.h>",
513 "#include <torch/torch.h>",
514 ],
515 },
516 )
517 aten_headers.append('#include "CustomOpsNativeFunctions.h"')
518 cpu_fm.write(
519 "Functions.h",
520 lambda: {
521 "static_dispatch_extra_headers": (
522 aten_headers if use_aten_lib else ['#include "NativeFunctions.h"']
523 ),
524 "Functions_declarations": gen_functions_declarations(
525 native_functions=native_functions,
526 kernel_index=kernel_index,
527 selector=selector,
528 use_aten_lib=use_aten_lib,
529 custom_ops_native_functions=custom_ops_native_functions,
530 ),
531 },
532 )
533 cpu_fm.write(
534 "RegisterKernels.h",
535 lambda: {

Calls 5

get_ns_grouped_kernelsFunction · 0.85
_to_backend_indexMethod · 0.80
writeMethod · 0.80
appendMethod · 0.45