xnn.common.cpu_kernels#
Triton kernels on the CPU.
launch() runs a @triton.jit kernel on CPU tensors as kernel[grid](*args, **meta) runs it on a GPU.
The kernel’s source is translated into C++ once per specialization (the constexpr values and the argument
dtypes, as Triton specializes), compiled with the system C++ compiler and cached on disk. Every lane of every
program becomes one iteration of a loop that OpenMP threads share; the helpers a kernel calls are inlined.
Lane semantics:
a masked load reads only where its mask holds;
an atomic add goes to a buffer of the calling thread and the buffers are summed into the tensor after all lanes ran (each thread sums a share of the touched blocks, so a run needs no atomics and its sums do not depend on the scheduling);
a block reduction
tl.sumis allowed only as the value of an atomic add, where each lane adds its own term;a value that is the same in every lane of a program (a program id, a scalar argument, a load at such an address) stays uniform, and an atomic add or a store of a uniform value at a uniform address runs once per program.
Literals follow Triton’s typing: a Python float with a float32 value is float32, with an integer value float32,
two literals stay a literal. A kernel outside these rules (another block reduction, a second grid axis) raises
Unsupported; its helpers can be given lane-wise twins with override().
Functions
Whether CPU kernels can be compiled here (Linux, a C++ compiler on the path, Triton importable); checked once per process (every launch asks). |
|
|
Run |
|
Translate the jit helper |
|
The launch |
|
The C++ source of a kernel for these arguments and constexpr values, and the names of its tensor arguments that receive atomic adds; |
Classes
|
Prepared launches whose atomic adds go to per-thread buffers shared by the launches with the same target tensor (float64), in one parallel region with no barrier between them; each target is summed once after them, then the |
|
A kernel launch with its arguments packed once: calling it runs the kernel on the tensors' current contents (they must stay allocated and in place). |
|
Prepared launches run in order in one parallel region: no thread start-up per kernel. |
|
A translated value: C++ code, a type (a scalar type or |
Exceptions
A construct the lane translation does not cover. |