Repository navigation
feat: support decomposing, indexing, and iterating Dim3 objects (fixes #134, #55) - #933
Open
reginaldalfret wants to merge 1 commit into
Open
reginaldalfret wants to merge 1 commit into
reginaldalfret wants to merge 1 commit into
Conversation
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.
Summary
In CUDA kernels and simulator code, thread and block dimensions/indices (
cuda.threadIdx,cuda.blockDim,cuda.blockIdx,cuda.gridDim) returnDim3objects. Previously,Dim3was modeled as an opaqueTypein the typing system with only.x,.y,.zattributes. Unpacking a Dim3 object (e.g.x, y, z = cuda.threadIdxorbx, by, bz = cuda.blockDim) failed withTypingError: failed to unpack Dim3. Furthermore, subscriptingcuda.threadIdx[0]or usinglen()/for v in cuda.threadIdx:was unsupported. In the simulator,Dim3had an__iter__method but lacked__getitem__and__len__, causingTypeError: 'Dim3' object is not subscriptable.Root Cause
numba_cuda/numba/cuda/types/ext_types.py,Dim3inherited directly fromTyperather thanNamedUniTuple, lacking sequence/unpacking typing protocol semantics.numba_cuda/numba/cuda/models.pyandcudaimpl.py,Dim3ModelusedStructModeland packed viacgutils.pack_structrather thancgutils.pack_arraymatchingUniTupleModel's contiguous homogeneous layout.numba_cuda/numba/cuda/simulator/kernelapi.pyandstubs.py,Dim3lacked__getitem__and__len__definitions.Changes
ext_types.py): Defined_Dim3Tuple = namedtuple("Dim3", ("x", "y", "z"))and updatedDim3to inherit fromNamedUniTuple(Integer.from_bitwidth(32, signed=True), 3, _Dim3Tuple).models.py): UpdatedDim3Modelto subclassmodels.UniTupleModel.cudaimpl.py): Updatedinitialize_dim3to pack elements usingcgutils.pack_array(builder, (x, y, z))matchingUniTupleModel.simulator/kernelapi.py,stubs.py): Added__getitem__and__len__methods toDim3for full feature parity across device and simulator targets.TestDim3Decomposeinnumba_cuda/numba/cuda/tests/cudapy/test_intrinsics.pytestingtest_decompose_threadIdx,test_decompose_blockDim,test_decompose_gridDim,test_indexing,test_len,test_iteration, andtest_attributes_still_work.test_dim3_sequence_supportinnumba_cuda/numba/cuda/tests/cudasim/test_cudasim_issues.py.Tests
numba.cuda.tests.cudasim.test_cudasim_issues.TestCudaSimIssues: 5/5 passednumba.cuda.tests.cudapy.test_intrinsics.TestDim3Decompose: 7/7 passednumba.cuda.tests.cudapy.test_print.TestPrint.test_dim3: 1/1 passedcompile_cuda) verifying correct PTX register read and unpack code generation: PASSEDruff check numba_cuda: 0 errorsgit diff --check: cleanValidation
compile_cuda.Issue
Fixes #134
Fixes #55