diff --git a/source/adapters/cuda/common.cpp b/source/adapters/cuda/common.cpp index 9f2a330262..f24df17beb 100644 --- a/source/adapters/cuda/common.cpp +++ b/source/adapters/cuda/common.cpp @@ -100,16 +100,6 @@ std::string getCudaVersionString() { return stream.str(); } -void detail::ur::die(const char *Message) { - std::cerr << "ur_die: " << Message << std::endl; - std::terminate(); -} - -void detail::ur::assertion(bool Condition, const char *Message) { - if (!Condition) - die(Message); -} - void detail::ur::cuPrint(const char *Message) { std::cerr << "ur_print: " << Message << std::endl; } diff --git a/source/adapters/cuda/common.hpp b/source/adapters/cuda/common.hpp index 67223c45bc..1ec184f71b 100644 --- a/source/adapters/cuda/common.hpp +++ b/source/adapters/cuda/common.hpp @@ -12,6 +12,16 @@ #include #include +/** + * Call an UR API and, if the result is not UR_RESULT_SUCCESS, automatically + * return from the current function. + */ +#define UR_RETURN_ON_FAILURE(urCall) \ + if (const ur_result_t ur_result_macro = urCall; \ + ur_result_macro != UR_RESULT_SUCCESS) { \ + return ur_result_macro; \ + } + ur_result_t mapErrorUR(CUresult Result); /// Converts CUDA error into UR error codes, and outputs error information @@ -46,16 +56,8 @@ void setPluginSpecificMessage(CUresult cu_res); namespace detail { namespace ur { -// Report error and no return (keeps compiler from printing warnings). -// TODO: Probably change that to throw a catchable exception, -// but for now it is useful to see every failure. -// -[[noreturn]] void die(const char *Message); - // Reports error messages void cuPrint(const char *Message); -void assertion(bool Condition, const char *Message = nullptr); - } // namespace ur } // namespace detail diff --git a/source/adapters/cuda/device.cpp b/source/adapters/cuda/device.cpp index a4877236ae..12b75dbe9e 100644 --- a/source/adapters/cuda/device.cpp +++ b/source/adapters/cuda/device.cpp @@ -59,7 +59,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(cuDeviceGetAttribute( &ComputeUnits, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT, hDevice->get())); - detail::ur::assertion(ComputeUnits >= 0); + if (ComputeUnits < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(static_cast(ComputeUnits)); } case UR_DEVICE_INFO_MAX_WORK_ITEM_DIMENSIONS: { @@ -73,15 +75,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int MaxX = 0, MaxY = 0, MaxZ = 0; UR_CHECK_ERROR(cuDeviceGetAttribute( &MaxX, CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_X, hDevice->get())); - detail::ur::assertion(MaxX >= 0); + if (MaxX < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } UR_CHECK_ERROR(cuDeviceGetAttribute( &MaxY, CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Y, hDevice->get())); - detail::ur::assertion(MaxY >= 0); + if (MaxY < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } UR_CHECK_ERROR(cuDeviceGetAttribute( &MaxZ, CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Z, hDevice->get())); - detail::ur::assertion(MaxZ >= 0); + if (MaxZ < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } ReturnSizes.Sizes[0] = size_t(MaxX); ReturnSizes.Sizes[1] = size_t(MaxY); @@ -96,15 +104,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int MaxX = 0, MaxY = 0, MaxZ = 0; UR_CHECK_ERROR(cuDeviceGetAttribute( &MaxX, CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_X, hDevice->get())); - detail::ur::assertion(MaxX >= 0); + if (MaxX < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } UR_CHECK_ERROR(cuDeviceGetAttribute( &MaxY, CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Y, hDevice->get())); - detail::ur::assertion(MaxY >= 0); + if (MaxY < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } UR_CHECK_ERROR(cuDeviceGetAttribute( &MaxZ, CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Z, hDevice->get())); - detail::ur::assertion(MaxZ >= 0); + if (MaxZ < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } ReturnSizes.Sizes[0] = size_t(MaxX); ReturnSizes.Sizes[1] = size_t(MaxY); @@ -118,7 +132,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, &MaxWorkGroupSize, CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK, hDevice->get())); - detail::ur::assertion(MaxWorkGroupSize >= 0); + if (MaxWorkGroupSize < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(size_t(MaxWorkGroupSize)); } @@ -261,7 +277,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int ClockFreq = 0; UR_CHECK_ERROR(cuDeviceGetAttribute( &ClockFreq, CU_DEVICE_ATTRIBUTE_CLOCK_RATE, hDevice->get())); - detail::ur::assertion(ClockFreq >= 0); + if (ClockFreq < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(static_cast(ClockFreq) / 1000u); } case UR_DEVICE_INFO_ADDRESS_BITS: { @@ -305,12 +323,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(cuDeviceGetAttribute( &TexHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_HEIGHT, hDevice->get())); - detail::ur::assertion(TexHeight >= 0); + if (TexHeight < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int SurfHeight = 0; UR_CHECK_ERROR(cuDeviceGetAttribute( &SurfHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_HEIGHT, hDevice->get())); - detail::ur::assertion(SurfHeight >= 0); + if (SurfHeight < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int Min = std::min(TexHeight, SurfHeight); @@ -322,12 +344,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(cuDeviceGetAttribute( &TexWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_WIDTH, hDevice->get())); - detail::ur::assertion(TexWidth >= 0); + if (TexWidth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int SurfWidth = 0; UR_CHECK_ERROR(cuDeviceGetAttribute( &SurfWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_WIDTH, hDevice->get())); - detail::ur::assertion(SurfWidth >= 0); + if (SurfWidth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int Min = std::min(TexWidth, SurfWidth); @@ -339,12 +365,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(cuDeviceGetAttribute( &TexHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_HEIGHT, hDevice->get())); - detail::ur::assertion(TexHeight >= 0); + if (TexHeight < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int SurfHeight = 0; UR_CHECK_ERROR(cuDeviceGetAttribute( &SurfHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_HEIGHT, hDevice->get())); - detail::ur::assertion(SurfHeight >= 0); + if (SurfHeight < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int Min = std::min(TexHeight, SurfHeight); @@ -356,12 +386,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(cuDeviceGetAttribute( &TexWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_WIDTH, hDevice->get())); - detail::ur::assertion(TexWidth >= 0); + if (TexWidth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int SurfWidth = 0; UR_CHECK_ERROR(cuDeviceGetAttribute( &SurfWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_WIDTH, hDevice->get())); - detail::ur::assertion(SurfWidth >= 0); + if (SurfWidth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int Min = std::min(TexWidth, SurfWidth); @@ -373,12 +407,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(cuDeviceGetAttribute( &TexDepth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_DEPTH, hDevice->get())); - detail::ur::assertion(TexDepth >= 0); + if (TexDepth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int SurfDepth = 0; UR_CHECK_ERROR(cuDeviceGetAttribute( &SurfDepth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_DEPTH, hDevice->get())); - detail::ur::assertion(SurfDepth >= 0); + if (SurfDepth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int Min = std::min(TexDepth, SurfDepth); @@ -390,12 +428,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(cuDeviceGetAttribute( &TexWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_WIDTH, hDevice->get())); - detail::ur::assertion(TexWidth >= 0); + if (TexWidth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int SurfWidth = 0; UR_CHECK_ERROR(cuDeviceGetAttribute( &SurfWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE1D_WIDTH, hDevice->get())); - detail::ur::assertion(SurfWidth >= 0); + if (SurfWidth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int Min = std::min(TexWidth, SurfWidth); @@ -464,15 +506,18 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int CacheSize = 0; UR_CHECK_ERROR(cuDeviceGetAttribute( &CacheSize, CU_DEVICE_ATTRIBUTE_L2_CACHE_SIZE, hDevice->get())); - detail::ur::assertion(CacheSize >= 0); + if (CacheSize < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } // The L2 cache is global to the GPU. return ReturnValue(static_cast(CacheSize)); } case UR_DEVICE_INFO_GLOBAL_MEM_SIZE: { size_t Bytes = 0; // Runtime API has easy access to this value, driver API info is scarse. - detail::ur::assertion(cuDeviceTotalMem(&Bytes, hDevice->get()) == - CUDA_SUCCESS); + if (cuDeviceTotalMem(&Bytes, hDevice->get()) != CUDA_SUCCESS) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } return ReturnValue(uint64_t{Bytes}); } case UR_DEVICE_INFO_MAX_CONSTANT_BUFFER_SIZE: { @@ -480,7 +525,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(cuDeviceGetAttribute( &ConstantMemory, CU_DEVICE_ATTRIBUTE_TOTAL_CONSTANT_MEMORY, hDevice->get())); - detail::ur::assertion(ConstantMemory >= 0); + if (ConstantMemory < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(static_cast(ConstantMemory)); } @@ -510,7 +557,9 @@ 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())); - detail::ur::assertion((ECCEnabled == 0) | (ECCEnabled == 1)); + if ((ECCEnabled != 0) | (ECCEnabled != 1)) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } auto Result = static_cast(ECCEnabled); return ReturnValue(Result); } @@ -519,7 +568,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(cuDeviceGetAttribute( &IsIntegrated, CU_DEVICE_ATTRIBUTE_INTEGRATED, hDevice->get())); - detail::ur::assertion((IsIntegrated == 0) | (IsIntegrated == 1)); + if ((IsIntegrated != 0) | (IsIntegrated != 1)) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } auto result = static_cast(IsIntegrated); return ReturnValue(result); } @@ -800,16 +851,18 @@ 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; - detail::ur::assertion(cuMemGetInfo(&FreeMemory, &TotalMemory) == - CUDA_SUCCESS, - "failed cuMemGetInfo() API."); + if (cuMemGetInfo(&FreeMemory, &TotalMemory) != CUDA_SUCCESS) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } return ReturnValue(FreeMemory); } case UR_DEVICE_INFO_MEMORY_CLOCK_RATE: { int Value = 0; UR_CHECK_ERROR(cuDeviceGetAttribute( &Value, CU_DEVICE_ATTRIBUTE_MEMORY_CLOCK_RATE, hDevice->get())); - detail::ur::assertion(Value >= 0); + if (Value < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } // Convert kilohertz to megahertz when returning. return ReturnValue(Value / 1000); } @@ -817,7 +870,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int Value = 0; UR_CHECK_ERROR(cuDeviceGetAttribute( &Value, CU_DEVICE_ATTRIBUTE_GLOBAL_MEMORY_BUS_WIDTH, hDevice->get())); - detail::ur::assertion(Value >= 0); + if (Value < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(Value); } case UR_DEVICE_INFO_MAX_COMPUTE_QUEUE_INDICES: { @@ -905,17 +960,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int Value = 0; UR_CHECK_ERROR(cuDeviceGetAttribute( &Value, CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID, hDevice->get())); - detail::ur::assertion(Value >= 0); + if (Value < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(Value); } case UR_DEVICE_INFO_UUID: { CUuuid UUID; #if (CUDA_VERSION >= 11040) - detail::ur::assertion(cuDeviceGetUuid_v2(&UUID, hDevice->get()) == - CUDA_SUCCESS); + if (cuDeviceGetUuid_v2(&UUID, hDevice->get()) != CUDA_SUCCESS) { + return UR_RESULT_ERROR_INVALID_DEVICE; + } #else - detail::ur::assertion(cuDeviceGetUuid(&UUID, hDevice->get()) == - CUDA_SUCCESS); + if (cuDeviceGetUuid(&UUID, hDevice->get()) != CUDA_SUCCESS) { + return UR_RESULT_ERROR_INVALID_DEVICE; + } #endif std::array Name; std::copy(UUID.bytes, UUID.bytes + 16, Name.begin()); @@ -994,7 +1053,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, &MaxRegisters, CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_BLOCK, hDevice->get())); - detail::ur::assertion(MaxRegisters >= 0); + if (MaxRegisters < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(static_cast(MaxRegisters)); } @@ -1008,7 +1069,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR( cuDeviceGetPCIBusId(AddressBuffer, AddressBufferSize, hDevice->get())); // CUDA API (8.x - 12.1) guarantees 12 bytes + \0 are written - detail::ur::assertion(strnlen(AddressBuffer, AddressBufferSize) == 12); + if (strnlen(AddressBuffer, AddressBufferSize) != 12) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } return ReturnValue(AddressBuffer, strnlen(AddressBuffer, AddressBufferSize - 1) + 1); } diff --git a/source/adapters/cuda/enqueue.cpp b/source/adapters/cuda/enqueue.cpp index c752c3fd14..24e94e9e29 100644 --- a/source/adapters/cuda/enqueue.cpp +++ b/source/adapters/cuda/enqueue.cpp @@ -843,23 +843,25 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferFill( } } -static size_t imageElementByteSize(CUDA_ARRAY_DESCRIPTOR ArrayDesc) { +static ur_result_t imageElementByteSize(CUDA_ARRAY_DESCRIPTOR ArrayDesc, + int *Size) { switch (ArrayDesc.Format) { case CU_AD_FORMAT_UNSIGNED_INT8: case CU_AD_FORMAT_SIGNED_INT8: - return 1; + *Size = 1; case CU_AD_FORMAT_UNSIGNED_INT16: case CU_AD_FORMAT_SIGNED_INT16: case CU_AD_FORMAT_HALF: - return 2; + *Size = 2; case CU_AD_FORMAT_UNSIGNED_INT32: case CU_AD_FORMAT_SIGNED_INT32: case CU_AD_FORMAT_FLOAT: - return 4; + *Size = 4; default: - detail::ur::die("Invalid image format."); - return 0; + return UR_RESULT_ERROR_INVALID_IMAGE_SIZE; + *Size = 0; } + return UR_RESULT_SUCCESS; } /// General ND memory copy operation for images (where N > 1). @@ -955,7 +957,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageRead( CUDA_ARRAY_DESCRIPTOR ArrayDesc; UR_CHECK_ERROR(cuArrayGetDescriptor(&ArrayDesc, Array)); - int ElementByteSize = imageElementByteSize(ArrayDesc); + int ElementByteSize = 0; + UR_RETURN_ON_FAILURE(imageElementByteSize(ArrayDesc, &ElementByteSize)); size_t ByteOffsetX = origin.x * ElementByteSize * ArrayDesc.NumChannels; size_t BytesToCopy = ElementByteSize * ArrayDesc.NumChannels * region.width; @@ -1027,7 +1030,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageWrite( CUDA_ARRAY_DESCRIPTOR ArrayDesc; UR_CHECK_ERROR(cuArrayGetDescriptor(&ArrayDesc, Array)); - int ElementByteSize = imageElementByteSize(ArrayDesc); + int ElementByteSize = 0; + UR_RETURN_ON_FAILURE(imageElementByteSize(ArrayDesc, &ElementByteSize)); size_t ByteOffsetX = origin.x * ElementByteSize * ArrayDesc.NumChannels; size_t BytesToCopy = ElementByteSize * ArrayDesc.NumChannels * region.width; @@ -1106,7 +1110,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageCopy( UR_ASSERT(SrcArrayDesc.NumChannels == DstArrayDesc.NumChannels, UR_RESULT_ERROR_INVALID_MEM_OBJECT); - int ElementByteSize = imageElementByteSize(SrcArrayDesc); + int ElementByteSize = 0; + UR_RETURN_ON_FAILURE(imageElementByteSize(SrcArrayDesc, &ElementByteSize)); size_t DstByteOffsetX = dstOrigin.x * ElementByteSize * SrcArrayDesc.NumChannels; diff --git a/source/adapters/cuda/event.cpp b/source/adapters/cuda/event.cpp index 6137f0ecce..23a6609b59 100644 --- a/source/adapters/cuda/event.cpp +++ b/source/adapters/cuda/event.cpp @@ -121,8 +121,7 @@ ur_result_t ur_event_handle_t_::record() { try { EventID = Queue->getNextEventID(); if (EventID == 0) { - detail::ur::die( - "Unrecoverable program state reached in event identifier overflow"); + return UR_RESULT_ERROR_INVALID_EVENT; } UR_CHECK_ERROR(cuEventRecord(EvEnd, Stream)); } catch (ur_result_t error) { @@ -183,10 +182,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(ur_event_handle_t hEvent, case UR_EVENT_INFO_CONTEXT: return ReturnValue(hEvent->getContext()); default: - detail::ur::die("Event info request not implemented"); + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; } - - return UR_RESULT_ERROR_INVALID_ENUMERATION; } /// Obtain profiling information from PI CUDA events @@ -213,8 +210,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo( default: break; } - detail::ur::die("Event Profiling info request not implemented"); - return {}; + + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; } UR_APIEXPORT ur_result_t UR_APICALL urEventSetCallback(ur_event_handle_t, @@ -248,8 +245,9 @@ 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(); - detail::ur::assertion(RefCount != 0, - "Reference count overflow detected in urEventRetain."); + if (RefCount == 0) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } return UR_RESULT_SUCCESS; } @@ -257,8 +255,9 @@ 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. - detail::ur::assertion(hEvent->getReferenceCount() != 0, - "Reference count overflow detected in urEventRelease."); + if (hEvent->getReferenceCount() == 0) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } // decrement ref count. If it is 0, delete the event. if (hEvent->decrementReferenceCount() == 0) { diff --git a/source/adapters/cuda/image.cpp b/source/adapters/cuda/image.cpp index 7ec53bd8bc..26ba1d0dea 100644 --- a/source/adapters/cuda/image.cpp +++ b/source/adapters/cuda/image.cpp @@ -781,7 +781,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageGetInfoExp( ChannelOrder = UR_IMAGE_CHANNEL_ORDER_RGBA; break; default: - die("Unexpected NumChannels returned by CUDA"); + return UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR; } if (pPropValue) { ((ur_image_format_t *)pPropValue)->channelType = ChannelType; diff --git a/source/adapters/cuda/memory.cpp b/source/adapters/cuda/memory.cpp index 824ab1f580..4f0dcce012 100644 --- a/source/adapters/cuda/memory.cpp +++ b/source/adapters/cuda/memory.cpp @@ -149,7 +149,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. - detail::ur::die("Unrecoverable program state reached in urMemRelease"); + return UR_RESULT_ERROR_INVALID_OPERATION; } return UR_RESULT_SUCCESS; @@ -306,8 +306,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageCreate( PixelTypeSizeBytes = 4; break; default: - detail::ur::die( - "urMemImageCreate given unsupported image_channel_data_type"); + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; } // 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 120d665524..955fe52bf7 100644 --- a/source/adapters/cuda/queue.cpp +++ b/source/adapters/cuda/queue.cpp @@ -260,12 +260,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle( UR_CHECK_ERROR(cuStreamGetFlags(CuStream, &CuFlags)); ur_queue_flags_t Flags = 0; - if (CuFlags == CU_STREAM_DEFAULT) + if (CuFlags == CU_STREAM_DEFAULT) { Flags = UR_QUEUE_FLAG_USE_DEFAULT_STREAM; - else if (CuFlags == CU_STREAM_NON_BLOCKING) + } else if (CuFlags == CU_STREAM_NON_BLOCKING) { Flags = UR_QUEUE_FLAG_SYNC_WITH_DEFAULT_STREAM; - else - detail::ur::die("Unknown cuda stream"); + } else { + return UR_RESULT_ERROR_INVALID_OPERATION; + } std::vector ComputeCuStreams(1, CuStream); std::vector TransferCuStreams(0); diff --git a/source/adapters/cuda/sampler.cpp b/source/adapters/cuda/sampler.cpp index 5c6b91de65..a6aedb939c 100644 --- a/source/adapters/cuda/sampler.cpp +++ b/source/adapters/cuda/sampler.cpp @@ -84,9 +84,9 @@ 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. - detail::ur::assertion( - hSampler->getReferenceCount() != 0, - "Reference count overflow detected in urSamplerRelease."); + if (hSampler->getReferenceCount() == 0) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } // decrement ref count. If it is 0, delete the sampler. if (hSampler->decrementReferenceCount() == 0) { diff --git a/source/adapters/hip/command_buffer.cpp b/source/adapters/hip/command_buffer.cpp index 3f68b88d8d..3dd20ee496 100644 --- a/source/adapters/hip/command_buffer.cpp +++ b/source/adapters/hip/command_buffer.cpp @@ -16,29 +16,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp( ur_context_handle_t, ur_device_handle_t, const ur_exp_command_buffer_desc_t *, ur_exp_command_buffer_handle_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for HIP adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferRetainExp(ur_exp_command_buffer_handle_t) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for HIP adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for HIP adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for HIP adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -47,8 +39,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp( const size_t *, const size_t *, const size_t *, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for HIP adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -56,8 +46,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemcpyUSMExp( ur_exp_command_buffer_handle_t, void *, const void *, size_t, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for HIP adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -65,8 +53,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMembufferCopyExp( ur_exp_command_buffer_handle_t, ur_mem_handle_t, ur_mem_handle_t, size_t, size_t, size_t, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for HIP adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -75,8 +61,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMembufferCopyRectExp( ur_rect_offset_t, ur_rect_offset_t, ur_rect_region_t, size_t, size_t, size_t, size_t, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for HIP adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -85,8 +69,6 @@ ur_result_t UR_APICALL urCommandBufferAppendMembufferWriteExp( ur_exp_command_buffer_handle_t, ur_mem_handle_t, size_t, size_t, const void *, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for HIP adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -95,8 +77,6 @@ ur_result_t UR_APICALL urCommandBufferAppendMembufferReadExp( ur_exp_command_buffer_handle_t, ur_mem_handle_t, size_t, size_t, void *, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for HIP adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -106,8 +86,6 @@ ur_result_t UR_APICALL urCommandBufferAppendMembufferWriteRectExp( ur_rect_offset_t, ur_rect_region_t, size_t, size_t, size_t, size_t, void *, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for HIP adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -117,15 +95,11 @@ ur_result_t UR_APICALL urCommandBufferAppendMembufferReadRectExp( ur_rect_offset_t, ur_rect_region_t, size_t, size_t, size_t, size_t, void *, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for HIP adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferEnqueueExp( ur_exp_command_buffer_handle_t, ur_queue_handle_t, uint32_t, const ur_event_handle_t *, ur_event_handle_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for HIP adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/hip/common.cpp b/source/adapters/hip/common.cpp index f1f8ec4fbb..8488c89845 100644 --- a/source/adapters/hip/common.cpp +++ b/source/adapters/hip/common.cpp @@ -156,16 +156,6 @@ hipError_t getHipVersionString(std::string &Version) { return Result; } -void detail::ur::die(const char *pMessage) { - std::cerr << "ur_die: " << pMessage << '\n'; - std::terminate(); -} - -void detail::ur::assertion(bool Condition, const char *pMessage) { - if (!Condition) - die(pMessage); -} - void detail::ur::hipPrint(const char *pMessage) { std::cerr << "ur_print: " << pMessage << '\n'; } @@ -188,3 +178,21 @@ ur_result_t urGetLastResult(ur_platform_handle_t, const char **ppMessage) { *ppMessage = &ErrorMessage[0]; return ErrorMessageCode; } + +ur_result_t GetHipFormatPixelSize(hipArray_Format Format, int *Size) { + switch (Format) { + case HIP_AD_FORMAT_UNSIGNED_INT8: + case HIP_AD_FORMAT_SIGNED_INT8: + *Size = 1; + case HIP_AD_FORMAT_UNSIGNED_INT16: + case HIP_AD_FORMAT_SIGNED_INT16: + case HIP_AD_FORMAT_HALF: + *Size = 2; + case HIP_AD_FORMAT_UNSIGNED_INT32: + case HIP_AD_FORMAT_SIGNED_INT32: + case HIP_AD_FORMAT_FLOAT: + *Size = 4; + default: + return UR_RESULT_ERROR_IMAGE_FORMAT_NOT_SUPPORTED; + } +} diff --git a/source/adapters/hip/common.hpp b/source/adapters/hip/common.hpp index 2649657f47..cefc23e2a8 100644 --- a/source/adapters/hip/common.hpp +++ b/source/adapters/hip/common.hpp @@ -15,6 +15,16 @@ #include #include +/** + * Call an UR API and, if the result is not UR_RESULT_SUCCESS, automatically + * return from the current function. + */ +#define UR_RETURN_ON_FAILURE(urCall) \ + if (const ur_result_t ur_result_macro = urCall; \ + ur_result_macro != UR_RESULT_SUCCESS) { \ + return ur_result_macro; \ + } + // Hipify doesn't support cuArrayGetDescriptor, on AMD the hipArray can just be // indexed, but on NVidia it is an opaque type and needs to go through // cuArrayGetDescriptor so implement a utility function to get the array @@ -98,17 +108,9 @@ extern thread_local char ErrorMessage[MaxMessageSize]; namespace detail { namespace ur { -// Report error and no return (keeps compiler from printing warnings). -// TODO: Probably change that to throw a catchable exception, -// but for now it is useful to see every failure. -// -[[noreturn]] void die(const char *pMessage); - // Reports error messages void hipPrint(const char *pMessage); -void assertion(bool Condition, const char *pMessage = nullptr); - } // namespace ur } // namespace detail @@ -168,7 +170,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::die("Unrecoverable program state reached in piMemRelease"); + detail::ur::hipPrint( + "Unrecoverable program state reached in piMemRelease"); } } } @@ -185,3 +188,5 @@ template class ReleaseGuard { /// UR object. void dismiss() { Captive = nullptr; } }; + +ur_result_t GetHipFormatPixelSize(hipArray_Format Format, int *Size); diff --git a/source/adapters/hip/device.cpp b/source/adapters/hip/device.cpp index 5b473c050e..9d672023d5 100644 --- a/source/adapters/hip/device.cpp +++ b/source/adapters/hip/device.cpp @@ -47,7 +47,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int ComputeUnits = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &ComputeUnits, hipDeviceAttributeMultiprocessorCount, hDevice->get())); - detail::ur::assertion(ComputeUnits >= 0); + if (ComputeUnits < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(static_cast(ComputeUnits)); } case UR_DEVICE_INFO_MAX_WORK_ITEM_DIMENSIONS: { @@ -61,15 +63,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int MaxX = 0, MaxY = 0, MaxZ = 0; UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxX, hipDeviceAttributeMaxBlockDimX, hDevice->get())); - detail::ur::assertion(MaxX >= 0); + if (MaxX < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxY, hipDeviceAttributeMaxBlockDimY, hDevice->get())); - detail::ur::assertion(MaxY >= 0); + if (MaxY < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxZ, hipDeviceAttributeMaxBlockDimZ, hDevice->get())); - detail::ur::assertion(MaxZ >= 0); + if (MaxZ < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return_sizes.sizes[0] = size_t(MaxX); return_sizes.sizes[1] = size_t(MaxY); @@ -85,15 +93,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int MaxX = 0, MaxY = 0, MaxZ = 0; UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxX, hipDeviceAttributeMaxGridDimX, hDevice->get())); - detail::ur::assertion(MaxX >= 0); + if (MaxX < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxY, hipDeviceAttributeMaxGridDimY, hDevice->get())); - detail::ur::assertion(MaxY >= 0); + if (MaxY < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxZ, hipDeviceAttributeMaxGridDimZ, hDevice->get())); - detail::ur::assertion(MaxZ >= 0); + if (MaxZ < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return_sizes.sizes[0] = size_t(MaxX); return_sizes.sizes[1] = size_t(MaxY); @@ -107,7 +121,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, hipDeviceAttributeMaxThreadsPerBlock, hDevice->get())); - detail::ur::assertion(MaxWorkGroupSize >= 0); + if (MaxWorkGroupSize < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(size_t(MaxWorkGroupSize)); } @@ -184,7 +200,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int ClockFreq = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &ClockFreq, hipDeviceAttributeClockRate, hDevice->get())); - detail::ur::assertion(ClockFreq >= 0); + if (ClockFreq < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(static_cast(ClockFreq) / 1000u); } case UR_DEVICE_INFO_ADDRESS_BITS: { @@ -199,8 +217,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, // CL_DEVICE_TYPE_CUSTOM. size_t Global = 0; - detail::ur::assertion(hipDeviceTotalMem(&Global, hDevice->get()) == - hipSuccess); + if (hipDeviceTotalMem(&Global, hDevice->get()) != hipSuccess) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } auto QuarterGlobal = static_cast(Global / 4u); @@ -235,11 +254,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int TexHeight = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &TexHeight, hipDeviceAttributeMaxTexture2DHeight, hDevice->get())); - detail::ur::assertion(TexHeight >= 0); + if (TexHeight < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int SurfHeight = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &SurfHeight, hipDeviceAttributeMaxTexture2DHeight, hDevice->get())); - detail::ur::assertion(SurfHeight >= 0); + if (SurfHeight < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int Min = std::min(TexHeight, SurfHeight); @@ -250,11 +273,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int TexWidth = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &TexWidth, hipDeviceAttributeMaxTexture2DWidth, hDevice->get())); - detail::ur::assertion(TexWidth >= 0); + if (TexWidth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int SurfWidth = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &SurfWidth, hipDeviceAttributeMaxTexture2DWidth, hDevice->get())); - detail::ur::assertion(SurfWidth >= 0); + if (SurfWidth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int Min = std::min(TexWidth, SurfWidth); @@ -265,11 +292,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int TexHeight = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &TexHeight, hipDeviceAttributeMaxTexture3DHeight, hDevice->get())); - detail::ur::assertion(TexHeight >= 0); + if (TexHeight < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int SurfHeight = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &SurfHeight, hipDeviceAttributeMaxTexture3DHeight, hDevice->get())); - detail::ur::assertion(SurfHeight >= 0); + if (SurfHeight < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int Min = std::min(TexHeight, SurfHeight); @@ -280,11 +311,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int TexWidth = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &TexWidth, hipDeviceAttributeMaxTexture3DWidth, hDevice->get())); - detail::ur::assertion(TexWidth >= 0); + if (TexWidth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int SurfWidth = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &SurfWidth, hipDeviceAttributeMaxTexture3DWidth, hDevice->get())); - detail::ur::assertion(SurfWidth >= 0); + if (SurfWidth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int Min = std::min(TexWidth, SurfWidth); @@ -295,11 +330,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int TexDepth = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &TexDepth, hipDeviceAttributeMaxTexture3DDepth, hDevice->get())); - detail::ur::assertion(TexDepth >= 0); + if (TexDepth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int SurfDepth = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &SurfDepth, hipDeviceAttributeMaxTexture3DDepth, hDevice->get())); - detail::ur::assertion(SurfDepth >= 0); + if (SurfDepth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int Min = std::min(TexDepth, SurfDepth); @@ -310,11 +349,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int TexWidth = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &TexWidth, hipDeviceAttributeMaxTexture1DWidth, hDevice->get())); - detail::ur::assertion(TexWidth >= 0); + if (TexWidth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int SurfWidth = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &SurfWidth, hipDeviceAttributeMaxTexture1DWidth, hDevice->get())); - detail::ur::assertion(SurfWidth >= 0); + if (SurfWidth < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } int Min = std::min(TexWidth, SurfWidth); @@ -377,7 +420,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int CacheSize = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &CacheSize, hipDeviceAttributeL2CacheSize, hDevice->get())); - detail::ur::assertion(CacheSize >= 0); + if (CacheSize < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } // The L2 cache is global to the GPU. return ReturnValue(static_cast(CacheSize)); } @@ -397,7 +442,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(hipDeviceGetAttribute(&ConstantMemory, hipDeviceAttributeTotalConstantMemory, hDevice->get())); - detail::ur::assertion(ConstantMemory >= 0); + if (ConstantMemory < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(static_cast(ConstantMemory)); } @@ -418,7 +465,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(hipDeviceGetAttribute( &LocalMemSize, hipDeviceAttributeMaxSharedMemoryPerBlock, hDevice->get())); - detail::ur::assertion(LocalMemSize >= 0); + if (LocalMemSize < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(static_cast(LocalMemSize)); } case UR_DEVICE_INFO_ERROR_CORRECTION_SUPPORT: { @@ -426,7 +475,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(hipDeviceGetAttribute( &EccEnabled, hipDeviceAttributeEccEnabled, hDevice->get())); - detail::ur::assertion((EccEnabled == 0) | (EccEnabled == 1)); + if ((EccEnabled != 0) | (EccEnabled != 1)) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } auto Result = static_cast(EccEnabled); return ReturnValue(Result); } @@ -435,7 +486,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(hipDeviceGetAttribute( &IsIntegrated, hipDeviceAttributeIntegrated, hDevice->get())); - detail::ur::assertion((IsIntegrated == 0) | (IsIntegrated == 1)); + if ((IsIntegrated != 0) | (IsIntegrated != 1)) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } auto Result = static_cast(IsIntegrated); return ReturnValue(Result); } @@ -493,8 +546,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, // name instead, this is also what AMD OpenCL devices return. if (strlen(Name) == 0) { hipDeviceProp_t Props; - detail::ur::assertion(hipGetDeviceProperties(&Props, hDevice->get()) == - hipSuccess); + if (hipGetDeviceProperties(&Props, hDevice->get()) != hipSuccess) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } return ReturnValue(Props.gcnArchName, strlen(Props.gcnArchName) + 1); } @@ -518,8 +572,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, std::stringstream S; hipDeviceProp_t Props; - detail::ur::assertion(hipGetDeviceProperties(&Props, hDevice->get()) == - hipSuccess); + if (hipGetDeviceProperties(&Props, hDevice->get()) != hipSuccess) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } #if defined(__HIP_PLATFORM_NVIDIA__) S << Props.major << "." << Props.minor; #elif defined(__HIP_PLATFORM_AMD__) @@ -542,8 +597,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, SupportedExtensions += " "; hipDeviceProp_t Props; - detail::ur::assertion(hipGetDeviceProperties(&Props, hDevice->get()) == - hipSuccess); + if (hipGetDeviceProperties(&Props, hDevice->get()) != hipSuccess) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } if (Props.arch.hasDoubles) { SupportedExtensions += "cl_khr_fp64 "; @@ -701,8 +757,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_ATOMIC_64: { hipDeviceProp_t Props; - detail::ur::assertion(hipGetDeviceProperties(&Props, hDevice->get()) == - hipSuccess); + if (hipGetDeviceProperties(&Props, hDevice->get()) != hipSuccess) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(Props.arch.hasGlobalInt64Atomics && Props.arch.hasSharedInt64Atomics); } @@ -710,9 +767,9 @@ 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; - detail::ur::assertion(hipMemGetInfo(&FreeMemory, &TotalMemory) == - hipSuccess, - "failed hipMemGetInfo() API."); + if (hipMemGetInfo(&FreeMemory, &TotalMemory) != hipSuccess) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(FreeMemory); } @@ -720,7 +777,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int Value = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &Value, hipDeviceAttributeMemoryClockRate, hDevice->get())); - detail::ur::assertion(Value >= 0); + if (Value < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } // Convert kilohertz to megahertz when returning. return ReturnValue(Value / 1000); } @@ -729,7 +788,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int Value = 0; UR_CHECK_ERROR(hipDeviceGetAttribute( &Value, hipDeviceAttributeMemoryBusWidth, hDevice->get())); - detail::ur::assertion(Value >= 0); + if (Value < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(Value); } case UR_DEVICE_INFO_MAX_COMPUTE_QUEUE_INDICES: { @@ -769,7 +830,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int Value = 0; UR_CHECK_ERROR(hipDeviceGetAttribute(&Value, hipDeviceAttributePciDeviceId, hDevice->get())); - detail::ur::assertion(Value >= 0); + if (Value < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(Value); } case UR_DEVICE_INFO_UUID: { @@ -777,8 +840,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, HIP_VERSION_MAJOR > 5) hipUUID UUID = {}; // Supported since 5.2+ - detail::ur::assertion(hipDeviceGetUuid(&UUID, hDevice->get()) == - hipSuccess); + if (hipDeviceGetUuid(&UUID, hDevice->get()) != hipSuccess) { + return UR_RESULT_ERROR_INVALID_SIZE; + } std::array Name; std::copy(UUID.bytes, UUID.bytes + 16, Name.begin()); return ReturnValue(Name.data(), 16); @@ -793,7 +857,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, UR_CHECK_ERROR(hipDeviceGetAttribute( &MaxRegisters, hipDeviceAttributeMaxRegistersPerBlock, hDevice->get())); - detail::ur::assertion(MaxRegisters >= 0); + if (MaxRegisters < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(static_cast(MaxRegisters)); } @@ -811,7 +877,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, // at least in 5.3-5.5. To be on the safe side, we make sure the terminating // \0 is set. AddressBuffer[AddressBufferSize - 1] = '\0'; - detail::ur::assertion(strnlen(AddressBuffer, AddressBufferSize) > 0); + if (strnlen(AddressBuffer, AddressBufferSize) < 0) { + return UR_RESULT_ERROR_INVALID_SIZE; + } return ReturnValue(AddressBuffer, strnlen(AddressBuffer, AddressBufferSize - 1) + 1); } diff --git a/source/adapters/hip/enqueue.cpp b/source/adapters/hip/enqueue.cpp index 1a73618c77..2547147ad0 100644 --- a/source/adapters/hip/enqueue.cpp +++ b/source/adapters/hip/enqueue.cpp @@ -17,25 +17,6 @@ namespace { -static size_t imageElementByteSize(hipArray_Format ArrayFormat) { - switch (ArrayFormat) { - case HIP_AD_FORMAT_UNSIGNED_INT8: - case HIP_AD_FORMAT_SIGNED_INT8: - return 1; - case HIP_AD_FORMAT_UNSIGNED_INT16: - case HIP_AD_FORMAT_SIGNED_INT16: - case HIP_AD_FORMAT_HALF: - return 2; - case HIP_AD_FORMAT_UNSIGNED_INT32: - case HIP_AD_FORMAT_SIGNED_INT32: - case HIP_AD_FORMAT_FLOAT: - return 4; - default: - detail::ur::die("Invalid image format."); - } - return 0; -} - ur_result_t enqueueEventsWait(ur_queue_handle_t CommandQueue, hipStream_t Stream, uint32_t NumEventsInWaitList, const ur_event_handle_t *EventWaitList) { @@ -902,7 +883,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageRead( size_t NumChannels; getArrayDesc(Array, Format, NumChannels); - int ElementByteSize = imageElementByteSize(Format); + int ElementByteSize = 0; + UR_RETURN_ON_FAILURE(GetHipFormatPixelSize(Format, &ElementByteSize)); size_t ByteOffsetX = origin.x * ElementByteSize * NumChannels; size_t BytesToCopy = ElementByteSize * NumChannels * region.depth; @@ -970,7 +952,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageWrite( size_t NumChannels; getArrayDesc(Array, Format, NumChannels); - int ElementByteSize = imageElementByteSize(Format); + int ElementByteSize = 0; + UR_RETURN_ON_FAILURE(GetHipFormatPixelSize(Format, &ElementByteSize)); size_t ByteOffsetX = origin.x * ElementByteSize * NumChannels; size_t BytesToCopy = ElementByteSize * NumChannels * region.depth; @@ -1050,7 +1033,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageCopy( UR_ASSERT(SrcNumChannels == DstNumChannels, UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR); - int ElementByteSize = imageElementByteSize(SrcFormat); + int ElementByteSize = 0; + UR_RETURN_ON_FAILURE(GetHipFormatPixelSize(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 4871335c9f..05b1082bee 100644 --- a/source/adapters/hip/event.cpp +++ b/source/adapters/hip/event.cpp @@ -143,8 +143,7 @@ ur_result_t ur_event_handle_t_::record() { try { EventId = Queue->getNextEventId(); if (EventId == 0) { - detail::ur::die( - "Unrecoverable program state reached in event identifier overflow"); + return UR_RESULT_ERROR_INVALID_OPERATION; } UR_CHECK_ERROR(hipEventRecord(EvEnd, Stream)); Result = UR_RESULT_SUCCESS; @@ -275,8 +274,9 @@ 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(); - detail::ur::assertion(RefCount != 0, - "Reference count overflow detected in urEventRetain."); + if (RefCount == 0) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } return UR_RESULT_SUCCESS; } @@ -284,8 +284,9 @@ 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. - detail::ur::assertion(hEvent->getReferenceCount() != 0, - "Reference count overflow detected in urEventRelease."); + if (hEvent->getReferenceCount() == 0) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } // decrement ref count. If it is 0, delete the event. if (hEvent->decrementReferenceCount() == 0) { diff --git a/source/adapters/hip/kernel.cpp b/source/adapters/hip/kernel.cpp index cc6f4384bc..77f06b4937 100644 --- a/source/adapters/hip/kernel.cpp +++ b/source/adapters/hip/kernel.cpp @@ -283,9 +283,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelSetArgMemObj( if (Format != HIP_AD_FORMAT_UNSIGNED_INT32 && Format != HIP_AD_FORMAT_SIGNED_INT32 && Format != HIP_AD_FORMAT_HALF && Format != HIP_AD_FORMAT_FLOAT) { - detail::ur::die( - "UR HIP kernels only support images with channel types int32, " - "uint32, float, and half."); + return UR_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT; } hipSurfaceObject_t hipSurf = std::get(hArgValue->Mem).getSurface(); diff --git a/source/adapters/hip/memory.cpp b/source/adapters/hip/memory.cpp index 3083d47744..83efbd3db0 100644 --- a/source/adapters/hip/memory.cpp +++ b/source/adapters/hip/memory.cpp @@ -13,28 +13,31 @@ #include #include -namespace { - -size_t GetHipFormatPixelSize(hipArray_Format Format) { +ur_result_t hip2urFormat(hipArray_Format Format, + ur_image_channel_type_t *ChannelType) { switch (Format) { case HIP_AD_FORMAT_UNSIGNED_INT8: - case HIP_AD_FORMAT_SIGNED_INT8: - return 1; + *ChannelType = UR_IMAGE_CHANNEL_TYPE_UNSIGNED_INT8; case HIP_AD_FORMAT_UNSIGNED_INT16: - case HIP_AD_FORMAT_SIGNED_INT16: - case HIP_AD_FORMAT_HALF: - return 2; + *ChannelType = UR_IMAGE_CHANNEL_TYPE_UNSIGNED_INT16; case HIP_AD_FORMAT_UNSIGNED_INT32: + *ChannelType = UR_IMAGE_CHANNEL_TYPE_UNSIGNED_INT32; + case HIP_AD_FORMAT_SIGNED_INT8: + *ChannelType = UR_IMAGE_CHANNEL_TYPE_SIGNED_INT8; + case HIP_AD_FORMAT_SIGNED_INT16: + *ChannelType = UR_IMAGE_CHANNEL_TYPE_SIGNED_INT16; case HIP_AD_FORMAT_SIGNED_INT32: + *ChannelType = UR_IMAGE_CHANNEL_TYPE_SIGNED_INT32; + case HIP_AD_FORMAT_HALF: + *ChannelType = UR_IMAGE_CHANNEL_TYPE_HALF_FLOAT; case HIP_AD_FORMAT_FLOAT: - return 4; + *ChannelType = UR_IMAGE_CHANNEL_TYPE_FLOAT; + default: - detail::ur::die("Invalid HIP format specifier"); + return UR_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT; } } -} // namespace - /// Decreases the reference count of the Mem object. /// If this is zero, calls the relevant HIP Free function /// \return UR_RESULT_SUCCESS unless deallocation error @@ -89,7 +92,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. - detail::ur::die("Unrecoverable program state reached in urMemRelease"); + return UR_RESULT_ERROR_INVALID_OPERATION; } return UR_RESULT_SUCCESS; @@ -275,9 +278,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemGetInfo(ur_mem_handle_t hMemory, } else if constexpr (std::is_same_v) { HIP_ARRAY3D_DESCRIPTOR ArrayDescriptor; UR_CHECK_ERROR(hipArray3DGetDescriptor(&ArrayDescriptor, Mem.Array)); - const auto PixelSizeBytes = - GetHipFormatPixelSize(ArrayDescriptor.Format) * - ArrayDescriptor.NumChannels; + auto PixelSize = 0; + UR_RETURN_ON_FAILURE( + GetHipFormatPixelSize(ArrayDescriptor.Format, &PixelSize)); + const auto PixelSizeBytes = PixelSize * ArrayDescriptor.NumChannels; const auto ImageSizeBytes = PixelSizeBytes * (ArrayDescriptor.Width ? ArrayDescriptor.Width : 1) * @@ -540,62 +544,23 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageGetInfo(ur_mem_handle_t hMemory, UR_CHECK_ERROR(hipArray3DGetDescriptor( &ArrayInfo, std::get(hMemory->Mem).Array)); - const auto hip2urFormat = - [](hipArray_Format HipFormat) -> ur_image_channel_type_t { - switch (HipFormat) { - case HIP_AD_FORMAT_UNSIGNED_INT8: - return UR_IMAGE_CHANNEL_TYPE_UNSIGNED_INT8; - case HIP_AD_FORMAT_UNSIGNED_INT16: - return UR_IMAGE_CHANNEL_TYPE_UNSIGNED_INT16; - case HIP_AD_FORMAT_UNSIGNED_INT32: - return UR_IMAGE_CHANNEL_TYPE_UNSIGNED_INT32; - case HIP_AD_FORMAT_SIGNED_INT8: - return UR_IMAGE_CHANNEL_TYPE_SIGNED_INT8; - case HIP_AD_FORMAT_SIGNED_INT16: - return UR_IMAGE_CHANNEL_TYPE_SIGNED_INT16; - case HIP_AD_FORMAT_SIGNED_INT32: - return UR_IMAGE_CHANNEL_TYPE_SIGNED_INT32; - case HIP_AD_FORMAT_HALF: - return UR_IMAGE_CHANNEL_TYPE_HALF_FLOAT; - case HIP_AD_FORMAT_FLOAT: - return UR_IMAGE_CHANNEL_TYPE_FLOAT; - - default: - detail::ur::die("Invalid Hip format specified."); - } - }; - - const auto hipFormatToElementSize = - [](hipArray_Format HipFormat) -> size_t { - switch (HipFormat) { - case HIP_AD_FORMAT_UNSIGNED_INT8: - case HIP_AD_FORMAT_SIGNED_INT8: - return 1; - case HIP_AD_FORMAT_UNSIGNED_INT16: - case HIP_AD_FORMAT_SIGNED_INT16: - case HIP_AD_FORMAT_HALF: - return 2; - case HIP_AD_FORMAT_UNSIGNED_INT32: - case HIP_AD_FORMAT_SIGNED_INT32: - case HIP_AD_FORMAT_FLOAT: - return 4; - default: - detail::ur::die("Invalid Hip format specified."); - } - }; - switch (propName) { case UR_IMAGE_INFO_FORMAT: - return ReturnValue(ur_image_format_t{UR_IMAGE_CHANNEL_ORDER_RGBA, - hip2urFormat(ArrayInfo.Format)}); + ur_image_channel_type_t ChannelType; + UR_RETURN_ON_FAILURE(hip2urFormat(ArrayInfo.Format, &ChannelType)); + return ReturnValue( + ur_image_format_t{UR_IMAGE_CHANNEL_ORDER_RGBA, ChannelType}); case UR_IMAGE_INFO_WIDTH: return ReturnValue(ArrayInfo.Width); case UR_IMAGE_INFO_HEIGHT: return ReturnValue(ArrayInfo.Height); case UR_IMAGE_INFO_DEPTH: return ReturnValue(ArrayInfo.Depth); - case UR_IMAGE_INFO_ELEMENT_SIZE: - return ReturnValue(hipFormatToElementSize(ArrayInfo.Format)); + case UR_IMAGE_INFO_ELEMENT_SIZE: { + int Size = 0; + UR_RETURN_ON_FAILURE(GetHipFormatPixelSize(ArrayInfo.Format, &Size)); + return ReturnValue(Size); + } case UR_IMAGE_INFO_ROW_PITCH: case UR_IMAGE_INFO_SLICE_PITCH: return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; diff --git a/source/adapters/hip/program.cpp b/source/adapters/hip/program.cpp index 2c71c53208..5ae57739d6 100644 --- a/source/adapters/hip/program.cpp +++ b/source/adapters/hip/program.cpp @@ -135,8 +135,10 @@ ur_result_t ur_program_handle_t_::finalizeRelocatable() { std::string ISA = "amdgcn-amd-amdhsa--"; hipDeviceProp_t Props; - detail::ur::assertion(hipGetDeviceProperties( - &Props, Context->getDevice()->get()) == hipSuccess); + if (hipGetDeviceProperties(&Props, Context->getDevice()->get()) != + hipSuccess) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } ISA += Props.gcnArchName; UR_CHECK_ERROR(amd_comgr_action_info_set_isa_name(Action, ISA.data())); diff --git a/source/adapters/hip/queue.cpp b/source/adapters/hip/queue.cpp index 910d7cf512..3f145a0807 100644 --- a/source/adapters/hip/queue.cpp +++ b/source/adapters/hip/queue.cpp @@ -275,12 +275,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle( UR_CHECK_ERROR(hipStreamGetFlags(HIPStream, &HIPFlags)); ur_queue_flags_t Flags = 0; - if (HIPFlags == hipStreamDefault) + if (HIPFlags == hipStreamDefault) { Flags = UR_QUEUE_FLAG_USE_DEFAULT_STREAM; - else if (HIPFlags == hipStreamNonBlocking) + } else if (HIPFlags == hipStreamNonBlocking) { Flags = UR_QUEUE_FLAG_SYNC_WITH_DEFAULT_STREAM; - else - detail::ur::die("Unknown hip stream"); + } else { + return UR_RESULT_ERROR_INVALID_OPERATION; + } std::vector ComputeHIPStreams(1, HIPStream); std::vector TransferHIPStreams(0); diff --git a/source/adapters/hip/sampler.cpp b/source/adapters/hip/sampler.cpp index 5a177d6a9f..4efb8b5d6b 100644 --- a/source/adapters/hip/sampler.cpp +++ b/source/adapters/hip/sampler.cpp @@ -69,9 +69,9 @@ 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. - detail::ur::assertion( - hSampler->getReferenceCount() != 0, - "Reference count overflow detected in urSamplerRelease."); + if (hSampler->getReferenceCount() == 0) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } // decrement ref count. If it is 0, delete the sampler. if (hSampler->decrementReferenceCount() == 0) { diff --git a/source/adapters/hip/usm_p2p.cpp b/source/adapters/hip/usm_p2p.cpp index 65635dc910..874c42446c 100644 --- a/source/adapters/hip/usm_p2p.cpp +++ b/source/adapters/hip/usm_p2p.cpp @@ -12,15 +12,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PEnablePeerAccessExp(ur_device_handle_t, ur_device_handle_t) { - detail::ur::die( - "urUsmP2PEnablePeerAccessExp is not implemented for HIP adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PDisablePeerAccessExp(ur_device_handle_t, ur_device_handle_t) { - detail::ur::die( - "urUsmP2PDisablePeerAccessExp is not implemented for HIP adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/level_zero/context.cpp b/source/adapters/level_zero/context.cpp index 2bd893b043..27ac5de530 100644 --- a/source/adapters/level_zero/context.cpp +++ b/source/adapters/level_zero/context.cpp @@ -125,7 +125,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextGetInfo( default: // TODO: implement other parameters - die("urGetContextInfo: unsuppported ParamName."); + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; } return UR_RESULT_SUCCESS; @@ -566,8 +566,9 @@ 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) - die("Invalid event release: event pool doesn't have unreleased events"); + if (NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } if (--NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0) { if (ZePoolCache->front() != Event->ZeEventPool) { ZePoolCache->push_back(Event->ZeEventPool); diff --git a/source/adapters/level_zero/device.cpp b/source/adapters/level_zero/device.cpp index f5b00d80cc..42398d3bf8 100644 --- a/source/adapters/level_zero/device.cpp +++ b/source/adapters/level_zero/device.cpp @@ -608,7 +608,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo( case UR_DEVICE_INFO_USM_SYSTEM_SHARED_SUPPORT: return ReturnValue(MapCaps(Props->sharedSystemAllocCapabilities)); default: - die("urDeviceGetInfo: unexpected ParamName."); + return UR_RESULT_ERROR_INVALID_ENUMERATION; } } diff --git a/source/adapters/level_zero/event.cpp b/source/adapters/level_zero/event.cpp index b979c8ab15..69f24c3ec5 100644 --- a/source/adapters/level_zero/event.cpp +++ b/source/adapters/level_zero/event.cpp @@ -512,8 +512,9 @@ ur_result_t ur_event_handle_t_::getOrCreateHostVisibleEvent( this->Mutex); if (!HostVisibleEvent) { - if (UrQueue->ZeEventsScope != OnDemandHostVisibleProxy) - die("getOrCreateHostVisibleEvent: missing host-visible event"); + if (UrQueue->ZeEventsScope != OnDemandHostVisibleProxy) { + return UR_RESULT_ERROR_INVALID_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 @@ -559,8 +560,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventWait( // ur_event_handle_t_ *Event = ur_cast(EventWaitList[I]); - if (!Event->hasExternalRefs()) - die("urEventsWait must not be called for an internal event"); + if (!Event->hasExternalRefs()) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } ze_event_handle_t ZeHostVisibleEvent; if (auto Res = Event->getOrCreateHostVisibleEvent(ZeHostVisibleEvent)) @@ -585,13 +587,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventWait( ur_cast(EventWaitList[I]); { std::shared_lock EventLock(Event->Mutex); - if (!Event->hasExternalRefs()) - die("urEventWait must not be called for an internal event"); + if (!Event->hasExternalRefs()) { + return UR_RESULT_ERROR_INVALID_OPERATION; + } if (!Event->Completed) { auto HostVisibleEvent = Event->HostVisibleEvent; - if (!HostVisibleEvent) - die("The host-visible proxy event missing"); + if (!HostVisibleEvent) { + return UR_RESULT_ERROR_INVALID_EVENT; + } ze_event_handle_t ZeEvent = HostVisibleEvent->ZeEvent; urPrint("ZeEvent = %#llx\n", ur_cast(ZeEvent)); diff --git a/source/adapters/level_zero/kernel.cpp b/source/adapters/level_zero/kernel.cpp index dfa8915197..fed5b56be3 100644 --- a/source/adapters/level_zero/kernel.cpp +++ b/source/adapters/level_zero/kernel.cpp @@ -574,8 +574,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetSubGroupInfo( } else if (PropName == UR_KERNEL_SUB_GROUP_INFO_SUB_GROUP_SIZE_INTEL) { ReturnValue(uint32_t{Kernel->ZeKernelProperties->requiredSubgroupSize}); } else { - die("urKernelGetSubGroupInfo: parameter not implemented"); - return {}; + return UR_RESULT_ERROR_INVALID_ENUMERATION; } return UR_RESULT_SUCCESS; } diff --git a/source/adapters/level_zero/memory.cpp b/source/adapters/level_zero/memory.cpp index aefa661dac..139f132188 100644 --- a/source/adapters/level_zero/memory.cpp +++ b/source/adapters/level_zero/memory.cpp @@ -1547,7 +1547,7 @@ static ur_result_t ur2zeImageDesc(const ur_image_format_t *ImageFormat, } default: urPrint("format layout = %d\n", ImageFormat->channelOrder); - die("urMemImageCreate: unsupported image format layout\n"); + return UR_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT; break; } @@ -1602,8 +1602,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageCreate( ) { // TODO: implement read-only, write-only if ((Flags & UR_MEM_FLAG_READ_WRITE) == 0) { - die("urMemImageCreate: Level-Zero implements only read-write buffer," - "no read-only or write-only yet."); + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } std::shared_lock Lock(Context->Mutex); @@ -1778,7 +1777,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreate( } else if (Flags == 0 || (Flags == UR_MEM_FLAG_READ_WRITE)) { // Nothing more to do. } else - die("urMemBufferCreate: not implemented"); + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; } *RetBuffer = reinterpret_cast(Buffer); @@ -1836,8 +1835,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferPartition( std::shared_lock Guard(Buffer->Mutex); if (Flags != UR_MEM_FLAG_READ_WRITE) { - die("urMemBufferPartition: Level-Zero implements only read-write buffer," - "no read-only or write-only yet."); + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } try { @@ -1902,7 +1900,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreateWithNativeHandle( // Memory allocation is unrelated to the context return UR_RESULT_ERROR_INVALID_CONTEXT; default: - die("Unexpected memory type"); + return UR_RESULT_ERROR_MEM_OBJECT_ALLOCATION_FAILURE; } ur_device_handle_t Device{}; @@ -1995,7 +1993,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemGetInfo( return ReturnValue(size_t{Buffer->Size}); } default: { - die("urMemGetInfo: Parameter is not implemented"); + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; } } @@ -2179,7 +2177,7 @@ ur_result_t _ur_buffer::getZeHandle(char *&ZeHandle, access_mode_t AccessMode, if (!Allocation.Valid) { // LastDeviceWithValidAllocation should always have valid allocation. if (Device == LastDeviceWithValidAllocation) - die("getZeHandle: last used allocation is not valid"); + return UR_RESULT_ERROR_INVALID_OPERATION; // For write-only access the allocation contents is not going to be used. // So don't do anything to make it "valid". @@ -2302,7 +2300,7 @@ ur_result_t _ur_buffer::free() { ZeUSMImport.doZeUSMRelease(UrContext->getPlatform()->ZeDriver, ZeHandle); break; default: - die("_ur_buffer::free(): Unhandled release action"); + return UR_RESULT_ERROR_INVALID_OPERATION; } ZeHandle = nullptr; // don't leave hanging pointers } diff --git a/source/adapters/level_zero/program.cpp b/source/adapters/level_zero/program.cpp index 92a3c87aea..60d07053d7 100644 --- a/source/adapters/level_zero/program.cpp +++ b/source/adapters/level_zero/program.cpp @@ -644,7 +644,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramGetInfo( return UR_RESULT_ERROR_UNKNOWN; } default: - die("urProgramGetInfo: not implemented"); + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; } return UR_RESULT_SUCCESS; diff --git a/source/adapters/level_zero/queue.cpp b/source/adapters/level_zero/queue.cpp index 994f595a5d..024a38dcdc 100755 --- a/source/adapters/level_zero/queue.cpp +++ b/source/adapters/level_zero/queue.cpp @@ -162,13 +162,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueGetInfo( case UR_QUEUE_INFO_REFERENCE_COUNT: return ReturnValue(uint32_t{Queue->RefCount.load()}); case UR_QUEUE_INFO_FLAGS: - die("UR_QUEUE_INFO_FLAGS in urQueueGetInfo not implemented\n"); + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; break; case UR_QUEUE_INFO_SIZE: - die("UR_QUEUE_INFO_SIZE in urQueueGetInfo not implemented\n"); + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; break; case UR_QUEUE_INFO_DEVICE_DEFAULT: - die("UR_QUEUE_INFO_DEVICE_DEFAULT in urQueueGetInfo not implemented\n"); + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; break; case UR_QUEUE_INFO_EMPTY: { // We can exit early if we have in-order queue. @@ -819,7 +819,7 @@ static const zeCommandListBatchConfig ZeCommandListBatchConfig(bool IsCopy) { Config.NumTimesClosedFullThreshold = Val; break; default: - die("Unexpected batch config"); + urPrint("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 { - die("No compute queue available/allowed."); + urPrint("No compute queue available/allowed."); } } if (UsingImmCmdLists) { @@ -1094,8 +1094,7 @@ ur_queue_handle_t_::executeCommandList(ur_command_list_ptr_t CommandList, if (hasOpenCommandList(UseCopyEngine) && CommandBatch.OpenCommandList != CommandList) - die("executeCommandList: OpenCommandList should be equal to" - "null or CommandList"); + return UR_RESULT_ERROR_INVALID_ARGUMENT; if (CommandList->second.size() < CommandBatch.QueueBatchSize) { CommandBatch.OpenCommandList = CommandList; @@ -1819,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) { - die("[L0] getZeQueue: failed to create queue"); + urPrint("[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 daec0408fb..03cbaf44dc 100644 --- a/source/adapters/level_zero/usm.cpp +++ b/source/adapters/level_zero/usm.cpp @@ -879,7 +879,7 @@ ur_result_t ZeMemFreeHelper(ur_context_handle_t Context, void *Ptr) { ContextsLock.lock(); auto It = Context->MemAllocs.find(Ptr); if (It == std::end(Context->MemAllocs)) { - die("All memory allocations must be tracked!"); + return UR_RESULT_ERROR_INVALID_OPERATION; } if (!It->second.RefCount.decrementAndTest()) { // Memory can't be deallocated yet. @@ -926,7 +926,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)) { - die("All memory allocations must be tracked!"); + return UR_RESULT_ERROR_INVALID_OPERATION; } if (!It->second.RefCount.decrementAndTest()) { // Memory can't be deallocated yet. diff --git a/source/adapters/native_cpu/command_buffer.cpp b/source/adapters/native_cpu/command_buffer.cpp index f79bf7e3c5..0c8e77c30f 100644 --- a/source/adapters/native_cpu/command_buffer.cpp +++ b/source/adapters/native_cpu/command_buffer.cpp @@ -20,29 +20,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp( ur_context_handle_t, ur_device_handle_t, const ur_exp_command_buffer_desc_t *, ur_exp_command_buffer_handle_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for the NativeCPU adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferRetainExp(ur_exp_command_buffer_handle_t) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for the NativeCPU adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for the NativeCPU adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for the NativeCPU adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -51,8 +43,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp( const size_t *, const size_t *, const size_t *, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for the NativeCPU adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -60,8 +50,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemcpyUSMExp( ur_exp_command_buffer_handle_t, void *, const void *, size_t, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for the NativeCPU adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -69,8 +57,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMembufferCopyExp( ur_exp_command_buffer_handle_t, ur_mem_handle_t, ur_mem_handle_t, size_t, size_t, size_t, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for the NativeCPU adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -79,8 +65,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMembufferCopyRectExp( ur_rect_offset_t, ur_rect_offset_t, ur_rect_region_t, size_t, size_t, size_t, size_t, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for the NativeCPU adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -89,8 +73,6 @@ ur_result_t UR_APICALL urCommandBufferAppendMembufferWriteExp( ur_exp_command_buffer_handle_t, ur_mem_handle_t, size_t, size_t, const void *, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for the NativeCPU adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -99,8 +81,6 @@ ur_result_t UR_APICALL urCommandBufferAppendMembufferReadExp( ur_exp_command_buffer_handle_t, ur_mem_handle_t, size_t, size_t, void *, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for the NativeCPU adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -110,8 +90,6 @@ ur_result_t UR_APICALL urCommandBufferAppendMembufferWriteRectExp( ur_rect_offset_t, ur_rect_region_t, size_t, size_t, size_t, size_t, void *, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for the NativeCPU adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -121,15 +99,11 @@ ur_result_t UR_APICALL urCommandBufferAppendMembufferReadRectExp( ur_rect_offset_t, ur_rect_region_t, size_t, size_t, size_t, size_t, void *, uint32_t, const ur_exp_command_buffer_sync_point_t *, ur_exp_command_buffer_sync_point_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for the NativeCPU adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferEnqueueExp( ur_exp_command_buffer_handle_t, ur_queue_handle_t, uint32_t, const ur_event_handle_t *, ur_event_handle_t *) { - detail::ur::die("Experimental Command-buffer feature is not " - "implemented for the NativeCPU adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/native_cpu/common.cpp b/source/adapters/native_cpu/common.cpp index 90fbc1183a..1fef898b38 100644 --- a/source/adapters/native_cpu/common.cpp +++ b/source/adapters/native_cpu/common.cpp @@ -27,8 +27,3 @@ ur_result_t urGetLastResult(ur_platform_handle_t, const char **ppMessage) { *ppMessage = &ErrorMessage[0]; return ErrorMessageCode; } - -void detail::ur::die(const char *pMessage) { - std::cerr << "ur_die: " << pMessage << '\n'; - std::terminate(); -} diff --git a/source/adapters/native_cpu/common.hpp b/source/adapters/native_cpu/common.hpp index d792cbbbcf..45a756ceba 100644 --- a/source/adapters/native_cpu/common.hpp +++ b/source/adapters/native_cpu/common.hpp @@ -17,45 +17,6 @@ constexpr size_t MaxMessageSize = 256; extern thread_local ur_result_t ErrorMessageCode; extern thread_local char ErrorMessage[MaxMessageSize]; -#define DIE_NO_IMPLEMENTATION \ - if (PrintTrace) { \ - std::cerr << "Not Implemented : " << __FUNCTION__ \ - << " - File : " << __FILE__; \ - std::cerr << " / Line : " << __LINE__ << std::endl; \ - } \ - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; - -#define CONTINUE_NO_IMPLEMENTATION \ - if (PrintTrace) { \ - std::cerr << "Warning : Not Implemented : " << __FUNCTION__ \ - << " - File : " << __FILE__; \ - std::cerr << " / Line : " << __LINE__ << std::endl; \ - } \ - return UR_RESULT_SUCCESS; - -#define CASE_UR_UNSUPPORTED(not_supported) \ - case not_supported: \ - if (PrintTrace) { \ - std::cerr << std::endl \ - << "Unsupported UR case : " << #not_supported << " in " \ - << __FUNCTION__ << ":" << __LINE__ << "(" << __FILE__ << ")" \ - << std::endl; \ - } \ - return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; - -/// ------ Error handling, matching OpenCL plugin semantics. -/// Taken from other adapter -namespace detail { -namespace ur { - -// Report error and no return (keeps compiler from printing warnings). -// TODO: Probably change that to throw a catchable exception, -// but for now it is useful to see every failure. -// -[[noreturn]] void die(const char *pMessage); -} // namespace ur -} // namespace detail - // Base class to store common data struct _ur_object { ur_shared_mutex Mutex; diff --git a/source/adapters/native_cpu/context.cpp b/source/adapters/native_cpu/context.cpp index 962525d1fc..7c129fd968 100644 --- a/source/adapters/native_cpu/context.cpp +++ b/source/adapters/native_cpu/context.cpp @@ -75,7 +75,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextGetNativeHandle( ur_context_handle_t hContext, ur_native_handle_t *phNativeContext) { std::ignore = hContext; std::ignore = phNativeContext; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urContextCreateWithNativeHandle( @@ -89,7 +89,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextCreateWithNativeHandle( std::ignore = pProperties; std::ignore = phContext; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urContextSetExtendedDeleter( @@ -99,5 +99,5 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextSetExtendedDeleter( std::ignore = pfnDeleter; std::ignore = pUserData; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/native_cpu/device.cpp b/source/adapters/native_cpu/device.cpp index 78540a1b90..742f6582eb 100644 --- a/source/adapters/native_cpu/device.cpp +++ b/source/adapters/native_cpu/device.cpp @@ -299,12 +299,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, return ReturnValue(Capabilities); } case UR_DEVICE_INFO_ESIMD_SUPPORT: - return ReturnValue(false); - - CASE_UR_UNSUPPORTED(UR_DEVICE_INFO_MAX_MEMORY_BANDWIDTH); - + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; default: - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } return UR_RESULT_SUCCESS; } @@ -332,7 +329,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDevicePartition( std::ignore = phSubDevices; std::ignore = pNumDevicesRet; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetNativeHandle( @@ -340,7 +337,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetNativeHandle( std::ignore = hDevice; std::ignore = phNativeDevice; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urDeviceCreateWithNativeHandle( @@ -352,7 +349,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceCreateWithNativeHandle( std::ignore = pProperties; std::ignore = phDevice; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetGlobalTimestamps( diff --git a/source/adapters/native_cpu/enqueue.cpp b/source/adapters/native_cpu/enqueue.cpp index d9e73c5453..60a267c486 100644 --- a/source/adapters/native_cpu/enqueue.cpp +++ b/source/adapters/native_cpu/enqueue.cpp @@ -56,7 +56,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch( UR_ASSERT(workDim < 4, UR_RESULT_ERROR_INVALID_WORK_DIMENSION); if (*pGlobalWorkSize == 0) { - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } // TODO: add proper error checking @@ -102,7 +102,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueEventsWait( std::ignore = phEventWaitList; std::ignore = phEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urEnqueueEventsWaitWithBarrier( @@ -113,7 +113,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueEventsWaitWithBarrier( std::ignore = phEventWaitList; std::ignore = phEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } template @@ -281,7 +281,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageRead( std::ignore = phEventWaitList; std::ignore = phEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageWrite( @@ -301,7 +301,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageWrite( std::ignore = phEventWaitList; std::ignore = phEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageCopy( @@ -320,7 +320,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageCopy( std::ignore = phEventWaitList; std::ignore = phEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferMap( @@ -405,7 +405,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch( std::ignore = phEventWaitList; std::ignore = phEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL @@ -417,7 +417,7 @@ urEnqueueUSMAdvise(ur_queue_handle_t hQueue, const void *pMem, size_t size, std::ignore = advice; std::ignore = phEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill2D( @@ -436,7 +436,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill2D( std::ignore = phEventWaitList; std::ignore = phEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMMemcpy2D( @@ -456,7 +456,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMMemcpy2D( std::ignore = phEventWaitList; std::ignore = phEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableWrite( @@ -475,7 +475,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableWrite( std::ignore = phEventWaitList; std::ignore = phEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableRead( @@ -494,7 +494,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableRead( std::ignore = phEventWaitList; std::ignore = phEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urEnqueueReadHostPipe( @@ -512,7 +512,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueReadHostPipe( std::ignore = phEventWaitList; std::ignore = phEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urEnqueueWriteHostPipe( @@ -530,5 +530,5 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueWriteHostPipe( std::ignore = phEventWaitList; std::ignore = phEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/native_cpu/event.cpp b/source/adapters/native_cpu/event.cpp index 112bb553c0..93bd36ec13 100644 --- a/source/adapters/native_cpu/event.cpp +++ b/source/adapters/native_cpu/event.cpp @@ -23,7 +23,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(ur_event_handle_t hEvent, std::ignore = pPropValue; std::ignore = pPropSizeRet; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo( @@ -35,7 +35,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo( std::ignore = pPropValue; std::ignore = pPropSizeRet; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL @@ -49,12 +49,12 @@ urEventWait(uint32_t numEvents, const ur_event_handle_t *phEventWaitList) { UR_APIEXPORT ur_result_t UR_APICALL urEventRetain(ur_event_handle_t hEvent) { std::ignore = hEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urEventRelease(ur_event_handle_t hEvent) { std::ignore = hEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urEventGetNativeHandle( @@ -62,7 +62,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetNativeHandle( std::ignore = hEvent; std::ignore = phNativeEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle( @@ -74,7 +74,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle( std::ignore = pProperties; std::ignore = phEvent; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL @@ -85,5 +85,5 @@ urEventSetCallback(ur_event_handle_t hEvent, ur_execution_info_t execStatus, std::ignore = pfnNotify; std::ignore = pUserData; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/native_cpu/kernel.cpp b/source/adapters/native_cpu/kernel.cpp index 7bfd3c328c..354c30a41a 100644 --- a/source/adapters/native_cpu/kernel.cpp +++ b/source/adapters/native_cpu/kernel.cpp @@ -97,7 +97,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo(ur_kernel_handle_t hKernel, default: return UR_RESULT_ERROR_INVALID_VALUE; } - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL @@ -180,7 +180,7 @@ urKernelGetSubGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice, #endif } } - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urKernelRetain(ur_kernel_handle_t hKernel) { @@ -235,7 +235,7 @@ urKernelSetArgSampler(ur_kernel_handle_t hKernel, uint32_t argIndex, std::ignore = pProperties; std::ignore = hArgValue; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL @@ -266,7 +266,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelSetSpecializationConstants( std::ignore = count; std::ignore = pSpecConstants; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urKernelGetNativeHandle( @@ -274,7 +274,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetNativeHandle( std::ignore = hKernel; std::ignore = phNativeKernel; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urKernelCreateWithNativeHandle( @@ -288,5 +288,5 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelCreateWithNativeHandle( std::ignore = pProperties; std::ignore = phKernel; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/native_cpu/memory.cpp b/source/adapters/native_cpu/memory.cpp index a190208ab7..0e19816ead 100644 --- a/source/adapters/native_cpu/memory.cpp +++ b/source/adapters/native_cpu/memory.cpp @@ -23,7 +23,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageCreate( std::ignore = pHost; std::ignore = phMem; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreate( @@ -65,7 +65,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreate( UR_APIEXPORT ur_result_t UR_APICALL urMemRetain(ur_mem_handle_t hMem) { std::ignore = hMem; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urMemRelease(ur_mem_handle_t hMem) { @@ -93,8 +93,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferPartition( std::shared_lock Guard(hBuffer->Mutex); if (flags != UR_MEM_FLAG_READ_WRITE) { - die("urMemBufferPartition: NativeCPU implements only read-write buffer," - "no read-only or write-only yet."); + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } try { @@ -115,7 +114,7 @@ urMemGetNativeHandle(ur_mem_handle_t hMem, ur_native_handle_t *phNativeMem) { std::ignore = hMem; std::ignore = phNativeMem; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreateWithNativeHandle( @@ -126,7 +125,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreateWithNativeHandle( std::ignore = pProperties; std::ignore = phMem; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urMemImageCreateWithNativeHandle( @@ -140,7 +139,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageCreateWithNativeHandle( std::ignore = pProperties; std::ignore = phMem; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urMemGetInfo(ur_mem_handle_t hMemory, @@ -154,7 +153,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemGetInfo(ur_mem_handle_t hMemory, std::ignore = pPropValue; std::ignore = pPropSizeRet; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urMemImageGetInfo(ur_mem_handle_t hMemory, @@ -168,5 +167,5 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageGetInfo(ur_mem_handle_t hMemory, std::ignore = pPropValue; std::ignore = pPropSizeRet; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/native_cpu/platform.cpp b/source/adapters/native_cpu/platform.cpp index 61093f3eed..9d58a992d7 100644 --- a/source/adapters/native_cpu/platform.cpp +++ b/source/adapters/native_cpu/platform.cpp @@ -81,7 +81,7 @@ urPlatformGetInfo(ur_platform_handle_t hPlatform, ur_platform_info_t propName, // https://github.com/oneapi-src/unified-runtime return ReturnValue(UR_PLATFORM_BACKEND_NATIVE_CPU); default: - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } return UR_RESULT_SUCCESS; @@ -94,7 +94,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetBackendOption( std::ignore = pFrontendOption; std::ignore = ppPlatformOption; - CONTINUE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urPlatformCreateWithNativeHandle( @@ -105,7 +105,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformCreateWithNativeHandle( std::ignore = pProperties; std::ignore = phPlatform; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetNativeHandle( @@ -113,5 +113,5 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGetNativeHandle( std::ignore = hPlatform; std::ignore = phNativePlatform; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/native_cpu/program.cpp b/source/adapters/native_cpu/program.cpp index ccd96a3a24..e894f97fb4 100644 --- a/source/adapters/native_cpu/program.cpp +++ b/source/adapters/native_cpu/program.cpp @@ -23,7 +23,7 @@ urProgramCreateWithIL(ur_context_handle_t hContext, const void *pIL, std::ignore = pProperties; std::ignore = phProgram; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinary( @@ -71,7 +71,7 @@ urProgramCompile(ur_context_handle_t hContext, ur_program_handle_t hProgram, std::ignore = hProgram; std::ignore = pOptions; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL @@ -84,7 +84,7 @@ urProgramLink(ur_context_handle_t hContext, uint32_t count, std::ignore = pOptions; std::ignore = phProgram; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urProgramCompileExp(ur_program_handle_t, @@ -127,7 +127,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramGetFunctionPointer( std::ignore = pFunctionName; std::ignore = ppFunctionPointer; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL @@ -173,7 +173,7 @@ urProgramGetBuildInfo(ur_program_handle_t hProgram, ur_device_handle_t hDevice, std::ignore = pPropValue; std::ignore = pPropSizeRet; - CONTINUE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urProgramSetSpecializationConstants( @@ -183,7 +183,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramSetSpecializationConstants( std::ignore = count; std::ignore = pSpecConstants; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urProgramGetNativeHandle( @@ -191,7 +191,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramGetNativeHandle( std::ignore = hProgram; std::ignore = phNativeProgram; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithNativeHandle( @@ -203,5 +203,5 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithNativeHandle( std::ignore = pProperties; std::ignore = phProgram; - DIE_NO_IMPLEMENTATION + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/native_cpu/queue.cpp b/source/adapters/native_cpu/queue.cpp index 516e66db64..2fc3a2db27 100644 --- a/source/adapters/native_cpu/queue.cpp +++ b/source/adapters/native_cpu/queue.cpp @@ -25,7 +25,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueGetInfo(ur_queue_handle_t hQueue, std::ignore = pPropValue; std::ignore = pPropSizeRet; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urQueueCreate( @@ -38,7 +38,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreate( auto Queue = new ur_queue_handle_t_(); *phQueue = Queue; - CONTINUE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urQueueRetain(ur_queue_handle_t hQueue) { @@ -61,7 +61,7 @@ urQueueGetNativeHandle(ur_queue_handle_t hQueue, ur_queue_native_desc_t *pDesc, std::ignore = pDesc; std::ignore = phNativeQueue; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle( @@ -74,7 +74,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle( std::ignore = pProperties; std::ignore = phQueue; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urQueueFinish(ur_queue_handle_t hQueue) { @@ -86,5 +86,5 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueFinish(ur_queue_handle_t hQueue) { UR_APIEXPORT ur_result_t UR_APICALL urQueueFlush(ur_queue_handle_t hQueue) { std::ignore = hQueue; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/native_cpu/sampler.cpp b/source/adapters/native_cpu/sampler.cpp index bf9a72ce3b..2534ba4397 100644 --- a/source/adapters/native_cpu/sampler.cpp +++ b/source/adapters/native_cpu/sampler.cpp @@ -19,21 +19,21 @@ urSamplerCreate(ur_context_handle_t hContext, const ur_sampler_desc_t *pDesc, std::ignore = pDesc; std::ignore = phSampler; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urSamplerRetain(ur_sampler_handle_t hSampler) { std::ignore = hSampler; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urSamplerRelease(ur_sampler_handle_t hSampler) { std::ignore = hSampler; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL @@ -45,7 +45,7 @@ urSamplerGetInfo(ur_sampler_handle_t hSampler, ur_sampler_info_t propName, std::ignore = pPropValue; std::ignore = pPropSizeRet; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urSamplerGetNativeHandle( @@ -53,7 +53,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urSamplerGetNativeHandle( std::ignore = hSampler; std::ignore = phNativeSampler; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urSamplerCreateWithNativeHandle( @@ -65,5 +65,5 @@ UR_APIEXPORT ur_result_t UR_APICALL urSamplerCreateWithNativeHandle( std::ignore = pProperties; std::ignore = phSampler; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/native_cpu/usm.cpp b/source/adapters/native_cpu/usm.cpp index 7cdac0cd8f..bda0e901f2 100644 --- a/source/adapters/native_cpu/usm.cpp +++ b/source/adapters/native_cpu/usm.cpp @@ -86,7 +86,7 @@ urUSMGetMemAllocInfo(ur_context_handle_t hContext, const void *pMem, std::ignore = pPropValue; std::ignore = pPropSizeRet; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL @@ -96,21 +96,21 @@ urUSMPoolCreate(ur_context_handle_t hContext, ur_usm_pool_desc_t *pPoolDesc, std::ignore = pPoolDesc; std::ignore = ppPool; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolRetain(ur_usm_pool_handle_t pPool) { std::ignore = pPool; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urUSMPoolRelease(ur_usm_pool_handle_t pPool) { std::ignore = pPool; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL @@ -122,7 +122,7 @@ urUSMPoolGetInfo(ur_usm_pool_handle_t hPool, ur_usm_pool_info_t propName, std::ignore = pPropValue; std::ignore = pPropSizeRet; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urUSMImportExp(ur_context_handle_t Context, @@ -130,12 +130,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMImportExp(ur_context_handle_t Context, std::ignore = Context; std::ignore = HostPtr; std::ignore = Size; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urUSMReleaseExp(ur_context_handle_t Context, void *HostPtr) { std::ignore = Context; std::ignore = HostPtr; - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/native_cpu/usm_p2p.cpp b/source/adapters/native_cpu/usm_p2p.cpp index dbb47d910e..7de083401a 100644 --- a/source/adapters/native_cpu/usm_p2p.cpp +++ b/source/adapters/native_cpu/usm_p2p.cpp @@ -12,16 +12,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PEnablePeerAccessExp(ur_device_handle_t, ur_device_handle_t) { - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PDisablePeerAccessExp(ur_device_handle_t, ur_device_handle_t) { - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PPeerAccessGetInfoExp(ur_device_handle_t, ur_device_handle_t, ur_exp_peer_info_t, size_t, void *, size_t *) { - DIE_NO_IMPLEMENTATION; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/opencl/common.cpp b/source/adapters/opencl/common.cpp index 4fe8bed408..b39f18af70 100644 --- a/source/adapters/opencl/common.cpp +++ b/source/adapters/opencl/common.cpp @@ -86,11 +86,6 @@ ur_result_t mapCLErrorToUR(cl_int Result) { } } -void cl_adapter::die(const char *Message) { - std::cerr << "ur_die: " << Message << "\n"; - std::terminate(); -} - /// Common API for getting the native handle of a UR object /// /// \param URObj is the UR object to get the native handle of diff --git a/source/adapters/opencl/common.hpp b/source/adapters/opencl/common.hpp index 0cb19694a6..9fcfb29c61 100644 --- a/source/adapters/opencl/common.hpp +++ b/source/adapters/opencl/common.hpp @@ -157,8 +157,6 @@ extern thread_local char ErrorMessage[MaxMessageSize]; [[maybe_unused]] void setErrorMessage(const char *Message, ur_result_t ErrorCode); -[[noreturn]] void die(const char *Message); - template To cast(From Value) { if constexpr (std::is_pointer_v) { diff --git a/source/adapters/opencl/sampler.cpp b/source/adapters/opencl/sampler.cpp index 5f58216446..56993096d5 100644 --- a/source/adapters/opencl/sampler.cpp +++ b/source/adapters/opencl/sampler.cpp @@ -12,11 +12,13 @@ namespace { -cl_sampler_info ur2CLSamplerInfo(ur_sampler_info_t URInfo) { +ur_result_t ur2CLSamplerInfo(ur_sampler_info_t URInfo, + cl_sampler_info *CLInfo) { switch (URInfo) { #define CASE(UR_INFO, CL_INFO) \ case UR_INFO: \ - return CL_INFO; + *CLInfo = CL_INFO; \ + return UR_RESULT_SUCCESS; CASE(UR_SAMPLER_INFO_REFERENCE_COUNT, CL_SAMPLER_REFERENCE_COUNT) CASE(UR_SAMPLER_INFO_CONTEXT, CL_SAMPLER_CONTEXT) @@ -27,16 +29,17 @@ cl_sampler_info ur2CLSamplerInfo(ur_sampler_info_t URInfo) { #undef CASE default: - cl_adapter::die("Unhandled: ur_sampler_info_t"); + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; } } -cl_addressing_mode ur2CLAddressingMode(ur_sampler_addressing_mode_t Mode) { +ur_result_t ur2CLAddressingMode(ur_sampler_addressing_mode_t Mode, + cl_addressing_mode *CLMode) { switch (Mode) { - #define CASE(UR_MODE, CL_MODE) \ case UR_MODE: \ - return CL_MODE; + *CLMode = CL_MODE; \ + return UR_RESULT_SUCCESS; CASE(UR_SAMPLER_ADDRESSING_MODE_NONE, CL_ADDRESS_NONE); CASE(UR_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE, CL_ADDRESS_CLAMP_TO_EDGE); @@ -48,16 +51,17 @@ cl_addressing_mode ur2CLAddressingMode(ur_sampler_addressing_mode_t Mode) { #undef CASE default: - cl_adapter::die("Unhandled: ur_sampler_addressing_mode_t"); + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; } } -cl_filter_mode ur2CLFilterMode(ur_sampler_filter_mode_t Mode) { +ur_result_t ur2CLFilterMode(ur_sampler_filter_mode_t Mode, + cl_filter_mode *CLMode) { switch (Mode) { - #define CASE(UR_MODE, CL_MODE) \ case UR_MODE: \ - return CL_MODE; + *CLMode = CL_MODE; \ + return UR_RESULT_SUCCESS; CASE(UR_SAMPLER_FILTER_MODE_NEAREST, CL_FILTER_NEAREST) CASE(UR_SAMPLER_FILTER_MODE_LINEAR, CL_FILTER_LINEAR) @@ -65,16 +69,17 @@ cl_filter_mode ur2CLFilterMode(ur_sampler_filter_mode_t Mode) { #undef CASE default: - cl_adapter::die("Unhandled: ur_sampler_filter_mode_t"); + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; } } -ur_sampler_addressing_mode_t cl2URAddressingMode(cl_addressing_mode Mode) { +ur_result_t cl2URAddressingMode(cl_addressing_mode Mode, + ur_sampler_addressing_mode_t *URMode) { switch (Mode) { - #define CASE(CL_MODE, UR_MODE) \ case CL_MODE: \ - return UR_MODE; + *URMode = UR_MODE; \ + return UR_RESULT_SUCCESS; CASE(CL_ADDRESS_NONE, UR_SAMPLER_ADDRESSING_MODE_NONE); CASE(CL_ADDRESS_CLAMP_TO_EDGE, UR_SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE); @@ -86,15 +91,17 @@ ur_sampler_addressing_mode_t cl2URAddressingMode(cl_addressing_mode Mode) { #undef CASE default: - cl_adapter::die("Unhandled: cl_addressing_mode"); + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; } } -ur_sampler_filter_mode_t cl2URFilterMode(cl_filter_mode Mode) { +ur_result_t cl2URFilterMode(cl_filter_mode Mode, + ur_sampler_filter_mode_t *URMode) { switch (Mode) { #define CASE(CL_MODE, UR_MODE) \ case CL_MODE: \ - return UR_MODE; + *URMode = UR_MODE; \ + return UR_RESULT_SUCCESS; CASE(CL_FILTER_NEAREST, UR_SAMPLER_FILTER_MODE_NEAREST) CASE(CL_FILTER_LINEAR, UR_SAMPLER_FILTER_MODE_LINEAR); @@ -102,7 +109,7 @@ ur_sampler_filter_mode_t cl2URFilterMode(cl_filter_mode Mode) { #undef CASE default: - cl_adapter::die("Unhandled: cl_filter_mode"); + return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; } } @@ -114,14 +121,17 @@ void cl2URSamplerInfoValue(cl_sampler_info Info, void *InfoValue) { case CL_SAMPLER_ADDRESSING_MODE: { cl_addressing_mode CLValue = *reinterpret_cast(InfoValue); + ur_sampler_addressing_mode_t AddressingMode; + cl2URAddressingMode(CLValue, &AddressingMode); *reinterpret_cast(InfoValue) = - cl2URAddressingMode(CLValue); + AddressingMode; break; } case CL_SAMPLER_FILTER_MODE: { cl_filter_mode CLMode = *reinterpret_cast(InfoValue); - *reinterpret_cast(InfoValue) = - cl2URFilterMode(CLMode); + ur_sampler_filter_mode_t FilterMode; + cl2URFilterMode(CLMode, &FilterMode); + *reinterpret_cast(InfoValue) = FilterMode; break; } @@ -138,9 +148,11 @@ ur_result_t urSamplerCreate(ur_context_handle_t hContext, // Initialize properties according to OpenCL 2.1 spec. ur_result_t ErrorCode; - cl_addressing_mode AddressingMode = - ur2CLAddressingMode(pDesc->addressingMode); - cl_filter_mode FilterMode = ur2CLFilterMode(pDesc->filterMode); + cl_addressing_mode AddressingMode; + UR_RETURN_ON_FAILURE( + ur2CLAddressingMode(pDesc->addressingMode, &AddressingMode)); + cl_filter_mode FilterMode; + UR_RETURN_ON_FAILURE(ur2CLFilterMode(pDesc->filterMode, &FilterMode)); // Always call OpenCL 1.0 API *phSampler = cl_adapter::cast(clCreateSampler( @@ -154,7 +166,8 @@ ur_result_t urSamplerCreate(ur_context_handle_t hContext, UR_APIEXPORT ur_result_t UR_APICALL urSamplerGetInfo(ur_sampler_handle_t hSampler, ur_sampler_info_t propName, size_t propSize, void *pPropValue, size_t *pPropSizeRet) { - cl_sampler_info SamplerInfo = ur2CLSamplerInfo(propName); + cl_sampler_info SamplerInfo; + UR_RETURN_ON_FAILURE(ur2CLSamplerInfo(propName, &SamplerInfo)); static_assert(sizeof(cl_addressing_mode) == sizeof(ur_sampler_addressing_mode_t)); diff --git a/source/adapters/opencl/usm_p2p.cpp b/source/adapters/opencl/usm_p2p.cpp index b0f51eac2b..9ee9920ad8 100644 --- a/source/adapters/opencl/usm_p2p.cpp +++ b/source/adapters/opencl/usm_p2p.cpp @@ -13,18 +13,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PEnablePeerAccessExp([[maybe_unused]] ur_device_handle_t commandDevice, [[maybe_unused]] ur_device_handle_t peerDevice) { - - cl_adapter::die( - "Experimental P2P feature is not implemented for OpenCL adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PDisablePeerAccessExp([[maybe_unused]] ur_device_handle_t commandDevice, [[maybe_unused]] ur_device_handle_t peerDevice) { - - cl_adapter::die( - "Experimental P2P feature is not implemented for OpenCL adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } @@ -34,8 +28,5 @@ UR_APIEXPORT ur_result_t UR_APICALL urUsmP2PPeerAccessGetInfoExp( [[maybe_unused]] ur_exp_peer_info_t propName, [[maybe_unused]] size_t propSize, [[maybe_unused]] void *pPropValue, [[maybe_unused]] size_t *pPropSizeRet) { - - cl_adapter::die( - "Experimental P2P feature is not implemented for OpenCL adapter."); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/ur/ur.hpp b/source/ur/ur.hpp index 0437d719ba..5bee999504 100644 --- a/source/ur/ur.hpp +++ b/source/ur/ur.hpp @@ -51,12 +51,6 @@ const ur_command_t UR_EXT_COMMAND_TYPE_USER = #define __SYCL_UR_PROGRAM_METADATA_GLOBAL_ID_MAPPING "@global_id_mapping" #define __SYCL_UR_PROGRAM_METADATA_TAG_NEED_FINALIZATION "Requires finalization" -// Terminates the process with a catastrophic error message. -[[noreturn]] inline void die(const char *Message) { - std::cerr << "die: " << Message << std::endl; - std::terminate(); -} - // A single-threaded app has an opportunity to enable this mode to avoid // overhead from mutex locking. Default value is 0 which means that single // thread mode is disabled.