Skip to content

Commit f3783fb

Browse files
committed
Return invalid value on USM allocation functions when alignmnet value is not power of 2
1 parent 2139109 commit f3783fb

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

source/adapters/level_zero/queue.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueFinish(
902902
UR_APIEXPORT ur_result_t UR_APICALL urQueueFlush(
903903
ur_queue_handle_t Queue ///< [in] handle of the queue to be flushed.
904904
) {
905-
std::scoped_lock<ur_shared_mutex> Lock(Queue->Mutex);
906-
return Queue->executeAllOpenCommandLists();
905+
// Flushing cross-queue dependencies is covered by
906+
// createAndRetainUrZeEventList, so this can be left as a no-op. return
907+
// Queue->executeAllOpenCommandLists();
908+
std::ignore = Queue;
909+
return UR_RESULT_SUCCESS;
907910
}
908911

909912
// Configuration of the command-list batching.

source/adapters/level_zero/usm.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)