|
8 | 8 |
|
9 | 9 | #include <CL/cl.h>
|
10 | 10 | #include <CL/cl_ext.h>
|
| 11 | +#include <CL/sycl.hpp> |
11 | 12 |
|
12 | 13 | #ifdef USE_PI_CUDA
|
13 | 14 | #include <cuda_driver.h>
|
|
17 | 18 | #include <string>
|
18 | 19 | #include <vector>
|
19 | 20 |
|
| 21 | +using namespace cl::sycl; |
| 22 | + |
20 | 23 | static const std::string help =
|
21 | 24 | " Help\n"
|
22 | 25 | " Example: ./get_device_count_by_type cpu opencl\n"
|
@@ -61,54 +64,29 @@ int main(int argc, char* argv[]) {
|
61 | 64 | }
|
62 | 65 | #endif // USE_PI_CUDA
|
63 | 66 |
|
64 |
| - cl_device_type device_type; |
| 67 | + info::device_type device_type; |
65 | 68 | if (type == "cpu") {
|
66 |
| - device_type = CL_DEVICE_TYPE_CPU; |
| 69 | + device_type = info::device_type::cpu; |
67 | 70 | } else if (type == "gpu") {
|
68 |
| - device_type = CL_DEVICE_TYPE_GPU; |
| 71 | + device_type = info::device_type::gpu; |
69 | 72 | } else if (type == "accelerator") {
|
70 |
| - device_type = CL_DEVICE_TYPE_ACCELERATOR; |
| 73 | + device_type = info::device_type::accelerator; |
71 | 74 | } else if (type == "default") {
|
72 |
| - device_type = CL_DEVICE_TYPE_DEFAULT; |
| 75 | + device_type = info::device_type::automatic; |
73 | 76 | } else if (type == "all") {
|
74 |
| - device_type = CL_DEVICE_TYPE_ALL; |
| 77 | + device_type = info::device_type::all; |
75 | 78 | } else {
|
76 | 79 | std::cout << "0:Incorrect device type." << std::endl
|
77 | 80 | << help << std::endl;
|
78 | 81 | return 0;
|
79 | 82 | }
|
80 | 83 |
|
81 |
| - cl_int iRet = CL_SUCCESS; |
82 |
| - cl_uint platformCount = 0; |
83 |
| - |
84 |
| - iRet = clGetPlatformIDs(0, nullptr, &platformCount); |
85 |
| - if (iRet != CL_SUCCESS) { |
86 |
| - if (iRet == CL_PLATFORM_NOT_FOUND_KHR) { |
87 |
| - std::cout << "0:OpenCL runtime not found " << std::endl; |
88 |
| - } else { |
89 |
| - std::cout << "0:A problem at calling function clGetPlatformIDs count " |
90 |
| - << iRet << std::endl; |
91 |
| - } |
92 |
| - return 0; |
93 |
| - } |
94 |
| - |
95 |
| - std::vector<cl_platform_id> platforms(platformCount); |
96 |
| - |
97 |
| - iRet = clGetPlatformIDs(platformCount, &platforms[0], nullptr); |
98 |
| - if (iRet != CL_SUCCESS) { |
99 |
| - std::cout << "0:A problem at when calling function clGetPlatformIDs ids " << iRet << std::endl; |
100 |
| - return 0; |
101 |
| - } |
102 |
| - |
103 |
| - for (cl_uint i = 0; i < platformCount; i++) { |
104 |
| - cl_uint deviceCountPart = 0; |
105 |
| - iRet = clGetDeviceIDs(platforms[i], device_type, 0, nullptr, &deviceCountPart); |
106 |
| - if (iRet == CL_SUCCESS) { |
107 |
| - deviceCount += deviceCountPart; |
108 |
| - } |
| 84 | + std::vector<platform> platforms(platform::get_platforms()); |
| 85 | + for (cl_uint i = 0; i < platforms.size(); i++) { |
| 86 | + std::vector<device> result = platforms[i].get_devices(device_type); |
| 87 | + deviceCount += result.size(); |
109 | 88 | }
|
110 | 89 |
|
111 | 90 | std::cout << deviceCount << ":" << backend << std::endl;
|
112 |
| - |
113 | 91 | return 0;
|
114 | 92 | }
|
0 commit comments