All examplesExamples pages
Examples
Examples
Ten complete kernels from the repository's examples/ directory, from a vector add to flash attention. Each one checks its result against a NumPy reference and prints the error.
Run an example
Each example is a standalone Python file with a kernel, a host wrapper, a NumPy reference, and a short demo. To run one, follow these steps:
- Clone the repository and change to its directory:
git clone https://github.com/kashifulhaque/enceladus cd enceladus - Install the dependencies:
uv sync - Run an example:
uv run python examples/01_vector_add.py
To run an example on the CPU instead of the GPU, set ENCELADUS_INTERPRET=1, for example ENCELADUS_INTERPRET=1 uv run python examples/03_layernorm.py. For more information about the interpreter, see Debugging.
All examples
ElementwiseVector addAdd two arrays elementwise with a 1D grid, block offsets, and a mask.
Reductions and normalizationRow softmaxCompute a softmax over each row, with one program per row and the whole row in one tile.
Reductions and normalizationLayerNormNormalize each row with a learned scale and shift, looping over the row in blocks.
Matrix multiplicationMatrix multiplicationMultiply matrices with pointer tiles or tensor descriptors, and autotune the block sizes.
ElementwiseFused GELUFuse a scale, a per-column bias add, and a GELU into one elementwise kernel.
Reductions and normalizationRMSNormDivide each row by its root mean square and scale it, with tl.rsqrt.
Matrix multiplicationMatmul with bias and GELUFuse a bias add and a GELU into a descriptor matmul's epilogue, on the accumulator registers.
AttentionFlash attentionCompute attention with an online softmax and an optional causal mask, and autotune it.
Atomics and scansHistogramCount float values into equal bins with tl.atomic_add on a shared histogram.
Atomics and scansCumulative sumCompute prefix or suffix sums along each row with tl.cumsum.