From ae9ae1e63c0f4f3ea01466b142086b49d4d76dc8 Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Thu, 30 Nov 2023 17:10:33 +0000 Subject: [PATCH] Address feedback - missing breaks in switches, more appropriate error codes or replacing original error message to use an assert from cassert header and some other minor fixes. --- source/adapters/cuda/common.hpp | 2 +- source/adapters/cuda/device.cpp | 9 ++++----- source/adapters/cuda/enqueue.cpp | 14 ++++++++------ source/adapters/cuda/event.cpp | 13 ++++--------- source/adapters/cuda/memory.cpp | 14 ++++++-------- source/adapters/cuda/queue.cpp | 2 +- source/adapters/cuda/sampler.cpp | 4 +--- source/adapters/hip/common.cpp | 5 ++++- source/adapters/hip/common.hpp | 8 ++++---- source/adapters/hip/device.cpp | 2 +- source/adapters/hip/enqueue.cpp | 6 +++--- source/adapters/hip/event.cpp | 12 +++--------- source/adapters/hip/memory.cpp | 8 ++++---- source/adapters/hip/queue.cpp | 2 +- source/adapters/hip/sampler.cpp | 4 +--- source/adapters/level_zero/context.cpp | 4 +--- source/adapters/level_zero/event.cpp | 16 ++++------------ source/adapters/level_zero/memory.cpp | 5 ++--- source/adapters/level_zero/queue.cpp | 12 ++++++------ source/adapters/level_zero/usm.cpp | 8 ++------ source/adapters/opencl/common.hpp | 2 +- 21 files changed, 62 insertions(+), 90 deletions(-) diff --git a/source/adapters/cuda/common.hpp b/source/adapters/cuda/common.hpp index 1ec184f71b..da77c6eeb9 100644 --- a/source/adapters/cuda/common.hpp +++ b/source/adapters/cuda/common.hpp @@ -13,7 +13,7 @@ #include /** - * Call an UR API and, if the result is not UR_RESULT_SUCCESS, automatically + * Call a UR API and, if the result is not UR_RESULT_SUCCESS, automatically * return from the current function. */ #define UR_RETURN_ON_FAILURE(urCall) \ diff --git a/source/adapters/cuda/device.cpp b/source/adapters/cuda/device.cpp index 43de54457c..93c7b3208a 100644 --- a/source/adapters/cuda/device.cpp +++ b/source/adapters/cuda/device.cpp @@ -558,7 +558,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(cuDeviceGetAttribute( &ECCEnabled, CU_DEVICE_ATTRIBUTE_ECC_ENABLED, hDevice->get())); - if ((ECCEnabled != 0) | (ECCEnabled != 1)) { + if ((ECCEnabled != 0) || (ECCEnabled != 1)) { return UR_RESULT_ERROR_INVALID_OPERATION; } auto Result = static_cast(ECCEnabled); @@ -569,7 +569,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(cuDeviceGetAttribute( &IsIntegrated, CU_DEVICE_ATTRIBUTE_INTEGRATED, hDevice->get())); - if ((IsIntegrated != 0) | (IsIntegrated != 1)) { + if ((IsIntegrated != 0) || (IsIntegrated != 1)) { return UR_RESULT_ERROR_INVALID_OPERATION; } auto result = static_cast(IsIntegrated); @@ -852,9 +852,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_GLOBAL_MEM_FREE: { size_t FreeMemory = 0; size_t TotalMemory = 0; - if (cuMemGetInfo(&FreeMemory, &TotalMemory) != CUDA_SUCCESS) { - return UR_RESULT_ERROR_INVALID_OPERATION; - } + assert(cuMemGetInfo(&FreeMemory, &TotalMemory) != CUDA_SUCCESS && + "failed cuMemGetInfo() API."); return ReturnValue(FreeMemory); } case UR_DEVICE_INFO_MEMORY_CLOCK_RATE: { diff --git a/source/adapters/cuda/enqueue.cpp b/source/adapters/cuda/enqueue.cpp index 24e94e9e29..7049f3c9f9 100644 --- a/source/adapters/cuda/enqueue.cpp +++ b/source/adapters/cuda/enqueue.cpp @@ -844,24 +844,26 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferFill( } static ur_result_t imageElementByteSize(CUDA_ARRAY_DESCRIPTOR ArrayDesc, - int *Size) { + unsigned int *Size) { switch (ArrayDesc.Format) { case CU_AD_FORMAT_UNSIGNED_INT8: case CU_AD_FORMAT_SIGNED_INT8: *Size = 1; + break; case CU_AD_FORMAT_UNSIGNED_INT16: case CU_AD_FORMAT_SIGNED_INT16: case CU_AD_FORMAT_HALF: *Size = 2; + break; case CU_AD_FORMAT_UNSIGNED_INT32: case CU_AD_FORMAT_SIGNED_INT32: case CU_AD_FORMAT_FLOAT: *Size = 4; + break; default: - return UR_RESULT_ERROR_INVALID_IMAGE_SIZE; + return UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR; *Size = 0; } - return UR_RESULT_SUCCESS; } /// General ND memory copy operation for images (where N > 1). @@ -957,7 +959,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageRead( CUDA_ARRAY_DESCRIPTOR ArrayDesc; UR_CHECK_ERROR(cuArrayGetDescriptor(&ArrayDesc, Array)); - int ElementByteSize = 0; + unsigned int ElementByteSize = 0; UR_RETURN_ON_FAILURE(imageElementByteSize(ArrayDesc, &ElementByteSize)); size_t ByteOffsetX = origin.x * ElementByteSize * ArrayDesc.NumChannels; @@ -1030,7 +1032,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageWrite( CUDA_ARRAY_DESCRIPTOR ArrayDesc; UR_CHECK_ERROR(cuArrayGetDescriptor(&ArrayDesc, Array)); - int ElementByteSize = 0; + unsigned int ElementByteSize = 0; UR_RETURN_ON_FAILURE(imageElementByteSize(ArrayDesc, &ElementByteSize)); size_t ByteOffsetX = origin.x * ElementByteSize * ArrayDesc.NumChannels; @@ -1110,7 +1112,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageCopy( UR_ASSERT(SrcArrayDesc.NumChannels == DstArrayDesc.NumChannels, UR_RESULT_ERROR_INVALID_MEM_OBJECT); - int ElementByteSize = 0; + unsigned int ElementByteSize = 0; UR_RETURN_ON_FAILURE(imageElementByteSize(SrcArrayDesc, &ElementByteSize)); size_t DstByteOffsetX = diff --git a/source/adapters/cuda/event.cpp b/source/adapters/cuda/event.cpp index 070b81601d..1ea9c0d37d 100644 --- a/source/adapters/cuda/event.cpp +++ b/source/adapters/cuda/event.cpp @@ -113,9 +113,7 @@ ur_result_t ur_event_handle_t_::record() { try { EventID = Queue->getNextEventID(); - if (EventID == 0) { - return UR_RESULT_ERROR_INVALID_EVENT; - } + assert(EventID == 0 && "Unrecoverable program state reached in event identifier overflow."); UR_CHECK_ERROR(cuEventRecord(EvEnd, Stream)); } catch (ur_result_t error) { Result = error; @@ -238,9 +236,8 @@ urEventWait(uint32_t numEvents, const ur_event_handle_t *phEventWaitList) { UR_APIEXPORT ur_result_t UR_APICALL urEventRetain(ur_event_handle_t hEvent) { const auto RefCount = hEvent->incrementReferenceCount(); - if (RefCount == 0) { - return UR_RESULT_ERROR_INVALID_OPERATION; - } + assert(RefCount == 0 && + "Reference count overflow detected in urEventRetain."); return UR_RESULT_SUCCESS; } @@ -248,9 +245,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventRetain(ur_event_handle_t hEvent) { UR_APIEXPORT ur_result_t UR_APICALL urEventRelease(ur_event_handle_t hEvent) { // double delete or someone is messing with the ref count. // either way, cannot safely proceed. - if (hEvent->getReferenceCount() == 0) { - return UR_RESULT_ERROR_INVALID_OPERATION; - } + assert(hEvent->getReferenceCount() == 0 && "Unrecoverable program state reached in urEventRetain."); // decrement ref count. If it is 0, delete the event. if (hEvent->decrementReferenceCount() == 0) { diff --git a/source/adapters/cuda/memory.cpp b/source/adapters/cuda/memory.cpp index 4f0dcce012..184680d9ac 100644 --- a/source/adapters/cuda/memory.cpp +++ b/source/adapters/cuda/memory.cpp @@ -144,13 +144,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemRelease(ur_mem_handle_t hMem) { Result = UR_RESULT_ERROR_OUT_OF_RESOURCES; } - if (Result != UR_RESULT_SUCCESS) { - // A reported CUDA error is either an implementation or an asynchronous CUDA - // error for which it is unclear if the function that reported it succeeded - // or not. Either way, the state of the program is compromised and likely - // unrecoverable. - return UR_RESULT_ERROR_INVALID_OPERATION; - } + // A reported CUDA error is either an implementation or an asynchronous CUDA + // error for which it is unclear if the function that reported it succeeded + // or not. Either way, the state of the program is compromised and likely + // unrecoverable. + assert(Result != UR_RESULT_SUCCESS && "Unrecoverable program state reached in urMemRelease."); return UR_RESULT_SUCCESS; } @@ -306,7 +304,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageCreate( PixelTypeSizeBytes = 4; break; default: - return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; + return UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR; } // When a dimension isn't used pImageDesc has the size set to 1 diff --git a/source/adapters/cuda/queue.cpp b/source/adapters/cuda/queue.cpp index 955fe52bf7..f99a6c35b3 100644 --- a/source/adapters/cuda/queue.cpp +++ b/source/adapters/cuda/queue.cpp @@ -265,7 +265,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle( } else if (CuFlags == CU_STREAM_NON_BLOCKING) { Flags = UR_QUEUE_FLAG_SYNC_WITH_DEFAULT_STREAM; } else { - return UR_RESULT_ERROR_INVALID_OPERATION; + assert(!"Unknown cuda stream."); } std::vector ComputeCuStreams(1, CuStream); diff --git a/source/adapters/cuda/sampler.cpp b/source/adapters/cuda/sampler.cpp index 4c0592abf9..dd9dcfc028 100644 --- a/source/adapters/cuda/sampler.cpp +++ b/source/adapters/cuda/sampler.cpp @@ -83,9 +83,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urSamplerRelease(ur_sampler_handle_t hSampler) { // double delete or someone is messing with the ref count. // either way, cannot safely proceed. - if (hSampler->getReferenceCount() == 0) { - return UR_RESULT_ERROR_INVALID_OPERATION; - } + assert (hSampler->getReferenceCount() == 0 && "Reference count overflow detected in urSamplerRelease."); // decrement ref count. If it is 0, delete the sampler. if (hSampler->decrementReferenceCount() == 0) { diff --git a/source/adapters/hip/common.cpp b/source/adapters/hip/common.cpp index 8488c89845..285a346f78 100644 --- a/source/adapters/hip/common.cpp +++ b/source/adapters/hip/common.cpp @@ -179,19 +179,22 @@ ur_result_t urGetLastResult(ur_platform_handle_t, const char **ppMessage) { return ErrorMessageCode; } -ur_result_t GetHipFormatPixelSize(hipArray_Format Format, int *Size) { +ur_result_t imageElementByteSize(hipArray_Format Format, unsigned int *Size) { switch (Format) { case HIP_AD_FORMAT_UNSIGNED_INT8: case HIP_AD_FORMAT_SIGNED_INT8: *Size = 1; + break; case HIP_AD_FORMAT_UNSIGNED_INT16: case HIP_AD_FORMAT_SIGNED_INT16: case HIP_AD_FORMAT_HALF: *Size = 2; + break; case HIP_AD_FORMAT_UNSIGNED_INT32: case HIP_AD_FORMAT_SIGNED_INT32: case HIP_AD_FORMAT_FLOAT: *Size = 4; + break; default: return UR_RESULT_ERROR_IMAGE_FORMAT_NOT_SUPPORTED; } diff --git a/source/adapters/hip/common.hpp b/source/adapters/hip/common.hpp index 657c939292..fdbafe89e9 100644 --- a/source/adapters/hip/common.hpp +++ b/source/adapters/hip/common.hpp @@ -20,7 +20,7 @@ #include /** - * Call an UR API and, if the result is not UR_RESULT_SUCCESS, automatically + * Call a UR API and, if the result is not UR_RESULT_SUCCESS, automatically * return from the current function. */ #define UR_RETURN_ON_FAILURE(urCall) \ @@ -189,8 +189,8 @@ template class ReleaseGuard { // HIP error for which it is unclear if the function that reported it // succeeded or not. Either way, the state of the program is compromised // and likely unrecoverable. - detail::ur::hipPrint( - "Unrecoverable program state reached in piMemRelease"); + assert( + !"Unrecoverable program state reached in piMemRelease"); } } } @@ -208,4 +208,4 @@ template class ReleaseGuard { void dismiss() { Captive = nullptr; } }; -ur_result_t GetHipFormatPixelSize(hipArray_Format Format, int *Size); +ur_result_t imageElementByteSize(hipArray_Format Format, int *Size); diff --git a/source/adapters/hip/device.cpp b/source/adapters/hip/device.cpp index 981407b26d..6360948838 100644 --- a/source/adapters/hip/device.cpp +++ b/source/adapters/hip/device.cpp @@ -475,7 +475,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(hipDeviceGetAttribute( &EccEnabled, hipDeviceAttributeEccEnabled, hDevice->get())); - if ((EccEnabled != 0) | (EccEnabled != 1)) { + if ((EccEnabled != 0) || (EccEnabled != 1)) { return UR_RESULT_ERROR_INVALID_OPERATION; } auto Result = static_cast(EccEnabled); diff --git a/source/adapters/hip/enqueue.cpp b/source/adapters/hip/enqueue.cpp index 8b544ef4b7..0c19b9f240 100644 --- a/source/adapters/hip/enqueue.cpp +++ b/source/adapters/hip/enqueue.cpp @@ -1057,7 +1057,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageRead( UR_CHECK_ERROR(getArrayDesc(Array, Format, NumChannels)); int ElementByteSize = 0; - UR_RETURN_ON_FAILURE(GetHipFormatPixelSize(Format, &ElementByteSize)); + UR_RETURN_ON_FAILURE(imageElementByteSize(Format, &ElementByteSize)); size_t ByteOffsetX = origin.x * ElementByteSize * NumChannels; size_t BytesToCopy = ElementByteSize * NumChannels * region.depth; @@ -1119,7 +1119,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageWrite( UR_CHECK_ERROR(getArrayDesc(Array, Format, NumChannels)); int ElementByteSize = 0; - UR_RETURN_ON_FAILURE(GetHipFormatPixelSize(Format, &ElementByteSize)); + UR_RETURN_ON_FAILURE(imageElementByteSize(Format, &ElementByteSize)); size_t ByteOffsetX = origin.x * ElementByteSize * NumChannels; size_t BytesToCopy = ElementByteSize * NumChannels * region.depth; @@ -1194,7 +1194,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageCopy( UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR); int ElementByteSize = 0; - UR_RETURN_ON_FAILURE(GetHipFormatPixelSize(SrcFormat, &ElementByteSize)); + UR_RETURN_ON_FAILURE(imageElementByteSize(SrcFormat, &ElementByteSize)); size_t DstByteOffsetX = dstOrigin.x * ElementByteSize * SrcNumChannels; size_t SrcByteOffsetX = srcOrigin.x * ElementByteSize * DstNumChannels; diff --git a/source/adapters/hip/event.cpp b/source/adapters/hip/event.cpp index fb89088b87..bec0934382 100644 --- a/source/adapters/hip/event.cpp +++ b/source/adapters/hip/event.cpp @@ -141,9 +141,7 @@ ur_result_t ur_event_handle_t_::record() { try { EventId = Queue->getNextEventId(); - if (EventId == 0) { - return UR_RESULT_ERROR_INVALID_OPERATION; - } + assert (EventId == 0 && "Unrecoverable program state reached in event identifier overflow."); UR_CHECK_ERROR(hipEventRecord(EvEnd, Stream)); Result = UR_RESULT_SUCCESS; } catch (ur_result_t Error) { @@ -278,9 +276,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventSetCallback(ur_event_handle_t, UR_APIEXPORT ur_result_t UR_APICALL urEventRetain(ur_event_handle_t hEvent) { const auto RefCount = hEvent->incrementReferenceCount(); - if (RefCount == 0) { - return UR_RESULT_ERROR_INVALID_OPERATION; - } + assert(RefCount == 0 && "Reference count overflow detected in urEventRetain."); return UR_RESULT_SUCCESS; } @@ -288,9 +284,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventRetain(ur_event_handle_t hEvent) { UR_APIEXPORT ur_result_t UR_APICALL urEventRelease(ur_event_handle_t hEvent) { // double delete or someone is messing with the ref count. // either way, cannot safely proceed. - if (hEvent->getReferenceCount() == 0) { - return UR_RESULT_ERROR_INVALID_OPERATION; - } + assert(hEvent->getReferenceCount() == 0 && "Reference count overflow detected in urEventRelease."); // decrement ref count. If it is 0, delete the event. if (hEvent->decrementReferenceCount() == 0) { diff --git a/source/adapters/hip/memory.cpp b/source/adapters/hip/memory.cpp index 6d230a9508..827dcb287f 100644 --- a/source/adapters/hip/memory.cpp +++ b/source/adapters/hip/memory.cpp @@ -71,7 +71,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemRelease(ur_mem_handle_t hMem) { // error for which it is unclear if the function that reported it succeeded // or not. Either way, the state of the program is compromised and likely // unrecoverable. - return UR_RESULT_ERROR_INVALID_OPERATION; + assert(!"Unrecoverable program state reached in urMemRelease"); } return UR_RESULT_SUCCESS; @@ -246,9 +246,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemGetInfo(ur_mem_handle_t hMemory, #else HIP_ARRAY3D_DESCRIPTOR ArrayDescriptor; UR_CHECK_ERROR(hipArray3DGetDescriptor(&ArrayDescriptor, Mem.Array)); - auto PixelSize = 0; + int PixelSize = 0; UR_RETURN_ON_FAILURE( - GetHipFormatPixelSize(ArrayDescriptor.Format, &PixelSize)); + imageElementByteSize(ArrayDescriptor.Format, &PixelSize)); const auto PixelSizeBytes = PixelSize * ArrayDescriptor.NumChannels; const auto ImageSizeBytes = PixelSizeBytes * @@ -397,7 +397,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageGetInfo(ur_mem_handle_t hMemory, return ReturnValue(ArrayInfo.Depth); case UR_IMAGE_INFO_ELEMENT_SIZE: { int Size = 0; - UR_RETURN_ON_FAILURE(GetHipFormatPixelSize(ArrayInfo.Format, &Size)); + UR_RETURN_ON_FAILURE(imageElementByteSize(ArrayInfo.Format, &Size)); return ReturnValue(Size); } case UR_IMAGE_INFO_ROW_PITCH: diff --git a/source/adapters/hip/queue.cpp b/source/adapters/hip/queue.cpp index c01cd7fe33..dc8dc7bd09 100644 --- a/source/adapters/hip/queue.cpp +++ b/source/adapters/hip/queue.cpp @@ -292,7 +292,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle( } else if (HIPFlags == hipStreamNonBlocking) { Flags = UR_QUEUE_FLAG_SYNC_WITH_DEFAULT_STREAM; } else { - return UR_RESULT_ERROR_INVALID_OPERATION; + assert(!"Unknown hip stream."); } std::vector ComputeHIPStreams(1, HIPStream); diff --git a/source/adapters/hip/sampler.cpp b/source/adapters/hip/sampler.cpp index e3d85bb14e..d307fe7616 100644 --- a/source/adapters/hip/sampler.cpp +++ b/source/adapters/hip/sampler.cpp @@ -68,9 +68,7 @@ ur_result_t urSamplerRetain(ur_sampler_handle_t hSampler) { ur_result_t urSamplerRelease(ur_sampler_handle_t hSampler) { // double delete or someone is messing with the ref count. // either way, cannot safely proceed. - if (hSampler->getReferenceCount() == 0) { - return UR_RESULT_ERROR_INVALID_OPERATION; - } + assert(hSampler->getReferenceCount() == 0 && "Reference count overflow detected in urSamplerRelease."); // decrement ref count. If it is 0, delete the sampler. if (hSampler->decrementReferenceCount() == 0) { diff --git a/source/adapters/level_zero/context.cpp b/source/adapters/level_zero/context.cpp index 27ac5de530..92afb4c4c3 100644 --- a/source/adapters/level_zero/context.cpp +++ b/source/adapters/level_zero/context.cpp @@ -566,9 +566,7 @@ ur_context_handle_t_::decrementUnreleasedEventsInPool(ur_event_handle_t Event) { getZeEventPoolCache(Event->isHostVisible(), Event->isProfilingEnabled()); // Put the empty pool to the cache of the pools. - if (NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0) { - return UR_RESULT_ERROR_INVALID_OPERATION; - } + assert(NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0 && "Invalid event release: event pool doesn't have unreleased events"); if (--NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0) { if (ZePoolCache->front() != Event->ZeEventPool) { ZePoolCache->push_back(Event->ZeEventPool); diff --git a/source/adapters/level_zero/event.cpp b/source/adapters/level_zero/event.cpp index c89ce1a797..1b25bf5940 100644 --- a/source/adapters/level_zero/event.cpp +++ b/source/adapters/level_zero/event.cpp @@ -585,9 +585,7 @@ ur_result_t ur_event_handle_t_::getOrCreateHostVisibleEvent( this->Mutex); if (!HostVisibleEvent) { - if (UrQueue->ZeEventsScope != OnDemandHostVisibleProxy) { - return UR_RESULT_ERROR_INVALID_EVENT; - } + assert(UrQueue->ZeEventsScope != OnDemandHostVisibleProxy && "getOrCreateHostVisibleEvent: missing host-visible event"); // Submit the command(s) signalling the proxy event to the queue. // We have to first submit a wait for the device-only event for which this @@ -633,9 +631,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventWait( // ur_event_handle_t_ *Event = ur_cast(EventWaitList[I]); - if (!Event->hasExternalRefs()) { - return UR_RESULT_ERROR_INVALID_OPERATION; - } + assert(!Event->hasExternalRefs() && "urEventsWait must not be called for an internal event"); ze_event_handle_t ZeHostVisibleEvent; if (auto Res = Event->getOrCreateHostVisibleEvent(ZeHostVisibleEvent)) @@ -660,15 +656,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventWait( ur_cast(EventWaitList[I]); { std::shared_lock EventLock(Event->Mutex); - if (!Event->hasExternalRefs()) { - return UR_RESULT_ERROR_INVALID_OPERATION; - } + assert(!Event->hasExternalRefs() && "urEventWait must not be called for an internal event"); if (!Event->Completed) { auto HostVisibleEvent = Event->HostVisibleEvent; - if (!HostVisibleEvent) { - return UR_RESULT_ERROR_INVALID_EVENT; - } + assert(!HostVisibleEvent && "The host-visible proxy event missing"); ze_event_handle_t ZeEvent = HostVisibleEvent->ZeEvent; urPrint("ZeEvent = %#llx\n", ur_cast(ZeEvent)); diff --git a/source/adapters/level_zero/memory.cpp b/source/adapters/level_zero/memory.cpp index c46671ea16..5676bc4b72 100644 --- a/source/adapters/level_zero/memory.cpp +++ b/source/adapters/level_zero/memory.cpp @@ -2176,8 +2176,7 @@ ur_result_t _ur_buffer::getZeHandle(char *&ZeHandle, access_mode_t AccessMode, // If some prior access invalidated this allocation then make it valid again. if (!Allocation.Valid) { // LastDeviceWithValidAllocation should always have valid allocation. - if (Device == LastDeviceWithValidAllocation) - return UR_RESULT_ERROR_INVALID_OPERATION; + assert(Device == LastDeviceWithValidAllocation && "getZeHandle: last used allocation is not valid."); // For write-only access the allocation contents is not going to be used. // So don't do anything to make it "valid". @@ -2300,7 +2299,7 @@ ur_result_t _ur_buffer::free() { ZeUSMImport.doZeUSMRelease(UrContext->getPlatform()->ZeDriver, ZeHandle); break; default: - return UR_RESULT_ERROR_INVALID_OPERATION; + assert(!"_ur_buffer::free(): Unhandled release action"); } ZeHandle = nullptr; // don't leave hanging pointers } diff --git a/source/adapters/level_zero/queue.cpp b/source/adapters/level_zero/queue.cpp index 39027474ec..bd99b5945a 100644 --- a/source/adapters/level_zero/queue.cpp +++ b/source/adapters/level_zero/queue.cpp @@ -819,7 +819,7 @@ static const zeCommandListBatchConfig ZeCommandListBatchConfig(bool IsCopy) { Config.NumTimesClosedFullThreshold = Val; break; default: - urPrint("Unexpected batch config"); + assert(!"Unexpected batch config"); } if (IsCopy) urPrint("UR_L0_COPY_BATCH_SIZE: dynamic batch param " @@ -937,7 +937,7 @@ ur_queue_handle_t_::ur_queue_handle_t_( ComputeQueueGroup.UpperIndex = FilterUpperIndex; ComputeQueueGroup.NextIndex = ComputeQueueGroup.LowerIndex; } else { - urPrint("No compute queue available/allowed."); + assert(!"No compute queue available/allowed."); } } if (UsingImmCmdLists) { @@ -1092,9 +1092,9 @@ ur_queue_handle_t_::executeCommandList(ur_command_list_ptr_t CommandList, if (OKToBatchCommand && this->isBatchingAllowed(UseCopyEngine) && (!ZeCommandListBatchConfig.dynamic() || !CurrentlyEmpty)) { - if (hasOpenCommandList(UseCopyEngine) && - CommandBatch.OpenCommandList != CommandList) - return UR_RESULT_ERROR_INVALID_ARGUMENT; + assert((hasOpenCommandList(UseCopyEngine) && + CommandBatch.OpenCommandList != CommandList) && "executeCommandList: OpenCommandList should be equal to" + "null or CommandList"); if (CommandList->second.size() < CommandBatch.QueueBatchSize) { CommandBatch.OpenCommandList = CommandList; @@ -1818,7 +1818,7 @@ ur_queue_handle_t_::ur_queue_group_t::getZeQueue(uint32_t *QueueGroupOrdinal) { zeCommandQueueCreate, (Queue->Context->ZeContext, Queue->Device->ZeDevice, &ZeCommandQueueDesc, &ZeQueue)); if (ZeResult) { - urPrint("[L0] getZeQueue: failed to create queue"); + assert(!"[L0] getZeQueue: failed to create queue"); } return ZeQueue; diff --git a/source/adapters/level_zero/usm.cpp b/source/adapters/level_zero/usm.cpp index bda813ee5e..883ff32b8c 100644 --- a/source/adapters/level_zero/usm.cpp +++ b/source/adapters/level_zero/usm.cpp @@ -948,9 +948,7 @@ ur_result_t ZeMemFreeHelper(ur_context_handle_t Context, void *Ptr) { if (IndirectAccessTrackingEnabled) { ContextsLock.lock(); auto It = Context->MemAllocs.find(Ptr); - if (It == std::end(Context->MemAllocs)) { - return UR_RESULT_ERROR_INVALID_OPERATION; - } + assert(It == std::end(Context->MemAllocs) && "All memory allocations must be tracked!"); if (!It->second.RefCount.decrementAndTest()) { // Memory can't be deallocated yet. return UR_RESULT_SUCCESS; @@ -995,9 +993,7 @@ ur_result_t USMFreeHelper(ur_context_handle_t Context, void *Ptr, if (IndirectAccessTrackingEnabled) { auto It = Context->MemAllocs.find(Ptr); - if (It == std::end(Context->MemAllocs)) { - return UR_RESULT_ERROR_INVALID_OPERATION; - } + assert(It == std::end(Context->MemAllocs) && "All memory allocations must be tracked!"); if (!It->second.RefCount.decrementAndTest()) { // Memory can't be deallocated yet. return UR_RESULT_SUCCESS; diff --git a/source/adapters/opencl/common.hpp b/source/adapters/opencl/common.hpp index 9fcfb29c61..7f2d823efc 100644 --- a/source/adapters/opencl/common.hpp +++ b/source/adapters/opencl/common.hpp @@ -24,7 +24,7 @@ } /** - * Call an UR API and, if the result is not UR_RESULT_SUCCESS, automatically + * Call a UR API and, if the result is not UR_RESULT_SUCCESS, automatically * return from the current function. */ #define UR_RETURN_ON_FAILURE(urCall) \