Skip to content

Commit 51f43d3

Browse files
aarongreigcallumfare
authored andcommitted
Use ext function cache helpers.
1 parent 5df2e7f commit 51f43d3

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

source/adapters/opencl/common.hpp

+9
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ CONSTFIX char CommandFillBufferName[] = "clCommandFillBufferKHR";
218218
CONSTFIX char EnqueueCommandBufferName[] = "clEnqueueCommandBufferKHR";
219219
CONSTFIX char GetCommandBufferInfoName[] = "clGetCommandBufferInfoKHR";
220220
CONSTFIX char UpdateMutableCommandsName[] = "clUpdateMutableCommandsKHR";
221+
CONSTFIX char CreateProgramWithILName[] = "clCreateProgramWithILKHR";
222+
CONSTFIX char GetKernelSubGroupInfoName[] = "clGetKernelSubGroupInfoKHR";
221223

222224
#undef CONSTFIX
223225

@@ -316,6 +318,13 @@ cl_int(CL_API_CALL *)(cl_command_buffer_khr command_buffer, cl_uint num_configs,
316318
const cl_command_buffer_update_type_khr *config_types,
317319
const void **configs);
318320

321+
using clCreateProgramWithILKHR_fn = CL_API_ENTRY
322+
cl_program(CL_API_CALL *)(cl_context, const void *, size_t, cl_int *);
323+
324+
using clGetKernelSubGroupInfoKHR_fn = CL_API_ENTRY
325+
cl_int(CL_API_CALL *)(cl_kernel, cl_device_id, cl_kernel_sub_group_info, size_t,
326+
const void *, size_t, void *, size_t *);
327+
319328
template <typename T> struct FuncPtrCache {
320329
std::map<cl_context, T> Map;
321330
std::mutex Mutex;

source/adapters/opencl/extension_functions.def

+2
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ CL_EXTENSION_FUNC(clCommandFillBufferKHR)
2424
CL_EXTENSION_FUNC(clEnqueueCommandBufferKHR)
2525
CL_EXTENSION_FUNC(clGetCommandBufferInfoKHR)
2626
CL_EXTENSION_FUNC(clUpdateMutableCommandsKHR)
27+
CL_EXTENSION_FUNC(clCreateProgramWithILKHR)
28+
CL_EXTENSION_FUNC(clGetKernelSubGroupInfoKHR)

source/adapters/opencl/kernel.cpp

+8-14
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,7 @@ urKernelGetSubGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice,
192192

193193
// We need to allow for the possibility that this device runs an older CL and
194194
// supports the original khr subgroup extension.
195-
using ApiFuncT =
196-
cl_int(CL_API_CALL *)(cl_kernel, cl_device_id, cl_kernel_sub_group_info,
197-
size_t, const void *, size_t, void *, size_t *);
198-
ApiFuncT GetKernelSubGroupInfo = nullptr;
195+
cl_ext::clGetKernelSubGroupInfoKHR_fn GetKernelSubGroupInfo = nullptr;
199196

200197
oclv::OpenCLVersion DevVer;
201198
CL_RETURN_ON_FAILURE(cl_adapter::getDeviceVersion(
@@ -210,16 +207,13 @@ urKernelGetSubGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice,
210207
if (!SubgroupExtSupported) {
211208
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
212209
}
213-
cl_platform_id Platform;
214-
CL_RETURN_ON_FAILURE(clGetDeviceInfo(
215-
cl_adapter::cast<cl_device_id>(hDevice), CL_DEVICE_PLATFORM,
216-
sizeof(Platform), &Platform, nullptr));
217-
GetKernelSubGroupInfo =
218-
reinterpret_cast<ApiFuncT>(clGetExtensionFunctionAddressForPlatform(
219-
Platform, "clGetKernelSubGroupInfoKHR"));
220-
if (!GetKernelSubGroupInfo) {
221-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
222-
}
210+
cl_context Context = nullptr;
211+
CL_RETURN_ON_FAILURE(clGetKernelInfo(cl_adapter::cast<cl_kernel>(hKernel),
212+
CL_KERNEL_CONTEXT, sizeof(Context),
213+
&Context, nullptr));
214+
UR_RETURN_ON_FAILURE(cl_ext::getExtFuncFromContext(
215+
Context, cl_ext::ExtFuncPtrCache->clGetKernelSubGroupInfoKHRCache,
216+
cl_ext::GetKernelSubGroupInfoName, &GetKernelSubGroupInfo));
223217
} else {
224218
GetKernelSubGroupInfo = clGetKernelSubGroupInfo;
225219
}

source/adapters/opencl/program.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithIL(
9999
}
100100
}
101101

102-
using ApiFuncT =
103-
cl_program(CL_API_CALL *)(cl_context, const void *, size_t, cl_int *);
104-
ApiFuncT FuncPtr =
105-
reinterpret_cast<ApiFuncT>(clGetExtensionFunctionAddressForPlatform(
106-
CurPlatform, "clCreateProgramWithILKHR"));
102+
cl_ext::clCreateProgramWithILKHR_fn CreateProgramWithIL = nullptr;
107103

108-
assert(FuncPtr != nullptr);
104+
UR_RETURN_ON_FAILURE(cl_ext::getExtFuncFromContext(
105+
cl_adapter::cast<cl_context>(hContext),
106+
cl_ext::ExtFuncPtrCache->clCreateProgramWithILKHRCache,
107+
cl_ext::CreateProgramWithILName, &CreateProgramWithIL));
109108

110-
*phProgram = cl_adapter::cast<ur_program_handle_t>(
111-
FuncPtr(cl_adapter::cast<cl_context>(hContext), pIL, length, &Err));
109+
*phProgram = cl_adapter::cast<ur_program_handle_t>(CreateProgramWithIL(
110+
cl_adapter::cast<cl_context>(hContext), pIL, length, &Err));
112111
}
113112

114113
// INVALID_VALUE is only returned in three circumstances according to the cl

0 commit comments

Comments
 (0)