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

extension_suffix()

File extension for a loadable Python extension module (.so on Linux and macOS, .pyd on Windows).

find_built_extension(build_dir, extension_name)

Locate the extension module a compiler just produced in build_dir.

Classes

BaseKernelCompiler(extension_name, src, ...)

Abstract base class for kernel compilers.

IcpxCompiler(extension_name, src, build_dir, ...)

Compiler class for SYCL programs using the Intel icpx compiler.

TorchCompiler(extension_name, src, ...[, ...])

Compiler class using the torch cpp_extension compiler.

kernelfoundry.compiler.extension_suffix() → str[source]#

File extension for a loadable Python extension module (.so on Linux and macOS, .pyd on 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 since torch.utils.cpp_extension.load writes <name>.so on Linux but <name>.pyd on 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.

abstract compile()[source]#

Compile the source into a loadable PyTorch extension.

Returns:

Build artifacts and captured compiler output. The exact keys depend on the

concrete compiler; all include the collected stdout and stderr so build failures can be reported back to the caller.

Return type:

dict

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().

classmethod failed_phase(returncode: int) → str | None[source]#

Which phase failed: "compile", "load", or None when nothing did.

compile()[source]#

Compile the source via torch.utils.cpp_extension.

Returns:

Build artifacts and captured compiler output.

Return type:

dict

class kernelfoundry.compiler.IcpxCompiler(extension_name: str, src: str, build_dir: str, gpu_arch: str, timeout: int = 120, verbose: bool = False)[source]#

Compiler class for SYCL programs using the Intel icpx compiler.

compile()[source]#

Compile the SYCL program into a PyTorch extension.