Enable global lists within kernels#584
Open
brandon-b-miller wants to merge 4 commits intoNVIDIA:mainfrom
Open
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Co-authored-by: Graham Markall <gmarkall@nvidia.com>
Contributor
Author
|
/ok to test |
|
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. |
gmarkall
reviewed
Nov 6, 2025
| if ty is None: | ||
| raise ValueError(f"Cannot type list element type {type(val[0])}") | ||
| return types.List(ty, reflected=True) | ||
| return ty[::1] |
Contributor
There was a problem hiding this comment.
This was a sketch of how things work for a 1D list only. A more robust implementation would:
- Check that the purpose of the typeof operation is for a constant. We should not accept lists as arguments to kernels.
- Convert the value to a NumPy array, then determine the Numba type of the NumPy array. This will allow handling of lists-of-lists, e.g.
[[1, 2], [3, 4]]. It also prevents having to handle what happens if there are different element types (e.g. int and float), whereas the existing implementation assumes that all list elements have the same type, which need not be the case. - Not check for zero-length, because a zero-length NumPy array is possible and can be typed. The inability to handle a zero-length list is an issue of the reflected list implementation in Numba that doesn't present an issue for freezing global lists as arrays.
gmarkall
requested changes
Nov 6, 2025
Contributor
gmarkall
left a comment
There was a problem hiding this comment.
A couple of other additions that should be required:
- Documentation. Not only is this a deviation from Python semantics (in terms of freezing the list as a constant), it even deviates from Numba list handling so could be surprising to a seasoned Numba user.
- Additional testing: test with multiple data types in the list, an unfreezable list (e.g. one that won't convert to a NumPy array), test with a list of lists once the implementation of
_typeof_listis modified according to comments.
gmarkall
reviewed
Nov 6, 2025
Contributor
There was a problem hiding this comment.
I think the changes here are now superfluous?
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.
Closes #580