A Python package for kernel testing
Project description
KernelFoundry
KernelFoundry is an evolutionary framework for hardware-aware GPU kernel optimization. It combines an automated kernel generation algorithm with a comprehensive test harness and evaluation pipeline, enabling rapid exploration of the GPU kernel design space.
The package provides:
- Kernel generation algorithm: An evolutionary approach using MAP-Elites quality-diversity search, meta-prompt evolution, and template-based parameter optimization to efficiently generate optimized GPU kernels.
- Evaluation pipeline: A distributed framework for benchmarking kernels, collecting profiler feedback, and storing results in a database.
- Web UI: Interactive visualization of generated kernels, performance metrics, and optimization progress.
- Task-side test harness: Base interfaces and utilities for implementing custom tasks and evaluating kernels locally.
Installation
Prerequesites:
- The package requires Python 3.10+ (we commonly use Python 3.12). Install into a virtual environment if desired.
- oneAPI: For compiling kernels on Intel GPUs, you need Intel OneAPI. See section below for installation instructions.
Install KernelFoundry Python package
A) For test harness only (evaluating existing kernels):
pip install kernelfoundry
# If tasks are based on pytorch, install torch for your hardware:
# - Intel: pip install torch==2.9.0 --index-url https://download.pytorch.org/whl/xpu
B) For kernel generation algorithm, UI, and full pipeline:
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
# Create and activate virtual environment with Python 3.12
uv venv --python 3.12
source .venv/bin/activate
# Install pip
uv pip install pip
# Install torch (Intel XPU wheels)
python -m pip install torch==2.9 torchvision==0.24 torchaudio==2.9.0 --index-url https://download.pytorch.org/whl/xpu
# - NVIDIA: pip install torch==2.9.0 --index-url https://download.pytorch.org/whl/cu129
# Install all dependencies
uv pip install -e .[all]
Install Intel oneAPI toolkit
For running kernel generation on Intel GPUs, you need OneAPI. Installation on Linux:
# Download and add Intel GPG key
wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB | \
gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null
# Add Intel OneAPI repository
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | \
sudo tee /etc/apt/sources.list.d/oneAPI.list
# Update and install Intel OneAPI toolkit and VTune
sudo apt update && sudo apt install -y \
intel-oneapi-base-toolkit-2025.2 \
intel-oneapi-vtune=2026.1.0-13
# Source Intel environment
source /opt/intel/oneapi/setvars.sh
Install profiler
For profiling SYCL kernels on Intel GPUs, we use unitrace. Install with:
git clone https://github.com/intel/pti-gpu.git
pushd pti-gpu/tools/unitrace
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_WITH_MPI=OFF ..
make
popd
# allow non root profiling
if [ -f /proc/sys/dev/i915/perf_stream_paranoid ]; then
sudo sh -c 'echo 0 > /proc/sys/dev/i915/perf_stream_paranoid'
fi
if [ -f /proc/sys/dev/xe/observation_paranoid ]; then
sudo sh -c 'echo 0 > /proc/sys/dev/xe/observation_paranoid'
fi
Alternatively, VTune is also supported as a profiler, which already comes with oneAPI. Make sure to enable non-root proofiling with:
if [ -f /proc/sys/kernel/kptr_restrict ]; then
sudo sh -c 'echo 0 > /proc/sys/kernel/kptr_restrict'
fi
For OpenCL kernel optimization, VTune is the default profiler. For SYCL, set profiler_kernel: vtune and profiler_reference: vtune.
Running KernelFoundry
1. Running the kernel generation algorithm
Generate optimized kernels by running the evolutionary algorithm on a task. The algorithm supports KernelBench tasks, robust_kbench, and custom tasks.
Optimize KernelBench task:
python -m kernelfoundry.algorithm run task=19_ReLU task_origin=KernelBench job_name=my_experiment gpu_arch=lnl language=SYCL
Optimize custom task (task=path/to/task/folder):
python -m kernelfoundry.algorithm run task=tasks/example_custom task_origin=custom job_name=my_custom_experiment gpu_arch=lnl language=SYCL
Common parameters:
task: Path to task folder or KernelBench task ID (e.g.,19_ReLUfor KernelBench task 19)task_origin: EitherKernelBench,robust_kbench, orcustomgpu_arch: GPU architecture (e.g.,lnlfor Intel Arc,Amperefor NVIDIA)language: Kernel language (SYCLorCUDA; defaults based on GPU type)job_name: your name for the optimization job (for tracking results; will appear in UI)
See main config for all available parameters.
Generated kernels are stored in a SQLite database (configurable via paths.kernels_db_path in the config).
2. Using the KernelFoundry test harness
Implement and evaluate your own kernel optimization tasks using the test harness:
- Create a task test class by deriving from
TestBase(from kernelfoundry import TestBase). - Implement build logic (optional) and correctness/performance tests (see task format).
- Compile candidate kernel code with
compile_torch_extension(...). - Run pytest to validate correctness and collect benchmark timings.
The test harness provides:
- A base task interface (
from kernelfoundry import TestBase) for implementing task-specific build and pytest test logic. - Build helpers for compiling candidate kernels into PyTorch extensions (via Torch or
icpx). - Pytest fixtures for correctness/performance runs and collecting runtime data.
- Validation helpers (
assert_allclose, cosine similarity, and related utilities). - Runtime and machine-info helpers for benchmarking and metadata capture.
- Support for SYCL, OpenCL, and CUDA kernels.
You can run the KernelFoundry algorithm with option validate to test a kernel without generating a new kernel. First, create a task and place your kernel in the EVOLVE-block (see example). Then run:
python -m kernelfoundry.algorithm run task=tasks/example_custom task_origin=custom job_name=my_custom_experiment gpu_arch=lnl language=SYCL validate=true max_iters=0
Visualization and monitoring
Monitor kernel generation progress and view results through the web-based UI:
python start_gui.py
The UI will be available at http://localhost:8885 and provides:
- Job logs and execution monitoring
- Kernel performance metrics and comparisons
- Optimization progress visualization
- Roofline analysis and performance profiling
- Detailed kernel implementations and metadata
MCP server
The KernelFoundry test harness can also be used as a tool by by installing the KF MCP server. See here for installation instructions and details.
Documentation
API documentation is available and can be built using Sphinx. To build the documentation:
pip install .[docs]
cd docs
make html
The generated documentation will be in docs/_build/html/. See the docs/README.md for more information.
References
If you use KernelFoundry in your research, please cite:
@inproceedings{wiedemann2026kernelfoundry,
title={KernelFoundry: Hardware-aware evolutionary GPU kernel optimization},
author={Wiedemann, Nina and Leboutet, Quentin and Paulitsch, Michael and Wofk, Diana and Ummenhofer, Benjamin},
booktitle={Proceedings of the 41st International Conference on Machine Learning (ICML 2026)},
year={2026}
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kernelfoundry-0.3.0-py3-none-any.whl.
File metadata
- Download URL: kernelfoundry-0.3.0-py3-none-any.whl
- Upload date:
- Size: 305.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ba39d26d16e2effa651f9a850d32f8c0e13d8d6c2124517f71c427c84bbe5c6
|
|
| MD5 |
f5a9da24e6bb1d9cc2b491d16f7f0019
|
|
| BLAKE2b-256 |
d9fbcc6174d47e700c721011a0d39ef3d847b74488d1c6dd1df2c78d6cd684c6
|
Provenance
The following attestation bundles were made for kernelfoundry-0.3.0-py3-none-any.whl:
Publisher:
release.yml on isl-org/kernelfoundry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kernelfoundry-0.3.0-py3-none-any.whl -
Subject digest:
9ba39d26d16e2effa651f9a850d32f8c0e13d8d6c2124517f71c427c84bbe5c6 - Sigstore transparency entry: 2046086811
- Sigstore integration time:
-
Permalink:
isl-org/kernelfoundry@dadd066e1613d9b9fafea09bca7bd015c4951dd1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/isl-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@dadd066e1613d9b9fafea09bca7bd015c4951dd1 -
Trigger Event:
push
-
Statement type: