Skip to content

Instantly share code, notes, and snippets.

@taroyabuki
Last active December 15, 2015 10:09
Show Gist options
  • Save taroyabuki/5244026 to your computer and use it in GitHub Desktop.
Save taroyabuki/5244026 to your computer and use it in GitHub Desktop.
OpenCLに対応するデバイスの列挙 http://blog.unfindable.net/archives/5829
#include <stdio.h>
#include <stdlib.h>
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
#define MAX_PLATFORM_IDS 8
#define MAX_DEVICE_IDS 8
#define BUFFER_SIZE 4096
int main(void)
{
cl_uint ret_num_platforms;
cl_uint ret_num_devices;
cl_platform_id platforms[MAX_PLATFORM_IDS];
cl_device_id devices[MAX_DEVICE_IDS];
unsigned int pidx, didx;
char value[BUFFER_SIZE];
size_t size;
cl_int ret = clGetPlatformIDs(MAX_PLATFORM_IDS, platforms, &ret_num_platforms);
if (ret != CL_SUCCESS) {
printf("Error (clGetPlatformIDs): %d\n", ret);
exit(1);
}
for (pidx = 0; pidx < ret_num_platforms; ++pidx) {
ret = clGetPlatformInfo(platforms[pidx], CL_PLATFORM_NAME, BUFFER_SIZE, value, &size);
printf("Platform: %s\n", value);
ret = clGetPlatformInfo(platforms[pidx], CL_PLATFORM_VERSION, BUFFER_SIZE, value, &size);
printf("CL_PLATFORM_VERSION: %s\n", value);
ret = clGetDeviceIDs(platforms[pidx], CL_DEVICE_TYPE_ALL, MAX_DEVICE_IDS, devices, &ret_num_devices);
if (ret != CL_SUCCESS) {
printf("Error (clGetDeviceIDs): %d\n", ret);
exit(1);
}
for (didx = 0; didx < ret_num_devices; ++didx) {
ret = clGetDeviceInfo(devices[didx], CL_DEVICE_NAME, BUFFER_SIZE, value, &size);
printf("\n Device: %s\n", value);
ret = clGetDeviceInfo(devices[didx], CL_DEVICE_VERSION, BUFFER_SIZE, value, &size);
printf(" CL_DEVICE_VERSION: %s\n", value);
}
printf("------------------------------------------------------------------------------\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment