Repository navigation
GPU: a kernel's read past an array's end gives 0 and is reported, as a write is - #1109
Open
ASDAlexander77 wants to merge 1 commit into
Open
ASDAlexander77 wants to merge 1 commit into
ASDAlexander77 wants to merge 1 commit into
Conversation
…a write is A kernel that does not wait at a barrier read past an array's end unchecked: whatever GPU memory was there, or a driver fault. Now such a read (an element, a field of one, a typed array's view past its own length) gives 0, the first is recorded in the fault global, and the program stops after the kernel: tslang gpu: the kernel 'k' read past the end of an array: element 4 of 4 (GPU thread 3) The record's flag says which (1 write, 2 read). The CPU still does not check a read past the end; barrier kernels keep giving 0 silently (their threads past n read their tiles). Cost, kept down: the read is always made, of the element or of a block of zeroes (a select), and only the record is branched to, so the array's data pointer and length are loaded once before a loop; the record's call has an alias scope of its own, never an array header. A matrix * vector kernel (2048 x 2048 floats, 200 launches): NVIDIA 37 ms unchecked, 37 ms checked; Intel's iGPU 246 ms -> 405 ms (a branch around the read was 60 ms and 524). Tests: faults/read.ts, read_field.ts, read_typed_array.ts; all 14 fault cases and all 26 programs pass on NVIDIA and Intel, JIT and exe; GPU ctests pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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 read past an array's end is now reported, the same way a write past the end is.
What changes
@kernelthat does not wait at a barrier. Before, such a read returned whatever GPU memory followed the array, or crashed the driver. Now:a[i] += vpast the end is reported as a read, because the read happens first.nread their tiles that way.Cost
A naive branch around each read reloaded the array's data pointer on every iteration of a loop. That made a matrix-vector kernel 1.6x slower on NVIDIA and 2.1x slower on Intel.
Two changes bring the cost down:
select(inside, element, zeroes), and only the cold record call sits behind a branch. The data pointer and length are then loaded once, before the loop.Matrix-vector, 2048 x 2048 floats, 200 launches:
A stencil kernel is 3% slower on Intel and unchanged on NVIDIA.
Tests
faults/read.ts,read_field.ts,read_typed_array.ts.docs/gpu.mdandfaults/README.mdare updated.🤖 Generated with Claude Code