Repository navigation
GPU: a kernel's write past an array's end is reported by name on every GPU - #1105
Merged
Merged
Conversation
…ry GPU, instead of a bare driver error A trap made it "running the kernel failed (719 unspecified launch failure)" on NVIDIA and AMD, and undefined on Intel. Now each element write in a kernel that does not wait at a barrier (a store, +=, Atomics, a tuple's field or whole element, in the kernel or a function it calls) is made only inside the array; the first one past the end is recorded in the module's __tslang_gpu_fault (a cmpxchg on its flag, then thread, index, length), and the runtime reads it where it waits for the kernel (the launch's own sync, gpuWait, the program's end) and stops: "tslang gpu: the kernel 'k' wrote past the end of an array: element 1000 of 1000 (GPU thread 995)", exit 1. The compiler's own check before a write goes only where that write is guarded; any other stays a trap. Drivers look the record up with cuModuleGetGlobal_v2 / hipModuleGetGlobal / zeModuleGetGlobalPointer, optional (missing: no report, the driver still runs). Barrier kernels keep dropping such writes silently. The write costs the one comparison it had; a launch's time is unchanged (0.066 ms median either way). tslang/test/gpu/faults/ has a program per way of writing: all 11 report right on the RTX 5080, JIT and exe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A kernel's write past an array's end is reported by name
Before this, a kernel that wrote past an array's end trapped. On NVIDIA and AMD the only report was a bare
running the kernel failed (719 unspecified launch failure); on Intel the behaviour was undefined. Now the program stops after the kernel, on every GPU, with:and exit code 1, which matches what a kernel called on the CPU already does.
How
+=,Atomics, a tuple's field and a whole tuple element. A write past the end is skipped, and the first one is recorded in the module's__tslang_gpu_faultglobal: a cmpxchg on its flag, then the thread, index and length.cuModuleGetGlobal_v2,hipModuleGetGlobalorzeModuleGetGlobalPointer. These entry points are optional: if one is missing, the driver still runs, just without the report. The runtime reads the record wherever it already waits for the GPU: a copying launch's own sync,gpuWait(gpuRead,gpuWrite,gpuFree, the end of a batch) and the program's end.Cost
A write still costs the one compare it already had; the old past-end check folds into it in the PTX. A launch's total time is unchanged. Medians over 150 launches each, using executables (the JIT's object cache had reused objects built against the old runtime, so my first numbers compared the same code): 0.34 ms with the record read and 0.36 ms without at 1000 elements, 0.52 / 0.52 ms at 100k, 8.64 / 8.57 ms at 4M. Before this change (
main) they are 0.36, 0.53 and 8.59 ms. The read only takes over a wait that copying the arrays back would otherwise pay.Tested
tslang/test/gpu/faults/has one program per way of writing: a store,+=,Atomics, a write in a helper, a field, a whole element, a negative index, a typed-array view, aGpuArrayreported atgpuReadand at the program's end, andgpuBatch. All 11 report correctly with exit code 1 under the JIT and as executables, on the RTX 5080 on Windows and on Linux (WSL).test-gpu-compile-faultschecks for the record global, 6 record calls and no trap left, plusspirv-valon the Intel output..visible .globalin the PTX, in the AMD object's dynamic symbols (protected), and with Export linkage in the SPIR-V.🤖 Generated with Claude Code