Replace ExceptionInfo with lightweight packed UInt64 atomic#894
Merged
Replace ExceptionInfo with lightweight packed UInt64 atomic#894
Conversation
The old exception handling inlined ~20 flat_store_byte instructions at every error site (bounds checks, div-by-zero, etc.), writing a 56-byte ExceptionInfo struct byte-by-byte through flat memory. This bloated register usage by ~15 VGPRs per error site, reducing occupancy even though the error paths are never taken at runtime. Replace with a single UInt64 packed with workgroup IDs (16 bits each) and an error code (8 bits), written via one atomic CAS. Each error site now needs ~3 VGPRs instead of ~15. Trade-offs: - Lost: per-workitem IDs, human-readable reason strings on device - Kept: workgroup IDs, error category (BoundsError, DomainError, etc.) - Gained: significantly lower register pressure on error paths Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Verify that the new packed UInt64 exception path does not generate flat_store_byte instructions (from the old byte-by-byte ExceptionInfo writes) and uses atomic cmpswap instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Verify that bounds-checked array access also generates zero flat_store_byte and uses atomic cmpswap for exception signaling. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Without kernel=true, code_native compiles as a device function and the AddKernelStatePass is skipped, leaving julia.gpu.state_getter as a real function call. This masks the true codegen improvement (10 VGPRs vs 41) and causes false test results. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4 tasks
vchuravy
reviewed
Mar 19, 2026
vchuravy
reviewed
Mar 19, 2026
| # TODO check specific exception type | ||
| end | ||
|
|
||
| @testset "Exception codegen" begin |
Member
There was a problem hiding this comment.
We should start using FileCheck.jl for these.
vchuravy
approved these changes
Mar 19, 2026
Co-authored-by: Valentin Churavy <v.churavy@gmail.com>
Member
Author
|
@luraess this is a breaking release I guess? |
Member
|
Would it break the higher level api? |
Member
|
I don't think this qualifies for a breaking release |
Member
Author
|
I don't know if we considered the exception info struct as API. The direct errors should be the same |
Member
|
We could tag a minor of this impacts some user code or patch else. |
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.
Summary
ExceptionInfostruct with a single packedUInt64, written via one atomic CASflat_store_byteinstructions writing the struct byte-by-byte, consuming ~15 VGPRs on never-taken error pathsglobal_atomic_cmpswap, ~3 VGPRs per error siteWhat's lost
What's kept
Why this matters
In the Oceananigans benchmark,
partial_mapreduce_devicekernels had 300-362flat_store_byteinstructions from inlined exception handling. The mapreduce kernel variants scaled from 59 to 105 VGPRs as dimension count increased, with ~15 VGPRs per dimension attributable to inlined exception paths. At 105 VGPRs the kernel is limited to 4 waves/SIMD; without the exception overhead the actual reduction logic needs ~40 VGPRs (8 waves/SIMD), doubling occupancy.Test plan
🤖 Generated with Claude Code