Skip to content

Commit 01f4a17

Browse files
committed
opencv_version: dump OpenCL information via opencv_version
fix missing "opencv2/core/opencl" headers from core module (updated install list)
1 parent f1c52e4 commit 01f4a17

File tree

6 files changed

+225
-176
lines changed

6 files changed

+225
-176
lines changed

apps/version/opencv_version.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <opencv2/core.hpp>
88
#include <opencv2/core/utils/trace.hpp>
99

10+
#include <opencv2/core/opencl/opencl_info.hpp>
11+
1012
int main(int argc, const char** argv)
1113
{
1214
CV_TRACE_FUNCTION();
@@ -17,18 +19,28 @@ int main(int argc, const char** argv)
1719
cv::CommandLineParser parser(argc, argv,
1820
"{ help h usage ? | | show this help message }"
1921
"{ verbose v | | show build configuration log }"
22+
"{ opencl | | show information about OpenCL (available platforms/devices, default selected device) }"
2023
);
24+
2125
if (parser.has("help"))
2226
{
2327
parser.printMessage();
28+
return 0;
2429
}
25-
else if (parser.has("verbose"))
30+
31+
if (parser.has("verbose"))
2632
{
2733
std::cout << cv::getBuildInformation().c_str() << std::endl;
2834
}
2935
else
3036
{
3137
std::cout << CV_VERSION << std::endl;
3238
}
39+
40+
if (parser.has("opencl"))
41+
{
42+
cv::dumpOpenCLInformation();
43+
}
44+
3345
return 0;
3446
}

cmake/templates/opencv_abi.xml.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<skip_headers>
2424
opencv2/core/hal/intrin*
2525
opencv2/core/cuda*
26+
opencv2/core/opencl*
2627
opencv2/core/private*
2728
opencv/cxeigen.hpp
2829
opencv2/core/eigen.hpp

modules/core/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ endif()
2727

2828
file(GLOB lib_cuda_hdrs "include/opencv2/${name}/cuda/*.hpp" "include/opencv2/${name}/cuda/*.h")
2929
file(GLOB lib_cuda_hdrs_detail "include/opencv2/${name}/cuda/detail/*.hpp" "include/opencv2/${name}/cuda/detail/*.h")
30+
file(GLOB_RECURSE module_opencl_hdrs "include/opencv2/${name}/opencl/*")
3031

3132
source_group("Include\\Cuda Headers" FILES ${lib_cuda_hdrs})
3233
source_group("Include\\Cuda Headers\\Detail" FILES ${lib_cuda_hdrs_detail})
3334

3435
source_group("Src" FILES "${OPENCV_MODULE_opencv_core_BINARY_DIR}/version_string.inc")
3536

3637
ocv_glob_module_sources(SOURCES "${OPENCV_MODULE_opencv_core_BINARY_DIR}/version_string.inc"
37-
HEADERS ${lib_cuda_hdrs} ${lib_cuda_hdrs_detail})
38+
HEADERS ${module_opencl_hdrs} ${lib_cuda_hdrs} ${lib_cuda_hdrs_detail})
3839

