mixle.engines.build_kernels module

Optionally compile the FMA double-double kernels (mixle.engines._dd_kernels).

mixle imports and runs fine WITHOUT any compiled extension (mixle.engines.extended falls back to the pure-numpy double-double path). Calling compile_dd_kernels() builds the optional accelerator; afterwards dd_dot automatically uses it (~3x via hardware FMA). Requires Cython + a C compiler. Keeping the build on demand avoids making a C compiler a hard installation dependency.

Every compile_* builder here writes into an isolated, user-writable cache directory (_kernel_cache_dir()) rather than the installed mixle package – some installs (a wheel unpacked into a shared/system site-packages tree, various read-only-filesystem container deployments) cannot be written to at all, and a build that requires writing there fails outright even though the documented pure-Python fallback would have been perfectly usable instead. Each builder then best-effort copies its result next to the .pyx source too, so a normal writable install keeps finding it via a plain import mixle.engines._xxx exactly as before; the *_kernels_available functions fall back to the isolated cache (extending mixle.engines.__path__) when that copy could not be made. Set MIXLE_KERNEL_CACHE_DIR to override the cache location.

The cache directory is verified privately-owned (0700, no symlink, this user only) before anything is built into or imported from it – a compiled extension is native code with no sandboxing, so a predictably-named shared cache must not become a spot another user on the same machine could plant a malicious build into (see _private_cache_base_dir()).

compile_dd_kernels(force=False)[source]

Cythonize + compile _dd_kernels.pyx; returns the built extension’s exact path.

Builds into an isolated cache directory and best-effort copies the result next to its source (see the module docstring). Raises ImportError if Cython/numpy build tooling is missing, or a build error otherwise.

Parameters:

force (bool)

Return type:

str

dd_kernels_available()[source]

True if the compiled FMA double-double kernels are importable.

Return type:

bool

compile_bitpacked_kernels(force=False)[source]

Cythonize + compile _bitpacked.pyx (popcount binary/ternary GEMM) into the isolated kernel cache; returns its exact path. Uses a portable, per-architecture hardware-popcount flag (see _native_popcount_flags()) rather than -mcpu=native. See the module docstring for the read-only-package rationale.

Parameters:

force (bool)

Return type:

str

bitpacked_kernels_available()[source]

True if the compiled popcount binary/ternary kernels are importable.

Return type:

bool

compile_lns_kernel(force=False)[source]

Cythonize + compile _lns_kernel.pyx (the integer log-sum-exp tree fold) into the isolated kernel cache; returns its exact path. See the module docstring for the read-only-package rationale. No architecture-specific flag: the tree fold has no hardware-ISA dependency (unlike _bitpacked.pyx’s popcount), so -mcpu=native never served a purpose here beyond the same portability bug it has in compile_bitpacked_kernels().

Parameters:

force (bool)

Return type:

str

lns_kernel_available()[source]

True if the compiled integer log-sum-exp kernel is importable.

Return type:

bool