@@ -154,6 +154,13 @@ __SYCL_EXPORT void *aligned_alloc(
154
154
const property_list &propList,
155
155
const detail::code_location &CodeLoc = detail::code_location::current());
156
156
157
+ // /
158
+ // Helper function used to determine if the Alignment argument is a power of 2
159
+ // /
160
+ inline size_t is_not_power_of_two (size_t Alignment) {
161
+ return (Alignment & (Alignment - 1 ));
162
+ }
163
+
157
164
// /
158
165
// Template forms
159
166
// /
@@ -179,6 +186,9 @@ T *aligned_alloc_device(
179
186
size_t Alignment, size_t Count, const device &Dev, const context &Ctxt,
180
187
const property_list &PropList = {},
181
188
const detail::code_location &CodeLoc = detail::code_location::current()) {
189
+ if (is_not_power_of_two (Alignment)) {
190
+ return nullptr ;
191
+ }
182
192
return static_cast <T *>(aligned_alloc_device (max (Alignment, alignof (T)),
183
193
Count * sizeof (T), Dev, Ctxt,
184
194
PropList, CodeLoc));
@@ -189,6 +199,9 @@ T *aligned_alloc_device(
189
199
size_t Alignment, size_t Count, const queue &Q,
190
200
const property_list &PropList = {},
191
201
const detail::code_location &CodeLoc = detail::code_location::current()) {
202
+ if (is_not_power_of_two (Alignment)) {
203
+ return nullptr ;
204
+ }
192
205
return aligned_alloc_device<T>(Alignment, Count, Q.get_device (),
193
206
Q.get_context (), PropList, CodeLoc);
194
207
}
@@ -230,6 +243,9 @@ T *aligned_alloc_host(
230
243
size_t Alignment, size_t Count, const context &Ctxt,
231
244
const property_list &PropList = {},
232
245
const detail::code_location &CodeLoc = detail::code_location::current()) {
246
+ if (is_not_power_of_two (Alignment)) {
247
+ return nullptr ;
248
+ }
233
249
return static_cast <T *>(aligned_alloc_host (std ::max (Alignment, alignof (T)),
234
250
Count * sizeof (T), Ctxt, PropList,
235
251
CodeLoc));
@@ -240,6 +256,9 @@ T *aligned_alloc_host(
240
256
size_t Alignment, size_t Count, const queue &Q,
241
257
const property_list &PropList = {},
242
258
const detail::code_location &CodeLoc = detail::code_location::current()) {
259
+ if (is_not_power_of_two (Alignment)) {
260
+ return nullptr ;
261
+ }
243
262
return aligned_alloc_host<T>(Alignment, Count, Q.get_context (), PropList,
244
263
CodeLoc);
245
264
}
@@ -249,6 +268,9 @@ T *aligned_alloc_shared(
249
268
size_t Alignment, size_t Count, const device &Dev, const context &Ctxt,
250
269
const property_list &PropList = {},
251
270
const detail::code_location &CodeLoc = detail::code_location::current()) {
271
+ if (is_not_power_of_two (Alignment)) {
272
+ return nullptr ;
273
+ }
252
274
return static_cast <T *>(aligned_alloc_shared (max (Alignment, alignof (T)),
253
275
Count * sizeof (T), Dev, Ctxt,
254
276
PropList, CodeLoc));
@@ -259,6 +281,9 @@ T *aligned_alloc_shared(
259
281
size_t Alignment, size_t Count, const queue &Q,
260
282
const property_list &PropList = {},
261
283
const detail::code_location &CodeLoc = detail::code_location::current()) {
284
+ if (is_not_power_of_two (Alignment)) {
285
+ return nullptr ;
286
+ }
262
287
return aligned_alloc_shared<T>(Alignment, Count, Q.get_device (),
263
288
Q.get_context (), PropList, CodeLoc);
264
289
}
@@ -286,6 +311,9 @@ T *aligned_alloc(
286
311
size_t Alignment, size_t Count, const device &Dev, const context &Ctxt,
287
312
usm::alloc Kind, const property_list &PropList = {},
288
313
const detail::code_location &CodeLoc = detail::code_location::current()) {
314
+ if (is_not_power_of_two (Alignment)) {
315
+ return nullptr ;
316
+ }
289
317
return static_cast <T *>(aligned_alloc (max (Alignment, alignof (T)),
290
318
Count * sizeof (T), Dev, Ctxt, Kind,
291
319
PropList, CodeLoc));
@@ -296,6 +324,9 @@ T *aligned_alloc(
296
324
size_t Alignment, size_t Count, const queue &Q, usm::alloc Kind,
297
325
const property_list &PropList = {},
298
326
const detail::code_location &CodeLoc = detail::code_location::current()) {
327
+ if (is_not_power_of_two (Alignment)) {
328
+ return nullptr ;
329
+ }
299
330
return aligned_alloc <T>(Alignment, Count, Q.get_device (), Q.get_context (),
300
331
Kind, PropList, CodeLoc);
301
332
}
0 commit comments