-
Notifications
You must be signed in to change notification settings - Fork 359
Move aligned_size_t, get_device_address and discard_memory to cuda/__memory/
#5239
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
bernhardmgruber
merged 12 commits into
NVIDIA:main
from
davebayer:move_functions_to_cuda_memory
Jul 22, 2025
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e52ba23
Move `aligned_size_t` and `get_device_address` to `cuda/__memory/`
davebayer 4f5df77
move tests
davebayer 879398b
fix review
davebayer fc4b798
Move `cuda::discard_memory` to `<cuda/memory>`
davebayer 6821384
Update date on license
miscco 631d0e6
add `cuda::device::is_address_from` docs
davebayer 06b9ee1
fix include
davebayer 4688831
fix one more include
davebayer 4f81213
remove outdated comment
davebayer 626899a
Add endif comment
miscco e2ad943
fix review
davebayer a4ac9aa
fix `is_address_from` release version
davebayer 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| .. _libcudacxx-extended-api-memory-is_address_from: | ||
|
|
||
| ``cuda::device::is_address_from`` | ||
| ================================= | ||
|
|
||
| .. code:: cuda | ||
|
|
||
| enum class address_space | ||
| { | ||
| global, | ||
| shared, | ||
| constant, | ||
| local, | ||
| grid_constant, | ||
| cluster_shared, | ||
| }; | ||
|
|
||
| template <typename T> | ||
| [[nodiscard]] __device__ inline | ||
| bool is_address_from(address_space space, const void* ptr) | ||
|
|
||
| The function checks if a pointer ``ptr`` with a generic address is from a ``space`` address state space. | ||
|
|
||
| **Parameters** | ||
|
|
||
| - ``space``: The address space. | ||
| - ``ptr``: The pointer. | ||
|
|
||
| **Return value** | ||
|
|
||
| - ``true`` if the pointer is from the specified address space, ``false`` otherwise. | ||
|
|
||
| **Performance considerations** | ||
|
|
||
| - If possible, the ``__isGlobal``, ``__isShared``, ``__isConstant``, ``__isLocal``, ``__isGridConstant``, or ``__isClusterShared`` built-in functions are used to determine the address space. | ||
|
|
||
| Example | ||
| ------- | ||
|
|
||
| .. code:: cuda | ||
|
|
||
| #include <cuda/memory> | ||
|
|
||
| struct MutableStruct | ||
| { | ||
| mutable int v; | ||
| }; | ||
|
|
||
| __device__ int global_var; | ||
| __constant__ int constant_var; | ||
|
|
||
| __global__ void kernel(const __grid_constant__ MutableStruct grid_constant_var) | ||
| { | ||
| __shared__ int shared_var; | ||
| int local_var{}; | ||
|
|
||
| assert(cuda::device::is_address_from(cuda::device::address_space::global, &global_var)); | ||
| assert(cuda::device::is_address_from(cuda::device::address_space::shared, &shared_var)); | ||
| assert(cuda::device::is_address_from(cuda::device::address_space::constant, &constant_var)); | ||
| assert(cuda::device::is_address_from(cuda::device::address_space::local, &local_var)); | ||
| assert(cuda::device::is_address_from(cuda::device::address_space::grid_constant, &grid_constant_var)); | ||
| } | ||
|
|
||
| int main(int, char**) | ||
| { | ||
| kernel<<<1, 1>>>(MutableStruct{42}); | ||
| cudaDeviceSynchronize(); | ||
| } | ||
|
|
||
| `See it on Godbolt 🔗 <https://godbolt.org/z/r1qb31szz>`_ |
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 was deleted.
Oops, something went wrong.
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.
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.