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