compiler#
Kernel compilation helpers for building PyTorch extensions.
Selected through eval_config.kernel_compiler. Task authors normally do not use these
directly: see kernelfoundry.TestBase.compile_torch_extension() for the high-level
interface called from a task’s build method.
Functions
|
Compiles a GLSL compute shader to SPIR-V via glslangValidator. |
File extension for a loadable Python extension module ( |
|
|
Locate the extension module a compiler just produced in |
Classes
|
Abstract base class for kernel compilers. |
|
Compiler class for SYCL programs using the Intel icpx compiler. |
|
Compiler class using the torch cpp_extension compiler. |
- kernelfoundry.compiler.compile_glsl_to_spirv(src: str | Path, out: str | Path | None = None, glslang_validator: str = 'glslangValidator', extra_args: list[str] | None = None) Path[source]#
Compiles a GLSL compute shader to SPIR-V via glslangValidator.
Used from a Vulkan task’s
build()method; the resulting.spvpath is whatkernelfoundry.eval_pipeline.utils.vulkan_support.create_vulkan_compute_context()expects.- Parameters:
src – Path to the .comp GLSL source file.
out – Output .spv path; defaults to src with its suffix replaced by .spv.
glslang_validator – Name/path of the glslangValidator executable.
extra_args – Additional CLI args to pass through to glslangValidator.
- Returns:
The path to the compiled SPIR-V module.
- Raises:
subprocess.CalledProcessError – If compilation fails, with the compiler’s stdout/stderr attached to the exception.
- kernelfoundry.compiler.extension_suffix() str[source]#
File extension for a loadable Python extension module (
.soon Linux and macOS,.pydon Windows).
- kernelfoundry.compiler.find_built_extension(build_dir: str | PathLike, extension_name: str) Path[source]#
Locate the extension module a compiler just produced in
build_dir. Search by extension sincetorch.utils.cpp_extension.loadwrites<name>.soon Linux but<name>.pydon Windows.- Raises:
FileNotFoundError – If no extension module is present
- class kernelfoundry.compiler.BaseKernelCompiler(extension_name: str, src: str, build_dir: str, gpu_arch: str, timeout: int = 120, verbose: bool = False)[source]#
Abstract base class for kernel compilers.
- __init__(extension_name: str, src: str, build_dir: str, gpu_arch: str, timeout: int = 120, verbose: bool = False)[source]#
Initialize the Compiler.
- Parameters:
extension_name (str) – Name of the PyTorch extension to build.
src (str) – Path to the source file.
build_dir (str) – Directory to store the compiled outputs.
gpu_arch (str) – GPU architecture string.
timeout (int) – Timeout for each compilation step in seconds.
verbose (bool) – Whether to enable verbose output.
- class kernelfoundry.compiler.TorchCompiler(extension_name: str, src: str, build_dir: str, gpu_arch: str, timeout: int = 120, verbose: bool = False)[source]#
Compiler class using the torch cpp_extension compiler.
- LOAD_FAILED_RETURNCODE = 87#
Exit code the build subprocess uses when the sources compiled but the module would not import. Distinct from 1 so the caller can tell the two failures apart; see compile().
- class kernelfoundry.compiler.IcpxCompiler(*args, spirv_translator_options: str | None = None, backend_compile_options: str | None = None, **kwargs)[source]#
Compiler class for SYCL programs using the Intel icpx compiler.
- __init__(*args, spirv_translator_options: str | None = None, backend_compile_options: str | None = None, **kwargs)[source]#
Initialize the Compiler.
- Parameters:
extension_name (str) – Name of the PyTorch extension to build.
src (str) – Path to the source file.
build_dir (str) – Directory to store the compiled outputs.
gpu_arch (str) – GPU architecture string.
timeout (int) – Timeout for each compilation step in seconds.
verbose (bool) – Whether to enable verbose output.