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