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.0.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.0.0-py3-none-any.whl (54.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tirx_kernels-0.0.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.0.0.tar.gz
Algorithm Hash digest
SHA256 0d2f73c390f755a1435f146a8b9190cbcc1959a3b00eb6ba563d04f94bf0a799
MD5 33fad984db61333dc764d811cb467fe7
BLAKE2b-256 e9d7e4de4cec6ffe76ff82bdb5d41dc6c48085a5c6089b5334aa7647004874a2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tirx_kernels-0.0.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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fba2251076dfe1a1f182de7513cb486247efb598d66c24d0ce4608c7c5ee0854
MD5 2cf16855f2a9d341df6e0e384805ad1b
BLAKE2b-256 1b702391633294a254119837721cdb93ce614156c9b11f76f36b5f79062f4695

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