一键导入
croq-dsl-triton
DSL-specific tuning contract for Triton kernels. Loaded by croq-tune when dsl=triton.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
DSL-specific tuning contract for Triton kernels. Loaded by croq-tune when dsl=triton.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
DSL-specific tuning contract for CuTe DSL (Python JIT) kernels. Loaded by croq-tune when dsl=cute-dsl.
DSL-specific tuning contract for CuTe/CUTLASS C++ template kernels. Loaded by croq-tune when dsl=cute-cpp.
Launch an infinite AI-driven kernel optimization loop for GPU kernels. Use when the user asks to "tune", "ai-tune", "optimize", "auto-tune", or "perf-tune" a kernel. Profiles with ncu, iterates optimizations indefinitely until interrupted.
Cursor-only kernel tuning entrypoint for GPU kernels. Use when the user asks to /croq-tune, continue tuning, resume tuning, ai-tune, auto-tune, optimize, or perf-tune a kernel in this repository. Profiles with ncu, iterates optimizations indefinitely until interrupted.
Reference collection of Choreo GPU kernel implementations. Use when studying kernel patterns, tiling strategies, warp specialization, TMA/DMA forms, or pipeline staging before editing .co files.
Launch an infinite AI-driven kernel optimization loop for GPU kernels. Use when the user asks to "tune", "ai-tune", "optimize", or "auto-tune" a kernel. Profiles with ncu, iterates optimizations indefinitely until interrupted.
| name | croq-dsl-triton |
| description | DSL-specific tuning contract for Triton kernels. Loaded by croq-tune when dsl=triton. |
Source extension: .py | Compiler: Triton JIT -> PTX via LLVM | Group: python-jit
python3 -c "import triton; print(triton.__version__)"
build_iter<NNN>.sh (syntax/import check):
#!/usr/bin/env bash
python3 -c "import ast; ast.parse(open('$SRC').read()); print('parse OK')"
python3 -c "
import importlib.util, sys
spec = importlib.util.spec_from_file_location('kernel', '$SRC')
mod = importlib.util.module_from_spec(spec); spec.loader.exec_module(mod)
print('import OK')
"
JIT compile errors surface at first run, not import. Treat first-run JIT failure
the same as a compile failure (bounded retry budget, then attempt<AAAA>).
run_iter<NNN>.sh:
#!/usr/bin/env bash
export PYTHONPATH="${PYTHONPATH}:$(pwd)"
python3 tuning/<gpu>/triton/srcs/<shape_key>/<model>/iter<NNN>_<tag>.py \
2>&1 | tee tuning/<gpu>/triton/perf/<shape_key>/<model>/timing_iter<NNN>.txt
Script must print: TFLOPS: <value> time_ms: <value>
ncu --target-processes all \
--set full \
--export tuning/<gpu>/triton/perf/<shape_key>/<model>/ncu_iter<NNN>.ncu-rep \
--force-overwrite \
python3 tuning/<gpu>/triton/srcs/<shape_key>/<model>/iter<NNN>_<tag>.py
ncu --import tuning/<gpu>/triton/perf/<shape_key>/<model>/ncu_iter<NNN>.ncu-rep \
--csv --page raw \
> tuning/<gpu>/triton/perf/<shape_key>/<model>/ncu_iter<NNN>.csv
Pre-profiling pin: Remove @triton.autotune decorator and use the best config's constants directly.
Allowed: @triton.jit kernels, tl.load/store/dot/atomic_*, warp-level
intrinsics, tl.inline_ptx_asm, fixed-config launchers (no @triton.autotune in iter001+).
Forbidden: torch.ops.* compute delegation, triton.ops.matmul, flash-attn
package calls. @triton.autotune is allowed only in iter000.
| Bottleneck | Ideas |
|---|---|
| Memory-bound | Increase BLOCK_M/N/K; add num_stages; eviction_policy="evict_last" |
| Compute-bound | Reduce register pressure; tune num_warps (4/8); tl.dot(allow_tf32=True) |
| Latency-bound | Increase num_stages; prefetch hints; warp specialization (warp_specialize=True) |
| Launch-bound | Persistent kernel: grid-stride loop; operator fusion |
| Swizzle / L2 | Program-ID swizzle: pid = (pid % GROUP_M) * (N // BLOCK_N) + pid // GROUP_M |
Key levers: BLOCK_M/N/K (32-256, powers of 2), num_warps (4/8/16),
num_stages (1-7), num_ctas (multi-CTA, Hopper), allow_tf32, swizzle, warp spec.
Kernel script must contain verify() and bench() functions:
verify(): compute with kernel + reference (torch.float32), assert max_abs_err < tol
(1e-2 for bf16, 1e-3 for f16), print VERIFY: PASS or VERIFY: FAIL max_abs_err=<v>.
bench(): CUDA event timing (never time.time()):
start = torch.cuda.Event(enable_timing=True)
end = torch.cuda.Event(enable_timing=True)
start.record()
for _ in range(iters): kernel_fn(...)
end.record()
torch.cuda.synchronize()
elapsed_ms = start.elapsed_time(end) / iters
tflops = 2 * M * N * K / elapsed_ms / 1e9
print(f"TFLOPS: {tflops:.2f} time_ms: {elapsed_ms:.3f}")
Default: 10 warmup + 50 timed iterations.
torch.matmul in Python script. Library calls allowed only in iter000.