add GPU module specific command line arguments
authormarina.kolpakova <marina.kolpakova@itseez.com>
Wed, 10 Oct 2012 11:16:28 +0000 (15:16 +0400)
committermarina.kolpakova <marina.kolpakova@itseez.com>
Wed, 10 Oct 2012 12:13:25 +0000 (16:13 +0400)
modules/gpu/perf/perf_main.cpp
modules/gpu/perf/utility.cpp
modules/gpu/perf/utility.hpp
modules/ts/include/opencv2/ts/ts_perf.hpp
modules/ts/src/ts_perf.cpp

index e8c7b20..f8eb23d 100644 (file)
@@ -1,3 +1,74 @@
 #include "perf_precomp.hpp"
 
-CV_PERF_TEST_MAIN(gpu)
\ No newline at end of file
+namespace{
+
+static void printOsInfo()
+{
+#if defined _WIN32
+#   if defined _WIN64
+        printf("[----------]\n[ GPU INFO ] \tRun on OS Windows x64.\n[----------]\n"), fflush(stdout);
+#   else
+        printf("[----------]\n[ GPU INFO ] \tRun on OS Windows x32.\n[----------]\n"), fflush(stdout);
+#   endif
+#elif defined linux
+#   if defined _LP64
+        printf("[----------]\n[ GPU INFO ] \tRun on OS Linux x64.\n[----------]\n"), fflush(stdout);
+#   else
+        printf("[----------]\n[ GPU INFO ] \tRun on OS Linux x32.\n[----------]\n"), fflush(stdout);
+#   endif
+#elif defined __APPLE__
+#   if defined _LP64
+        printf("[----------]\n[ GPU INFO ] \tRun on OS Apple x64.\n[----------]\n"), fflush(stdout);
+#   else
+        printf("[----------]\n[ GPU INFO ] \tRun on OS Apple x32.\n[----------]\n"), fflush(stdout);
+#   endif
+#endif
+
+}
+
+static void printCudaInfo()
+{
+    printOsInfo();
+#ifndef HAVE_CUDA
+    printf("[----------]\n[ GPU INFO ] \tOpenCV was built without CUDA support.\n[----------]\n"), fflush(stdout);
+#else
+    int driver;
+    cudaDriverGetVersion(&driver);
+
+    printf("[----------]\n"), fflush(stdout);
+    printf("[ GPU INFO ] \tCUDA Driver  version: %d.\n", driver), fflush(stdout);
+    printf("[ GPU INFO ] \tCUDA Runtime version: %d.\n", CUDART_VERSION), fflush(stdout);
+    printf("[----------]\n"), fflush(stdout);
+
+    printf("[----------]\n"), fflush(stdout);
+    printf("[ GPU INFO ] \tGPU module was compiled for the following GPU archs.\n"), fflush(stdout);
+    printf("[      BIN ] \t%s.\n", CUDA_ARCH_BIN), fflush(stdout);
+    printf("[      PTX ] \t%s.\n", CUDA_ARCH_PTX), fflush(stdout);
+    printf("[----------]\n"), fflush(stdout);
+
+    printf("[----------]\n"), fflush(stdout);
+    int deviceCount = cv::gpu::getCudaEnabledDeviceCount();
+    printf("[ GPU INFO ] \tCUDA device count:: %d.\n", deviceCount), fflush(stdout);
+    printf("[----------]\n"), fflush(stdout);
+
+    for (int i = 0; i < deviceCount; ++i)
+    {
+        cv::gpu::DeviceInfo info(i);
+
+        printf("[----------]\n"), fflush(stdout);
+        printf("[ DEVICE   ] \t# %d %s.\n", i, info.name().c_str()), fflush(stdout);
+        printf("[          ] \tCompute capability: %d.%d\n", (int)info.majorVersion(), (int)info.minorVersion()), fflush(stdout);
+        printf("[          ] \tMulti Processor Count:  %d\n", info.multiProcessorCount()), fflush(stdout);
+        printf("[          ] \tTotal memory: %d Mb\n", static_cast<int>(static_cast<int>(info.totalMemory() / 1024.0) / 1024.0)), fflush(stdout);
+        printf("[          ] \tFree  memory: %d Mb\n", static_cast<int>(static_cast<int>(info.freeMemory()  / 1024.0) / 1024.0)), fflush(stdout);
+        if (!info.isCompatible())
+            printf("[ GPU INFO ] \tThis device is NOT compatible with current GPU module build\n");
+        printf("[----------]\n"), fflush(stdout);
+    }
+
+#endif
+}
+
+}
+
+CV_PERF_TEST_MAIN(gpu, printCudaInfo())
\ No newline at end of file
index 2808b85..cb043c1 100644 (file)
@@ -188,69 +188,4 @@ void PrintTo(const CvtColorInfo& info, ostream* os)
     };\r
 \r
     *os << str[info.code];\r
