1 #include <CL/opencl.hpp> 2 3 #include <vector> // std::vector 4 #include <exception> // std::runtime_error, std::exception 5 #include <iostream> // std::cout 6 #include <cstdlib> // EXIT_FAILURE 7 main()8int main() 9 { 10 try 11 { 12 std::vector<cl::Platform> platforms; 13 cl::Platform::get(&platforms); 14 15 std::cout << 16 "Found " << 17 platforms.size() << 18 " platform" << 19 (platforms.size() > 1 ? "s.\n" : ".\n") << 20 std::endl; 21 22 for (const auto& platform : platforms) 23 { 24 std::cout << platform.getInfo<CL_PLATFORM_VENDOR>() << std::endl; 25 26 std::vector<cl::Device> devices; 27 platform.getDevices(CL_DEVICE_TYPE_ALL, &devices); 28 29 for (const auto& device : devices) 30 std::cout << "\t" << device.getInfo<CL_DEVICE_NAME>() << std::endl; 31 } 32 } 33 catch (cl::Error& error) // If any OpenCL error occurs 34 { 35 if(error.err() == CL_PLATFORM_NOT_FOUND_KHR) 36 { 37 std::cout << "No OpenCL platform found." << std::endl; 38 std::exit(EXIT_SUCCESS); 39 } 40 else 41 { 42 std::cerr << error.what() << "(" << error.err() << ")" << std::endl; 43 std::exit(error.err()); 44 } 45 } 46 catch (std::exception& error) // If STL/CRT error occurs 47 { 48 std::cerr << error.what() << std::endl; 49 std::exit(EXIT_FAILURE); 50 } 51 } 52