-
Notifications
You must be signed in to change notification settings - Fork 125
Improve CUDA/HIP local argument handling #2298
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
79f3ccf
[CUDA][HIP] Fix for command-buffer local argument update
EwanC 31dc790
Improve solution
EwanC 0b5bc82
Add extra more basic CTS test
EwanC a5d2bda
FIx comment typos
EwanC 7d126f3
Add non command-buffer test
EwanC e578228
Document hip extra arg behavior
EwanC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,6 +148,39 @@ take the extra global offset argument. Use of the global offset is not | |
recommended for non SYCL compiler toolchains. This parameter can be ignored if | ||
the user does not wish to use the global offset. | ||
|
||
Local Memory Arguments | ||
---------------------- | ||
|
||
In UR local memory is a region of memory shared by all the work-items in | ||
a work-group. A kernel function signature can include local memory address | ||
space pointer arguments, which are set by the user with | ||
``urKernelSetArgLocal`` with the number of bytes of local memory to allocate | ||
and make available from the pointer argument. | ||
|
||
The CUDA adapter implements local memory in a kernel as a single ``__shared__`` | ||
memory allocation, and each individual local memory argument is a ``u32`` byte | ||
offset kernel parameter which is combined inside the kernel with the | ||
``__shared__`` memory allocation. Therefore for ``N`` local arguments that need | ||
set on a kernel with ``urKernelSetArgLocal``, the total aligned size across the | ||
``N`` calls to ``urKernelSetArgLocal`` is calculated for the ``__shared__`` | ||
memory allocation by the CUDA adapter and passed as the ``sharedMemBytes`` | ||
argument to ``cuLaunchKernel`` (or variants like ``cuLaunchCooperativeKernel`` | ||
or ``cuGraphAddKernelNode``). | ||
|
||
For each kernel ``u32`` local memory offset parameter, aligned offsets into the | ||
single memory location are calculated and passed at runtime by the adapter via | ||
``kernelParams`` when launching the kernel (or adding the kernel as a graph | ||
node). When a user calls ``urKernelSetArgLocal`` with an argument index that | ||
has already been set on the kernel, the adapter recalculates the size of the | ||
``__shared__`` memory allocation and offset for the index, as well as the | ||
offsets of any local memory arguments at following indices. | ||
|
||
.. warning:: | ||
|
||
The CUDA UR adapter implementation of local memory assumes the kernel created | ||
has been created by DPC++, instrumenting the device code so that local memory | ||
arguments are offsets rather than pointers. | ||
|
||
Other Notes | ||
=========== | ||
|
||
|
@@ -164,4 +197,5 @@ Contributors | |
------------ | ||
|
||
* Hugh Delaney `[email protected] <[email protected]>`_ | ||
* Ewan Crawford `[email protected] <[email protected]>`_ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,46 @@ take the extra global offset argument. Use of the global offset is not | |
recommended for non SYCL compiler toolchains. This parameter can be ignored if | ||
the user does not wish to use the global offset. | ||
|
||
Local Memory Arguments | ||
---------------------- | ||
|
||
In UR local memory is a region of memory shared by all the work-items in | ||
a work-group. A kernel function signature can include local memory address | ||
space pointer arguments, which are set by the user with | ||
``urKernelSetArgLocal`` with the number of bytes of local memory to allocate | ||
and make available from the pointer argument. | ||
|
||
The HIP adapter implements local memory in a kernel as a single ``__shared__`` | ||
memory allocation, and each individual local memory argument is a ``u32`` byte | ||
offset kernel parameter which is combined inside the kernel with the | ||
``__shared__`` memory allocation. Therefore for ``N`` local arguments that need | ||
set on a kernel with ``urKernelSetArgLocal``, the total aligned size across the | ||
``N`` calls to ``urKernelSetArgLocal`` is calculated for the ``__shared__`` | ||
memory allocation by the HIP adapter and passed as the ``sharedMemBytes`` | ||
argument to ``hipModuleLaunchKernel`` or ``hipGraphAddKernelNode``. | ||
|
||
For each kernel ``u32`` local memory offset parameter, aligned offsets into the | ||
single memory location are calculated and passed at runtime by the adapter via | ||
``kernelParams`` when launching the kernel (or adding the kernel as a graph | ||
node). When a user calls ``urKernelSetArgLocal`` with an argument index that | ||
has already been set on the kernel, the adapter recalculates the size of the | ||
``__shared__`` memory allocation and offset for the index, as well as the | ||
offsets of any local memory arguments at following indices. | ||
|
||
.. warning:: | ||
|
||
The HIP UR adapter implementation of local memory assumes the kernel created | ||
has been created by DPC++, instrumenting the device code so that local memory | ||
arguments are offsets rather than pointers. | ||
|
||
|
||
HIP kernels that are generated for DPC++ kernels with SYCL local accessors | ||
contain extra value arguments on top of the local memory argument for the | ||
local accessor. For each ``urKernelSetArgLocal`` argument, a user needs | ||
to make 3 calls to ``urKernelSetArgValue`` with each of the next 3 consecutive | ||
argument indexes. This represents a 3 dimensional offset into the local | ||
accessor. | ||
|
||
Other Notes | ||
=========== | ||
|
||
|
@@ -100,4 +140,5 @@ Contributors | |
------------ | ||
|
||
* Hugh Delaney `[email protected] <[email protected]>`_ | ||
* Ewan Crawford `[email protected] <[email protected]>`_ | ||
|
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.