cuda::is_aligned#
Defined in the header <cuda/memory>.
namespace cuda {
[[nodiscard]] __host__ __device__ inline
bool is_aligned(const void* ptr, size_t alignment) noexcept
} // namespace cuda
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.
Note
The function is similar to the C++ standard library function cuda::std::is_sufficiently_aligned() from the <cuda/std/memory> header. The differences are the following:
cuda::is_aligned()doesn’t have a template parameter and might be less expensive to compile.cuda::is_aligned()supports run-time values ofalignment.cuda::std::is_sufficiently_aligned()additionally checks the compatibility between the alignment of the pointer type and the specified alignment.
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;
}