ocl: dump device info in tests
authorAlexander Alekhin <alexander.alekhin@itseez.com>
Fri, 11 Oct 2013 14:24:59 +0000 (18:24 +0400)
committerAlexander Alekhin <alexander.alekhin@itseez.com>
Fri, 11 Oct 2013 14:24:59 +0000 (18:24 +0400)
modules/ocl/include/opencv2/ocl/private/opencl_dumpinfo.hpp [new file with mode: 0644]
modules/ocl/perf/main.cpp
modules/ocl/test/main.cpp
modules/ts/include/opencv2/ts/ts.hpp
modules/ts/include/opencv2/ts/ts_perf.hpp

diff --git a/modules/ocl/include/opencv2/ocl/private/opencl_dumpinfo.hpp b/modules/ocl/include/opencv2/ocl/private/opencl_dumpinfo.hpp
new file mode 100644 (file)
index 0000000..83d6f93
--- /dev/null
@@ -0,0 +1,104 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
+//                           License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
+// Third party copyrights are property of their respective owners.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+//   * Redistribution's of source code must retain the above copyright notice,
+//     this list of conditions and the following disclaimer.
+//
+//   * Redistribution's in binary form must reproduce the above copyright notice,
+//     this list of conditions and the following disclaimer in the documentation
+//     and/or other oclMaterials provided with the distribution.
+//
+//   * The name of the copyright holders may not be used to endorse or promote products
+//     derived from this software without specific prior written permission.
+//
+// This software is provided by the copyright holders and contributors "as is" and
+// any express or implied warranties, including, but not limited to, the implied
+// warranties of merchantability and fitness for a particular purpose are disclaimed.
+// In no event shall contributors be liable for any direct,
+// indirect, incidental, special, exemplary, or consequential damages
+// (including, but not limited to, procurement of substitute goods or services;
+// loss of use, data, or profits; or business interruption) however caused
+// and on any theory of liability, whether in contract, strict liability,
+// or tort (including negligence or otherwise) arising in any way out of
+// the use of this software, even if advised of the possibility of such damage.
+//
+//M*/
+
+#if !defined(DUMP_INFO_STDOUT) && !defined(DUMP_INFO_XML)
+#error Invalid usage
+#endif
+
+#if !defined(DUMP_INFO_STDOUT)
+#define DUMP_INFO_STDOUT(...)
+#endif
+
+#if !defined(DUMP_INFO_XML)
+#define DUMP_INFO_XML(...)
+#endif
+
+static void dumpOpenCLDevice()
+{
+    using namespace cv::ocl;
+    try
+    {
+        const cv::ocl::DeviceInfo& deviceInfo = cv::ocl::Context::getContext()->getDeviceInfo();
+
+        const char* deviceTypeStr = deviceInfo.deviceType == CVCL_DEVICE_TYPE_CPU
+                        ? "CPU" :
+                        (deviceInfo.deviceType == CVCL_DEVICE_TYPE_GPU ? "GPU" : "unknown");
+        DUMP_INFO_STDOUT("Device type", deviceTypeStr);
+        DUMP_INFO_XML("cv_ocl_deviceType", deviceTypeStr);
+
+        DUMP_INFO_STDOUT("Platform name", deviceInfo.platform->platformName);
+        DUMP_INFO_XML("cv_ocl_platformName", deviceInfo.platform->platformName);
+
+        DUMP_INFO_STDOUT("Device name", deviceInfo.deviceName);
+        DUMP_INFO_XML("cv_ocl_deviceName", deviceInfo.deviceName);
+
+        DUMP_INFO_STDOUT("Device version", deviceInfo.deviceVersion);
+        DUMP_INFO_XML("cv_ocl_deviceVersion", deviceInfo.deviceVersion);
+
+        DUMP_INFO_STDOUT("Compute units", deviceInfo.maxComputeUnits);
+        DUMP_INFO_XML("cv_ocl_maxComputeUnits", deviceInfo.maxComputeUnits);
+
+        DUMP_INFO_STDOUT("Max work group size", deviceInfo.maxWorkGroupSize);
+        DUMP_INFO_XML("cv_ocl_maxWorkGroupSize", deviceInfo.maxWorkGroupSize);
+
+        DUMP_INFO_STDOUT("Local memory size", deviceInfo.localMemorySize);
+        DUMP_INFO_XML("cv_ocl_localMemorySize", deviceInfo.localMemorySize);
+
+        DUMP_INFO_STDOUT("Max memory allocation size", deviceInfo.maxMemAllocSize);
+        DUMP_INFO_XML("cv_ocl_maxMemAllocSize", deviceInfo.maxMemAllocSize);
+
+        const char* doubleSupportStr = deviceInfo.haveDoubleSupport ? "Yes" : "No";
+        DUMP_INFO_STDOUT("Double support", doubleSupportStr);
+        DUMP_INFO_XML("cv_ocl_haveDoubleSupport", deviceInfo.haveDoubleSupport);
+
+        const char* isUnifiedMemoryStr = deviceInfo.isUnifiedMemory ? "Yes" : "No";
+        DUMP_INFO_STDOUT("Unified memory", isUnifiedMemoryStr);
+        DUMP_INFO_XML("cv_ocl_isUnifiedMemory", deviceInfo.isUnifiedMemory);
+    }
+    catch (...)
+    {
+        DUMP_INFO_STDOUT("OpenCL device", "not available");
+        DUMP_INFO_XML("cv_ocl", "not available");
+    }
+}
+
+#undef DUMP_INFO_STDOUT
+#undef DUMP_INFO_XML
index 9f87054e6d8b803739164845150169fe2a9cfa44..6f5eaa1ab610e8f95029d04ff3861ba6f13ac1b5 100644 (file)
@@ -13,7 +13,7 @@
 // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
 // Third party copyrights are property of their respective owners.
