the opencl_test example displays the opencl platforms and devices found on the system using the opencl api directly. if this test fails to compile and/or run, there is a problem with the opencl implementation found on the system. users should ensure this test runs successfuly before using any of the boost.compute apis (which depend on a working opencl implementation).
| 23 | // system. users should ensure this test runs successfuly before using any of |
| 24 | // the boost.compute apis (which depend on a working opencl implementation). |
| 25 | int main() |
| 26 | { |
| 27 | // query number of opencl platforms |
| 28 | cl_uint num_platforms = 0; |
| 29 | cl_int ret = clGetPlatformIDs(0, NULL, &num_platforms); |
| 30 | if(ret != CL_SUCCESS){ |
| 31 | std::cerr << "failed to query platforms: " << ret << std::endl; |
| 32 | return -1; |
| 33 | } |
| 34 | |
| 35 | // check that at least one platform was found |
| 36 | if(num_platforms == 0){ |
| 37 | std::cerr << "found 0 platforms" << std::endl; |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | // get platform ids |
| 42 | cl_platform_id *platforms = new cl_platform_id[num_platforms]; |
| 43 | clGetPlatformIDs(num_platforms, platforms, NULL); |
| 44 | |
| 45 | // iterate through each platform and query its devices |
| 46 | for(cl_uint i = 0; i < num_platforms; i++){ |
| 47 | cl_platform_id platform = platforms[i]; |
| 48 | |
| 49 | // query number of opencl devices |
| 50 | cl_uint num_devices = 0; |
| 51 | ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices); |
| 52 | if(ret != CL_SUCCESS){ |
| 53 | std::cerr << "failed to lookup devices for platform " << i << std::endl; |
| 54 | continue; |
| 55 | } |
| 56 | |
| 57 | // print number of devices found |
| 58 | std::cout << "platform " << i << " has " << num_devices << " devices:" << std::endl; |
| 59 | |
| 60 | // get device ids for the platform |
| 61 | cl_device_id *devices = new cl_device_id[num_devices]; |
| 62 | ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, num_devices, devices, NULL); |
| 63 | if(ret != CL_SUCCESS){ |
| 64 | std::cerr << "failed to query platform devices" << std::endl; |
| 65 | delete[] devices; |
| 66 | continue; |
| 67 | } |
| 68 | |
| 69 | // iterate through each device on the platform and print its name |
| 70 | for(cl_uint j = 0; j < num_devices; j++){ |
| 71 | cl_device_id device = devices[j]; |
| 72 | |
| 73 | // get length of the device name string |
| 74 | size_t name_length = 0; |
| 75 | ret = clGetDeviceInfo(device, CL_DEVICE_NAME, 0, NULL, &name_length); |
| 76 | if(ret != CL_SUCCESS){ |
| 77 | std::cerr << "failed to query device name length for device " << j << std::endl; |
| 78 | continue; |
| 79 | } |
| 80 | |
| 81 | // get the device name string |
| 82 | char *name = new char[name_length]; |
nothing calls this directly
no outgoing calls
no test coverage detected