Search code examples
opencldeviceplatform

OpenCL Device not Exist


I have ATI HD Radeon 5470 , in my Dell 1558 , and the AMDAPP SDK 2.8 installed on my win7-64 the problem is when i use the opencl code to fine the device it say that :

"couldn't find any device:no errors"

i know that i have installed the latest catalyst driver & all other my programs work good with GPU , but i don't know why it make this report . here is the code i used to find the device : thank to every one help me find out what's the problem ?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef MAC
#include <OpenCL/cl.h>
#else
#include <CL/cl.h>
#endif
int main() {
cl_platform_id platform;
cl_device_id *devices;
cl_uint num_devices, addr_data;
cl_int i, err;
char name_data[48], ext_data[4096];
err = clGetPlatformIDs(1, &platform, NULL);
if(err < 0) {
perror("Couldn't find any platforms");
exit(1);
}
err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL,
1, NULL, &num_devices);
if(err < 0) {
perror("Couldn't find any devices");
exit(1);
}
devices = (cl_device_id*)
malloc(sizeof(cl_device_id) * num_devices);
clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL,
num_devices, devices, NULL);
for(i=0; i<num_devices; i++) {
err = clGetDeviceInfo(devices[i], CL_DEVICE_NAME,
sizeof(name_data), name_data, NULL);
if(err < 0) {
perror("Couldn't read extension data");
exit(1);
}
clGetDeviceInfo(devices[i], CL_DEVICE_ADDRESS_BITS,
sizeof(ext_data), &addr_data, NULL);
clGetDeviceInfo(devices[i], CL_DEVICE_EXTENSIONS,
sizeof(ext_data), ext_data, NULL);
printf("NAME: %s\nADDRESS_WIDTH: %u\nEXTENSIONS: %s",
name_data, addr_data, ext_data);
}
free(devices);
return 0;
}

Solution

  • The first call to clGetDeviceIDs() returns an error on my machine because the third argument is 1. Changing the 1 to a 0 gets past that. Next problem is that the call to clGetDeviceInfo fails. This is because name_data is too small. Not sure if opencl has a direct way to find the needed size, but passing a bigger buffer works around the problem. The final problem is that the second call to clGetDeviceInfo has a typing error where sizeof(addr_data) is intended but sizeof(ext_data) is used. For my test, this causes local variable i to get overwritten, resulting in an infinite loop. Once that is fixed, the code prints:

    NAME: ATI RV710 ADDRESS_WIDTH: 32 EXTENSIONS: cl_khr_gl_sharing cl_amd_device_attribute_query cl_khr_d3d10_sharing NAME: Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz ADDRESS_WIDTH: 64 EXTENSIONS: cl_khr_fp64 cl_amd_fp64 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_i nt32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_byt e_addressable_store cl_khr_gl_sharing cl_ext_device_fission cl_amd_device_attribute_query cl_amd_vec3 cl_amd_printf cl_a md_media_ops cl_amd_popcnt cl_khr_d3d10_sharing