From: marina.kolpakova Date: Wed, 10 Oct 2012 11:16:28 +0000 (+0400) Subject: add GPU module specific command line arguments X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~4180^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b28acfc12e4e37c1bb64b28c78e6d299da9c945f;p=platform%2Fupstream%2Fopencv.git add GPU module specific command line arguments --- diff --git a/modules/gpu/perf/perf_main.cpp b/modules/gpu/perf/perf_main.cpp index e8c7b20..f8eb23d 100644 --- a/modules/gpu/perf/perf_main.cpp +++ b/modules/gpu/perf/perf_main.cpp @@ -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(static_cast(info.totalMemory() / 1024.0) / 1024.0)), fflush(stdout); + printf("[ ] \tFree memory: %d Mb\n", static_cast(static_cast(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 diff --git a/modules/gpu/perf/utility.cpp b/modules/gpu/perf/utility.cpp index 2808b85..cb043c1 100644 --- a/modules/gpu/perf/utility.cpp +++ b/modules/gpu/perf/utility.cpp @@ -188,69 +188,4 @@ void PrintTo(const CvtColorInfo& info, ostream* os) }; *os << str[info.code]; -} - -void ts::printOsInfo() -{ -#if defined _WIN32 -# if defined _WIN64 - cout << "OS: Windows x64 \n" << endl; -# else - cout << "OS: Windows x32 \n" << endl; -# endif -#elif defined linux -# if defined _LP64 - cout << "OS: Linux x64 \n" << endl; -# else - cout << "OS: Linux x32 \n" << endl; -# endif -#elif defined __APPLE__ -# if defined _LP64 - cout << "OS: Apple x64 \n" << endl; -# else - cout << "OS: Apple x32 \n" << endl; -# endif -#endif -} - -void ts::printCudaInfo() -{ -#if !defined HAVE_CUDA || defined(CUDA_DISABLER) - cout << "OpenCV was built without CUDA support \n" << endl; -#else - int driver; - cudaDriverGetVersion(&driver); - - cout << "CUDA Driver version: " << driver << '\n'; - cout << "CUDA Runtime version: " << CUDART_VERSION << '\n'; - - cout << endl; - - cout << "GPU module was compiled for the following GPU archs:" << endl; - cout << " BIN: " << CUDA_ARCH_BIN << '\n'; - cout << " PTX: " << CUDA_ARCH_PTX << '\n'; - - cout << endl; - - int deviceCount = getCudaEnabledDeviceCount(); - cout << "CUDA device count: " << deviceCount << '\n'; - - cout << endl; - - for (int i = 0; i < deviceCount; ++i) - { - DeviceInfo info(i); - - cout << "Device [" << i << "] \n"; - cout << "\t Name: " << info.name() << '\n'; - cout << "\t Compute capability: " << info.majorVersion() << '.' << info.minorVersion()<< '\n'; - cout << "\t Multi Processor Count: " << info.multiProcessorCount() << '\n'; - cout << "\t Total memory: " << static_cast(static_cast(info.totalMemory() / 1024.0) / 1024.0) << " Mb \n"; - cout << "\t Free memory: " << static_cast(static_cast(info.freeMemory() / 1024.0) / 1024.0) << " Mb \n"; - if (!info.isCompatible()) - cout << "\t !!! This device is NOT compatible with current GPU module build \n"; - - cout << endl; - } -#endif -} +} \ No newline at end of file diff --git a/modules/gpu/perf/utility.hpp b/modules/gpu/perf/utility.hpp index 6ce031a..6a0fbb0 100644 --- a/modules/gpu/perf/utility.hpp +++ b/modules/gpu/perf/utility.hpp @@ -46,21 +46,16 @@ DEF_PARAM_TEST(Sz_Depth_Cn, cv::Size, MatDepth, MatCn); #define GPU_TYPICAL_MAT_SIZES testing::Values(perf::sz720p, perf::szSXGA, perf::sz1080p) -namespace ts { - void printOsInfo(); - void printCudaInfo(); -} - #define GPU_SANITY_CHECK(dmat, ...) \ do{ \ cv::Mat d##dmat(dmat); \ SANITY_CHECK(d##dmat, ## __VA_ARGS__); \ - } while(0); + } while(0) #define CPU_SANITY_CHECK(cmat, ...) \ do{ \ SANITY_CHECK(cmat, ## __VA_ARGS__); \ - } while(0); + } while(0) #define GPU_SANITY_CHECK_KEYPOINTS(alg, dmat, ...) \ do{ \ @@ -75,13 +70,13 @@ namespace ts { ::perf::Regression::add(this, std::string(#dmat) + "-angle-row", __angle, ## __VA_ARGS__); \ ::perf::Regression::add(this, std::string(#dmat) + "octave-row", __octave, ## __VA_ARGS__); \ ::perf::Regression::add(this, std::string(#dmat) + "-pt-size-row", __size, ## __VA_ARGS__); \ - } while(0); + } while(0) #define GPU_SANITY_CHECK_RESPONSE(alg, dmat, ...) \ do{ \ cv::Mat d##dmat(dmat); \ cv::Mat __response = d##dmat.row(cv::gpu::alg##_GPU::RESPONSE_ROW); \ ::perf::Regression::add(this, std::string(#dmat) + "-response-row", __response, ## __VA_ARGS__); \ - } while(0); + } while(0) #endif // __OPENCV_PERF_GPU_UTILITY_HPP__ diff --git a/modules/ts/include/opencv2/ts/ts_perf.hpp b/modules/ts/include/opencv2/ts/ts_perf.hpp index e58d27a..04aefb6 100644 --- a/modules/ts/include/opencv2/ts/ts_perf.hpp +++ b/modules/ts/include/opencv2/ts/ts_perf.hpp @@ -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);\ diff --git a/modules/ts/src/ts_perf.cpp b/modules/ts/src/ts_perf.cpp index 61081b1..b9eac49 100644 --- a/modules/ts/src/ts_perf.cpp +++ b/modules/ts/src/ts_perf.cpp @@ -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 +#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("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 \*****************************************************************************************/