cuda
build_error
ai_generated
true
RuntimeError: Triton compilation failed: LLVM ERROR: out of memory when compiling kernel with large shared memory
ID: cuda/triton-compilation-llvm-crash
72%Fix Rate
83%Confidence
1Evidence
2025-05-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Triton 2.3.0 | active | — | — | — |
| CUDA 12.5 | active | — | — | — |
| LLVM 18.1.0 | active | — | — | — |
| PyTorch 2.5.0 | active | — | — | — |
Root Cause
Triton JIT compiler invokes LLVM to optimize kernel code, but the kernel uses excessive shared memory (>48KB per block on most GPUs), causing LLVM's memory allocation for register spilling or optimization to exceed available host memory.
generic中文
Triton JIT编译器调用LLVM优化内核代码,但内核使用了过多的共享内存(大多数GPU上超过48KB每块),导致LLVM为寄存器溢出或优化分配的内存超过可用主机内存。
Official Documentation
https://triton-lang.org/main/python-api/generated/triton.compiler.CompilationError.htmlWorkarounds
-
80% success Reduce shared memory usage in the Triton kernel: decrease block size or use fewer shared memory allocations. Example: change tl.constexpr BLOCK_SIZE from 128 to 64, and ensure shared memory is not allocated per-thread but per-block.
Reduce shared memory usage in the Triton kernel: decrease block size or use fewer shared memory allocations. Example: change tl.constexpr BLOCK_SIZE from 128 to 64, and ensure shared memory is not allocated per-thread but per-block.
-
75% success Set environment variable TRITON_MAX_SHARED_MEMORY to a lower value (e.g., 32768 bytes) to force Triton to generate kernels within limits. Command: export TRITON_MAX_SHARED_MEMORY=32768 before running the script.
Set environment variable TRITON_MAX_SHARED_MEMORY to a lower value (e.g., 32768 bytes) to force Triton to generate kernels within limits. Command: export TRITON_MAX_SHARED_MEMORY=32768 before running the script.
中文步骤
Reduce shared memory usage in the Triton kernel: decrease block size or use fewer shared memory allocations. Example: change tl.constexpr BLOCK_SIZE from 128 to 64, and ensure shared memory is not allocated per-thread but per-block.
Set environment variable TRITON_MAX_SHARED_MEMORY to a lower value (e.g., 32768 bytes) to force Triton to generate kernels within limits. Command: export TRITON_MAX_SHARED_MEMORY=32768 before running the script.
Dead Ends
Common approaches that don't work:
-
90% fail
The error is not about total system memory but about LLVM's internal allocation limits during compilation; more RAM does not help if the kernel design is flawed.
-
95% fail
Caching is unrelated to compilation memory; it only affects reuse of compiled kernels.