I have a fairly simple sample which works perfect on my NVIDIA 8800 GT, however I am kind of wondering why the following piece of code only allows me pick one platform (the NV8800 GT)
cl_int status = CL_SUCCESS;
cl_uint numPlatforms;
status |= clGetPlatformIDs (0, NULL, &numPlatforms);
I have an Intel QuadCore2 (Q6600); Isnt there some way where I can get my code to run on the CPU ?
The only CPU driver for OpenCL that I’m aware of on windows/linux is AMD’s. Nvidia does not support CPU devices. If you want Nvidia+CPU you have to use Mac OS X or figure out how to get the platform layer working. (I’m not sure if it’s working yet, so I can’t advise you there.)
I do my first steps with OpenCL i translated the include files to FreeBASIC.
Now i can run OpenCL code on a installed NVIDIA GPU (GT240)
or i select the AMD platform and select the CPU emulation on the fly.
First i installed my NVIDIA driver with CUDA and OpenCL support
than i installed the AMD OpenCL runtime.
here are how i select NVIDIA or AMD with CPU emulation
...
if (numPlatforms > 0) then
dim as cl_platform_id_t ptr platforms = callocate(numPlatforms*sizeof(cl_platform_id_t))
status = clGetPlatformIDs(numPlatforms, platforms, NULL)
if (status<>CL_SUCCESS) then
print "Error: Getting Platform Ids. (clGetPlatformsIDs)"
return
end if
dim as zstring ptr pbuff = callocate(255)
for i as uinteger = 0 to numPlatforms-1
status = clGetPlatformInfo(platforms[i], _
CL_PLATFORM_VENDOR, _
255, _
pbuff, _
NULL)
if (status<>CL_SUCCESS) then
print "Error: Getting Platform Info. (clGetPlatformInfo)"
return
end if
print "platform[" & i & "] = " & *pbuff
platform = platforms[i]
#ifdef USE_ATI
if instr(*pbuff, "Advanced Micro Devices, Inc.") then
#else
if instr(*pbuff, "NVIDIA") then
#endif
exit for
end if
next
deallocate platforms
end if ' if (numPlatforms > 0) then
' If we could find our platform, use it.
' Otherwise pass a NULL and get whatever
' the implementation thinks we should be using.
dim as cl_context_properties_t cps(2)
cps(0) = CL_CONTEXT_PLATFORM
cps(1) = cast(cl_context_properties_t,platform)
cps(2) = 0
dim as cl_context_properties_t ptr cprops
if (NULL=platform) then
cprops = NULL
else
cprops = @cps(0)
end if
#ifdef USE_ATI
' Create an OpenCL context with CPU emulation
g_context = clCreateContextFromType(cprops, _
CL_DEVICE_TYPE_CPU, _
NULL, _
NULL, _
@status)
#else
' Create an OpenCL context with real GPU
g_context = clCreateContextFromType(cprops, _
CL_DEVICE_TYPE_GPU, _
NULL, _
NULL, _
@status)
#endif
...