-
+//
 // Redistribution and use in source and binary forms, with or without modification,
 // are permitted provided that the following conditions are met:
 //
 
 #include "perf_precomp.hpp"
 
-const char * impls[] =
+#define DUMP_INFO_STDOUT(propertyDisplayName, propertyValue) \
+    do { \
+        std::cout << (propertyDisplayName) << ": " << (propertyValue) << std::endl; \
+    } while (false)
+
+#define DUMP_INFO_XML(propertyXMLName, propertyValue) \
+    do { \
+        std::stringstream ss; ss << propertyValue; \
+        ::testing::Test::RecordProperty((propertyXMLName), ss.str()); \
+    } while (false)
+
+#include "opencv2/ocl/private/opencl_dumpinfo.hpp"
+
+static const char * impls[] =
 {
     IMPL_OCL,
     IMPL_PLAIN,
@@ -51,59 +64,8 @@ const char * impls[] =
 #endif
 };
 
-using namespace cv::ocl;
 
 int main(int argc, char ** argv)
 {
-    const char * keys =
-        "{ h | help     | false              | print help message }"
-        "{ t | type     | gpu                | set device type:cpu or gpu}"
-        "{ p | platform | -1                 | set platform id }"
-        "{ d | device   | 0                  | set device id }";
-
-    if (getenv("OPENCV_OPENCL_DEVICE") == NULL) // TODO Remove this after buildbot updates
-    {
-        CommandLineParser cmd(argc, argv, keys);
-        if (cmd.get<bool>("help"))
-        {
-            cout << "Available options besides google test option:" << endl;
-            cmd.printParams();
-            return 0;
-        }
-
-        string type = cmd.get<string>("type");
-        int pid = cmd.get<int>("platform");
-        int device = cmd.get<int>("device");
-
-        int flag = type == "cpu" ? cv::ocl::CVCL_DEVICE_TYPE_CPU :
-                                   cv::ocl::CVCL_DEVICE_TYPE_GPU;
-
-        cv::ocl::PlatformsInfo platformsInfo;
-        cv::ocl::getOpenCLPlatforms(platformsInfo);
-        if (pid >= (int)platformsInfo.size())
-        {
-            std::cout << "platform is invalid\n";
-            return 1;
-        }
-
-        cv::ocl::DevicesInfo devicesInfo;
-        int devnums = cv::ocl::getOpenCLDevices(devicesInfo, flag, (pid < 0) ? NULL : platformsInfo[pid]);
-        if (device < 0 || device >= devnums)
-        {
-            std::cout << "device/platform invalid\n";
-            return 1;
-        }
-
-        cv::ocl::setDevice(devicesInfo[device]);
-    }
-
-    const DeviceInfo& deviceInfo = cv::ocl::Context::getContext()->getDeviceInfo();
-
-    cout << "Device type: " << (deviceInfo.deviceType == CVCL_DEVICE_TYPE_CPU ?
-                "CPU" :
-                (deviceInfo.deviceType == CVCL_DEVICE_TYPE_GPU ? "GPU" : "unknown")) << endl
-         << "Platform name: " << deviceInfo.platform->platformName << endl
-         << "Device name: " << deviceInfo.deviceName << endl;
-
-    CV_PERF_TEST_MAIN_INTERNALS(ocl, impls)
+    CV_PERF_TEST_MAIN_INTERNALS(ocl, impls, dumpOpenCLDevice())
 }
