cuda::device::is_address_from and cuda::device::is_object_from#
2026-10-23
2 min read time
This page documents cuda::device::is_address_from and cuda::device::is_object_from, which check whether a pointer or object belongs to a specific device address space.
Defined in the <cuda/memory> header.
namespace cuda::device {
enum class address_space
{
global, // Global state space
shared, // Shared state space
constant, // Constant state space
local, // Local state space
grid_constant, // Kernel function parameter in the parameter state space
cluster_shared, // Cluster shared window within the shared state space
};
} // namespace cuda::device
Enumeration of device address spaces used with the is_address_from() and is_object_from() functions.
namespace cuda::device {
[[nodiscard]] __device__ inline
bool is_address_from(const volatile void* ptr, address_space space) noexcept; // (1)
} // namespace cuda::device
Checks whether a generic-address pointer ptr is from the specified address space.
namespace cuda::device {
template <typename T>
[[nodiscard]] __device__ inline
bool is_object_from(T& obj, address_space space) noexcept; // (2)
} // namespace cuda::device
Checks whether an object obj with a generic address is from the specified address space.
In debug mode, is_address_from() and is_object_from() also check that the pointer is not null.
Parameters
ptr: The pointer. (1)obj: The object. (2)space: The address space. (1, 2)
Return value
Returns
trueif the pointer (1) or object (2) is from the specified address space;falseotherwise.
Note
If the GPU architecture does not support the requested address space, the function always returns false.
On AMD GPUs, address_space::grid_constant queries always return false, and address_space::cluster_shared
queries are equivalent to address_space::shared queries. address_space::constant queries are not supported:
__constant__ variables cannot be distinguished from global memory, and the query traps at run time.
Preconditions
ptrmust not be null. (1)
Performance considerations
When available, the built-in functions (
__isGlobal(),__isShared(),__isConstant(),__isLocal(),__isGridConstant(), or__isClusterShared()) are used to determine the address space.If the memory space of the input pointer matches the requested address space, the function marks the pointer as belonging to that address space.
Example#
#include <cuda/memory>
__device__ int global_var;
__global__ void kernel()
{
using cuda::device::address_space;
__shared__ int shared_var;
int local_var{};
assert(cuda::device::is_address_from(&global_var, address_space::global));
assert(cuda::device::is_address_from(&shared_var, address_space::shared));
assert(cuda::device::is_address_from(&local_var, address_space::local));
assert(cuda::device::is_object_from(global_var, address_space::global));
assert(cuda::device::is_object_from(shared_var, address_space::shared));
assert(cuda::device::is_object_from(local_var, address_space::local));
}
int main(int, char**)
{
kernel<<<1, 1>>>();
hipDeviceSynchronize();
}