@@ -306,7 +306,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMHostAlloc(
306
306
uint32_t Align = USMDesc ? USMDesc->align : 0 ;
307
307
// L0 supports alignment up to 64KB and silently ignores higher values.
308
308
// We flag alignment > 64KB as an invalid value.
309
- if (Align > 65536 )
309
+ // L0 spec says that alignment values that are not powers of 2 are invalid.
310
+ if (Align > 65536 || (Align & (Align - 1 )) != 0 )
310
311
return UR_RESULT_ERROR_INVALID_VALUE;
311
312
312
313
ur_platform_handle_t Plt = Context->getPlatform ();
@@ -335,11 +336,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMHostAlloc(
335
336
// find the allocator depending on context as we do for Shared and Device
336
337
// allocations.
337
338
umf_memory_pool_handle_t hPoolInternal = nullptr ;
338
- if (!UseUSMAllocator ||
339
- // L0 spec says that allocation fails if Alignment != 2^n, in order to
340
- // keep the same behavior for the allocator, just call L0 API directly and
341
- // return the error code.
342
- ((Align & (Align - 1 )) != 0 )) {
339
+ if (!UseUSMAllocator) {
343
340
hPoolInternal = Context->HostMemProxyPool .get ();
344
341
} else if (Pool) {
345
342
hPoolInternal = Pool->HostMemPool .get ();
@@ -379,7 +376,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMDeviceAlloc(
379
376
380
377
// L0 supports alignment up to 64KB and silently ignores higher values.
381
378
// We flag alignment > 64KB as an invalid value.
382
- if (Alignment > 65536 )
379
+ // L0 spec says that alignment values that are not powers of 2 are invalid.
380
+ if (Alignment > 65536 || (Alignment & (Alignment - 1 )) != 0 )
383
381
return UR_RESULT_ERROR_INVALID_VALUE;
384
382
385
383
ur_platform_handle_t Plt = Device->Platform ;
@@ -406,11 +404,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMDeviceAlloc(
406
404
}
407
405
408
406
umf_memory_pool_handle_t hPoolInternal = nullptr ;
409
- if (!UseUSMAllocator ||
410
- // L0 spec says that allocation fails if Alignment != 2^n, in order to
411
- // keep the same behavior for the allocator, just call L0 API directly and
412
- // return the error code.
413
- ((Alignment & (Alignment - 1 )) != 0 )) {
407
+ if (!UseUSMAllocator) {
414
408
auto It = Context->DeviceMemProxyPools .find (Device->ZeDevice );
415
409
if (It == Context->DeviceMemProxyPools .end ())
416
410
return UR_RESULT_ERROR_INVALID_VALUE;
@@ -483,7 +477,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMSharedAlloc(
483
477
484
478
// L0 supports alignment up to 64KB and silently ignores higher values.
485
479
// We flag alignment > 64KB as an invalid value.
486
- if (Alignment > 65536 )
480
+ // L0 spec says that alignment values that are not powers of 2 are invalid.
481
+ if (Alignment > 65536 || (Alignment & (Alignment - 1 )) != 0 )
487
482
return UR_RESULT_ERROR_INVALID_VALUE;
488
483
489
484
ur_platform_handle_t Plt = Device->Platform ;
@@ -506,11 +501,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMSharedAlloc(
506
501
}
507
502
508
503
umf_memory_pool_handle_t hPoolInternal = nullptr ;
509
- if (!UseUSMAllocator ||
510
- // L0 spec says that allocation fails if Alignment != 2^n, in order to
511
- // keep the same behavior for the allocator, just call L0 API directly and
512
- // return the error code.
513
- ((Alignment & (Alignment - 1 )) != 0 )) {
504
+ if (!UseUSMAllocator) {
514
505
auto &Allocator = (DeviceReadOnly ? Context->SharedReadOnlyMemProxyPools
515
506
: Context->SharedMemProxyPools );
516
507
auto It = Allocator.find (Device->ZeDevice );
0 commit comments