GitHub - triton-lang/triton: Development repository for the Triton language and compiler (original) (raw)

Triton logo

Documentation Nightly Wheels
Documentation Wheels

Triton

This is the development repository of Triton, a language and compiler for writing highly efficient custom Deep-Learning primitives. The aim of Triton is to provide an open-source environment to write fast code at higher productivity than CUDA, but also with higher flexibility than other existing DSLs.

The foundations of this project are described in the following MAPL2019 publication: Triton: An Intermediate Language and Compiler for Tiled Neural Network Computations. Please consider citing this work if you use Triton!

The official documentation contains installation instructions and tutorials. See also these third-party Triton puzzles, which can all be run using the Triton interpreter -- no GPU required.

Quick Installation

You can install the latest stable release of Triton from pip:

Binary wheels are available for CPython 3.9-3.13.

Enabling Blackwell Support

The main branch now features support for NVIDIA Blackwell GPUs using 5th generation tensor cores. To enable this, you will need two additional steps:

  1. Build a pre-release PyTorch from source with CUDA 12.8
  2. Build triton from the latest source

First, to build pytorch you need to have CUDA 12.8 installed locally. If not, follow the instructions for your platform

Clone and checkout pytorch 2.6 release candidate

git clone https://github.com/pytorch/pytorch cd pytorch git checkout v2.6.0-rc9 git submodule sync git submodule update --init --recursive -j 8

Install build dependencies (assumes you already have a system compiler)

pip install -r requirements.txt pip install mkl-static mkl-include wheel

Build PyTorch (will take a long time)

export CUDA_HOME=/usr/local/cuda-12.8 export CUDA_PATH=$CUDA_HOME export TORCH_CUDA_ARCH_LIST=Blackwell python setup.py develop

Optional, package build into a wheel to install on other machines.

python setup.py bdist_wheel ls dist # Wheel should be output in this directory

Note that if you use the domain libraries (torchvision, torchtext,torchaudio, etc.) these will need to be built from source as well, otherwise their custom PyTorch extensions will not work.

Finally, follow the instructions below to install triton from source.

Install from source

git clone https://github.com/triton-lang/triton.git cd triton

pip install -r python/requirements.txt # build-time dependencies pip install -e .

Or with a virtualenv:

git clone https://github.com/triton-lang/triton.git cd triton

python -m venv .venv --prompt triton source .venv/bin/activate

pip install -r python/requirements.txt # build-time dependencies pip install -e .

Building with a custom LLVM

Triton uses LLVM to generate code for GPUs and CPUs. Normally, the Triton build downloads a prebuilt LLVM, but you can also build LLVM from source and use that.

LLVM does not have a stable API, so the Triton build will not work at an arbitrary LLVM version.

  1. Find the version of LLVM that Triton builds against. Checkcmake/llvm-hash.txt to see the current version. For example, if it says: 49af6502c6dcb4a7f7520178bd14df396f78240c
    This means that the version of Triton you have builds againstLLVM 49af6502.
  2. git checkout LLVM at this revision. Optionally, make additional modifications to LLVM.
  3. Build LLVM. For example, you might run
$ cd $HOME/llvm-project  # your clone of LLVM.  
$ mkdir build  
$ cd build  
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON ../llvm -DLLVM_ENABLE_PROJECTS="mlir;llvm;lld" -DLLVM_TARGETS_TO_BUILD="host;NVPTX;AMDGPU"  
$ ninja  
  1. Grab a snack, this will take a while.
  2. Build Triton as above, but set the following environment variables.
# Modify as appropriate to point to your LLVM build.  
$ export LLVM_BUILD_DIR=$HOME/llvm-project/build  
$ cd <triton install>  
$ LLVM_INCLUDE_DIRS=$LLVM_BUILD_DIR/include \  
  LLVM_LIBRARY_DIR=$LLVM_BUILD_DIR/lib \  
  LLVM_SYSPATH=$LLVM_BUILD_DIR \  
  pip install -e .  

Tips for building

Running tests

There currently isn't a turnkey way to run all the Triton tests, but you can follow the following recipe.

One-time setup. Note this will reinstall local Triton because torch

overwrites it with the public version.

$ make dev-install

To run all tests (requires a GPU)

$ make test

Or, to run tests without a gpu

$ make test-nogpu

Tips for hacking

For detailed instructions on how to debug Triton's frontend, please refer to this tutorial. The following includes additional tips for hacking on Triton's backend.

Configuration knobs

See python/triton/knobs.py for the full list of configuration knobs. You can set those knobs directly in python or use environment variables to control them. Below are some of the environment variables you can specify (see knobs.py for the full list):

N.B. Some of these environment variables don't have a knob in knobs.py-- those are only relevant to the C++ layer(s), hence they don't exist in the python layer.

Kernel Override Steps

export TRITON_ALWAYS_COMPILE=1 export TRITON_KERNEL_DUMP=1 export TRITON_DUMP_DIR= export TRITON_KERNEL_OVERRIDE=1 export TRITON_OVERRIDE_DIR=

Step 1: Run the kernel once to dump kernel's IRs and ptx/amdgcn in $TRITON_DUMP_DIR

Step 2: Copy TRITONDUMPDIR/<kernelhash>toTRITON_DUMP_DIR/<kernel_hash> to TRITONDUMPDIR/<kernelhash>toTRITON_OVERRIDE_DIR

Step 3: Delete the stages that you do not want to override and modify the stage you do want to override

Step 4: Run the kernel again to see the overridden result

Changelog

Version 2.0 is out! New features include:

Contributing

Community contributions are more than welcome, whether it be to fix bugs or to add new features at github. For more detailed instructions, please visit our contributor's guide.

Compatibility

Supported Platforms:

Supported Hardware:

Development Container (Dev Container)

Dev Containers for the Triton project are available from the triton-dev-containers repository

Key Benefits:

How to Use the Dev Container:

For detailed instructions on how to use the dev containers please see the dev container user guide