@@ -308,7 +308,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMHostAlloc(
308308 uint32_t Align = USMDesc ? USMDesc->align : 0 ;
309309 // L0 supports alignment up to 64KB and silently ignores higher values.
310310 // We flag alignment > 64KB as an invalid value.
311- if (Align > 65536 )
311+ if (Align > 65536 || Align & (Align - 1 ) != 0 )
312312 return UR_RESULT_ERROR_INVALID_VALUE;
313313
314314 ur_platform_handle_t Plt = Context->getPlatform ();
@@ -337,11 +337,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMHostAlloc(
337337 // find the allocator depending on context as we do for Shared and Device
338338 // allocations.
339339 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) {
345341 hPoolInternal = Context->HostMemProxyPool .get ();
346342 } else if (Pool) {
347343 hPoolInternal = Pool->HostMemPool .get ();
@@ -381,7 +377,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMDeviceAlloc(
381377
382378 // L0 supports alignment up to 64KB and silently ignores higher values.
383379 // 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 )
385382 return UR_RESULT_ERROR_INVALID_VALUE;
386383
387384 ur_platform_handle_t Plt = Device->Platform ;
@@ -408,11 +405,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMDeviceAlloc(
408405 }
409406
410407 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) {
416409 auto It = Context->DeviceMemProxyPools .find (Device->ZeDevice );
417410 if (It == Context->DeviceMemProxyPools .end ())
418411 return UR_RESULT_ERROR_INVALID_VALUE;
@@ -485,7 +478,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMSharedAlloc(
485478
486479 // L0 supports alignment up to 64KB and silently ignores higher values.
487480 // 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 )
489483 return UR_RESULT_ERROR_INVALID_VALUE;
490484
491485 ur_platform_handle_t Plt = Device->Platform ;
@@ -508,11 +502,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMSharedAlloc(
508502 }
509503
510504 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) {
516506 auto &Allocator = (DeviceReadOnly ? Context->SharedReadOnlyMemProxyPools
517507 : Context->SharedMemProxyPools );
518508 auto It = Allocator.find (Device->ZeDevice );
0 commit comments