index 02df8419cad261d9e0d2f11a13261167bbcc937a..cafefa5ab26aaf21a67c7c01ea3a202145b60d55 100644 (file)
@@ -10,7 +10,8 @@
 //                        Intel License Agreement
 //                For Open Source Computer Vision Library
 //
-// Copyright (C) 2000, Intel Corporation, all rights reserved.
+// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
+// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
 // Third party copyrights are property of their respective owners.
 //
 // Redistribution and use in source and binary forms, with or without modification,
 
 #include "test_precomp.hpp"
 
-#ifdef HAVE_OPENCL
+#define DUMP_INFO_STDOUT(propertyDisplayName, propertyValue) \
+    do { \
+        std::cout << (propertyDisplayName) << ": " << (propertyValue) << std::endl; \
+    } while (false)
 
-using namespace std;
-using namespace cv;
-using namespace cv::ocl;
-using namespace cvtest;
-using namespace testing;
+#define DUMP_INFO_XML(propertyXMLName, propertyValue) \
+    do { \
+        std::stringstream ss; ss << propertyValue; \
+        ::testing::Test::RecordProperty((propertyXMLName), ss.str()); \
+    } while (false)
 
-void print_info()
-{
-    printf("\n");
-#if defined _WIN32
-#   if defined _WIN64
-    puts("OS: Windows 64");
-#   else
-    puts("OS: Windows 32");
-#   endif
-#elif defined linux
-#   if defined _LP64
-    puts("OS: Linux 64");
-#   else
-    puts("OS: Linux 32");
-#   endif
-#elif defined __APPLE__
-#   if defined _LP64
-    puts("OS: Apple 64");
-#   else
-    puts("OS: Apple 32");
-#   endif
-#endif
+#include "opencv2/ocl/private/opencl_dumpinfo.hpp"
 
-}
-int main(int argc, char **argv)
-{
-    TS::ptr()->init(".");
-    InitGoogleTest(&argc, argv);
-    const char *keys =
-        "{ h | help     | false              | print help message }"
-        "{ t | type     | gpu                | set device type:cpu or gpu}"
-        "{ p | platform | -1                 | set platform id }"
-        "{ d | device   | 0                  | set device id }";
 
-    if (getenv("OPENCV_OPENCL_DEVICE") == NULL) // TODO Remove this after buildbot updates
-    {
-        CommandLineParser cmd(argc, argv, keys);
-        if (cmd.get<bool>("help"))
-        {
-            cout << "Available options besides google test option:" << endl;
-            cmd.printParams();
-            return 0;
-        }
-        string type = cmd.get<string>("type");
-        int pid = cmd.get<int>("platform");
-        int device = cmd.get<int>("device");
-
-        print_info();
-        int flag = CVCL_DEVICE_TYPE_GPU;
-        if(type == "cpu")
-        {
-            flag = CVCL_DEVICE_TYPE_CPU;
-        }
-
-        cv::ocl::PlatformsInfo platformsInfo;
-        cv::ocl::getOpenCLPlatforms(platformsInfo);
-        if (pid >= (int)platformsInfo.size())
-        {
-            std::cout << "platform is invalid\n";
-            return 1;
-        }
-
-        cv::ocl::DevicesInfo devicesInfo;
-        int devnums = cv::ocl::getOpenCLDevices(devicesInfo, flag, (pid < 0) ? NULL : platformsInfo[pid]);
-        if (device < 0 || device >= devnums)
-        {
-            std::cout << "device/platform invalid\n";
-            return 1;
-        }
-
-        cv::ocl::setDevice(devicesInfo[device]);
-    }
-
-    const DeviceInfo& deviceInfo = cv::ocl::Context::getContext()->getDeviceInfo();
-
-    cout << "Device type: " << (deviceInfo.deviceType == CVCL_DEVICE_TYPE_CPU ?
-                "CPU" :
-                (deviceInfo.deviceType == CVCL_DEVICE_TYPE_GPU ? "GPU" : "unknown")) << endl
-         << "Platform name: " << deviceInfo.platform->platformName << endl
-         << "Device name: " << deviceInfo.deviceName << endl;
-    return RUN_ALL_TESTS();
-}
-
-#else // DON'T HAVE_OPENCL
-
-int main()
-{
-    printf("OpenCV was built without OpenCL support\n");
-    return 0;
-}
-
-
-#endif // HAVE_OPENCL
+CV_TEST_MAIN(".", dumpOpenCLDevice())
index 2f32c244cc8a22d589d12828bf746757856a7879..8ea1ad93bac477a8bba3465915db59c8096d91aa 100644 (file)
@@ -564,12 +564,23 @@ CV_EXPORTS void  cvTsConvert( const CvMat* src, CvMat* dst );
 CV_EXPORTS void cvTsGEMM( const CvMat* a, const CvMat* b, double alpha,
                          const CvMat* c, double beta, CvMat* d, int flags );
 
