Skip to content

Commit

Permalink
[OpenCL] Make extension function lookup return unusupported error
Browse files Browse the repository at this point in the history
This commit changes the error code of failing to look up extension
pointers in OpenCL return UR_RESULT_ERROR_UNSUPPORTED_FEATURE instead
of UR_RESULT_ERROR_INVALID_VALUE. Likewise, some of the places this
lookup was used, error would return UR_RESULT_ERROR_INVALID_OPERATION.
The motivation behind this change is to make the error codes for cases
where extensions are not supported for the OpenCL target clearer.

Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
  • Loading branch information
steffenlarsen committed Mar 15, 2024
1 parent 6513abc commit bc54043
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
40 changes: 20 additions & 20 deletions source/adapters/opencl/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp(
CLContext, cl_ext::ExtFuncPtrCache->clCreateCommandBufferKHRCache,
cl_ext::CreateCommandBufferName, &clCreateCommandBufferKHR);

if (!clCreateCommandBufferKHR || Res != CL_SUCCESS)
return UR_RESULT_ERROR_INVALID_OPERATION;
if (Res != CL_SUCCESS)
return Res;

auto CLCommandBuffer = clCreateCommandBufferKHR(
1, cl_adapter::cast<cl_command_queue *>(&Queue), nullptr, &Res);
Expand Down Expand Up @@ -55,8 +55,8 @@ urCommandBufferRetainExp(ur_exp_command_buffer_handle_t hCommandBuffer) {
CLContext, cl_ext::ExtFuncPtrCache->clRetainCommandBufferKHRCache,
cl_ext::RetainCommandBufferName, &clRetainCommandBuffer);

if (!clRetainCommandBuffer || Res != CL_SUCCESS)
return UR_RESULT_ERROR_INVALID_OPERATION;
if (Res != CL_SUCCESS)
return Res;

CL_RETURN_ON_FAILURE(clRetainCommandBuffer(hCommandBuffer->CLCommandBuffer));
return UR_RESULT_SUCCESS;
Expand All @@ -73,8 +73,8 @@ urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t hCommandBuffer) {
CLContext, cl_ext::ExtFuncPtrCache->clReleaseCommandBufferKHRCache,
cl_ext::ReleaseCommandBufferName, &clReleaseCommandBufferKHR);

if (!clReleaseCommandBufferKHR || Res != CL_SUCCESS)
return UR_RESULT_ERROR_INVALID_OPERATION;
if (Res != CL_SUCCESS)
return Res;

CL_RETURN_ON_FAILURE(
clReleaseCommandBufferKHR(hCommandBuffer->CLCommandBuffer));
Expand All @@ -90,8 +90,8 @@ urCommandBufferFinalizeExp(ur_exp_command_buffer_handle_t hCommandBuffer) {
CLContext, cl_ext::ExtFuncPtrCache->clFinalizeCommandBufferKHRCache,
cl_ext::FinalizeCommandBufferName, &clFinalizeCommandBufferKHR);

if (!clFinalizeCommandBufferKHR || Res != CL_SUCCESS)
return UR_RESULT_ERROR_INVALID_OPERATION;
if (Res != CL_SUCCESS)
return Res;

CL_RETURN_ON_FAILURE(
clFinalizeCommandBufferKHR(hCommandBuffer->CLCommandBuffer));
Expand All @@ -114,8 +114,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
CLContext, cl_ext::ExtFuncPtrCache->clCommandNDRangeKernelKHRCache,
cl_ext::CommandNRRangeKernelName, &clCommandNDRangeKernelKHR);

if (!clCommandNDRangeKernelKHR || Res != CL_SUCCESS)
return UR_RESULT_ERROR_INVALID_OPERATION;
if (Res != CL_SUCCESS)
return Res;

