Skip to content

Commit

Permalink
Merge pull request #968 from martygrant/martin/versionCheckSpecializa…
Browse files Browse the repository at this point in the history
…tionConstants

[OpenCL] Add version check for urProgramSetSpecializationConstants
  • Loading branch information
kbenzie authored Nov 3, 2023
2 parents be53fb3 + f2a365c commit ba994bb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 14 deletions.
8 changes: 4 additions & 4 deletions source/adapters/opencl/enqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueReadHostPipe(
return mapCLErrorToUR(CLErr);
}

clEnqueueReadHostPipeINTEL_fn FuncPtr = nullptr;
cl_ext::clEnqueueReadHostPipeINTEL_fn FuncPtr = nullptr;
ur_result_t RetVal =
cl_ext::getExtFuncFromContext<clEnqueueReadHostPipeINTEL_fn>(
cl_ext::getExtFuncFromContext<cl_ext::clEnqueueReadHostPipeINTEL_fn>(
CLContext, cl_ext::ExtFuncPtrCache->clEnqueueReadHostPipeINTELCache,
cl_ext::EnqueueReadHostPipeName, &FuncPtr);

Expand Down Expand Up @@ -382,9 +382,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueWriteHostPipe(
return mapCLErrorToUR(CLErr);
}

clEnqueueWriteHostPipeINTEL_fn FuncPtr = nullptr;
cl_ext::clEnqueueWriteHostPipeINTEL_fn FuncPtr = nullptr;
ur_result_t RetVal =
cl_ext::getExtFuncFromContext<clEnqueueWriteHostPipeINTEL_fn>(
cl_ext::getExtFuncFromContext<cl_ext::clEnqueueWriteHostPipeINTEL_fn>(
CLContext, cl_ext::ExtFuncPtrCache->clEnqueueWriteHostPipeINTELCache,
cl_ext::EnqueueWriteHostPipeName, &FuncPtr);

Expand Down
58 changes: 48 additions & 10 deletions source/adapters/opencl/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,20 +316,58 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramSetSpecializationConstants(
CL_RETURN_ON_FAILURE(clGetProgramInfo(CLProg, CL_PROGRAM_CONTEXT, sizeof(Ctx),
&Ctx, &RetSize));

cl_ext::clSetProgramSpecializationConstant_fn F = nullptr;
const ur_result_t URResult = cl_ext::getExtFuncFromContext<decltype(F)>(
Ctx, cl_ext::ExtFuncPtrCache->clSetProgramSpecializationConstantCache,
cl_ext::SetProgramSpecializationConstantName, &F);
std::unique_ptr<std::vector<cl_device_id>> DevicesInCtx;
cl_adapter::getDevicesFromContext(cl_adapter::cast<ur_context_handle_t>(Ctx),
DevicesInCtx);

if (URResult != UR_RESULT_SUCCESS) {
return URResult;
}
cl_platform_id CurPlatform;
clGetDeviceInfo((*DevicesInCtx)[0], CL_DEVICE_PLATFORM,
sizeof(cl_platform_id), &CurPlatform, nullptr);

oclv::OpenCLVersion PlatVer;
cl_adapter::getPlatformVersion(CurPlatform, PlatVer);

bool UseExtensionLookup = false;
if (PlatVer < oclv::V2_2) {
UseExtensionLookup = true;
} else {
for (cl_device_id Dev : *DevicesInCtx) {
oclv::OpenCLVersion DevVer;

for (uint32_t i = 0; i < count; ++i) {
CL_RETURN_ON_FAILURE(F(CLProg, pSpecConstants[i].id, pSpecConstants[i].size,
pSpecConstants[i].pValue));
cl_adapter::getDeviceVersion(Dev, DevVer);

if (DevVer < oclv::V2_2) {
UseExtensionLookup = true;
break;
}
}
}

if (UseExtensionLookup == false) {
for (uint32_t i = 0; i < count; ++i) {
CL_RETURN_ON_FAILURE(clSetProgramSpecializationConstant(
CLProg, pSpecConstants[i].id, pSpecConstants[i].size,
pSpecConstants[i].pValue));
}
} else {
cl_ext::clSetProgramSpecializationConstant_fn
SetProgramSpecializationConstant = nullptr;
const ur_result_t URResult = cl_ext::getExtFuncFromContext<
decltype(SetProgramSpecializationConstant)>(
Ctx, cl_ext::ExtFuncPtrCache->clSetProgramSpecializationConstantCache,
cl_ext::SetProgramSpecializationConstantName,
&SetProgramSpecializationConstant);

if (URResult != UR_RESULT_SUCCESS) {
return URResult;
}

for (uint32_t i = 0; i < count; ++i) {
CL_RETURN_ON_FAILURE(SetProgramSpecializationConstant(
CLProg, pSpecConstants[i].id, pSpecConstants[i].size,
pSpecConstants[i].pValue));
}
}
return UR_RESULT_SUCCESS;
}

Expand Down

0 comments on commit ba994bb

Please sign in to comment.