7
#include <opencv2/core.hpp>
8
#include <opencv2/core/ocl.hpp>
10
#ifndef DUMP_CONFIG_PROPERTY
11
#define DUMP_CONFIG_PROPERTY(...)
14
#ifndef DUMP_MESSAGE_STDOUT
15
#define DUMP_MESSAGE_STDOUT(...) do { std::cout << __VA_ARGS__ << std::endl; } while (false)
21
static
std::string bytesToStringRepr(
size_t
value)
23
size_t
b = value % 1024;
26
size_t
kb = value % 1024;
29
size_t
mb = value % 1024;
34
std::ostringstream stream;
37
stream << gb <<
" GB ";
39
stream << mb <<
" MB ";
41
stream << kb <<
" KB ";
45
std::string s = stream.str();
46
if
(s[s.size() - 1] ==
' ')
47
s = s.substr(0, s.size() - 1);
53
if
(device.type() == cv::ocl::Device::TYPE_CPU) {
57
if
(device.type() == cv::ocl::Device::TYPE_GPU) {
58
if
(device.hostUnifiedMemory()) {
69
static
void
dumpOpenCLInformation()
71
using namespace
cv::ocl;
75
if
(!haveOpenCL() || !useOpenCL())
77
DUMP_MESSAGE_STDOUT(
"OpenCL is disabled");
78
DUMP_CONFIG_PROPERTY(
"cv_ocl",
"disabled");
82
std::vector<PlatformInfo> platforms;
83
cv::ocl::getPlatfomsInfo(platforms);
84
if
(platforms.empty())
86
DUMP_MESSAGE_STDOUT(
"OpenCL is not available");
87
DUMP_CONFIG_PROPERTY(
"cv_ocl",
"not available");
91
DUMP_MESSAGE_STDOUT(
"OpenCL Platforms: ");
92
for
(
size_t
i = 0; i < platforms.size(); i++)
95
DUMP_MESSAGE_STDOUT(
" "
<< platform->name());
97
for
(
int
j = 0; j < platform->deviceNumber(); j++)
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()) );
107
const
Device& device = Device::getDefault();
108
if
(!device.available())
109
CV_Error(Error::OpenCLInitError,
"OpenCL device is not available");
111
DUMP_MESSAGE_STDOUT(
"Current OpenCL device: ");
113
String deviceTypeStr = getDeviceTypeString(device);
114
DUMP_MESSAGE_STDOUT(
" Type = "
<< deviceTypeStr);
115
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_deviceType", deviceTypeStr);
117
DUMP_MESSAGE_STDOUT(
" Name = "
<< device.name());
118
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_deviceName", device.name());
120
DUMP_MESSAGE_STDOUT(
" Version = "
<< device.version());
121
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_deviceVersion", device.version());
123
DUMP_MESSAGE_STDOUT(
" Driver version = "
<< device.driverVersion());
124
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_driverVersion", device.driverVersion());
126
DUMP_MESSAGE_STDOUT(
" Address bits = "
<< device.addressBits());
127
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_addressBits", device.addressBits());
129
DUMP_MESSAGE_STDOUT(
" Compute units = "
<< device.maxComputeUnits());
130
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_maxComputeUnits", device.maxComputeUnits());
132
DUMP_MESSAGE_STDOUT(
" Max work group size = "
<< device.maxWorkGroupSize());
133
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_maxWorkGroupSize", device.maxWorkGroupSize());
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());
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());
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);
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);
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());
155
DUMP_MESSAGE_STDOUT(
" Device extensions:");
156
String extensionsStr = device.extensions();
158
while
(pos < extensionsStr.size())
160
size_t
pos2 = extensionsStr.find(
' ', pos);
161
if
(pos2 == String::npos)
162
pos2 = extensionsStr.size();
165
String extensionName = extensionsStr.substr(pos, pos2 - pos);
166
DUMP_MESSAGE_STDOUT(
" "
<< extensionName);
170
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_extensions", extensionsStr);
172
const
char* haveAmdBlasStr = haveAmdBlas() ?
"Yes"
:
"No";
173
DUMP_MESSAGE_STDOUT(
" Has AMD Blas = "
<< haveAmdBlasStr);
174
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_AmdBlas", haveAmdBlas());
176
const
char* haveAmdFftStr = haveAmdFft() ?
"Yes"
:
"No";
177
DUMP_MESSAGE_STDOUT(
" Has AMD Fft = "
<< haveAmdFftStr);
178
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_AmdFft", haveAmdFft());
181
DUMP_MESSAGE_STDOUT(
" Preferred vector width char = "
<< device.preferredVectorWidthChar());
182
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_preferredVectorWidthChar", device.preferredVectorWidthChar());
184
DUMP_MESSAGE_STDOUT(
" Preferred vector width short = "
<< device.preferredVectorWidthShort());
185
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_preferredVectorWidthShort", device.preferredVectorWidthShort());
187
DUMP_MESSAGE_STDOUT(
" Preferred vector width int = "
<< device.preferredVectorWidthInt());
188
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_preferredVectorWidthInt", device.preferredVectorWidthInt());
190
DUMP_MESSAGE_STDOUT(
" Preferred vector width long = "
<< device.preferredVectorWidthLong());
191
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_preferredVectorWidthLong", device.preferredVectorWidthLong());
193
DUMP_MESSAGE_STDOUT(
" Preferred vector width float = "
<< device.preferredVectorWidthFloat());
194
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_preferredVectorWidthFloat", device.preferredVectorWidthFloat());
196
DUMP_MESSAGE_STDOUT(
" Preferred vector width double = "
<< device.preferredVectorWidthDouble());
197
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_preferredVectorWidthDouble", device.preferredVectorWidthDouble());
199
DUMP_MESSAGE_STDOUT(
" Preferred vector width half = "
<< device.preferredVectorWidthHalf());
200
DUMP_CONFIG_PROPERTY(
"cv_ocl_current_preferredVectorWidthHalf", device.preferredVectorWidthHalf());
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");
209
#undef DUMP_MESSAGE_STDOUT
210
#undef DUMP_CONFIG_PROPERTY
#define CV_Error(code, msg)
Call the error handler.
Definition:
base.hpp:320
"black box" representation of the file storage associated with a file on disk.
Definition:
aruco.hpp:75