Repository navigation
kernox 1.1.0
kernox now runs on CPUs: a native, multithreaded and vectorized cpu backend joins cuda, hip and sycl. A new compile option, flush_denormals, lets backends flush subnormal numbers to zero.
Added
- Native CPU backend
cpu(Linux x86-64,g++≥ 12 with OpenMP, a CPU build of PyTorch). Each reduction is generated as C++17, compiled withg++ -O3 -march=native -fopenmpand loaded throughctypes, without any dependency on the PyTorch C++ ABI.- Every core: rows are split across OpenMP threads, and the
jaxis too when there are few rows. A reduction usestorch.get_num_threads()threads from the OpenMP pool it shares with PyTorch, sotorch.set_num_threadsandOMP_NUM_THREADSapply to both; results are bitwise identical whatever the number of threads. - Every vector unit: the inner loop over
jis vectorized for the host by-march=native(AVX2, AVX-512, native AVX512-FP16 when present), andexp,log,sin,cos, … go through glibc's vector math library (libmvec). - Same rules as the GPU backends: IEEE arithmetic (never
-ffast-math), accumulators peracc_dtype, everysum_scheme, FP16 through_Float16, block-sparseranges, batch dimensions, gradients. The whole conformance suite passes. - Compiled modules are cached on disk (
$KERNOX_CACHE_DIR/cpu, default~/.cache/kernox/cpu). The key holds the source, the exact compiler version and the target CPU, so a cache shared over NFS between different machines never hands a binary to a CPU that cannot run it. Concurrent processes compile each kernel only once. - Speed, float32, M = N = 20,000, on 2 × AMD EPYC 9654 (192 threads), in billions of pairs per second against a blockwise PyTorch implementation: Gaussian kernel sum 187 vs 1.65 (× 113), log-sum-exp 233 vs 2.55 (× 91), 10 nearest neighbours 280 vs 3.55 (× 79).
KERNOX_CPU_CXXselects another compiler,KERNOX_CPU_LIBMVEC=0disables libmvec.kernox.diagnosticsreports the CPU, the compiler, the number of threads, the vector functions and FP16 support.- Documentation: CPU backend (design, vector math, threads, tuning, measured performance).
- Every core: rows are split across OpenMP threads, and the
flush_denormalscompile option (kp.compile(..., flush_denormals=True), defaultFalse). It allows the backend to flush subnormal numbers (below about 10⁻³⁸ in float32, 10⁻³⁰⁸ in float64) to zero, as PyKeOps'-use_fast_mathdoes. Operations that produce subnormal numbers are many times slower on CPUs, and narrow Gaussian kernels produce many: with the option, a Gaussian kernel sum with a small bandwidth runs 4.8 times faster on an Intel Xeon and 1.5 times faster on an AMD EPYC. Results only lose terms smaller than the smallest normal number.cpu: FTZ and DAZ set for the kernel's threads only, and restored afterwards: PyTorch, which shares the threads, still sees subnormal numbers.cuda: NVRTC--ftz=true(float32; float64 is unchanged).oracle: accepted, subnormal numbers kept.hip,sycl: refused withUnsupportedError.- Part of the compilation key only when enabled (existing caches stay valid); gradients inherit it. See Numerics.
Changed
backend="auto"on CPU tensors now selects thecpubackend, where kernox 1.0 raised an error asking forbackend="oracle". The oracle is still available explicitly.
Upgrading
Nothing to change in existing code. To run on the CPU, install a CPU build of PyTorch and g++ 12 or later, and pass CPU tensors.
Full changelog: v1.0.2...v1.1.0