Skip to content

Commit 53bf6b7

Browse files
fuyou4546voltjia
andauthored
feat(triton): add JIT backend with add operator (#800)
* feat(triton): add JIT backend * refactor(triton): modify naming and move JIT to slot 10 * refactor(triton): replace `CUDA` calls with `InfiniRT` Runtime and Driver APIs * refactor(triton): simplify JIT backend architecture (#925) * refactor(triton): simplify JIT backend architecture * refactor: simplify Triton auto-tuning config * refactor: minimize Triton JIT operator API * docs: remove Triton version constraint * refactor: simplify Triton scalar validation * refactor: separate Triton platform registration * refactor: combine Triton Add registration * style: format Triton JIT headers --------- Co-authored-by: Jiacheng Huang <45955067+voltjia@users.noreply.github.com>
1 parent 7f4201e commit 53bf6b7

18 files changed

Lines changed: 3019 additions & 50 deletions

CMakeLists.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ option(WITH_LINKED "Enable linked third-party operator backends" OFF)
2626

2727
option(WITH_NINETOOTHED "Enable NineToothed-generated kernels" OFF)
2828

29+
option(WITH_TRITON "Enable the Triton JIT backend" OFF)
30+
2931
# Custom `AscendC` kernels under `src/native/ascend/custom/`. `ON` by default
3032
# so CI and routine dev builds always exercise `implementation_index=1/2`
3133
# for `RmsNorm` / `AddRmsNorm`. Gated by `WITH_ASCEND` in
@@ -344,10 +346,29 @@ if(WITH_NINETOOTHED)
344346
set(NINETOOTHED_PYTHON_EXECUTABLE "" CACHE FILEPATH "Python executable used to run NineToothed code generation")
345347
endif()
346348

349+
if(WITH_TRITON)
350+
if(NOT WITH_NVIDIA)
351+
message(
352+
FATAL_ERROR
353+
"`WITH_TRITON` requires `WITH_NVIDIA=ON` because NVIDIA is the only implemented Triton JIT backend."
354+
)
355+
endif()
356+
if(NOT GENERATE_PYTHON_BINDINGS)
357+
message(
358+
FATAL_ERROR
359+
"`WITH_TRITON` requires `GENERATE_PYTHON_BINDINGS=ON` because the runtime compiler is shipped in the Python package."
360+
)
361+
endif()
362+
endif()
363+
347364
if(WITH_NVIDIA)
348365
add_compile_definitions(WITH_NVIDIA=1)
349366
enable_language(CUDA)
350-
find_package(CUDAToolkit REQUIRED)
367+
if(WITH_TRITON)
368+
find_package(CUDAToolkit 12.0 REQUIRED)
369+
else()
370+
find_package(CUDAToolkit REQUIRED)
371+
endif()
351372
endif()
352373

353374
# Iluvatar: CUDA-compatible device. CoreX clang++ works for `-x ivcore`

docs/build.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ entry is `python -m pip install` with CMake options passed through
1919
| `WITH_TORCH` | Enable PyTorch C++ ATen-backed operators. | `OFF` |
2020
| `WITH_LINKED` | Enable operators linked from installed third-party libraries. | `OFF` |
2121
| `WITH_NINETOOTHED` | Enable NineToothed-generated kernels. | `OFF` |
22+
| `WITH_TRITON` | Enable the NVIDIA Triton JIT backend. Requires Python bindings and CUDA Toolkit 12.0 or newer. | `OFF` |
2223
| `AUTO_DETECT_DEVICES` | Auto-detect available device files. | `OFF` |
2324
| `AUTO_DETECT_BACKENDS` | Auto-detect available backend packages. | `OFF` |
2425
| `GENERATE_OPERATOR_CALL_INSTANTIATIONS` | Generate explicit C++ operator call instantiations. | `ON` |
@@ -51,6 +52,28 @@ python -m pip install .[dev] \
5152
--config-settings=cmake.define.WITH_NVIDIA=ON
5253
```
5354

55+
Install the Triton JIT runtime dependencies, then enable the implementation:
56+
57+
```bash
58+
python -m pip install torch triton
59+
python -m pip install . \
60+
--config-settings=cmake.define.INFINI_RT_ROOT=/path/to/infini-rt-prefix \
61+
--config-settings=cmake.define.WITH_NVIDIA=ON \
62+
--config-settings=cmake.define.WITH_TRITON=ON
63+
```
64+
65+
The InfiniOps JIT bridge and kernel sources are packaged only with the Python
66+
wheel. It requires CUDA Toolkit 12.0 or newer. Standalone C++ installations do
67+
not provide this runtime.
68+
69+
Compiled kernels are cached in the platform cache directory. Set
70+
`INFINI_OPS_TRITON_CACHE_DIR` to override that location.
71+
72+
Python calls with an explicit Triton config construct an operator for that
73+
call instead of entering the generic operator cache. The compiled kernel and
74+
auto-tuning result are still cached using the complete Triton config
75+
identity.
76+
5477
Full builds with both `WITH_NVIDIA=ON` and `WITH_LINKED=ON` include
5578
`flash_attn_with_kvcache` and require a compatible FlashAttention Python
5679
distribution in the build environment. The distribution must provide a

0 commit comments

Comments
 (0)