-#define CV_TEST_MAIN(resourcesubdir) \
+#ifndef __CV_TEST_EXEC_ARGS
+#if defined(_MSC_VER) && (_MSC_VER <= 1400)
+#define __CV_TEST_EXEC_ARGS(...)    \
+    while (++argc >= (--argc,-1)) {__VA_ARGS__; break;} /*this ugly construction is needed for VS 2005*/
+#else
+#define __CV_TEST_EXEC_ARGS(...)    \
+    __VA_ARGS__;
+#endif
+#endif
+
+#define CV_TEST_MAIN(resourcesubdir, ...) \
 int main(int argc, char **argv) \
 { \
     cvtest::TS::ptr()->init(resourcesubdir); \
     ::testing::InitGoogleTest(&argc, argv); \
-    cvtest::printVersionInfo();\
+    cvtest::printVersionInfo(); \
+    __CV_TEST_EXEC_ARGS(__VA_ARGS__) \
     return RUN_ALL_TESTS(); \
 }
 
index 70ad571e09b4c22f244224834d246b584abdc31b..91605c61c91c15336eff1a84b680935b9b4a16ee 100644 (file)
@@ -477,23 +477,25 @@ CV_EXPORTS void PrintTo(const Size& sz, ::std::ostream* os);
     INSTANTIATE_TEST_CASE_P(/*none*/, fixture##_##name, params);\
     void fixture##_##name::PerfTestBody()
 
+#ifndef __CV_TEST_EXEC_ARGS
 #if defined(_MSC_VER) && (_MSC_VER <= 1400)
-#define CV_PERF_TEST_MAIN_INTERNALS_ARGS(...)  \
+#define __CV_TEST_EXEC_ARGS(...)    \
     while (++argc >= (--argc,-1)) {__VA_ARGS__; break;} /*this ugly construction is needed for VS 2005*/
 #else
-#define CV_PERF_TEST_MAIN_INTERNALS_ARGS(...)  \
+#define __CV_TEST_EXEC_ARGS(...)    \
     __VA_ARGS__;
 #endif
+#endif
 
 #define CV_PERF_TEST_MAIN_INTERNALS(modulename, impls, ...)    \
-    CV_PERF_TEST_MAIN_INTERNALS_ARGS(__VA_ARGS__) \
-    ::perf::Regression::Init(#modulename);\
-    ::perf::TestBase::Init(std::vector<std::string>(impls, impls + sizeof impls / sizeof *impls),\
-                           argc, argv);\
-    ::testing::InitGoogleTest(&argc, argv);\
-    cvtest::printVersionInfo();\
-    ::testing::Test::RecordProperty("cv_module_name", #modulename);\
-    ::perf::TestBase::RecordRunParameters();\
+    ::perf::Regression::Init(#modulename); \
+    ::perf::TestBase::Init(std::vector<std::string>(impls, impls + sizeof impls / sizeof *impls), \
+                           argc, argv); \
+    ::testing::InitGoogleTest(&argc, argv); \
+    cvtest::printVersionInfo(); \
+    ::testing::Test::RecordProperty("cv_module_name", #modulename); \
+    ::perf::TestBase::RecordRunParameters(); \
+    __CV_TEST_EXEC_ARGS(__VA_ARGS__) \
     return RUN_ALL_TESTS();
 
 // impls must be an array, not a pointer; "plain" should always be one of the implementations