diff --git a/source/adapters/opencl/command_buffer.cpp b/source/adapters/opencl/command_buffer.cpp index 88c661b4ae..ac5650b1a1 100644 --- a/source/adapters/opencl/command_buffer.cpp +++ b/source/adapters/opencl/command_buffer.cpp @@ -21,14 +21,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp( cl_context CLContext = cl_adapter::cast(hContext); cl_ext::clCreateCommandBufferKHR_fn clCreateCommandBufferKHR = nullptr; - cl_int Res = + UR_RETURN_ON_FAILURE( cl_ext::getExtFuncFromContext( CLContext, cl_ext::ExtFuncPtrCache->clCreateCommandBufferKHRCache, - cl_ext::CreateCommandBufferName, &clCreateCommandBufferKHR); - - if (!clCreateCommandBufferKHR || Res != CL_SUCCESS) - return UR_RESULT_ERROR_INVALID_OPERATION; + cl_ext::CreateCommandBufferName, &clCreateCommandBufferKHR)); + cl_int Res = CL_SUCCESS; auto CLCommandBuffer = clCreateCommandBufferKHR( 1, cl_adapter::cast(&Queue), nullptr, &Res); CL_RETURN_ON_FAILURE_AND_SET_NULL(Res, phCommandBuffer); @@ -51,12 +49,10 @@ urCommandBufferRetainExp(ur_exp_command_buffer_handle_t hCommandBuffer) { cl_context CLContext = cl_adapter::cast(hCommandBuffer->hContext); cl_ext::clRetainCommandBufferKHR_fn clRetainCommandBuffer = nullptr; - cl_int Res = cl_ext::getExtFuncFromContext( - CLContext, cl_ext::ExtFuncPtrCache->clRetainCommandBufferKHRCache, - cl_ext::RetainCommandBufferName, &clRetainCommandBuffer); - - if (!clRetainCommandBuffer || Res != CL_SUCCESS) - return UR_RESULT_ERROR_INVALID_OPERATION; + UR_RETURN_ON_FAILURE( + cl_ext::getExtFuncFromContext( + CLContext, cl_ext::ExtFuncPtrCache->clRetainCommandBufferKHRCache, + cl_ext::RetainCommandBufferName, &clRetainCommandBuffer)); CL_RETURN_ON_FAILURE(clRetainCommandBuffer(hCommandBuffer->CLCommandBuffer)); return UR_RESULT_SUCCESS; @@ -68,13 +64,10 @@ urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t hCommandBuffer) { cl_context CLContext = cl_adapter::cast(hCommandBuffer->hContext); cl_ext::clReleaseCommandBufferKHR_fn clReleaseCommandBufferKHR = nullptr; - cl_int Res = + UR_RETURN_ON_FAILURE( cl_ext::getExtFuncFromContext( CLContext, cl_ext::ExtFuncPtrCache->clReleaseCommandBufferKHRCache, - cl_ext::ReleaseCommandBufferName, &clReleaseCommandBufferKHR); - - if (!clReleaseCommandBufferKHR || Res != CL_SUCCESS) - return UR_RESULT_ERROR_INVALID_OPERATION; + cl_ext::ReleaseCommandBufferName, &clReleaseCommandBufferKHR)); CL_RETURN_ON_FAILURE( clReleaseCommandBufferKHR(hCommandBuffer->CLCommandBuffer)); @@ -85,13 +78,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t hCommandBuffer) { cl_context CLContext = cl_adapter::cast(hCommandBuffer->hContext); cl_ext::clFinalizeCommandBufferKHR_fn clFinalizeCommandBufferKHR = nullptr; - cl_int Res = + UR_RETURN_ON_FAILURE( cl_ext::getExtFuncFromContext( CLContext, cl_ext::ExtFuncPtrCache->clFinalizeCommandBufferKHRCache, - cl_ext::FinalizeCommandBufferName, &clFinalizeCommandBufferKHR); - - if (!clFinalizeCommandBufferKHR || Res != CL_SUCCESS) - return UR_RESULT_ERROR_INVALID_OPERATION; + cl_ext::FinalizeCommandBufferName, &clFinalizeCommandBufferKHR)); CL_RETURN_ON_FAILURE( clFinalizeCommandBufferKHR(hCommandBuffer->CLCommandBuffer)); @@ -109,13 +99,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp( cl_context CLContext = cl_adapter::cast(hCommandBuffer->hContext); cl_ext::clCommandNDRangeKernelKHR_fn clCommandNDRangeKernelKHR = nullptr; - cl_int Res = + UR_RETURN_ON_FAILURE( cl_ext::getExtFuncFromContext( CLContext, cl_ext::ExtFuncPtrCache->clCommandNDRangeKernelKHRCache, - cl_ext::CommandNRRangeKernelName, &clCommandNDRangeKernelKHR); - - if (!clCommandNDRangeKernelKHR || Res != CL_SUCCESS) - return UR_RESULT_ERROR_INVALID_OPERATION; + cl_ext::CommandNRRangeKernelName, &clCommandNDRangeKernelKHR)); CL_RETURN_ON_FAILURE(clCommandNDRangeKernelKHR( hCommandBuffer->CLCommandBuffer, nullptr, nullptr, @@ -157,12 +144,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferCopyExp( cl_context CLContext = cl_adapter::cast(hCommandBuffer->hContext); cl_ext::clCommandCopyBufferKHR_fn clCommandCopyBufferKHR = nullptr; - cl_int Res = cl_ext::getExtFuncFromContext( - CLContext, cl_ext::ExtFuncPtrCache->clCommandCopyBufferKHRCache, - cl_ext::CommandCopyBufferName, &clCommandCopyBufferKHR); - - if (!clCommandCopyBufferKHR || Res != CL_SUCCESS) - return UR_RESULT_ERROR_INVALID_OPERATION; + UR_RETURN_ON_FAILURE( + cl_ext::getExtFuncFromContext( + CLContext, cl_ext::ExtFuncPtrCache->clCommandCopyBufferKHRCache, + cl_ext::CommandCopyBufferName, &clCommandCopyBufferKHR)); CL_RETURN_ON_FAILURE(clCommandCopyBufferKHR( hCommandBuffer->CLCommandBuffer, nullptr, @@ -193,13 +178,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferCopyRectExp( cl_context CLContext = cl_adapter::cast(hCommandBuffer->hContext); cl_ext::clCommandCopyBufferRectKHR_fn clCommandCopyBufferRectKHR = nullptr; - cl_int Res = + UR_RETURN_ON_FAILURE( cl_ext::getExtFuncFromContext( CLContext, cl_ext::ExtFuncPtrCache->clCommandCopyBufferRectKHRCache, - cl_ext::CommandCopyBufferRectName, &clCommandCopyBufferRectKHR); - - if (!clCommandCopyBufferRectKHR || Res != CL_SUCCESS) - return UR_RESULT_ERROR_INVALID_OPERATION; + cl_ext::CommandCopyBufferRectName, &clCommandCopyBufferRectKHR)); CL_RETURN_ON_FAILURE(clCommandCopyBufferRectKHR( hCommandBuffer->CLCommandBuffer, nullptr, @@ -283,12 +265,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferFillExp( cl_context CLContext = cl_adapter::cast(hCommandBuffer->hContext); cl_ext::clCommandFillBufferKHR_fn clCommandFillBufferKHR = nullptr; - cl_int Res = cl_ext::getExtFuncFromContext( - CLContext, cl_ext::ExtFuncPtrCache->clCommandFillBufferKHRCache, - cl_ext::CommandFillBufferName, &clCommandFillBufferKHR); - - if (!clCommandFillBufferKHR || Res != CL_SUCCESS) - return UR_RESULT_ERROR_INVALID_OPERATION; + UR_RETURN_ON_FAILURE( + cl_ext::getExtFuncFromContext( + CLContext, cl_ext::ExtFuncPtrCache->clCommandFillBufferKHRCache, + cl_ext::CommandFillBufferName, &clCommandFillBufferKHR)); CL_RETURN_ON_FAILURE(clCommandFillBufferKHR( hCommandBuffer->CLCommandBuffer, nullptr, @@ -339,13 +319,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferEnqueueExp( cl_context CLContext = cl_adapter::cast(hCommandBuffer->hContext); cl_ext::clEnqueueCommandBufferKHR_fn clEnqueueCommandBufferKHR = nullptr; - cl_int Res = + UR_RETURN_ON_FAILURE( cl_ext::getExtFuncFromContext( CLContext, cl_ext::ExtFuncPtrCache->clEnqueueCommandBufferKHRCache, - cl_ext::EnqueueCommandBufferName, &clEnqueueCommandBufferKHR); - - if (!clEnqueueCommandBufferKHR || Res != CL_SUCCESS) - return UR_RESULT_ERROR_INVALID_OPERATION; + cl_ext::EnqueueCommandBufferName, &clEnqueueCommandBufferKHR)); const uint32_t NumberOfQueues = 1; @@ -382,13 +359,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferGetInfoExp( cl_context CLContext = cl_adapter::cast(hCommandBuffer->hContext); cl_ext::clGetCommandBufferInfoKHR_fn clGetCommandBufferInfoKHR = nullptr; - cl_int Res = + UR_RETURN_ON_FAILURE( cl_ext::getExtFuncFromContext( CLContext, cl_ext::ExtFuncPtrCache->clGetCommandBufferInfoKHRCache, - cl_ext::GetCommandBufferInfoName, &clGetCommandBufferInfoKHR); - - if (!clGetCommandBufferInfoKHR || Res != CL_SUCCESS) - return UR_RESULT_ERROR_INVALID_OPERATION; + cl_ext::GetCommandBufferInfoName, &clGetCommandBufferInfoKHR)); if (propName != UR_EXP_COMMAND_BUFFER_INFO_REFERENCE_COUNT) { return UR_RESULT_ERROR_INVALID_ENUMERATION; diff --git a/source/adapters/opencl/common.hpp b/source/adapters/opencl/common.hpp index d99a0bd417..256fce0c22 100644 --- a/source/adapters/opencl/common.hpp +++ b/source/adapters/opencl/common.hpp @@ -373,9 +373,9 @@ static ur_result_t getExtFuncFromContext(cl_context Context, if (It != FPtrMap.end()) { auto F = It->second; // if cached that extension is not available return nullptr and - // UR_RESULT_ERROR_INVALID_VALUE + // UR_RESULT_ERROR_UNSUPPORTED_FEATURE *Fptr = F; - return F ? UR_RESULT_SUCCESS : UR_RESULT_ERROR_INVALID_VALUE; + return F ? UR_RESULT_SUCCESS : UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } cl_uint DeviceCount; @@ -409,7 +409,7 @@ static ur_result_t getExtFuncFromContext(cl_context Context, if (!FuncPtr) { // Cache that the extension is not available FPtrMap[Context] = nullptr; - return UR_RESULT_ERROR_INVALID_VALUE; + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } *Fptr = FuncPtr; diff --git a/source/adapters/opencl/enqueue.cpp b/source/adapters/opencl/enqueue.cpp index 506796a07b..9fb4239c38 100644 --- a/source/adapters/opencl/enqueue.cpp +++ b/source/adapters/opencl/enqueue.cpp @@ -347,12 +347,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableWrite( return mapCLErrorToUR(Res); cl_ext::clEnqueueWriteGlobalVariable_fn F = nullptr; - Res = cl_ext::getExtFuncFromContext( + UR_RETURN_ON_FAILURE(cl_ext::getExtFuncFromContext( Ctx, cl_ext::ExtFuncPtrCache->clEnqueueWriteGlobalVariableCache, - cl_ext::EnqueueWriteGlobalVariableName, &F); - - if (!F || Res != CL_SUCCESS) - return UR_RESULT_ERROR_INVALID_OPERATION; + cl_ext::EnqueueWriteGlobalVariableName, &F)); Res = F(cl_adapter::cast(hQueue), cl_adapter::cast(hProgram), name, blockingWrite, count, @@ -378,12 +375,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableRead( return mapCLErrorToUR(Res); cl_ext::clEnqueueReadGlobalVariable_fn F = nullptr; - Res = cl_ext::getExtFuncFromContext( + UR_RETURN_ON_FAILURE(cl_ext::getExtFuncFromContext( Ctx, cl_ext::ExtFuncPtrCache->clEnqueueReadGlobalVariableCache, - cl_ext::EnqueueReadGlobalVariableName, &F); - - if (!F || Res != CL_SUCCESS) - return UR_RESULT_ERROR_INVALID_OPERATION; + cl_ext::EnqueueReadGlobalVariableName, &F)); Res = F(cl_adapter::cast(hQueue), cl_adapter::cast(hProgram), name, blockingRead, count, @@ -409,13 +403,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueReadHostPipe( } cl_ext::clEnqueueReadHostPipeINTEL_fn FuncPtr = nullptr; - ur_result_t RetVal = + UR_RETURN_ON_FAILURE( cl_ext::getExtFuncFromContext( CLContext, cl_ext::ExtFuncPtrCache->clEnqueueReadHostPipeINTELCache, - cl_ext::EnqueueReadHostPipeName, &FuncPtr); + cl_ext::EnqueueReadHostPipeName, &FuncPtr)); if (FuncPtr) { - RetVal = mapCLErrorToUR( + CL_RETURN_ON_FAILURE( FuncPtr(cl_adapter::cast(hQueue), cl_adapter::cast(hProgram), pipe_symbol, blocking, pDst, size, numEventsInWaitList, @@ -423,7 +417,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueReadHostPipe( cl_adapter::cast(phEvent))); } - return RetVal; + return UR_RESULT_SUCCESS; } UR_APIEXPORT ur_result_t UR_APICALL urEnqueueWriteHostPipe( @@ -441,13 +435,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueWriteHostPipe( } cl_ext::clEnqueueWriteHostPipeINTEL_fn FuncPtr = nullptr; - ur_result_t RetVal = + UR_RETURN_ON_FAILURE( cl_ext::getExtFuncFromContext( CLContext, cl_ext::ExtFuncPtrCache->clEnqueueWriteHostPipeINTELCache, - cl_ext::EnqueueWriteHostPipeName, &FuncPtr); + cl_ext::EnqueueWriteHostPipeName, &FuncPtr)); if (FuncPtr) { - RetVal = mapCLErrorToUR( + CL_RETURN_ON_FAILURE( FuncPtr(cl_adapter::cast(hQueue), cl_adapter::cast(hProgram), pipe_symbol, blocking, pSrc, size, numEventsInWaitList, @@ -455,5 +449,5 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueWriteHostPipe( cl_adapter::cast(phEvent))); } - return RetVal; + return UR_RESULT_SUCCESS; } diff --git a/source/adapters/opencl/memory.cpp b/source/adapters/opencl/memory.cpp index 2397e2b5f9..5de850f1e2 100644 --- a/source/adapters/opencl/memory.cpp +++ b/source/adapters/opencl/memory.cpp @@ -232,11 +232,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreate( clCreateBufferWithPropertiesINTEL_fn FuncPtr = nullptr; cl_context CLContext = cl_adapter::cast(hContext); // First we need to look up the function pointer - RetErr = + UR_RETURN_ON_FAILURE( cl_ext::getExtFuncFromContext( CLContext, cl_ext::ExtFuncPtrCache->clCreateBufferWithPropertiesINTELCache, - cl_ext::CreateBufferWithPropertiesName, &FuncPtr); + cl_ext::CreateBufferWithPropertiesName, &FuncPtr)); if (FuncPtr) { std::vector PropertiesIntel; auto Prop = static_cast(pProperties->pNext);