As promised, here’s a mini-review on how to dynamically link multiple OCL implementations
cl.h has all the function prototypes for OCL which look like this:
extern CL_API_ENTRY cl_int CL_API_CALL
clGetPlatformIDs(cl_uint /* num_entries */,
cl_platform_id * /* platforms */,
cl_uint * /* num_platforms */) CL_API_SUFFIX__VERSION_1_0;
These are “extern” functions, which means their actual definitions are located during linking, which are in the OpenCL.dll library. We need to define a type for these functions, link it using GetProcAddress, and write a non-extern wrapper function which calls the linked function. I created a cpp file and header for these typedefs and linking functions, then include the header from my OCL program.
For each of these prototypes, create a type definition for the function type under a different name:
// function type definition, CL_API_CALL pointer to the function with the parameters uncommented
typedef CL_API_ENTRY cl_int (CL_API_CALL*clGetPlatformIDsFuncType) (
cl_uint num_entries,
cl_platform_id * platforms,
cl_uint * num_platforms) CL_API_SUFFIX__VERSION_1_0;
clGetPlatformIDsFuncType clGetPlatformIDsFunc;
Then link it in a separate function, here is mine:
HMODULE hCLModule;
void LoadOCLLib()
{
hCLModule = LoadLibrary(TEXT("OpenCL.dll"));
clGetPlatformIDsFunc=(clGetPlatformIDsFuncType) GetProcAddress(pLibModule,"clGetPlatformIDs");
// other functions here
}
Finally, to use the same function names as defined in cl.h, create function wrappers like so (function types are the same as the cl.h functions but without extern):
CL_API_ENTRY cl_int CL_API_CALL clGetPlatformIDs( cl_uint num_entries,
cl_platform_id * platforms,
cl_uint * num_platforms)
{
return clGetPlatformIDsFunc(num_entries, platforms, num_platforms);
}
Then use LoadOCLLib() before using any cl API functions and create an UnloadOCLLib() using FreeLibrary(hCLModule) to unload on program exit. Take OpenCL.lib out of your linker and you’re set to dynamically link.
Now will rename OpenCL.dll’s that i have to OpenCL_Intel.dll, OpenCL_ATI.dll, OpenCL_NV.dll and link them all separately.
Any feedback is much appreciated also!