Created
October 7, 2012 05:54
-
-
Save JosephLaurino/3847254 to your computer and use it in GitHub Desktop.
enumerate all available opencl devices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
I modified some code I found to correctly enumerate all OpenCL devices on my laptop... | |
Here's the output: | |
NAME: Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz | |
ADDRESS_WIDTH: 32 | |
EXTENSIONS: cl_APPLE_SetMemObjectDestructor cl_APPLE_ContextLoggingFunctions cl_APPLE_clut cl_APPLE_query_kernel_names cl_APPLE_gl_sharing cl_khr_gl_event cl_khr_fp64 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_3d_image_writes cl_APPLE_fp64_basic_ops cl_APPLE_fixed_alpha_channel_orders cl_APPLE_biased_fixed_point_image_formats | |
NAME: GeForce GT 650M | |
ADDRESS_WIDTH: 32 | |
EXTENSIONS: cl_APPLE_SetMemObjectDestructor cl_APPLE_ContextLoggingFunctions cl_APPLE_clut cl_APPLE_query_kernel_names cl_APPLE_gl_sharing cl_khr_gl_event cl_khr_byte_addressable_store cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_APPLE_fp64_basic_ops | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define MAC | |
#ifdef MAC | |
#include <OpenCL/cl.h> | |
#else | |
#include <CL/cl.h> | |
#endif | |
int main() { | |
/* Host/device data structures */ | |
cl_platform_id platform; | |
cl_device_id *devices; | |
cl_uint num_devices, addr_data; | |
cl_int i, err; | |
/* Extension data */ | |
char name_data[256], ext_data[4096]; | |
/* Identify a platform */ | |
err = clGetPlatformIDs(1, &platform, NULL); | |
if(err < 0) { | |
perror("Couldn't find any platforms"); | |
exit(1); | |
} | |
/* Determine number of connected devices */ | |
err = clGetDeviceIDs(platform, | |
// CL_DEVICE_TYPE_GPU, | |
CL_DEVICE_TYPE_ALL, // jyl -- query for all available opencl devices | |
1, | |
NULL, | |
&num_devices); | |
if(err < 0) { | |
perror("Couldn't find any devices"); | |
exit(1); | |
} | |
/* Access connected devices */ | |
devices = (cl_device_id*) malloc(sizeof(cl_device_id) * num_devices); | |
clGetDeviceIDs(platform, | |
// CL_DEVICE_TYPE_GPU, | |
CL_DEVICE_TYPE_ALL, // jyl -- query for all available opencl devices | |
num_devices, | |
devices, | |
NULL); | |
/* Obtain data for each connected device */ | |
for(i=0; i<num_devices; i++) { | |
err = clGetDeviceInfo(devices[i], CL_DEVICE_NAME, | |
sizeof(name_data), name_data, NULL); | |
if(err < 0) { | |
perror("\nERROR! 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("\n\nNAME: %s\nADDRESS_WIDTH: %u\nEXTENSIONS: %s", | |
name_data, addr_data, ext_data); | |
} | |
free(devices); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment