Skip to main content

High-performance GPU kernels (GEMM + FlashAttention4) written in TIRx

Project description

tirx-kernels

High-performance GPU kernels written in TIRx.

Official PyPI package: install only from tirx-kernels published by this repository (mlc-ai/tirx-kernels). Do not use similarly named packages from other publishers.

Kernels

Name dtype Arch
fp16_bf16_gemm fp16 / bf16 sm_100a
fp8_blockwise_gemm fp8 (blockwise) sm_100a
nvfp4_gemm nvfp4 sm_100a
flash_attention4 bf16 sm_100a

Installation

pip install tirx-kernels          # from a release
# or, from a checkout:
pip install -e .

External dependencies

These are not on PyPI and must be installed/available separately. They are imported lazily, so import tirx_kernels and kernel discovery work without them — they are only needed to actually compile/run a kernel:

Dependency Needed by Notes
tvm.tirx all kernels (compile + run) The TIRx compiler. Put it on PYTHONPATH, e.g. /path/to/tir/python.
torch all kernels CUDA build matching your GPU.
deep_gemm fp8_blockwise_gemm data/baseline Used for fp8 quantization helpers and the reference.
flashinfer nvfp4_gemm data/baseline Used for nvfp4 quantization and the baseline.

Usage

Command line

# List discovered kernels (with their config labels)
python -m tirx_kernels.registry --format json

# Run correctness tests (optionally filter by kernel / config label)
python -m tirx_kernels.test
python -m tirx_kernels.test --kernel fp16_bf16_gemm
python -m tirx_kernels.test --kernel fp16_bf16_gemm --config bf16_1024x1024x1024

# Benchmark
python -m tirx_kernels.bench --kernel nvfp4_gemm

Programmatic API

Every kernel module exposes a small, uniform interface (see tirx_kernels/_protocol.py):

from tirx_kernels.registry import discover_kernels

kernels = discover_kernels()          # {name: module}
mod = kernels["fp16_bf16_gemm"]

mod.run_test(M=1024, N=1024, K=1024)  # compile + run + correctness check
mod.run_bench(M=1024, N=1024, K=1024) # profile (needs a GPU)

func = mod.get_kernel(M=1024, N=1024, K=1024)  # the TIRx PrimFunc

Each module also provides KERNEL_META (name / category / compute_capability) and CONFIGS (the test/bench parameter sweeps) that the registry and CLI use.

License

Apache License 2.0. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tirx_kernels-0.1.0.tar.gz (50.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tirx_kernels-0.1.0-py3-none-any.whl (54.7 kB view details)

Uploaded Python 3

File details

Details for the file tirx_kernels-0.1.0.tar.gz.

File metadata

  • Download URL: tirx_kernels-0.1.0.tar.gz
  • Upload date:
  • Size: 50.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for tirx_kernels-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6517a250c32b93afec2f1a69a218d16e190c0aa39ec1abb5fd1f4f60e681317d
MD5 49bb98be53cea3dbda3c2a15db2316d3
BLAKE2b-256 ed3b3ec38856b76496c9350f38938be990cc447c4cc8138e381c19e46b6ec559

See more details on using hashes here.

File details

Details for the file tirx_kernels-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tirx_kernels-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 54.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for tirx_kernels-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a87e14a0c740fe7faa68f7b5d5195406325c6632bee874d5d2b4de0162243fb
MD5 96962f686423fe9518906e22e9dc0e7b
BLAKE2b-256 1e2dfe83485dfd5b6fb6f6ce7a053265db0298aa90903bab403408cec2ad9f71

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page