-}\r
-\r
-void ts::printOsInfo()\r
-{\r
-#if defined _WIN32\r
-#   if defined _WIN64\r
-        cout << "OS: Windows x64 \n" << endl;\r
-#   else\r
-        cout << "OS: Windows x32 \n" << endl;\r
-#   endif\r
-#elif defined linux\r
-#   if defined _LP64\r
-        cout << "OS: Linux x64 \n" << endl;\r
-#   else\r
-        cout << "OS: Linux x32 \n" << endl;\r
-#   endif\r
-#elif defined __APPLE__\r
-#   if defined _LP64\r
-        cout << "OS: Apple x64 \n" << endl;\r
-#   else\r
-        cout << "OS: Apple x32 \n" << endl;\r
-#   endif\r
-#endif\r
-}\r
-\r
-void ts::printCudaInfo()\r
-{\r
-#if !defined HAVE_CUDA || defined(CUDA_DISABLER)\r
-    cout << "OpenCV was built without CUDA support \n" << endl;\r
-#else\r
-    int driver;\r
-    cudaDriverGetVersion(&driver);\r
-\r
-    cout << "CUDA Driver  version: " << driver << '\n';\r
-    cout << "CUDA Runtime version: " << CUDART_VERSION << '\n';\r
-\r
-    cout << endl;\r
-\r
-    cout << "GPU module was compiled for the following GPU archs:" << endl;\r
-    cout << "    BIN: " << CUDA_ARCH_BIN << '\n';\r
-    cout << "    PTX: " << CUDA_ARCH_PTX << '\n';\r
-\r
-    cout << endl;\r
-\r
-    int deviceCount = getCudaEnabledDeviceCount();\r
-    cout << "CUDA device count: " << deviceCount << '\n';\r
-\r
-    cout << endl;\r
-\r
-    for (int i = 0; i < deviceCount; ++i)\r
-    {\r
-        DeviceInfo info(i);\r
-\r
-        cout << "Device [" << i << "] \n";\r
-        cout << "\t Name: " << info.name() << '\n';\r
-        cout << "\t Compute capability: " << info.majorVersion() << '.' << info.minorVersion()<< '\n';\r
-        cout << "\t Multi Processor Count: " << info.multiProcessorCount() << '\n';\r
-        cout << "\t Total memory: " << static_cast<int>(static_cast<int>(info.totalMemory() / 1024.0) / 1024.0) << " Mb \n";\r
-        cout << "\t Free  memory: " << static_cast<int>(static_cast<int>(info.freeMemory() / 1024.0) / 1024.0) << " Mb \n";\r
-        if (!info.isCompatible())\r
-            cout << "\t !!! This device is NOT compatible with current GPU module build \n";\r
-\r
-        cout << endl;\r
-    }\r
-#endif\r
-}\r
+}
\ No newline at end of file
index 6ce031a..6a0fbb0 100644 (file)
@@ -46,21 +46,16 @@ DEF_PARAM_TEST(Sz_Depth_Cn, cv::Size, MatDepth, MatCn);
 \r
 #define GPU_TYPICAL_MAT_SIZES testing::Values(perf::sz720p, perf::szSXGA, perf::sz1080p)\r
 \r
