Skip to content

Instantly share code, notes, and snippets.

@pvinis
Created May 15, 2015 08:42
Show Gist options
  • Select an option

  • Save pvinis/f93b2e1c04664e78c493 to your computer and use it in GitHub Desktop.

Select an option

Save pvinis/f93b2e1c04664e78c493 to your computer and use it in GitHub Desktop.
opencl-device-detect
#include <stdio.h>
#include <stdlib.h>
#include <OpenCL/opencl.h>
int main(int argc, char* const argv[]) {
cl_uint num_devices, i;
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
cl_device_id* devices = calloc(sizeof(cl_device_id), num_devices);
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);
fprintf(stdout, "Devices found: %d\n", num_devices);
char buf[128];
for (i = 0; i < num_devices; i++) {
clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 128, buf, NULL);
fprintf(stdout, "Device %s supports ", buf);
clGetDeviceInfo(devices[i], CL_DEVICE_VERSION, 128, buf, NULL);
fprintf(stdout, "%s\n", buf);
}
free(devices);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment