Skip to content

Commit 21515a7

Browse files
evhunterfacebook-github-bot
authored andcommitted
Add is_aligned<T>() device utility function in fbgemm_cuda_utils.cuh (#486)
Summary: Pull Request resolved: #486 Add `is_aligned<T>()` device utility function in `fbgemm_cuda_utils.cuh`. Mainly will be used to check the vector types are properly aligned before accessing. Reviewed By: jianyuh Differential Revision: D25964805 fbshipit-source-id: fe48443fd2ba63a6902b628021094f87e7a7d4c7
1 parent 5fda125 commit 21515a7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fbgemm_gpu/include/fbgemm_gpu/fbgemm_cuda_utils.cuh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,4 +622,11 @@ struct SharedMemory<Vec4T<at::acc_type<double, true>>> {
622622
}
623623
};
624624

625+
// Return if the address is aligned to the type (mainly for Vec4T).
626+
template <class T>
627+
DEVICE_INLINE bool is_aligned(const void* ptr) {
628+
auto iptr = reinterpret_cast<std::uintptr_t>(ptr);
629+
return !(iptr % alignof(T));
630+
}
631+
625632
} // namespace fbgemm_gpu

0 commit comments

Comments
 (0)