-namespace ts {\r
-    void printOsInfo();\r
-    void printCudaInfo();\r
-}\r
-\r
 #define GPU_SANITY_CHECK(dmat, ...) \\r
     do{ \\r
         cv::Mat d##dmat(dmat); \\r
         SANITY_CHECK(d##dmat, ## __VA_ARGS__); \\r
-    } while(0);\r
+    } while(0)\r
 \r
 #define CPU_SANITY_CHECK(cmat, ...) \\r
     do{ \\r
         SANITY_CHECK(cmat, ## __VA_ARGS__); \\r
-    } while(0);\r
+    } while(0)\r
 \r
 #define GPU_SANITY_CHECK_KEYPOINTS(alg, dmat, ...)                                          \\r
     do{                                                                                     \\r
@@ -75,13 +70,13 @@ namespace ts {
         ::perf::Regression::add(this, std::string(#dmat) + "-angle-row",    __angle,    ## __VA_ARGS__); \\r
         ::perf::Regression::add(this, std::string(#dmat) + "octave-row",    __octave,   ## __VA_ARGS__); \\r
         ::perf::Regression::add(this, std::string(#dmat) + "-pt-size-row",  __size,     ## __VA_ARGS__); \\r
-    } while(0);\r
+    } while(0)\r
 \r
 #define GPU_SANITY_CHECK_RESPONSE(alg, dmat, ...) \\r
     do{                                                                                     \\r
         cv::Mat d##dmat(dmat);                                                              \\r
         cv::Mat __response  = d##dmat.row(cv::gpu::alg##_GPU::RESPONSE_ROW);                \\r
         ::perf::Regression::add(this, std::string(#dmat) + "-response-row", __response, ## __VA_ARGS__); \\r
-    } while(0);\r
+    } while(0)\r
 \r
 #endif // __OPENCV_PERF_GPU_UTILITY_HPP__\r
index e58d27a..04aefb6 100644 (file)
@@ -206,7 +206,6 @@ private:
 #define SANITY_CHECK_MATCHES(array, ...) ::perf::Regression::addMatches(this, #array, array , ## __VA_ARGS__)
 
 #ifdef HAVE_CUDA
-//#error "CUDA"
 class CV_EXPORTS GpuPerf
 {
 public:
@@ -215,7 +214,7 @@ public:
 
 # define PERF_RUN_GPU()  ::perf::GpuPerf::targetDevice()
 #else
-# define PERF_RUN_GPU()
+# define PERF_RUN_GPU()  false
 #endif
 
 
@@ -478,9 +477,10 @@ CV_EXPORTS void PrintTo(const Size& sz, ::std::ostream* os);
     void fixture##_##name::PerfTestBody()
 
 
-#define CV_PERF_TEST_MAIN(testsuitname) \
+#define CV_PERF_TEST_MAIN(testsuitname, ...) \
 int main(int argc, char **argv)\
 {\
+    __VA_ARGS__;\
     ::perf::Regression::Init(#testsuitname);\
     ::perf::TestBase::Init(argc, argv);\
     ::testing::InitGoogleTest(&argc, argv);\
index 61081b1..b9eac49 100644 (file)
@@ -17,18 +17,20 @@ const std::string command_line_keys =
     "{   perf_seed           |809564   |seed for random numbers generator}"
     "{   perf_tbb_nthreads   |-1       |if TBB is enabled, the number of TBB threads}"
     "{   perf_write_sanity   |         |allow to create new records for sanity checks}"
-    #ifdef ANDROID
+#ifdef ANDROID
     "{   perf_time_limit     |6.0      |default time limit for a single test (in seconds)}"
     "{   perf_affinity_mask  |0        |set affinity mask for the main thread}"
     "{   perf_log_power_checkpoints  | |additional xml logging for power measurement}"
-    #else
+#else
     "{   perf_time_limit     |3.0      |default time limit for a single test (in seconds)}"
-    #endif
+#endif
     "{   perf_max_deviation  |1.0      |}"
     "{   help h              |         |print help info}"
-    #ifdef HAVE_CUDA
-    "{   perf_run_cpu        |false    |run GPU performance tests for analogy CPU functions}"
-    #endif
+#ifdef HAVE_CUDA
+    "{   perf_run_cpu        |false    |run GPU performance tests for analogical CPU functions}"
+    "{   perf_cuda_device    |0        |run GPU test suite onto specific CUDA capable device}"
+    "{   perf_cuda_info_only |false    |print an information about system and an available CUDA devices and then exit.}"
+#endif
 ;
 
 static double       param_max_outliers;
@@ -41,6 +43,7 @@ static int          param_tbb_nthreads;
 static bool         param_write_sanity;
 #ifdef HAVE_CUDA
 static bool         param_run_cpu;
+static int          param_cuda_device;
 #endif
 #ifdef ANDROID
 static int          param_affinity_mask;
@@ -64,6 +67,10 @@ static void setCurrentThreadAffinityMask(int mask)
 
 #endif
 
+#ifdef HAVE_CUDA
+# include <opencv2/core/gpumat.hpp>
+#endif
+
 static void randu(cv::Mat& m)
 {
     const int bigValue = 0x00000FFF;
@@ -617,12 +624,30 @@ void TestBase::Init(int argc, const char* const argv[])
 #endif
 
 #ifdef HAVE_CUDA
+
+    bool printOnly        = args.has("perf_cuda_info_only");
+
+    if (printOnly)
+        exit(0);
+
     param_run_cpu         = args.has("perf_run_cpu");
+    param_cuda_device      = std::max(0, std::min(cv::gpu::getCudaEnabledDeviceCount(), args.get<int>("perf_cuda_device")));
 
     if (param_run_cpu)
         printf("[----------]\n[ GPU INFO ] \tRun test suite on CPU.\n[----------]\n"), fflush(stdout);
     else
-        printf("[----------]\n[ GPU INFO ] \tRun test suite on GPU.\n[----------]\n"), fflush(stdout);
+    {
+        cv::gpu::DeviceInfo info(param_cuda_device);
+        if (!info.isCompatible())
+        {
+            printf("[----------]\n[ FAILURE  ] \tDevice %s is NOT compatible with current GPU module build.\n[----------]\n", info.name().c_str()), fflush(stdout);
+            exit(-1);
+        }
+
+        cv::gpu::setDevice(param_cuda_device);
+
+        printf("[----------]\n[ GPU INFO ] \tRun test suite on %s GPU.\n[----------]\n", info.name().c_str()), fflush(stdout);
+    }
 #endif
 
     if (!args.check())
@@ -1212,7 +1237,6 @@ bool perf::GpuPerf::targetDevice()
 }
 #endif
 
-
 /*****************************************************************************************\
 *                                  ::perf::PrintTo
 \*****************************************************************************************/