Skip to content

Commit 3a91cec

Browse files
[SYCL] Align usm_allocator with the specification (#6191)
According to https://www.khronos.org/registry/SYCL/specs/sycl-2020/html/sycl-2020.html#_c_allocator_interface the default value for the "Alignment" template parameter must be 0. Otherwise the rebound allocator wouldn't change the alignment properly. Test added in intel/llvm-test-suite#1038
1 parent ae16f9c commit 3a91cec

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

sycl/include/CL/sycl/usm/usm_allocator.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ __SYCL_EXPORT void *aligned_alloc(size_t alignment, size_t size,
3030
__SYCL_EXPORT void free(void *ptr, const context &ctxt,
3131
const detail::code_location CodeLoc);
3232

33-
template <typename T, usm::alloc AllocKind, size_t Alignment = alignof(T)>
33+
template <typename T, usm::alloc AllocKind, size_t Alignment = 0>
3434
class usm_allocator {
3535
public:
3636
using value_type = T;
@@ -116,7 +116,9 @@ class usm_allocator {
116116
}
117117

118118
private:
119-
constexpr size_t getAlignment() const { return Alignment; }
119+
constexpr size_t getAlignment() const {
120+
return std::max(alignof(T), Alignment);
121+
}
120122

121123
template <class U, usm::alloc AllocKindU, size_t AlignmentU>
122124
friend class usm_allocator;

0 commit comments

Comments
 (0)