CL_RETURN_ON_FAILURE(clCommandNDRangeKernelKHR(
hCommandBuffer->CLCommandBuffer, nullptr, nullptr,
Expand Down Expand Up @@ -161,8 +161,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferCopyExp(
CLContext, cl_ext::ExtFuncPtrCache->clCommandCopyBufferKHRCache,
cl_ext::CommandCopyBufferName, &clCommandCopyBufferKHR);

if (!clCommandCopyBufferKHR || Res != CL_SUCCESS)
return UR_RESULT_ERROR_INVALID_OPERATION;
if (Res != CL_SUCCESS)
return Res;

CL_RETURN_ON_FAILURE(clCommandCopyBufferKHR(
hCommandBuffer->CLCommandBuffer, nullptr,
Expand Down Expand Up @@ -198,8 +198,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferCopyRectExp(
CLContext, cl_ext::ExtFuncPtrCache->clCommandCopyBufferRectKHRCache,
cl_ext::CommandCopyBufferRectName, &clCommandCopyBufferRectKHR);

if (!clCommandCopyBufferRectKHR || Res != CL_SUCCESS)
return UR_RESULT_ERROR_INVALID_OPERATION;
if (Res != CL_SUCCESS)
return Res;

CL_RETURN_ON_FAILURE(clCommandCopyBufferRectKHR(
hCommandBuffer->CLCommandBuffer, nullptr,
Expand Down Expand Up @@ -287,8 +287,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferFillExp(
CLContext, cl_ext::ExtFuncPtrCache->clCommandFillBufferKHRCache,
cl_ext::CommandFillBufferName, &clCommandFillBufferKHR);

if (!clCommandFillBufferKHR || Res != CL_SUCCESS)
return UR_RESULT_ERROR_INVALID_OPERATION;
if (Res != CL_SUCCESS)
return Res;

CL_RETURN_ON_FAILURE(clCommandFillBufferKHR(
hCommandBuffer->CLCommandBuffer, nullptr,
Expand Down Expand Up @@ -344,8 +344,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferEnqueueExp(
CLContext, cl_ext::ExtFuncPtrCache->clEnqueueCommandBufferKHRCache,
cl_ext::EnqueueCommandBufferName, &clEnqueueCommandBufferKHR);

if (!clEnqueueCommandBufferKHR || Res != CL_SUCCESS)
return UR_RESULT_ERROR_INVALID_OPERATION;
if (Res != CL_SUCCESS)
return Res;

const uint32_t NumberOfQueues = 1;

Expand Down Expand Up @@ -387,8 +387,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferGetInfoExp(
CLContext, cl_ext::ExtFuncPtrCache->clGetCommandBufferInfoKHRCache,
cl_ext::GetCommandBufferInfoName, &clGetCommandBufferInfoKHR);

if (!clGetCommandBufferInfoKHR || Res != CL_SUCCESS)
return UR_RESULT_ERROR_INVALID_OPERATION;
if (Res != CL_SUCCESS)
return Res;

if (propName != UR_EXP_COMMAND_BUFFER_INFO_REFERENCE_COUNT) {
return UR_RESULT_ERROR_INVALID_ENUMERATION;
Expand Down
6 changes: 3 additions & 3 deletions source/adapters/opencl/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,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;
Expand Down Expand Up @@ -401,7 +401,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;
Expand Down
8 changes: 4 additions & 4 deletions source/adapters/opencl/enqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableWrite(
Ctx, cl_ext::ExtFuncPtrCache->clEnqueueWriteGlobalVariableCache,
cl_ext::EnqueueWriteGlobalVariableName, &F);

if (!F || Res != CL_SUCCESS)
return UR_RESULT_ERROR_INVALID_OPERATION;
if (Res != CL_SUCCESS)
return Res;

Res = F(cl_adapter::cast<cl_command_queue>(hQueue),
cl_adapter::cast<cl_program>(hProgram), name, blockingWrite, count,
Expand Down Expand Up @@ -382,8 +382,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableRead(
Ctx, cl_ext::ExtFuncPtrCache->clEnqueueReadGlobalVariableCache,
cl_ext::EnqueueReadGlobalVariableName, &F);

if (!F || Res != CL_SUCCESS)
return UR_RESULT_ERROR_INVALID_OPERATION;
if (Res != CL_SUCCESS)
return Res;

Res = F(cl_adapter::cast<cl_command_queue>(hQueue),
cl_adapter::cast<cl_program>(hProgram), name, blockingRead, count,
Expand Down

0 comments on commit bc54043

Please sign in to comment.