MCPcopy Create free account
hub / github.com/RightNow-AI/autokernel / export_kernel

Function export_kernel

export_hf.py:674–799  ·  view source on GitHub ↗

Main export pipeline. Parameters ---------- kernel_path : str Path to the AutoKernel kernel file (kernel.py or similar). name : str Name for the exported kernel project (used in build.toml, module name). Must be a valid Python identifier. output_dir

(
    kernel_path: str,
    name: str,
    output_dir: str,
    repo_id: Optional[str] = None,
)

Source from the content-addressed store, hash-verified

672# ---------------------------------------------------------------------------
673
674def export_kernel(
675 kernel_path: str,
676 name: str,
677 output_dir: str,
678 repo_id: Optional[str] = None,
679) -> str:
680 """
681 Main export pipeline.
682
683 Parameters
684 ----------
685 kernel_path : str
686 Path to the AutoKernel kernel file (kernel.py or similar).
687 name : str
688 Name for the exported kernel project (used in build.toml, module name).
689 Must be a valid Python identifier.
690 output_dir : str
691 Directory where the HF Kernels project will be created.
692 repo_id : str, optional
693 HuggingFace repo ID (e.g., "rightnow-ai/matmul-kernel").
694 Used in documentation and __init__.py usage examples.
695
696 Returns
697 -------
698 str
699 Path to the exported project directory.
700 """
701 # Validate name is a valid Python identifier
702 if not name.isidentifier():
703 print(f"ERROR: '{name}' is not a valid Python identifier.")
704 print(" Use a name like 'my_matmul' or 'fused_attention'.")
705 sys.exit(1)
706
707 # Default repo_id
708 if repo_id is None:
709 repo_id = f"your-username/{name}"
710
711 # Read the kernel file
712 if not os.path.exists(kernel_path):
713 print(f"ERROR: Kernel file not found: {kernel_path}")
714 sys.exit(1)
715
716 with open(kernel_path, "r", encoding="utf-8") as f:
717 source = f.read()
718
719 if not source.strip():
720 print(f"ERROR: Kernel file is empty: {kernel_path}")
721 sys.exit(1)
722
723 # Detect backend
724 backend = detect_backend(source)
725 kernel_type = detect_kernel_type(source)
726
727 print(f"=== AutoKernel HuggingFace Kernels Export ===")
728 print()
729 print(f" Kernel file: {kernel_path}")
730 print(f" Backend: {backend}")
731 if kernel_type:

Callers 1

mainFunction · 0.85

Calls 6

detect_backendFunction · 0.85
detect_kernel_typeFunction · 0.85
_export_cuda_kernelFunction · 0.85
_export_triton_kernelFunction · 0.85
extract_cuda_sourceFunction · 0.85

Tested by

no test coverage detected