On this page
Your vector-add kernel passed every test yesterday, yet today its first call stalls for 300 ms or crashes on a newer GPU with "no kernel image is available". Reading the source again won't explain either failure. A GPU never executes CUDA C++ or Python directly; both symptoms live in the compiler artifacts between source and silicon.
One addition, several representations
To compute out[i] = x[i] + y[i] for floats with 256 threads per block, CUDA launches four blocks (1,024 threads) and guards the 24 tail threads. Notice the size_t index widening and overflow-safe block calculation (n / threads + (n % threads != 0) instead of (n + threads - 1) / threads, which overflows signed int near INT_MAX):
__global__ void add_kernel(const float* x, const float* y, float* out, int n) {
std::size_t i = static_cast<std::size_t>(blockIdx.x) * blockDim.x + threadIdx.x;
if (i < static_cast<std::size_t>(n)) out[i] = x[i] + y[i];
}
void launch_add(const float* x, const float* y, float* out, int n) {
if (n <= 0) return; // Zero-block launches are invalid.
constexpr int threads = 256;
int blocks = n / threads + (n % threads != 0);
add_kernel<<<blocks, threads>>>(x, y, out, n);
}At source level you see the bounds check, not the emitted instructions or physical registers. For SIMT kernels, nvcc lowers device code through four distinct artifacts:[1][2][3][4][5]
- PTX (Parallel Thread Execution): Versioned virtual ISA using virtual registers (
%f1,%f2,%rd3). Portable forward to compatible newer GPUs only when the driver supports that PTX ISA version. ptxas-> cubin: Optimizing assembler allocates physical registers, schedules instructions, inserts spills if needed, and writes target-specific machine code into an ELF cubin (e.g.sm_90).- SASS: Human-readable disassembly of native machine code inside a cubin (
nvdisasm), not an executable source format.
![CUDA block 0 thread 1 lowers through NVVM IR and LLVM IR while Triton pid 0 offset 1 mask 1 lowers through TTIR, TTGIR, and LLVM IR into PTX. PTX loads x[1]=0.25 into %f1 and y[1]=-2 into %f2, adds to %f3=-1.75, and stores out[1]=-1.75. Toolkit ptxas allocates physical registers to build a target ELF cubin for GPU driver execution or nvdisasm SASS disassembly.](https://assets.leetllm.com/v1/a41c47e614b6/fundamentals/gpu-compilers-kernel-languages/illustrations/_generated/compiler_artifact_path_dark.png)
nvcc packages host code with architecture-specific device images
nvcc separates host C++ from device code and embeds one or more device images inside a fatbinary (fatbin).[1] The flags distinguish virtual vs. native intent:
| Target spelling | Artifact embedded | Runtime effect |
|---|---|---|
compute_90 | PTX for virtual compute capability 9.0 | Driver can JIT-compile forward for compatible newer GPUs |
sm_90 | Native cubin for 9.0 silicon | Loads natively without PTX JIT |
Suffixes (compute_90a, compute_100f) | Architecture- or family-restricted PTX | Disables general forward compatibility across major architectures |
At load time, the CUDA driver prefers a compatible native cubin; only a cubin miss triggers PTX driver JIT (which still requires a driver supporting the emitted PTX ISA version).

Produce artifacts you can inspect
Compile both a native cubin and forward-compatible PTX, then inspect the fatbin with cuobjdump (works on host executables and fatbins) and standalone cubins with nvdisasm (adds source-line and register-liveness views):[3]
nvcc -O3 -lineinfo -Xptxas -v \
--generate-code arch=compute_90,code=sm_90 \
--generate-code arch=compute_90,code=compute_90 \
vector_add.cu -o build/vector_add
cuobjdump --list-elf --list-ptx --dump-resource-usage build/vector_add
nvcc -O3 -lineinfo --cubin --generate-code arch=compute_90,code=sm_90 \
vector_add.cu -o build/vector_add.sm_90.cubin
nvdisasm --print-code --print-line-info --print-life-ranges \
build/vector_add.sm_90.cubin > build/vector_add.liveness.sassRegister pressure, occupancy cliffs, and spilling
Every SM holds 65,536 32-bit registers (64 max warps on Hopper sm_90 and Blackwell sm_100; 48 max warps on Ada sm_89 and Blackwell sm_120).[6][7][8] Because hardware allocates registers per warp in 256-register granules, a single extra register per thread (32 to 33) rounds each 32-lane warp from 1,024 to 1,280 registers, dropping an 8-warp block from 8 resident blocks (64 warps, 100%) to 6 blocks (48 warps, 75%)!
import math
def resident_warps(regs, *, warp_limit=64, shared_per_block=0):
warps_per_block = 8
regs_per_warp = math.ceil(32 * regs / 256) * 256
blocks = min(65536 // (warps_per_block * regs_per_warp), warp_limit // warps_per_block)
if shared_per_block:
blocks = min(blocks, (96 * 1024) // shared_per_block)
return blocks * warps_per_block
for r in (32, 33, 41, 65, 129):
w = resident_warps(r)
print(f"R={r:3d}: {w:2d} warps ({100 * w / 64:5.1f}% of 64)")
print(f"R=33 on 48-warp SM: {resident_warps(33, warp_limit=48)} warps (100%)")
print(f"R=32 + 32 KiB shared (96 KiB SM): {resident_warps(32, shared_per_block=32768)} warps (37.5%)")R= 32: 64 warps (100.0% of 64)
R= 33: 48 warps ( 75.0% of 64)
R= 41: 40 warps ( 62.5% of 64)
R= 65: 24 warps ( 37.5% of 64)
R=129: 8 warps ( 12.5% of 64)
R=33 on 48-warp SM: 48 warps (100%)
R=32 + 32 KiB shared (96 KiB SM): 24 warps (37.5%)
Spills, ptxas -v, and artifact identity
When registers run out, ptxas spills values to .local memory (device-backed and cached, not automatically an HBM stall; CUDA 13.0 also adds opt-in shared-memory spilling in whole-program mode[9]). Control limits with --maxrregcount=N or __launch_bounds__(maxThreadsPerBlock, minBlocksPerMultiprocessor) (launching more than maxThreadsPerBlock fails at runtime) and always compare -Xptxas -v logs alongside warm timings.[1][10]
For reproducible JIT caches, hash the complete compilation recipe: source plus transitive headers, compiler version, ordered flags, target architecture (note sm_90a for WGMMA vs. sm_90), shape, strides, dtype, block size, num_warps, and num_stages. Hashing only the top-level source file silently reuses stale binaries when an included header or tensor stride changes:[11]
from dataclasses import asdict, dataclass, replace
import hashlib, json
@dataclass(frozen=True)
class Recipe:
source_sha256: str
toolchain: str
target: str
flags: tuple[str, ...]
shape: tuple[int, ...]
strides: tuple[int, ...]
dtype: str
block: int
def key(self, headers=None):
deps = sorted((k, hashlib.sha256(v).hexdigest()) for k, v in (headers or {}).items())
return hashlib.sha256(json.dumps([asdict(self), deps], sort_keys=True).encode()).hexdigest()
base = Recipe(hashlib.sha256(b"v1").hexdigest(), "nvcc-12.8", "sm_90", ("-O3",), (1000,), (1,), "fp32", 256)
k_v1 = base.key({"scale.cuh": b"#define SCALE 1\n"})
k_v2 = base.key({"scale.cuh": b"#define SCALE 2\n"})
k_stride2 = replace(base, strides=(2,)).key({"scale.cuh": b"#define SCALE 1\n"})
assert len({k_v1, k_v2, k_stride2}) == 3
print("header edit and stride-2 view both produce distinct cache keys")header edit and stride-2 view both produce distinct cache keys
JIT is part of request latency
Runtime compilers (NVRTC, nvJitLink, driver PTX JIT, and Triton) shift compilation latency onto the first request.[11][12][13] Moreover, CUDA module loading is lazy by default, so even a native cubin can pay first-call load latency unless warmed up outside the request path.[14] Test both branches in fresh processes:
CUDA_FORCE_PTX_JIT=1 CUDA_CACHE_DISABLE=1 ./build/vector_add
CUDA_DISABLE_PTX_JIT=1 ./build/vector_add
Eight ranks, two different cache questions
When eight workers miss the same cache entry concurrently, separate atomic visibility from duplicate work: Triton stages into a unique temp path and publishes via os.replace so readers never observe partial files (without guaranteeing cross-file group atomicity or power-loss durability), while an optional cooperating-writer lock with exact-key recheck prevents eight redundant compiles.[15] A rank-0 warmup helps other ranks only when both shared cache storage and exact target/recipe identity match.


Same kernel, different unit of thought
CUDA C++ describes one scalar thread; Triton describes one blocked program instance over a vector of offsets:[16][17]
import triton, triton.language as tl
@triton.jit
def add_kernel(x_ptr, y_ptr, out_ptr, n, BLOCK: tl.constexpr):
offsets = tl.program_id(0).to(tl.int64) * BLOCK + tl.arange(0, BLOCK)
mask = offsets < n
x = tl.load(x_ptr + offsets, mask=mask, other=0.0)
y = tl.load(y_ptr + offsets, mask=mask, other=0.0)
tl.store(out_ptr + offsets, x + y, mask=mask)How Triton compiles: the MLIR lowering pipeline
On NVIDIA GPUs, Triton lowers through five MLIR/backend stages: TTIR (target-agnostic block ops) -> TTGIR (distributed lane/warp layouts, coalescing, swizzles, software pipelining) -> LLVM IR (shared-memory allocation, zero for plain vector add) -> PTX -> ptxas cubin (invoked directly by Triton's backend).[18]

Check ownership without a GPU
Always test edge lengths (0, 1, 255, 256, 257) and INT_MAX arithmetic so off-by-one <= masks and 32-bit offset wraps get caught before touching hardware:
def covered(n, block=256, include_equal=False):
blocks = n // block + (n % block != 0)
idx = [p * block + l for p in range(blocks) for l in range(block)
if p * block + l < n or (include_equal and p * block + l == n)]
return blocks, idx
for n in (0, 1, 255, 256, 257, 1000):
b, idx = covered(n)
assert idx == list(range(n))
print(f"n={n:4d}: blocks={b}, masked={b * 256 - n}")
assert covered(256, include_equal=True)[1] == list(range(256)) # Full block hides <= bug!
assert covered(257, include_equal=True)[1][-1] == 257 # n=257 exposes it.
n_max = (1 << 31) - 1
blocks = n_max // 256 + (n_max % 256 != 0)
print(f"INT_MAX: {blocks} blocks, {blocks * 256 - n_max} masked lane (no int32 overflow)")n= 0: blocks=0, masked=0
n= 1: blocks=1, masked=255
n= 255: blocks=1, masked=1
n= 256: blocks=1, masked=0
n= 257: blocks=2, masked=255
n=1000: blocks=4, masked=24
INT_MAX: 8388608 blocks, 1 masked lane (no int32 overflow)![Stacked bar of n=1,000 split across four 256-lane blocks (CUDA blocks B0 to B3 and Triton pid 0 to 3): blocks 0 to 2 are full, while block 3 holds 232 valid lanes (768 to 999) and 24 masked lanes (1000 to 1023), with sums x[0]+y[0]=-3 and x[1]+y[1]=-1.75. Below left, a lane grid contrasts n=256 hiding <= against n=257 exposing lane 257 out of bounds. Below right, quotient-plus-remainder arithmetic for INT_MAX computes 8,388,608 blocks and 1 masked lane without 32-bit overflow.](https://assets.leetllm.com/v1/5c25e8a731cb/fundamentals/gpu-compilers-kernel-languages/illustrations/_generated/scalar_thread_blocked_ownership_dark.png)
Six authoring surfaces, six control contracts
Kernel languages are not a ranking from "easy" to "fast"; each picks which decisions belong to the author vs. the compiler:
| Surface | Main authoring unit | What you control explicitly | Target scope |
|---|---|---|---|
| CUDA C++[13] | Scalar thread, warp, block | Thread geometry, sync, intrinsics, memory spaces | NVIDIA GPUs |
| Triton[16][19] | Blocked program | Tile shapes, masked loads/stores, launch meta-params | NVIDIA & AMD GPUs |
| CUTLASS / CuTe[20] | Hierarchical layouts & hardware atoms | Exact layout algebra, copy/MMA atoms, C++ or Python CuTe-DSL | NVIDIA GPUs |
| CUDA Tile[21] | Block-level immutable tiles | Power-of-two tile ops; compiler owns intra-block threads | CUDA Tile-capable NVIDIA stack |
| Pallas[22][23] | Grid program over Refs & BlockSpec | HBM/VMEM or SMEM transfers and JAX composition | JAX GPU & TPU |
| NKI[24] | Tile over Neuron engines & SBUF | Explicit HBM SBUF DMA and nki.isa ops | AWS Inferentia2 & Trainium |
Diagnose the first failing boundary
Isolate compiler bugs by finding the last stage that produced valid output:
| Symptom | Failing stage | First evidence to inspect |
|---|---|---|
| Type/intrinsic compile error | Source -> Frontend IR | Compiler log + minimal reproducer + pinned API version |
ptxas rejects instruction | PTX -> cubin | PTX .target / .version, toolkit version, sm suffix (sm_90a) |
"No kernel image" at launch | Fatbin loader | GPU compute capability vs. cuobjdump --list-elf --list-ptx |
| Forced PTX JIT fails, cubin works | Driver PTX JIT | Embedded PTX ISA version vs. installed driver floor |
| Slow first call, fast warm calls | JIT or lazy module load | Fresh-process trace, cache state, warm exact shapes ahead of traffic |
| Registers jump & speed drops | IR / ptxas allocation | Diff -Xptxas -v logs, SASS liveness, occupancy & stall counters |
| Edge shape or strided view wrong | Mask or JIT cache key | Test n=255, 257 and stride-2; check specialization key fields |
Choose by the decision you must own
Start with framework ops and vendor libraries (cuBLAS, cuDNN, FlashAttention). Drop to Triton for custom block fusion, Pallas for JAX GPU/TPU integration, NKI for AWS Neuron SBUF control, CUDA Tile when compiler-owned threads suffice, CUTLASS/CuTe for custom MMA/layout pipelines, and CUDA C++ when irregular per-thread control or custom intrinsics are required.