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