Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't attempt to register overloads that aren't for this target in BaseContext and related fixes #9454

Merged
merged 7 commits into from Apr 26, 2024

Conversation

gmarkall
Copy link
Member

@gmarkall gmarkall commented Feb 21, 2024

Fixes a cascading plethora of issues discovered as a result of looking into #9432. See individual commit messages for details of fixes - the pattern is generally that each fix exposed a new issue, resolved by a subsequent commit.

@gmarkall
Copy link
Member Author

Plan following discussion with @stuartarchibald Wait for #9447 to be merged, then rebase and tidy this up to be ready for review, in the 0.60 milestone.

@gmarkall gmarkall added the skip_release_notes Skip towncrier requirement label Apr 10, 2024
…rent target

This moves the target check from inside the `_OverloadMethodTemplate` to
the `BaseContext.install_registry()` method. The effect of this change
is that instead of attempting to register all overloaded method
templates with all targets and then silently failing inside the
registration, we only attempt to register overloaded methods that are
appropriate for the target.

The `_OverloadAttributeTemplate` never contained this check, which
appears curious at first sight - however, there is a related bug in
overloading of attributes that causes their metadata to be lost, and
therefore all attributes get registered for all targets regardless of
whether they are for the current target or not. This error will be
addressed in the following commit.
Decorator keywords arguments other than `inline` were dropped, so other
metadata such as the target were silently lost. We resolve this by
passing all keyword arguments to `make_overload_attribute_template()`.

Also add a test that verifies that the metadata still exists, which
prevents a CUDA-only attribute overload being used on the CPU target,
with a sensible TypingError as the result.
This is analagous to the similar test added for CUDA in the previous
commit, but doesn't require CUDA to run so can be a part of the main
test suite.
The DPU target should have been setting a target override during
compilation (similar to how the CUDA target does), and it should also
set the `target_backend` target option, mirroring what the default
`@jit` decorator does. Not setting these doesn't seem to have had any
ill effect within the testsuite, but these settings should both be made
to avoid running into latent issues in future.
When typing contexts are refreshed, there may be registrations for
invalid targets pending (e.g. from other tests that exercise error
handling in the presence of invalid user code). These registrations need
to be ignored - see the comments in the code for further detail.

Attempting to compile a call to an overload with an invalid target now
causes a `NonexistentTargetError` to be raised, so the target extension
tests are updated accordingly.
@gmarkall
Copy link
Member Author

gpuci run tests

@gmarkall gmarkall marked this pull request as ready for review April 11, 2024 10:55
@gmarkall gmarkall changed the title WIP: Don't attempt to register overloads that aren't for this target in BaseContext Don't attempt to register overloads that aren't for this target in BaseContext and related fixes Apr 11, 2024
Copy link
Contributor

@stuartarchibald stuartarchibald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this @gmarkall. As we have debugged, discussed and worked on this logic through many OOB conversations I'm reasonably convinced that this fixes the issues with the use of target= in @overload_method etc and also a number of additional issues discovered in the debugging process. There's a few minor things to address, otherwise looks good.

numba/core/extending.py Show resolved Hide resolved
numba/core/typing/context.py Show resolved Hide resolved
numba/cuda/tests/cudapy/test_overload.py Outdated Show resolved Hide resolved
numba/tests/test_target_extension.py Outdated Show resolved Hide resolved
numba/tests/test_target_extension.py Outdated Show resolved Hide resolved
@stuartarchibald stuartarchibald added 4 - Waiting on author Waiting for author to respond to review and removed 3 - Ready for Review labels Apr 24, 2024
@stuartarchibald stuartarchibald mentioned this pull request Apr 24, 2024
40 tasks
This option is going to be removed by numba#9539 when it is merged.
Instead of reusing `MyDummyType` and `mydummy_type` from
`test_extending`, we use the `make_dummy_type` method of the test
classes to create types that are unique to the current test.

A minor (inconsequential) error in the signatures in the tests is also
fixed.
@gmarkall
Copy link
Member Author

gpuci run tests

@gmarkall gmarkall added 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed 4 - Waiting on author Waiting for author to respond to review labels Apr 26, 2024
Copy link
Contributor

@stuartarchibald stuartarchibald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch and fixes!

@stuartarchibald stuartarchibald added 5 - Ready to merge Review and testing done, is ready to merge and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Apr 26, 2024
@sklam sklam merged commit 34b5b8d into numba:main Apr 26, 2024
22 checks passed
@gmarkall gmarkall deleted the target-mismatch-refactor branch May 2, 2024 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to merge Review and testing done, is ready to merge skip_release_notes Skip towncrier requirement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants