code: def main() -> None:
      parser = argparse.ArgumentParser(
          description="Generate operator source files"
      )
      # Although we don't refer to --source-path directly, make_file_manager()
      # expects it to point to a directory that contains a templates/ subdirectory
      # containing the file templates.
      parser.add_argument(
          "-s",
          "--source-path",
          help="path to source directory for kernel templates",
      )
      parser.add_argument(
          "--functions-yaml-path",
          "--functions_yaml_path",
          help="path to the functions.yaml file to use. Optional, but at least "
          "one of --functions-yaml-path and --custom-ops-yaml-path must be "
          "specified.",
      )
      parser.add_argument(
          "--custom-ops-yaml-path",
          "--custom_ops_yaml_path",
          help="path to the custom_ops.yaml file to use. Optional, but at least "
          "one of --functions-yaml-path and --custom-ops-yaml-path must be "
          "specified.",
      )
      parser.add_argument(
          "--aten-yaml-path",
          "--aten_yaml_path",
          help="path to native_functions.yaml file.",
      )
      # Note that make_file_manager() also looks at --install-dir.
      parser.add_argument(
          "-d",
          "--install-dir",
          "--install_dir",
          help="output directory",
          default="build/generated",
      )
      parser.add_argument(
          "-o",
          "--output-dependencies",
          help="output a list of dependencies into the given file and exit",
      )
      # Although we don't refer to --dry-run directly, make_file_manager() looks
      # for it.
      parser.add_argument(
          "--dry-run",
          action="store_true",
          help="run without writing any files (still updates outputs)",
      )
      parser.add_argument(
          "--static-dispatch-backend",
          "--static_dispatch_backend",
          nargs="*",
          help="generate static dispatch code for the specific backend (if set)",
      )
      parser.add_argument(
          "--op-registration-whitelist",
          "--op_registration_whitelist",
          nargs="*",
          help="filter op registrations by the whitelist (if set); "
          "each item is `namespace`::`operator name` without overload name; "
          "e.g.: aten::empty aten::conv2d ...",
      )
      parser.add_argument(
          "--op-selection-yaml-path",
          "--op_selection_yaml_path",
          help="Provide a path to the operator selection (for custom build) YAML "
          "that contains the information about the set of selected operators "
          "and their categories (training, ...). Each operator is either a "
          "full operator name with overload or just a bare operator name. "
          "The operator names also contain the namespace prefix (e.g. aten::)",
      )
      parser.add_argument(
          "--tags-path",
          help="Path to tags.yaml. Required by yaml parsing in codegen system.",
      )
      parser.add_argument(
          "--rocm",
          action="store_true",
          help="reinterpret CUDA as ROCm/HIP and adjust filepaths accordingly",
      )
      parser.add_argument(
          "--use-aten-lib",
          "--use_aten_lib",
          action="store_true",
          help="a boolean flag to indicate whether we use ATen kernels or not, in the future this flag will be per "
          "operator",
      )
      parser.add_argument(
          "--manual_registration",
          "--manual-registration",
          action="store_true",
          help="a boolean flag to indicate whether we want to manually call"
          "register_kernels() or rely on static init. ",
      )
      parser.add_argument(
          "--generate",
          type=str,
          nargs="*",
          choices=["headers", "sources"],
          default=["headers", "sources"],
          help="Generate only a subset of files",
      )
      options = parser.parse_args()
      assert (
          options.tags_path
      ), "tags.yaml is required by codegen yaml parsing."
  
      selector = get_custom_build_selector(
          options.op_registration_whitelist,
          options.op_selection_yaml_path,
      )
  
      parsed_yaml, custom_ops_parsed_yaml = parse_yaml_files(
          aten_yaml_path=options.aten_yaml_path,
          tags_yaml_path=options.tags_path,
          native_yaml_path=options.functions_yaml_path,
          custom_ops_yaml_path=options.custom_ops_yaml_path,
          selector=selector,
          use_aten_lib=options.use_aten_lib,
      )
      native_functions, kernel_index = (
          parsed_yaml.native_functions,
          parsed_yaml.kernel_index,
      )
      custom_ops_native_functions = (
          custom_ops_parsed_yaml.native_functions
          if custom_ops_parsed_yaml
          else []
      )
  
      cpu_fm = make_file_manager(options=options)
  
      if "headers" in options.generate:
          # generate CustomOpsNativeFunctions.h when custom_ops.yaml is present, to match the build system.
          gen_headers(
              native_functions=native_functions,
              gen_custom_ops_header=options.custom_ops_yaml_path,
              custom_ops_native_functions=custom_ops_native_functions,
              selector=selector,
              kernel_index=kernel_index,
              cpu_fm=cpu_fm,
              use_aten_lib=options.use_aten_lib,
          )
  
      if "sources" in options.generate:
          gen_unboxing(
              native_functions=native_functions,
              cpu_fm=cpu_fm,
              selector=selector,
              use_aten_lib=options.use_aten_lib,
              kernel_index=kernel_index,
              manual_registration=options.manual_registration,
          )
          if custom_ops_native_functions:
              gen_custom_ops(
                  native_functions=custom_ops_native_functions,
                  selector=selector,
                  kernel_index=kernel_index,
                  cpu_fm=cpu_fm,
                  rocm=options.rocm,
              )
  
      if options.output_dependencies:
          depfile_path = pathlib.Path(
              options.output_dependencies
          ).resolve()
          depfile_name = depfile_path.name
          depfile_stem = depfile_path.stem
  
          for fm, prefix in [
              (cpu_fm, ""),
          ]:
              varname = prefix + depfile_stem
              path = depfile_path.parent / (prefix + depfile_name)
              fm.write_outputs(varname, str(path))
  
imports: import argparse
  import os
  import pathlib
  from collections import defaultdict
  from dataclasses import dataclass
  from typing import Any, Callable, Dict, List, Optional, Sequence, TextIO, Tuple, Union
  import yaml
  from torchgen import dest
  from torchgen.api import cpp
  from torchgen.api.types import CppSignature, CppSignatureGroup, CType, NamedCType
  from torchgen.context import method_with_native_function, method_with_nested_native_function, with_native_function_and_index
  from torchgen.executorch.api import et_cpp
  from torchgen.executorch.api.custom_ops import ComputeNativeFunctionStub, gen_custom_ops_registration
  from torchgen.executorch.api.types import contextArg, ExecutorchCppSignature
  from torchgen.executorch.api.unboxing import Unboxing
  from torchgen.executorch.model import ETKernelIndex, ETKernelKey, ETParsedYaml
  from torchgen.executorch.parse import ET_FIELDS, parse_et_yaml, parse_et_yaml_struct
  from torchgen.gen import get_custom_build_selector, get_native_function_declarations, get_native_function_declarations_from_ns_grouped_kernels, get_native_function_schema_registrations, LineLoader, parse_native_yaml
  from torchgen.model import BackendIndex, BackendMetadata, DEFAULT_KERNEL_NAMESPACE, DispatchKey, FunctionSchema, Location, NativeFunction, NativeFunctionsGroup, OperatorName, Variant
  from torchgen.selective_build.selector import SelectiveBuilder
  from torchgen.utils import context, FileManager, make_file_manager, mapMaybe, NamespaceHelper
label_desc: Use image node_id 12 for calling a global function with example usage: main() without return types