@@ -311,8 +311,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMHostAlloc(
311311 // L0 supports alignment up to 64KB and silently ignores higher values.
312312 // We flag alignment > 64KB as an invalid value.
313313 // L0 spec says that alignment values that are not powers of 2 are invalid.
314- if (Align > 65536 || (Align & (Align - 1 )) != 0 )
315- return UR_RESULT_ERROR_INVALID_VALUE;
314+ // If alignment == 0, then we are allowing the L0 driver to choose the
315+ // alignment so no need to check.
316+ if (Align > 0 ) {
317+ if (Align > 65536 || (Align & (Align - 1 )) != 0 )
318+ return UR_RESULT_ERROR_INVALID_VALUE;
319+ }
316320
317321 ur_platform_handle_t Plt = Context->getPlatform ();
318322 // If indirect access tracking is enabled then lock the mutex which is
@@ -381,8 +385,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMDeviceAlloc(
381385 // L0 supports alignment up to 64KB and silently ignores higher values.
382386 // We flag alignment > 64KB as an invalid value.
383387 // L0 spec says that alignment values that are not powers of 2 are invalid.
384- if (Alignment > 65536 || (Alignment & (Alignment - 1 )) != 0 )
385- return UR_RESULT_ERROR_INVALID_VALUE;
388+ // If alignment == 0, then we are allowing the L0 driver to choose the
389+ // alignment so no need to check.
390+ if (Alignment > 0 ) {
391+ if (Alignment > 65536 || (Alignment & (Alignment - 1 )) != 0 )
392+ return UR_RESULT_ERROR_INVALID_VALUE;
393+ }
386394
387395 ur_platform_handle_t Plt = Device->Platform ;
388396
@@ -482,8 +490,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMSharedAlloc(
482490 // L0 supports alignment up to 64KB and silently ignores higher values.
483491 // We flag alignment > 64KB as an invalid value.
484492 // L0 spec says that alignment values that are not powers of 2 are invalid.
485- if (Alignment > 65536 || (Alignment & (Alignment - 1 )) != 0 )
486- return UR_RESULT_ERROR_INVALID_VALUE;
493+ // If alignment == 0, then we are allowing the L0 driver to choose the
494+ // alignment so no need to check.
495+ if (Alignment > 0 ) {
496+ if (Alignment > 65536 || (Alignment & (Alignment - 1 )) != 0 )
497+ return UR_RESULT_ERROR_INVALID_VALUE;
498+ }
487499
488500 ur_platform_handle_t Plt = Device->Platform ;
489501
0 commit comments