cuda::is_aligned#
[[nodiscard]] __host__ __device__ inline
bool is_aligned(const void* ptr, size_t alignment) noexcept
The function determines if a pointer is aligned to a specific alignment.
Parameters
ptr: The pointer.alignment: The alignment.
Return value
trueif the pointer is aligned to the specified alignment,falseotherwise.
Constraints
alignmentmust be a power of two.
Example#
#include <cuda/memory>
__global__ void kernel(const void* ptr) {
assert(cuda::is_aligned(ptr, 16));
}
int main() {
void* ptr;
cudaMalloc(&ptr, 100 * sizeof(int));
kernel<<<1, 1>>>(ptr);
cudaDeviceSynchronize();
return 0;
}