kernel-tileir-optimization

작성자: nvidia

기존 Triton 커널을 Blackwell GPU(sm_100+)의 NVIDIA TileIR 백엔드용으로 최적화합니다. TileIR 특화 자동 튜닝 구성을 추가합니다: occupancy, num_ctas, TMA…

npx skills add https://github.com/nvidia/tensorrt-llm --skill kernel-tileir-optimization

Triton TileIR Optimization

Optimize EXISTING Triton kernels for NVIDIA's TileIR backend on Blackwell GPUs. This skill does NOT write kernels from scratch -- that is the Triton Specialist's job.

Principles

TileIR vs PTX Backend

TileIR is NVIDIA's compiler backend for Triton that generates optimized CUDA code using CGA-level (Cooperative Grid Array) tile representations. Critical differences:

ParameterPTX BackendTileIR Backend
num_warpsStrict directiveIgnored (compiler decides)
num_stagesStrict directiveCost hint (compiler optimizes)
occupancyNot availableCritical tuning param (1-32)
num_ctasLimited2CTA mode for Blackwell
Block sizesSmaller often betterLarger often better
TMANot availableRequired for dot kernels

Key implication: Do not tune num_warps for TileIR -- focus on occupancy instead.

Triton Package Landscape

Three packages share import triton:

PackageSourceUse Case
pytorch-tritonPyTorch wheeltorch.compile, standard kernels
tritonOpenAI PyPIOfficial Triton from triton-lang.org
nvtritonTriton-to-tile-IRTileIR backend for Blackwell

Only one triton package should be installed at a time. "Converting to TileIR" means adding TileIR-specific configs, NOT changing imports. TileIR activates via ENABLE_TILE=1.

When TileIR Applies

TileIR targets Blackwell (sm_100+). Without nvtriton or Blackwell hardware, the specialist still adds TileIR-optimized configs that standard triton safely ignores, enabling future deployment.

Expected speedups (with nvtriton on Blackwell):

Kernel TypeSpeedupKey Lever
Dot-Related (GEMM, Attention)1.2-2.0xTMA + 2CTA
Norm-Like (LayerNorm, Softmax)2.0-5.0xHigh occupancy
Element-Wise (ReLU, Add, Exp)1.5-3.0xOccupancy + num_stages
Reduction (Sum, Mean, Max)1.8-4.0xHigh occupancy

Workflow

Five-phase workflow: compatibility, classify, transform, validate, benchmark.

Phase 1: Compatibility Test (ENABLE_TILE=0)

Verify the kernel works in PTX mode before applying TileIR optimizations.

python scripts/tileir_check.py

Then use the kernel-triton-writing skill's verify_kernel.py to verify with ENABLE_TILE=0:

python scripts/verify_kernel.py --kernel path/to/kernel.py --reference 'torch reference' --shapes '{"x": [32, 512, 4096]}' --dtypes '{"x": "bfloat16"}'

Phase 2: Classify Kernel

Determine kernel type to select the optimization strategy.

python scripts/classify_kernel.py --file kernel.py

Classification decision tree:

Contains tl.dot()?
  YES --> dot-related: TMA + 2CTA + occupancy + larger blocks
  NO  --> Has reduction + normalization?
            YES --> norm-like: high occupancy (2, 4) + num_warps (4, 8)
            NO  --> Point-wise only?
                      YES --> element-wise: occupancy (1-16) + num_stages (2-4)
                      NO  --> reduction: high occupancy + num_warps

Phase 3: Apply Transformations

Classify and apply optimizations in one step:

python scripts/classify_kernel.py --file kernel.py --apply-optimizations

Output JSON includes optimized_code and changes_applied fields.

Type-specific transformations:

Dot-related (highest priority):

  1. Convert tl.load/tl.store to TMA descriptors (MANDATORY). See references/tma-conversion.md.
  2. Add 2CTA configs (num_ctas=2) with SM oversubscription guard in pre-hook.
  3. Add occupancy (1, 2, 4) and extended num_stages (4, 6).
  4. Use larger block sizes (256x256, 256x128).

