OpenCV 4.5.3(日本語機械翻訳)
opencl_info.hpp
1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
4
5 #include <iostream>
6
7 #include <opencv2/core.hpp>
8 #include <opencv2/core/ocl.hpp>
9
10 #ifndef DUMP_CONFIG_PROPERTY
11 #define DUMP_CONFIG_PROPERTY(...)
12 #endif
13
14 #ifndef DUMP_MESSAGE_STDOUT
15 #define DUMP_MESSAGE_STDOUT(...) do { std::cout << __VA_ARGS__ << std::endl; } while (false)
16 #endif
17
18 namespace cv {
19
20 namespace {
21 static std::string bytesToStringRepr(size_t value)
22{
23 size_t b = value % 1024;
24 value /= 1024;
25
26 size_t kb = value % 1024;
27 value /= 1024;
28
29 size_t mb = value % 1024;
30 value /= 1024;
31
32 size_t gb = value;
33
34 std::ostringstream stream;
35
36 if (gb > 0)
37 stream << gb << " GB ";
38 if (mb > 0)
39 stream << mb << " MB ";
40 if (kb > 0)
41 stream << kb << " KB ";
42 if (b > 0)
43 stream << b << " B";
44
45 std::string s = stream.str();
46 if (s[s.size() - 1] == ' ')
47 s = s.substr(0, s.size() - 1);
48 return s;
49}
50
51 static String getDeviceTypeString(const cv::ocl::Device& device)
52{
53 if (device.type() == cv::ocl::Device::TYPE_CPU) {
54 return "CPU";
55 }
56
57 if (device.type() == cv::ocl::Device::TYPE_GPU) {
58 if (device.hostUnifiedMemory()) {
59 return "iGPU";
60 } else {
61 return "dGPU";
62 }
63 }
64
65 return "unknown";
66}
67} // namespace
68
69 static void dumpOpenCLInformation()
70{
71 using namespace cv::ocl;
72
73 try
74 {
75 if (!haveOpenCL() || !useOpenCL())
76 {
77 DUMP_MESSAGE_STDOUT("OpenCL is disabled");
78 DUMP_CONFIG_PROPERTY("cv_ocl", "disabled");
79 return;
80 }
81
82 std::vector<PlatformInfo> platforms;
83 cv::ocl::getPlatfomsInfo(platforms);
84 if (platforms.empty())
85 {
86 DUMP_MESSAGE_STDOUT("OpenCL is not available");
87 DUMP_CONFIG_PROPERTY("cv_ocl", "not available");
88 return;
89 }
90
91 DUMP_MESSAGE_STDOUT("OpenCL Platforms: ");
92 for (size_t i = 0; i < platforms.size(); i++)
93 {
94 const PlatformInfo* platform = &platforms[i];
95 DUMP_MESSAGE_STDOUT(" " << platform->name());
96 Device current_device;
97 for (int j = 0; j < platform->deviceNumber(); j++)
98 {
99 platform->getDevice(current_device, j);
100 String deviceTypeStr = getDeviceTypeString(current_device);
101 DUMP_MESSAGE_STDOUT( " " << deviceTypeStr << ": " << current_device.name() << " (" << current_device.version() << ")");
102 DUMP_CONFIG_PROPERTY( cv::format("cv_ocl_platform_%d_device_%d", (int)i, j ),
103 cv::format("(Platform=%s)(Type=%s)(Name=%s)(Version=%s)",
104 platform->name().c_str(), deviceTypeStr.c_str(), current_device.name().c_str(), current_device.version().c_str()) );
105 }
106 }
107 const Device& device = Device::getDefault();
108 if (!device.available())
109 CV_Error(Error::OpenCLInitError, "OpenCL device is not available");
110
111 DUMP_MESSAGE_STDOUT("Current OpenCL device: ");
112
113 String deviceTypeStr = getDeviceTypeString(device);
114 DUMP_MESSAGE_STDOUT(" Type = " << deviceTypeStr);
115 DUMP_CONFIG_PROPERTY("cv_ocl_current_deviceType", deviceTypeStr);
116
117 DUMP_MESSAGE_STDOUT(" Name = " << device.name());
118 DUMP_CONFIG_PROPERTY("cv_ocl_current_deviceName", device.name());
119
120 DUMP_MESSAGE_STDOUT(" Version = " << device.version());
121 DUMP_CONFIG_PROPERTY("cv_ocl_current_deviceVersion", device.version());
122
123 DUMP_MESSAGE_STDOUT(" Driver version = " << device.driverVersion());
124 DUMP_CONFIG_PROPERTY("cv_ocl_current_driverVersion", device.driverVersion());
125
126 DUMP_MESSAGE_STDOUT(" Address bits = " << device.addressBits());
127 DUMP_CONFIG_PROPERTY("cv_ocl_current_addressBits", device.addressBits());
128
129 DUMP_MESSAGE_STDOUT(" Compute units = " << device.maxComputeUnits());
130 DUMP_CONFIG_PROPERTY("cv_ocl_current_maxComputeUnits", device.maxComputeUnits());
131
132 DUMP_MESSAGE_STDOUT(" Max work group size = " << device.maxWorkGroupSize());
133 DUMP_CONFIG_PROPERTY("cv_ocl_current_maxWorkGroupSize", device.maxWorkGroupSize());
134
135 std::string localMemorySizeStr = bytesToStringRepr(device.localMemSize());
136 DUMP_MESSAGE_STDOUT(" Local memory size = " << localMemorySizeStr);
137 DUMP_CONFIG_PROPERTY("cv_ocl_current_localMemSize", device.localMemSize());
138
139 std::string maxMemAllocSizeStr = bytesToStringRepr(device.maxMemAllocSize());
140 DUMP_MESSAGE_STDOUT(" Max memory allocation size = " << maxMemAllocSizeStr);
141 DUMP_CONFIG_PROPERTY("cv_ocl_current_maxMemAllocSize", device.maxMemAllocSize());
142
143 const char* doubleSupportStr = device.doubleFPConfig() > 0 ? "Yes" : "No";
144 DUMP_MESSAGE_STDOUT(" Double support = " << doubleSupportStr);
145 DUMP_CONFIG_PROPERTY("cv_ocl_current_haveDoubleSupport", device.doubleFPConfig() > 0);
146
147 const char* halfSupportStr = device.halfFPConfig() > 0 ? "Yes" : "No";
148 DUMP_MESSAGE_STDOUT(" Half support = " << halfSupportStr);
149 DUMP_CONFIG_PROPERTY("cv_ocl_current_haveHalfSupport", device.halfFPConfig() > 0);
150
151 const char* isUnifiedMemoryStr = device.hostUnifiedMemory() ? "Yes" : "No";
152 DUMP_MESSAGE_STDOUT(" Host unified memory = " << isUnifiedMemoryStr);
153 DUMP_CONFIG_PROPERTY("cv_ocl_current_hostUnifiedMemory", device.hostUnifiedMemory());
154
155 DUMP_MESSAGE_STDOUT(" Device extensions:");
156 String extensionsStr = device.extensions();
157 size_t pos = 0;
158 while (pos < extensionsStr.size())
159 {
160 size_t pos2 = extensionsStr.find(' ', pos);
161 if (pos2 == String::npos)
162 pos2 = extensionsStr.size();
163 if (pos2 > pos)
164 {
165 String extensionName = extensionsStr.substr(pos, pos2 - pos);
166 DUMP_MESSAGE_STDOUT(" " << extensionName);
167 }
168 pos = pos2 + 1;
169 }
170 DUMP_CONFIG_PROPERTY("cv_ocl_current_extensions", extensionsStr);
171
172 const char* haveAmdBlasStr = haveAmdBlas() ? "Yes" : "No";
173 DUMP_MESSAGE_STDOUT(" Has AMD Blas = " << haveAmdBlasStr);
174 DUMP_CONFIG_PROPERTY("cv_ocl_current_AmdBlas", haveAmdBlas());
175
176 const char* haveAmdFftStr = haveAmdFft() ? "Yes" : "No";
177 DUMP_MESSAGE_STDOUT(" Has AMD Fft = " << haveAmdFftStr);
178 DUMP_CONFIG_PROPERTY("cv_ocl_current_AmdFft", haveAmdFft());
179
180
181 DUMP_MESSAGE_STDOUT(" Preferred vector width char = " << device.preferredVectorWidthChar());
182 DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthChar", device.preferredVectorWidthChar());
183
184 DUMP_MESSAGE_STDOUT(" Preferred vector width short = " << device.preferredVectorWidthShort());
185 DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthShort", device.preferredVectorWidthShort());
186
187 DUMP_MESSAGE_STDOUT(" Preferred vector width int = " << device.preferredVectorWidthInt());
188 DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthInt", device.preferredVectorWidthInt());
189
190 DUMP_MESSAGE_STDOUT(" Preferred vector width long = " << device.preferredVectorWidthLong());
191 DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthLong", device.preferredVectorWidthLong());
192
193 DUMP_MESSAGE_STDOUT(" Preferred vector width float = " << device.preferredVectorWidthFloat());
194 DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthFloat", device.preferredVectorWidthFloat());
195
196 DUMP_MESSAGE_STDOUT(" Preferred vector width double = " << device.preferredVectorWidthDouble());
197 DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthDouble", device.preferredVectorWidthDouble());
198
199 DUMP_MESSAGE_STDOUT(" Preferred vector width half = " << device.preferredVectorWidthHalf());
200 DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthHalf", device.preferredVectorWidthHalf());
201 }
202 catch (...)
203 {
204 DUMP_MESSAGE_STDOUT("Exception. Can't dump OpenCL info");
205 DUMP_MESSAGE_STDOUT("OpenCL device not available");
206 DUMP_CONFIG_PROPERTY("cv_ocl", "not available");
207 }
208}
209 #undef DUMP_MESSAGE_STDOUT
210 #undef DUMP_CONFIG_PROPERTY
211
212} // namespace
Definition: ocl.hpp:73
Definition: ocl.hpp:651
#define CV_Error(code, msg)
Call the error handler.
Definition: base.hpp:320
cv
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75