#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
#define BOOST_COMPUTE_GCC_DIAG_STR(s) #s
#define BOOST_COMPUTE_GCC_DIAG_JOINSTR(x,y) BOOST_COMPUTE_GCC_DIAG_STR(x ## y)
# define BOOST_COMPUTE_GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
# define BOOST_COMPUTE_GCC_DIAG_PRAGMA(x) BOOST_COMPUTE_GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
# if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
# define BOOST_COMPUTE_GCC_DIAG_OFF(x) BOOST_COMPUTE_GCC_DIAG_PRAGMA(push) \
BOOST_COMPUTE_GCC_DIAG_PRAGMA(ignored BOOST_COMPUTE_GCC_DIAG_JOINSTR(-W,x))
# define BOOST_COMPUTE_GCC_DIAG_ON(x) BOOST_COMPUTE_GCC_DIAG_PRAGMA(pop)
# else
# define BOOST_COMPUTE_GCC_DIAG_OFF(x) \
BOOST_COMPUTE_GCC_DIAG_PRAGMA(ignored BOOST_COMPUTE_GCC_DIAG_JOINSTR(-W,x))
# define BOOST_COMPUTE_GCC_DIAG_ON(x) \
BOOST_COMPUTE_GCC_DIAG_PRAGMA(warning BOOST_COMPUTE_GCC_DIAG_JOINSTR(-W,x))
# endif
#else
# define BOOST_COMPUTE_GCC_DIAG_OFF(x)
# define BOOST_COMPUTE_GCC_DIAG_ON(x)
#endif
#ifdef __clang__
# define BOOST_COMPUTE_CLANG_DIAG_STR(s) # s
# define BOOST_COMPUTE_CLANG_DIAG_JOINSTR(x,y) BOOST_COMPUTE_CLANG_DIAG_STR(x ## y)
# define BOOST_COMPUTE_CLANG_DIAG_DO_PRAGMA(x) _Pragma (#x)
# define BOOST_COMPUTE_CLANG_DIAG_PRAGMA(x) \
BOOST_COMPUTE_CLANG_DIAG_DO_PRAGMA(clang diagnostic x)
# define BOOST_COMPUTE_CLANG_DIAG_OFF(x) BOOST_COMPUTE_CLANG_DIAG_PRAGMA(push) \
BOOST_COMPUTE_CLANG_DIAG_PRAGMA(ignored BOOST_COMPUTE_CLANG_DIAG_JOINSTR(-W,x))
# define BOOST_COMPUTE_CLANG_DIAG_ON(x) BOOST_COMPUTE_CLANG_DIAG_PRAGMA(pop)
#else
# define BOOST_COMPUTE_CLANG_DIAG_OFF(x)
# define BOOST_COMPUTE_CLANG_DIAG_ON(x)
# define BOOST_COMPUTE_CLANG_DIAG_PRAGMA(x)
#endif
#if defined(_MSC_VER)
# define BOOST_COMPUTE_MSVC_DIAG_DO_PRAGMA(x) __pragma(x)
# define BOOST_COMPUTE_MSVC_DIAG_PRAGMA(x) \
BOOST_COMPUTE_MSVC_DIAG_DO_PRAGMA(warning(x))
# define BOOST_COMPUTE_MSVC_DIAG_OFF(x) BOOST_COMPUTE_MSVC_DIAG_PRAGMA(push) \
BOOST_COMPUTE_MSVC_DIAG_PRAGMA(disable: x)
# define BOOST_COMPUTE_MSVC_DIAG_ON(x) BOOST_COMPUTE_MSVC_DIAG_PRAGMA(pop)
#else
# define BOOST_COMPUTE_MSVC_DIAG_OFF(x)
# define BOOST_COMPUTE_MSVC_DIAG_ON(x)
#endif
#include <iostream>
#if defined(__APPLE__)
#include <OpenCL/cl.h>
#else
#include <CL/cl.h>
#endif
int main()
{
BOOST_COMPUTE_MSVC_DIAG_OFF(4996); BOOST_COMPUTE_GCC_DIAG_OFF(deprecated-declarations); BOOST_COMPUTE_CLANG_DIAG_OFF(deprecated-declarations);
cl_uint num_platforms = 0;
cl_int ret = clGetPlatformIDs(0, NULL, &num_platforms);
if(ret != CL_SUCCESS){
std::cerr << "failed to query platforms: " << ret << std::endl;
return -1;
}
if(num_platforms == 0){
std::cerr << "found 0 platforms" << std::endl;
return 0;
}
cl_platform_id *platforms = new cl_platform_id[num_platforms];
clGetPlatformIDs(num_platforms, platforms, NULL);
for(cl_uint i = 0; i < num_platforms; i++){
cl_platform_id platform = platforms[i];
cl_uint num_devices = 0;
ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
if(ret != CL_SUCCESS){
std::cerr << "failed to lookup devices for platform " << i << std::endl;
continue;
}
std::cout << "platform " << i << " has " << num_devices << " devices:" << std::endl;
cl_device_id *devices = new cl_device_id[num_devices];
ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);
if(ret != CL_SUCCESS){
std::cerr << "failed to query platform devices" << std::endl;
delete[] devices;
continue;
}
for(cl_uint j = 0; j < num_devices; j++){
cl_device_id device = devices[j];
size_t name_length = 0;
ret = clGetDeviceInfo(device, CL_DEVICE_NAME, 0, NULL, &name_length);
if(ret != CL_SUCCESS){
std::cerr << "failed to query device name length for device " << j << std::endl;
continue;
}
char *name = new char[name_length];
ret = clGetDeviceInfo(device, CL_DEVICE_NAME, name_length, name, NULL);
if(ret != CL_SUCCESS){
std::cerr << "failed to query device name string for device " << j << std::endl;
delete[] name;
continue;
}
std::cout << " device: " << name << std::endl;
delete[] name;
}
delete[] devices;
}
delete[] platforms;
BOOST_COMPUTE_CLANG_DIAG_ON(deprecated-declarations); BOOST_COMPUTE_GCC_DIAG_ON(deprecated-declarations); BOOST_COMPUTE_MSVC_DIAG_OFF(4996);
return 0;
}