Norm-like (LayerNorm, Softmax, RMSNorm):

  • Add occupancy (2, 4), num_warps (4, 8). No TMA needed.

Element-wise (ReLU, GELU, Add, Mul, Exp):

  • Add occupancy (1, 2, 4, 16), num_stages (2, 3, 4). Include extreme configs for small inputs.

Reduction (Sum, Mean, Max):

  • Same strategy as norm-like: high occupancy (2, 4), num_warps (4, 8).

Gate TileIR-specific configs for sm_100+:

import torch

def get_configs_with_gating(pre_hook=None):
    configs = get_baseline_configs()
    if torch.cuda.is_available() and torch.cuda.get_device_capability()[0] >= 10:
        configs.extend(get_tileir_specific_configs(pre_hook))
    return configs

See references/config-templates.md for complete config templates per kernel type.

Phase 4: TileIR Validation (ENABLE_TILE=1)

Use the kernel-triton-writing skill's verify_kernel.py to verify the optimized kernel with TileIR backend:

python scripts/verify_kernel.py --kernel path/to/optimized_kernel.py --reference 'torch reference' --shapes '{"x": [32, 512, 4096]}' --dtypes '{"x": "bfloat16"}'

Set ENABLE_TILE=1 before running. Check: numerical correctness, no compilation errors, TMA/2CTA patterns compile successfully.

Phase 5: Benchmark

Use triton.testing.do_bench() (as documented in the perf-workload-profiling skill) to compare PTX (ENABLE_TILE=0) vs TileIR (ENABLE_TILE=1).

Benchmark across multiple input sizes (128, 1024, 8192) -- performance varies by size.

Scripts

tileir_check.py

Check TileIR availability (nvtriton, ENABLE_TILE, Blackwell GPU):

python scripts/tileir_check.py

Returns JSON: nvtriton_installed, tileir_active, blackwell_gpu, gpu_capability, recommendation.

classify_kernel.py

Classify kernel type and optionally apply TileIR optimizations:

# Classify only
python scripts/classify_kernel.py --file kernel.py

# Classify + apply optimizations
python scripts/classify_kernel.py --file kernel.py --apply-optimizations

# From inline code
python scripts/classify_kernel.py --code '<kernel_code>'

Returns JSON: classification, confidence, indicators, recommendations. With --apply-optimizations: adds optimized_code and changes_applied.

Error Handling

Common Pitfalls

TMA descriptor errors (dot-related kernels):

  • Always pass pre_hook=tma_set_block_size_hook to config generation -- without it, TMA descriptors keep dummy block sizes, causing runtime errors or wrong results.
  • For GEMM: pass b.T.contiguous() in wrapper and use tl.dot(a, b.T, accumulator) in kernel. Transposition mismatch produces incorrect results silently.

2CTA oversubscription:

  • Adjust SM count in pre-hook when using num_ctas=2:
    if "NUM_SMS" in nargs and "NUM_CTAS" in nargs:
        nargs["NUM_SMS"] = nargs["NUM_SMS"] // nargs["NUM_CTAS"]
    

Config function signatures:

  • ALL config helper functions MUST accept pre_hook=None, even if unused. Without it: TypeError: get_autotune_configs() takes 0 positional arguments.

Hardware gating:

  • Gate TileIR configs with torch.cuda.get_device_capability()[0] >= 10. TMA/2CTA on pre-Blackwell GPUs causes runtime crashes.

API availability:

  • Use 1.0 / (1.0 + tl.exp(-x)) instead of tl.sigmoid(x) -- not available in all Triton versions including some nvtriton builds.

Performance tuning:

  • Do not over-tune num_warps -- TileIR ignores it. Focus on occupancy.
  • Use larger block sizes (256x256, 256x128) for TileIR, not PTX-tuned small blocks.
  • Benchmark across small/medium/large inputs; one-size configs underperform.
  • For exp/log heavy kernels, enable approximate math:
    export TILEIR_ENABLE_APPROX=1
    export TILEIR_ENABLE_FTZ=1
    

When to Abort

Stop and report if:

  1. No triton installed -- cannot proceed.
  2. Compatibility test fails -- kernel has syntax/runtime errors before optimization.
  3. TileIR validation fails -- optimized kernel produces wrong results.
  4. No speedup -- TileIR version is slower than PTX baseline (with nvtriton).
  5. Not Blackwell GPU -- still add configs for future deployment, but skip ENABLE_TILE testing and benchmarking.

Output Format

After optimization, return:

## TileIR Optimization: kernel_name

### Classification
- Kernel type: [dot-related | norm-like | element-wise | reduction]
- Strategy: [TMA + 2CTA | High occupancy | Occupancy + num_stages]

### Compatibility Check (ENABLE_TILE=0)
[PASSED | FAILED] — Max difference: X.Xe-Y

### Transformations Applied
- [List of transformations]

### TileIR Validation (ENABLE_TILE=1)
[PASSED | FAILED] — Max difference: X.Xe-Y

### Benchmark Comparison
| Backend | Time (ms) | Speedup |
|---------|-----------|---------|
| PTX (ENABLE_TILE=0) | X.XXX | 1.0x |
| TileIR (ENABLE_TILE=1) | X.XXX | Y.Yx |

### Output
File: kernel_name_tileir.py

nvidia의 다른 스킬

compileiq-debug
nvidia
무언가 잘못되었을 때 사용: Search()가 멈추거나, 모든 평가가 INVALID_SCORE를 반환하거나, 점수가 개선되지 않거나, 모든 설정이 동일한 숫자를 반환하거나, ptxas 오류 등이 발생할 때
create-github-pr
nvidia
gh CLI를 사용하여 GitHub 풀 리퀘스트를 생성합니다. 사용자가 새 PR을 만들거나, 코드 리뷰를 제출하거나, 풀 리퀘스트를 열고자 할 때 사용합니다. 트리거 키워드 -…
nemoclaw-maintainer-cross-issue-sweep
nvidia
다른 열린 이슈들을 스캔하여 주어진 PR이 함께 수정하거나 실수로 망가뜨릴 수 있는 이슈를 찾습니다. 인접 수정 기회와 모순 위험을 file:line…과 함께 출력합니다.
fhir-basics
nvidia
에이전트에게 FHIR R4 API의 작동 방식, 사용 가능한 리소스, 검색 매개변수를 사용한 쿼리 방법, 모든 응답 형식을 올바르게 파싱하는 방법을 가르칩니다…
compileiq-validate-result
nvidia
검색이 완료된 후, 속도 향상을 청구하거나 ACF를 발송하기 전에 사용합니다. dump_results CSV를 로드하고, 상위 K개 후보(단일 목표)를 추출합니다…
changelog-audit
nvidia
릴리스 전에 Warp CHANGELOG.md를 감사합니다: 누락된 항목 복구, 사용자 영향별 정렬, 항목 언어 다듬기, 줄 바꿈, (릴리스 브랜치 모드) 비교 업데이트…
maintain-dynamic-plugins
nvidia
NeMo Relay 동적 플러그인 로더, 매니페스트, Rust 네이티브 SDK, gRPC 워커 프로토콜, Python 워커 SDK, 문서, 테스트 및 릴리스 워크플로 커버리지를 유지 관리합니다.
dgx-diagnose
nvidia
일반적인 DGX Station GB300 문제 진단 — CUDA 충돌, 잘못된 GPU 타겟팅, vLLM/SGLang 컨테이너 버그, MIG 상태 문제, NVLink/Fabric Manager 오류,…