Skip to content

Add Cuda Vector Types - #7949

Merged
sklam merged 47 commits into
numba:mainfrom
isVoid:fea/cuda_vector_types
Jun 13, 2022
Merged

sklam merged 47 commits into
numba:mainfrom
isVoid:fea/cuda_vector_types

Conversation

@isVoid

@isVoid isVoid commented Mar 29, 2022 •

Copy link
Copy Markdown
Contributor

This is the initial introduction of cuda vector types. This PR adds support to vector type creation and readouts. Note that not only vector types can be constructed a number of primitive types, but also with all valid combinations of vector type and primitives. Such as:

f3 = float32x3(float32(1.0), float32x2(float32(2.0), float32(3.0)))
u4 = uint32x4(uint32x2(4, 3), uint32x2(2, 1))

Contributes to #7943 .

@esc esc added CUDA CUDA related issue/PR 2 - In Progress labels Mar 30, 2022
@isVoid
isVoid marked this pull request as ready for review April 12, 2022 21:05
@isVoid
isVoid requested a review from gmarkall as a code owner April 12, 2022 21:05
@gmarkall

Copy link
Copy Markdown
Member

gpuci run tests

@gmarkall gmarkall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've partially reviewed this so far, but I think it's worth posting some comments now with more to follow - there are some comments / suggestions on the diff.

Can we support casting between vectors that are essentially the same? For example, the following:

from numba import cuda, types

def f(c):
    if c:
        return cuda.int2(2, 2)
    else:
        return cuda.long2(2, 2)

cuda.compile_ptx(f, (types.boolean,), device=True)

presently gives:

numba.core.errors.TypingError: Failed in cuda mode pipeline (step: nopython frontend)
Can't unify return type from the following types: int2, long2
Return of: IR name '$16return_value.5', type 'int2', location: 
File "cast_same.py", line 6:
def f(c):
    <source elided>
    if c:
        return cuda.int2(2, 2)
        ^
Return of: IR name '$28return_value.5', type 'long2', location: 
File "cast_same.py", line 8:
def f(c):
    <source elided>
    else:
        return cuda.long2(2, 2)
        ^

Do we need the once decorator in vector_types.py? Is it to prevent a circular import? If it is needed, can we just call the function initialize()? (I feel like the "once" part of it is an implementation detail, in a sense).

I've still yet to properly look at the majority of vector_types.py and the tests - I'll look at these in the next pass.

Comment thread numba/cuda/stubs.py Outdated
Comment thread docs/source/cuda-reference/kernel.rst Outdated
Comment thread docs/source/cuda-reference/kernel.rst Outdated
Comment thread docs/source/cuda-reference/kernel.rst Outdated
Comment thread docs/source/cuda-reference/kernel.rst Outdated
Comment thread numba/cuda/device_init.py Outdated
Comment thread docs/source/cuda-reference/kernel.rst Outdated
Comment thread numba/cuda/device_init.py
Comment thread numba/cuda/stubs.py
@isVoid

isVoid commented Apr 27, 2022 •

Copy link
Copy Markdown
Contributor Author

Can we support casting between vectors that are essentially the same?

To clarify - int32 happens to be the base type for both intx and longx, are you asking that for the vector types that has the same base type and number of elements should be recognized as the same type? Not asking for conversion rules such as intx -> longx?

Do we need the once decorator in vector_types.py?

initialize is called twice in target.py. Once for impl and once for decl. Since I believe the order with which decl and impl are called is an implementation detail, the once guard is set to prevent the vector types being initialized twice.

@gmarkall gmarkall added 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed 3 - Ready for Review labels Apr 28, 2022
@isVoid

isVoid commented Apr 29, 2022

Copy link
Copy Markdown
Contributor Author

Can we support casting between vectors that are essentially the same?

@gmarkall and I discussed offline on this and there are two solutions: one is to implement the same integer types as aliases and the other is to implement the casting rules. We favored implemented as aliases; it aligns more with how numba types are implemented. The main cons of this solutions are that the kernels won't be portable across platforms. For example int and long are aliased as the same type on one platform but could be different on another so the example given in @gmarkall 's comment above cannot compile for some platforms.

To address this concern - we plan to define the vector type for python kernels with a new set of names more aligned with numpy's naming conventions: it would look like int32x4 for 32 bit vectors with 4 elements. This makes bitwidth of the base type unambiguous. Developers who writes new kernels in numba cuda is encouraged to follow this convention.

In addition, all names from native CUDA will be aliased on this new naming convention (based on machine definition of int and long). This is for convenience for people who want to transcribe their cuda kernel to python easily. And since there isn't a casting rule in native cuda between intx in longx, we don't expect this aliasing should break during these migration.

@isVoid isVoid mentioned this pull request Apr 29, 2022
@gmarkall

gmarkall commented Jun 6, 2022

Copy link
Copy Markdown
Member

gpuci run tests

@gmarkall gmarkall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Many thanks for the updates - just some very small comments / questions on the diff.

Comment thread docs/source/cuda-reference/types.rst Outdated
Comment thread numba/cuda/simulator/vector_types.py Outdated
Comment thread numba/cuda/stubs.py Outdated
Comment thread numba/cuda/simulator/vector_types.py
@gmarkall

gmarkall commented Jun 7, 2022

Copy link
Copy Markdown
Member

gpuci run tests

@gmarkall gmarkall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Many thanks for addressing the comments!

@gmarkall gmarkall added Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm 4 - Waiting on CI Review etc done, waiting for CI to finish and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Jun 7, 2022
@gmarkall

gmarkall commented Jun 7, 2022

Copy link
Copy Markdown
Member

@esc / @stuartarchibald Could this have a CUDA buildfarm smoketest please?

@esc

esc commented Jun 8, 2022

Copy link
Copy Markdown
Member

@esc / @stuartarchibald Could this have a CUDA buildfarm smoketest please?

Build numba_smoketest_cuda_yaml_131 has started

@stuartarchibald

Copy link
Copy Markdown
Contributor

@esc / @stuartarchibald Could this have a CUDA buildfarm smoketest please?

Build numba_smoketest_cuda_yaml_131 has started

Thanks @esc, this passed.

@stuartarchibald stuartarchibald added BuildFarm Passed For PRs that have been through the buildfarm and passed 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm 4 - Waiting on CI Review etc done, waiting for CI to finish labels Jun 8, 2022
@gmarkall

Copy link
Copy Markdown
Member

Thanks for the buildfarm run @esc / @stuartarchibald.

From OOB discussion, there was some concern about the length of time the Windows builders in the buildfarm took - however, I tested this on my machine locally (Win11, RTX 6000, Xeon 6128, 96GB RAM) and the increase in test time on Windows was negligible on a modern quiescent machine - it is likely that what was observed was just the general slowness of the Windows buildfarm machines.

@gmarkall gmarkall 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 Jun 13, 2022
@sklam
sklam merged commit 26edbbf into numba:main Jun 13, 2022
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 BuildFarm Passed For PRs that have been through the buildfarm and passed CUDA CUDA related issue/PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants