pystencils.jit.cpu.CpuJit

pystencils.jit.cpu.CpuJit#

class pystencils.jit.cpu.CpuJit(compiler_info=None, objcache=AUTO, *, module_builder=None, emit_warnings=False)#

Just-in-time compiler for CPU kernels.

The CpuJit turns pystencils Kernel objects into executable Python functions by wrapping them in a C++ extension module with glue code to the Python and NumPy API. That module is then compiled by a host compiler and dynamically loaded into the Python session.

Implementation Details

The CpuJit class acts as an orchestrator between two components:

  • The extension module builder produces the code of the dynamically built extension module that contains the kernel and its invocation wrappers;

  • The compiler info describes the host compiler used to compile and link that extension module.

Parameters:
  • compiler_info (Optional[CompilerInfo]) – Compiler info object defining capabilities and interface of the host compiler. If None, a default compiler configuration will be determined from the current OS and runtime environment.

  • objcache (str | Path | _AUTO_TYPE | None) – Directory used for caching compilation results. If set to AUTO, a persistent cache directory in the current user’s home will be used. If set to None, compilation results will not be cached–this may impact performance.

  • module_builder (Optional[ExtensionModuleBuilderBase]) – Optionally, an extension module builder to be used by the JIT compiler. When left at None, the default implementation will be used.

  • emit_warnings (bool)

compile(kernel)#

Compile the given kernel to an executable function.

Parameters:

kernel (Kernel) – The kernel object to be compiled.

Return type:

KernelWrapper

Returns:

Wrapper object around the compiled function