3940
ocv_module_include_directories(${the_module} ${ZLIB_INCLUDE_DIRS} ${OPENCL_INCLUDE_DIRS})
4041
if(ANDROID AND HAVE_CPUFEATURES)
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
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+
} // namespace
51+
52+
static void dumpOpenCLInformation()
53+
{
54+
using namespace cv::ocl;
55+
56+
try
57+
{
58+
if (!haveOpenCL() || !useOpenCL())
59+
{
60+
DUMP_MESSAGE_STDOUT("OpenCL is disabled");
61+
DUMP_CONFIG_PROPERTY("cv_ocl", "disabled");
62+
return;
63+
}
64+
65+
std::vector<PlatformInfo> platforms;
66+
cv::ocl::getPlatfomsInfo(platforms);
67+
if (platforms.size() > 0)
68+
{
69+
DUMP_MESSAGE_STDOUT("OpenCL Platforms: ");
70+
for (size_t i = 0; i < platforms.size(); i++)
71+
{
72+
const PlatformInfo* platform = &platforms[i];
73+
DUMP_MESSAGE_STDOUT(" " << platform->name().c_str());
74+
Device current_device;
75+
for (int j = 0; j < platform->deviceNumber(); j++)
76+
{
77+
platform->getDevice(current_device, j);
78+
const char* deviceTypeStr = current_device.type() == Device::TYPE_CPU
79+
? ("CPU") : (current_device.type() == Device::TYPE_GPU ? current_device.hostUnifiedMemory() ? "iGPU" : "dGPU" : "unknown");
80+
DUMP_MESSAGE_STDOUT( " " << deviceTypeStr << ": " << current_device.name().c_str() << " (" << current_device.version().c_str() << ")");
81+
DUMP_CONFIG_PROPERTY( cv::format("cv_ocl_platform_%d_device_%d", (int)i, (int)j ),
82+
cv::format("(Platform=%s)(Type=%s)(Name=%s)(Version=%s)",
83+
platform->name().c_str(), deviceTypeStr, current_device.name().c_str(), current_device.version().c_str()) );
84+
}
85+
}
86+
}
87+
else
88+
{
89+
DUMP_MESSAGE_STDOUT("OpenCL is not available");
90+
DUMP_CONFIG_PROPERTY("cv_ocl", "not available");
91+
return;
92+
}
93+
94+
const Device& device = Device::getDefault();
95+
if (!device.available())
96+
CV_ErrorNoReturn(Error::OpenCLInitError, "OpenCL device is not available");
97+
98+
DUMP_MESSAGE_STDOUT("Current OpenCL device: ");
99+
100+
#if 0
101+
DUMP_MESSAGE_STDOUT(" Platform = " << device.getPlatform().name());
102+
DUMP_CONFIG_PROPERTY("cv_ocl_current_platformName", device.getPlatform().name());
103+
#endif
104+
105+
const char* deviceTypeStr = device.type() == Device::TYPE_CPU
106+
? ("CPU") : (device.type() == Device::TYPE_GPU ? device.hostUnifiedMemory() ? "iGPU" : "dGPU" : "unknown");
107+
DUMP_MESSAGE_STDOUT(" Type = " << deviceTypeStr);
108+
DUMP_CONFIG_PROPERTY("cv_ocl_current_deviceType", deviceTypeStr);
109+
110+
DUMP_MESSAGE_STDOUT(" Name = " << device.name());
111+
DUMP_CONFIG_PROPERTY("cv_ocl_current_deviceName", device.name());
112+
113+
DUMP_MESSAGE_STDOUT(" Version = " << device.version());
114+
DUMP_CONFIG_PROPERTY("cv_ocl_current_deviceVersion", device.version());
115+
116+
DUMP_MESSAGE_STDOUT(" Driver version = " << device.driverVersion());
117+
DUMP_CONFIG_PROPERTY("cv_ocl_current_driverVersion", device.driverVersion());
118+
119+
DUMP_MESSAGE_STDOUT(" Address bits = " << device.addressBits());
120+
DUMP_CONFIG_PROPERTY("cv_ocl_current_addressBits", device.addressBits());
121+
122+
DUMP_MESSAGE_STDOUT(" Compute units = " << device.maxComputeUnits());
123+
DUMP_CONFIG_PROPERTY("cv_ocl_current_maxComputeUnits", device.maxComputeUnits());
124+
125+
DUMP_MESSAGE_STDOUT(" Max work group size = " << device.maxWorkGroupSize());
126+
DUMP_CONFIG_PROPERTY("cv_ocl_current_maxWorkGroupSize", device.maxWorkGroupSize());
127+
128+
std::string localMemorySizeStr = bytesToStringRepr(device.localMemSize());
129+
DUMP_MESSAGE_STDOUT(" Local memory size = " << localMemorySizeStr);
130+
DUMP_CONFIG_PROPERTY("cv_ocl_current_localMemSize", device.localMemSize());
131+
132+
std::string maxMemAllocSizeStr = bytesToStringRepr(device.maxMemAllocSize());
133+
DUMP_MESSAGE_STDOUT(" Max memory allocation size = " << maxMemAllocSizeStr);
134+
DUMP_CONFIG_PROPERTY("cv_ocl_current_maxMemAllocSize", device.maxMemAllocSize());
135+
136+
const char* doubleSupportStr = device.doubleFPConfig() > 0 ? "Yes" : "No";
137+
DUMP_MESSAGE_STDOUT(" Double support = " << doubleSupportStr);
138+
DUMP_CONFIG_PROPERTY("cv_ocl_current_haveDoubleSupport", device.doubleFPConfig() > 0);
139+
140+
const char* isUnifiedMemoryStr = device.hostUnifiedMemory() ? "Yes" : "No";
141+
DUMP_MESSAGE_STDOUT(" Host unified memory = " << isUnifiedMemoryStr);
142+
DUMP_CONFIG_PROPERTY("cv_ocl_current_hostUnifiedMemory", device.hostUnifiedMemory());
143+
144+
DUMP_MESSAGE_STDOUT(" Device extensions:");
145+
String extensionsStr = device.extensions();
146+
size_t pos = 0;
147+
while (pos < extensionsStr.size())
148+
{
149+
size_t pos2 = extensionsStr.find(' ', pos);
150+
if (pos2 == String::npos)
151+
pos2 = extensionsStr.size();
152+
if (pos2 > pos)
153+
{
154+
String extensionName = extensionsStr.substr(pos, pos2 - pos);
155+
DUMP_MESSAGE_STDOUT(" " << extensionName);
156+
}
157+
pos = pos2 + 1;
158+
}
159+
DUMP_CONFIG_PROPERTY("cv_ocl_current_extensions", extensionsStr.c_str());
160+
161+
const char* haveAmdBlasStr = haveAmdBlas() ? "Yes" : "No";
162+
DUMP_MESSAGE_STDOUT(" Has AMD Blas = " << haveAmdBlasStr);
163+
DUMP_CONFIG_PROPERTY("cv_ocl_current_AmdBlas", haveAmdBlas());
164+
165+
const char* haveAmdFftStr = haveAmdFft() ? "Yes" : "No";
166+
DUMP_MESSAGE_STDOUT(" Has AMD Fft = " << haveAmdFftStr);
167+
DUMP_CONFIG_PROPERTY("cv_ocl_current_AmdFft", haveAmdFft());
168+
169+
170+
DUMP_MESSAGE_STDOUT(" Preferred vector width char = " << device.preferredVectorWidthChar());
171+
DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthChar", device.preferredVectorWidthChar());
172+
173+
DUMP_MESSAGE_STDOUT(" Preferred vector width short = " << device.preferredVectorWidthShort());
174+
DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthShort", device.preferredVectorWidthShort());
175+
176+
DUMP_MESSAGE_STDOUT(" Preferred vector width int = " << device.preferredVectorWidthInt());
177+
DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthInt", device.preferredVectorWidthInt());
178+
179+
DUMP_MESSAGE_STDOUT(" Preferred vector width long = " << device.preferredVectorWidthLong());
180+
DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthLong", device.preferredVectorWidthLong());
181+
182+
DUMP_MESSAGE_STDOUT(" Preferred vector width float = " << device.preferredVectorWidthFloat());
183+
DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthFloat", device.preferredVectorWidthFloat());
184+
185+
DUMP_MESSAGE_STDOUT(" Preferred vector width double = " << device.preferredVectorWidthDouble());
186+
DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthDouble", device.preferredVectorWidthDouble());
187+
}
188+
catch (...)
189+
{
190+
DUMP_MESSAGE_STDOUT("Exception. Can't dump OpenCL info");
191+
DUMP_MESSAGE_STDOUT("OpenCL device not available");
192+
DUMP_CONFIG_PROPERTY("cv_ocl", "not available");
193+
}
194+
}
195+
#undef DUMP_MESSAGE_STDOUT
196+
#undef DUMP_CONFIG_PROPERTY
197+
198+
} // namespace

modules/python/bindings/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ ocv_list_filterout(opencv_hdrs "modules/core/.*/cuda")
3232
ocv_list_filterout(opencv_hdrs "modules/cuda.*")
3333
ocv_list_filterout(opencv_hdrs "modules/cudev")
3434
ocv_list_filterout(opencv_hdrs "modules/core/.*/hal/")
35+
ocv_list_filterout(opencv_hdrs "modules/core/.*/opencl/")
3536
ocv_list_filterout(opencv_hdrs "modules/.+/utils/.*")
3637
ocv_list_filterout(opencv_hdrs "modules/.*\\\\.inl\\\\.h*")
3738
ocv_list_filterout(opencv_hdrs "modules/.*_inl\\\\.h*")

0 commit comments

Comments
 (0)