Skip to content

Instantly share code, notes, and snippets.

@ytn86
Last active November 7, 2019 04:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytn86/1b0e56f8c719f34ca7803770d474b17d to your computer and use it in GitHub Desktop.
Save ytn86/1b0e56f8c719f34ca7803770d474b17d to your computer and use it in GitHub Desktop.
show OpenCL device list
#include <stdio.h>
#include <CL/cl.h>
#define MAX_PLATFORM_SIZE 256
#define MAX_DEVICE_SIZE 256
int main()
{
cl_device_id devices[256];
cl_platform_id platforms[256];
cl_uint numDevices;
cl_uint numPlatforms;
cl_uint ret;
cl_uint i, j;
char buf[4096];
ret = clGetPlatformIDs(MAX_PLATFORM_SIZE, platforms, &numPlatforms);
if (ret != CL_SUCCESS) {
exit(-1);
}
for (i=0; i<numPlatforms; i++) {
ret = clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, sizeof(buf), buf, NULL);
if (ret != CL_SUCCESS) {
exit(-1);
}
printf("Platform[%d] : %s\n\n", i, buf);
ret = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, MAX_DEVICE_SIZE, devices, &numDevices);
if (ret != CL_SUCCESS) {
exit(-1);
}
for (j=0; j<numDevices; j++) {
printf("--- Device[%d] ---\n", j);
ret = clGetDeviceInfo(devices[j], CL_DEVICE_NAME, sizeof(buf), buf, NULL);
if (ret != CL_SUCCESS) {
exit(-1);
}
printf("Device Name : %s\n", buf);
ret = clGetDeviceInfo(devices[j], CL_DEVICE_VENDOR, sizeof(buf), buf, NULL);
if (ret != CL_SUCCESS) {
exit(-1);
}
printf("Device Vendor : %s\n", buf);
printf("------\n");
}
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment