Skip to content

Commit

Permalink
Return invalid value from USM when alignment not power of 2
Browse files Browse the repository at this point in the history
  • Loading branch information
lbushi25 committed May 1, 2024
1 parent 4ed848e commit e8b8722
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions source/adapters/level_zero/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMDeviceAlloc(

// L0 supports alignment up to 64KB and silently ignores higher values.
// We flag alignment > 64KB as an invalid value.
if (Alignment > 65536)
// L0 spec says that alignment values that are not powers of 2 are invalid.
if (Alignment > 65536 || Alignment & (Alignment - 1) != 0)
return UR_RESULT_ERROR_INVALID_VALUE;

ur_platform_handle_t Plt = Device->Platform;
Expand All @@ -408,11 +409,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMDeviceAlloc(
}

umf_memory_pool_handle_t hPoolInternal = nullptr;
if (!UseUSMAllocator ||
// L0 spec says that allocation fails if Alignment != 2^n, in order to
// keep the same behavior for the allocator, just call L0 API directly and
// return the error code.
((Alignment & (Alignment - 1)) != 0)) {
if (!UseUSMAllocator) {
auto It = Context->DeviceMemProxyPools.find(Device->ZeDevice);
if (It == Context->DeviceMemProxyPools.end())
return UR_RESULT_ERROR_INVALID_VALUE;
Expand Down Expand Up @@ -485,7 +482,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMSharedAlloc(

// L0 supports alignment up to 64KB and silently ignores higher values.
// We flag alignment > 64KB as an invalid value.
if (Alignment > 65536)
// L0 spec says that alignment values that are not powers of 2 are invalid.
if (Alignment > 65536 || Alignment && (Alignment - 1) != 0)
return UR_RESULT_ERROR_INVALID_VALUE;

ur_platform_handle_t Plt = Device->Platform;
Expand All @@ -508,11 +506,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMSharedAlloc(
}

umf_memory_pool_handle_t hPoolInternal = nullptr;
if (!UseUSMAllocator ||
// L0 spec says that allocation fails if Alignment != 2^n, in order to
// keep the same behavior for the allocator, just call L0 API directly and
// return the error code.
((Alignment & (Alignment - 1)) != 0)) {
if (!UseUSMAllocator) {
auto &Allocator = (DeviceReadOnly ? Context->SharedReadOnlyMemProxyPools
: Context->SharedMemProxyPools);
auto It = Allocator.find(Device->ZeDevice);
Expand Down

0 comments on commit e8b8722

Please sign in to comment.