Repository navigation
GPU: gpuBatch keeps typed arrays on the GPU, by their elements - #1106
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>
A typed array reaches a launch as a view header of its own (made for the launch), so gpuBatch could not find it again and copied it each launch (GPU_ARRAY_PER_LAUNCH). Now its kind says GPU_ARRAY_VIEW (0x80000) and the batch keeps it by its first element, length and element size: the same typed array, or a new subarray of the same elements, is the GPU's copy at every launch after the first. A view whose elements overlap another the GPU holds (subarrays of one buffer) sends that one back first (after the GPU is done with it) and is copied in from there, so the two copies never part. The table's pointer into the elements keeps the typed array's store alive (the collector takes interior pointers). gpu_batch_views.ts: 100 saxpy launches copy in once; apart, overlapping and temporary (collected between steps) typed arrays all right on the RTX 5080. The stale "on the GPU that is a trap" in __tslang_gpu_past_end's message is gone. 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.
gpuBatch keeps typed arrays on the GPU too
Inside
gpuBatch, plain arrays stay on the GPU between launches, but a typed array was copied in and out at every launch. Each launch builds the typed array its own view header, so the batch never recognised it as the same array. This change makes the batch recognise it.elementSize | 0x80000(GPU_ARRAY_VIEW) instead of the per-launch flag.ALL_INTERIOR_POINTERS) treats that as a reference. A typed array created for one step and then dropped therefore stays alive until the batch ends.__tslang_gpu_past_end's message, left over from GPU: a kernel's write past an array's end is reported by name on every GPU #1105.Tested
gpu_batch_views.tscovers four cases:Float32Arrays, where only the first copies anything in (checked withTSLANG_GPU_PROFILE);Int32Arrays collected between steps.main: 10,491 tests run, none failing. The 72 GPU ctests pass after the merge.🤖 Generated with Claude Code