fix(errors): restore CUDA exception hierarchy to avoid slow string compilation#796
Merged
gmarkall merged 5 commits intoNVIDIA:mainfrom Feb 27, 2026
Merged
Conversation
Contributor
|
Automatic reviews are disabled for this repository. |
|
Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Contributor
Author
|
/ok to test |
1 similar comment
Contributor
Author
|
/ok to test |
…compilation (NVIDIA#755) The error module redirect (491f552) replaced the CUDA exception subclass hierarchy with identity aliases to numba.core.errors classes. This broadened isinstance checks throughout the CUDA compiler, causing it to catch upstream exceptions it previously ignored and try far more compilation passes -- resulting in orders-of-magnitude slower compile times for types with many overload candidates (e.g. strings). Use dynamic diamond inheritance to create local exception subclasses: for every upstream NumbaError descendant, a local class is created that inherits from both the local parent and the upstream class. This restores the narrow isinstance semantics the compiler relies on while preserving the user-facing catch semantics that 491f552 introduced. Co-authored-by: Cursor <cursoragent@cursor.com>
Add a focused hierarchy invariants test to ensure CUDA error classes remain local subclasses of core errors while preserving narrow core-vs-CUDA isinstance behavior relied on by compile-time control flow. Co-authored-by: Cursor <cursoragent@cursor.com>
Update local numba-cuda package entries in pixi.lock to the current 0.27.0 version so the lockfile metadata stays consistent with this branch. Co-authored-by: Cursor <cursoragent@cursor.com>
Use direct attribute assignment for `NumbaError` on the redirected module to satisfy ruff while preserving existing error hierarchy behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
832d56f to
60493cf
Compare
gmarkall
approved these changes
Feb 27, 2026
Contributor
|
/ok to test |
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
numba_cuda/numba/cuda/core/errors.pyas CUDA-local subclasses of correspondingnumba.core.errorsclasses.numba_cuda/numba/cuda/core/errors.py(_mod.NumbaError = NumbaError) with no behavior change.numba_cuda/numba/cuda/tests/cudapy/test_errors.pythat asserts hierarchy invariants acrossNumbaErrordescendants.pixi.lockpackage entries so localnumba-cudalock metadata matches the current0.27.0version.Problem statement
The redirect in
numba_cuda/numba/cuda/core/errors.pymade CUDA error names direct aliases ofnumba.core.errors. That broadened exception checks in CUDA typing/overload resolution, so some compile paths (notably string-heavy cases) stopped short-circuiting and became much slower.Alternatives considered
The options were evaluated on behavior restoration, compatibility, implementation effort, and maintenance.
Option A: Revert redirect and restore independent CUDA error classes
isinstancebehavior.numba.core.errorsshape.Option B: Keep aliasing and patch compiler callsites
Option C: Manually mirror CUDA hierarchy as subclasses of core classes
numba.core.errors.Option D: Dynamically mirror hierarchy at import time
NumbaErrordescendant while preserving parent-child structure.Comparison at a glance
Selected approach in this PR
This PR implements Option D and adds regression tests to lock in the hierarchy invariants:
issubclass(cuda_error, core_error)remains true for matching classes.issubclass(core_error, numba.cuda.core.errors.NumbaError)remains false to preserve narrow compile-time gates.Closes #755