Skip to content

Commit 3114f02

Browse files
[SYCL] Fix returned alignment of allocation functions (#6205)
1 parent 7384e43 commit 3114f02

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

sycl/include/CL/sycl/usm.hpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ T *malloc_device(
158158
const property_list &PropList = {},
159159
const detail::code_location CodeLoc = detail::code_location::current()) {
160160
return static_cast<T *>(
161-
malloc_device(Count * sizeof(T), Dev, Ctxt, PropList, CodeLoc));
161+
aligned_alloc_device(std::max(alignof(T), alignof(std::max_align_t)),
162+
Count * sizeof(T), Dev, Ctxt, PropList, CodeLoc));
162163
}
163164

164165
template <typename T>
@@ -174,8 +175,9 @@ T *aligned_alloc_device(
174175
size_t Alignment, size_t Count, const device &Dev, const context &Ctxt,
175176
const property_list &PropList = {},
176177
const detail::code_location CodeLoc = detail::code_location::current()) {
177-
return static_cast<T *>(aligned_alloc_device(Alignment, Count * sizeof(T),
178-
Dev, Ctxt, PropList, CodeLoc));
178+
return static_cast<T *>(aligned_alloc_device(std::max(Alignment, alignof(T)),
179+
Count * sizeof(T), Dev, Ctxt,
180+
PropList, CodeLoc));
179181
}
180182

181183
template <typename T>
@@ -192,7 +194,8 @@ T *malloc_host(
192194
size_t Count, const context &Ctxt, const property_list &PropList = {},
193195
const detail::code_location CodeLoc = detail::code_location::current()) {
194196
return static_cast<T *>(
195-
malloc_host(Count * sizeof(T), Ctxt, PropList, CodeLoc));
197+
aligned_alloc_host(std::max(alignof(T), alignof(std::max_align_t)),
198+
Count * sizeof(T), Ctxt, PropList, CodeLoc));
196199
}
197200

198201
template <typename T>
@@ -208,7 +211,8 @@ T *malloc_shared(
208211
const property_list &PropList = {},
209212
const detail::code_location CodeLoc = detail::code_location::current()) {
210213
return static_cast<T *>(
211-
malloc_shared(Count * sizeof(T), Dev, Ctxt, PropList, CodeLoc));
214+
aligned_alloc_shared(std::max(alignof(T), alignof(std::max_align_t)),
215+
Count * sizeof(T), Dev, Ctxt, PropList, CodeLoc));
212216
}
213217

214218
template <typename T>
@@ -224,8 +228,9 @@ T *aligned_alloc_host(
224228
size_t Alignment, size_t Count, const context &Ctxt,
225229
const property_list &PropList = {},
226230
const detail::code_location CodeLoc = detail::code_location::current()) {
227-
return static_cast<T *>(aligned_alloc_host(Alignment, Count * sizeof(T), Ctxt,
228-
PropList, CodeLoc));
231+
return static_cast<T *>(aligned_alloc_host(std ::max(Alignment, alignof(T)),
232+
Count * sizeof(T), Ctxt, PropList,
233+
CodeLoc));
229234
}
230235

231236
template <typename T>
@@ -242,8 +247,9 @@ T *aligned_alloc_shared(
242247
size_t Alignment, size_t Count, const device &Dev, const context &Ctxt,
243248
const property_list &PropList = {},
244249
const detail::code_location CodeLoc = detail::code_location::current()) {
245-
return static_cast<T *>(aligned_alloc_shared(Alignment, Count * sizeof(T),
246-
Dev, Ctxt, PropList, CodeLoc));
250+
return static_cast<T *>(aligned_alloc_shared(std::max(Alignment, alignof(T)),
251+
Count * sizeof(T), Dev, Ctxt,
252+
PropList, CodeLoc));
247253
}
248254

249255
template <typename T>
@@ -261,7 +267,8 @@ T *malloc(
261267
const property_list &PropList = {},
262268
const detail::code_location CodeLoc = detail::code_location::current()) {
263269
return static_cast<T *>(
264-
malloc(Count * sizeof(T), Dev, Ctxt, Kind, PropList, CodeLoc));
270+
aligned_alloc(std::max(alignof(T), alignof(std::max_align_t)),
271+
Count * sizeof(T), Dev, Ctxt, Kind, PropList, CodeLoc));
265272
}
266273

267274
template <typename T>
@@ -278,8 +285,9 @@ T *aligned_alloc(
278285
size_t Alignment, size_t Count, const device &Dev, const context &Ctxt,
279286
usm::alloc Kind, const property_list &PropList = {},
280287
const detail::code_location CodeLoc = detail::code_location::current()) {
281-
return static_cast<T *>(aligned_alloc(Alignment, Count * sizeof(T), Dev, Ctxt,
282-
Kind, PropList, CodeLoc));
288+
return static_cast<T *>(aligned_alloc(std::max(Alignment, alignof(T)),
289+
Count * sizeof(T), Dev, Ctxt, Kind,
290+
PropList, CodeLoc));
283291
}
284292

285293
template <typename T>

0 commit comments

Comments
 (0)