Ideally, Khronos should code a .H in this way:
1) The OpenCL.h should have all the methods inlined, so it will be open-source and it won't need a .lib/.a/.so to link.
2) The OpenCL.h just finds the OpenCL.dll/.so into the system folder ( c:\windows\system32 or /shared/lib or whatever it is ) and it extracts via GetProcAddress/dlsym the OpenCL function pointers.
Some pseudocode:
#ifdef _WINDOWS
#include
#else
#include
#endif
typedef eERROR_CODE (fnclInit) ();
typedef void* (fnclAllocBuffer) ( const size_t nBytes, const eBUFFER_TYPE );
typedef clHandle (fcnCompileKernel) ( const char* code );
typedef struct tOpenCLProcs
{
fnclInit *clInit;
fnclAllocBuffer *clAllocBuffer;
fnclCompileKernel *clCompileKernel;
}sOpenCLProcs;
typedef struct tOpenCLPlatform
{
sOpenCLProcs procs;
char name[255];
size_t maxImageWidth, maxImageHeight;
//and other caps...
}sOpenCLPlatform;
size_t clInitialize ( sOpenCLPlatform *p ) //p is an allocated array or platforms
{
#ifdef _WINDOWS
array platforms ( find_file ( "OpenCL*.dll" ) );
if ( 0==p ) return platforms.size();
for_each ( int i, string s in platforms )
{
HANDLE h = ::LoadLibrary(s);
p->clInit = (fnclInit*)GetProcAdress(h,"clInit");
p->clAllocBuffer = (fnclAllocBuffer*)GetProcAdress(h,"clAllocBuffer");
p->clCompileKernel = (fnclCompileKernel*)GetProcAdress (h,"clCompileKernel");
}
#else
//dlsym, etc...
#endif
}
so we could use it as:
size_t numPlat = clInitialize ( 0 );
sOpenCLPlatform *platforms = malloc(sizeof(sOpenCLPlatform)*numPlat);
clInitialize ( platforms);
platforms[0].procs.clInit();
void *buff = platforms[0].procs.clAllocBuffer ( 1024*2, CPU_TO_HOST);
clHandle khnd = platforms[0].procs.clCompileKernel ( "__kernel doSomething() {}" );
3) A OpenCL_1_0_0_ATI.dll could be simply deployed into the system folder(windows\system32 or whatever it is in linux/macos) by the Catalyst drivers.
Advantages over the existing method:
1) In that way there could be possible also to co-exist multivendor OpenCL implementations ( for instance, in a computer with an ATI on PCI-slot #1, NVIDIA on PCI-slot #3 and CPU OpenCL emulator ) using THE SAME common SDK.
2) No .lib/.a/.so will be needed to link with the OpenCL SDK. That saves you to compile 32 different .lib versions for VS2005, VS2008, gcc 3, gcc 4.0 apple, gcc 4.3 linux, /MD, /MTD.... only a .H is needed!
3) Khnonos have just to modify the .H to add a OpenCL 2.0 implementation. No dependency on Microsoft to update the obsolete OpenGL 1.3 .lib ...