Skip to content

Commit

Permalink
Merge pull request #1448 from steffenlarsen/steffen/make_ext_func_fai…
Browse files Browse the repository at this point in the history
…l_unsupported

[OpenCL] Make extension function lookup return unusupported error
  • Loading branch information
kbenzie authored Apr 4, 2024
2 parents e60c3c2 + 9287547 commit 3609afc
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 76 deletions.
80 changes: 27 additions & 53 deletions source/adapters/opencl/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferCreateExp(

cl_context CLContext = cl_adapter::cast<cl_context>(hContext);
cl_ext::clCreateCommandBufferKHR_fn clCreateCommandBufferKHR = nullptr;
cl_int Res =
UR_RETURN_ON_FAILURE(
cl_ext::getExtFuncFromContext<decltype(clCreateCommandBufferKHR)>(
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<cl_command_queue *>(&Queue), nullptr, &Res);
CL_RETURN_ON_FAILURE_AND_SET_NULL(Res, phCommandBuffer);
Expand All @@ -51,12 +49,10 @@ urCommandBufferRetainExp(ur_exp_command_buffer_handle_t hCommandBuffer) {

cl_context CLContext = cl_adapter::cast<cl_context>(hCommandBuffer->hContext);
cl_ext::clRetainCommandBufferKHR_fn clRetainCommandBuffer = nullptr;
cl_int Res = cl_ext::getExtFuncFromContext<decltype(clRetainCommandBuffer)>(
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<decltype(clRetainCommandBuffer)>(
CLContext, cl_ext::ExtFuncPtrCache->clRetainCommandBufferKHRCache,
cl_ext::RetainCommandBufferName, &clRetainCommandBuffer));

CL_RETURN_ON_FAILURE(clRetainCommandBuffer(hCommandBuffer->CLCommandBuffer));
return UR_RESULT_SUCCESS;
Expand All @@ -68,13 +64,10 @@ urCommandBufferReleaseExp(ur_exp_command_buffer_handle_t hCommandBuffer) {

cl_context CLContext = cl_adapter::cast<cl_context>(hCommandBuffer->hContext);
cl_ext::clReleaseCommandBufferKHR_fn clReleaseCommandBufferKHR = nullptr;
cl_int Res =
UR_RETURN_ON_FAILURE(
cl_ext::getExtFuncFromContext<decltype(clReleaseCommandBufferKHR)>(
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));
Expand All @@ -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<cl_context>(hCommandBuffer->hContext);
cl_ext::clFinalizeCommandBufferKHR_fn clFinalizeCommandBufferKHR = nullptr;
cl_int Res =
UR_RETURN_ON_FAILURE(
cl_ext::getExtFuncFromContext<decltype(clFinalizeCommandBufferKHR)>(
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));
Expand All @@ -109,13 +99,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(

cl_context CLContext = cl_adapter::cast<cl_context>(hCommandBuffer->hContext);
cl_ext::clCommandNDRangeKernelKHR_fn clCommandNDRangeKernelKHR = nullptr;
cl_int Res =
UR_RETURN_ON_FAILURE(
cl_ext::getExtFuncFromContext<decltype(clCommandNDRangeKernelKHR)>(
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,
Expand Down Expand Up @@ -157,12 +144,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferCopyExp(

cl_context CLContext = cl_adapter::cast<cl_context>(hCommandBuffer->hContext);
cl_ext::clCommandCopyBufferKHR_fn clCommandCopyBufferKHR = nullptr;
cl_int Res = cl_ext::getExtFuncFromContext<decltype(clCommandCopyBufferKHR)>(
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<decltype(clCommandCopyBufferKHR)>(
CLContext, cl_ext::ExtFuncPtrCache->clCommandCopyBufferKHRCache,
cl_ext::CommandCopyBufferName, &clCommandCopyBufferKHR));

CL_RETURN_ON_FAILURE(clCommandCopyBufferKHR(
hCommandBuffer->CLCommandBuffer, nullptr,
Expand Down Expand Up @@ -193,13 +178,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferCopyRectExp(

cl_context CLContext = cl_adapter::cast<cl_context>(hCommandBuffer->hContext);
cl_ext::clCommandCopyBufferRectKHR_fn clCommandCopyBufferRectKHR = nullptr;
cl_int Res =
UR_RETURN_ON_FAILURE(
cl_ext::getExtFuncFromContext<decltype(clCommandCopyBufferRectKHR)>(
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,
Expand Down Expand Up @@ -283,12 +265,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferFillExp(

cl_context CLContext = cl_adapter::cast<cl_context>(hCommandBuffer->hContext);
cl_ext::clCommandFillBufferKHR_fn clCommandFillBufferKHR = nullptr;
cl_int Res = cl_ext::getExtFuncFromContext<decltype(clCommandFillBufferKHR)>(
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<decltype(clCommandFillBufferKHR)>(
CLContext, cl_ext::ExtFuncPtrCache->clCommandFillBufferKHRCache,
cl_ext::CommandFillBufferName, &clCommandFillBufferKHR));

CL_RETURN_ON_FAILURE(clCommandFillBufferKHR(
hCommandBuffer->CLCommandBuffer, nullptr,
Expand Down Expand Up @@ -339,13 +319,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferEnqueueExp(

cl_context CLContext = cl_adapter::cast<cl_context>(hCommandBuffer->hContext);
cl_ext::clEnqueueCommandBufferKHR_fn clEnqueueCommandBufferKHR = nullptr;
cl_int Res =
UR_RETURN_ON_FAILURE(
cl_ext::getExtFuncFromContext<decltype(clEnqueueCommandBufferKHR)>(
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;

Expand Down Expand Up @@ -382,13 +359,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferGetInfoExp(

cl_context CLContext = cl_adapter::cast<cl_context>(hCommandBuffer->hContext);
cl_ext::clGetCommandBufferInfoKHR_fn clGetCommandBufferInfoKHR = nullptr;
cl_int Res =
UR_RETURN_ON_FAILURE(
cl_ext::getExtFuncFromContext<decltype(clGetCommandBufferInfoKHR)>(
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;
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 @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
30 changes: 12 additions & 18 deletions source/adapters/opencl/enqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<decltype(F)>(
UR_RETURN_ON_FAILURE(cl_ext::getExtFuncFromContext<decltype(F)>(
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<cl_command_queue>(hQueue),
cl_adapter::cast<cl_program>(hProgram), name, blockingWrite, count,
Expand All @@ -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<decltype(F)>(
UR_RETURN_ON_FAILURE(cl_ext::getExtFuncFromContext<decltype(F)>(
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<cl_command_queue>(hQueue),
cl_adapter::cast<cl_program>(hProgram), name, blockingRead, count,
Expand All @@ -409,21 +403,21 @@ 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<cl_ext::clEnqueueReadHostPipeINTEL_fn>(
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<cl_command_queue>(hQueue),
cl_adapter::cast<cl_program>(hProgram), pipe_symbol, blocking,
pDst, size, numEventsInWaitList,
cl_adapter::cast<const cl_event *>(phEventWaitList),
cl_adapter::cast<cl_event *>(phEvent)));
}

return RetVal;
return UR_RESULT_SUCCESS;
}

UR_APIEXPORT ur_result_t UR_APICALL urEnqueueWriteHostPipe(
Expand All @@ -441,19 +435,19 @@ 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<cl_ext::clEnqueueWriteHostPipeINTEL_fn>(
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<cl_command_queue>(hQueue),
cl_adapter::cast<cl_program>(hProgram), pipe_symbol, blocking,
pSrc, size, numEventsInWaitList,
cl_adapter::cast<const cl_event *>(phEventWaitList),
cl_adapter::cast<cl_event *>(phEvent)));
}

return RetVal;
return UR_RESULT_SUCCESS;
}
4 changes: 2 additions & 2 deletions source/adapters/opencl/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreate(
clCreateBufferWithPropertiesINTEL_fn FuncPtr = nullptr;
cl_context CLContext = cl_adapter::cast<cl_context>(hContext);
// First we need to look up the function pointer
RetErr =
UR_RETURN_ON_FAILURE(
cl_ext::getExtFuncFromContext<clCreateBufferWithPropertiesINTEL_fn>(
CLContext,
cl_ext::ExtFuncPtrCache->clCreateBufferWithPropertiesINTELCache,
cl_ext::CreateBufferWithPropertiesName, &FuncPtr);
cl_ext::CreateBufferWithPropertiesName, &FuncPtr));
if (FuncPtr) {
std::vector<cl_mem_properties_intel> PropertiesIntel;
auto Prop = static_cast<ur_base_properties_t *>(pProperties->pNext);
Expand Down

0 comments on commit 3609afc

Please sign in to comment.