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// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved. 6 7#include "../perf_precomp.hpp" 8#include "opencv2/ts/ocl_perf.hpp" 9 10#ifdef HAVE_OPENCL 11 12namespace cvtest { 13namespace ocl { 14 15struct BufferPoolState 16{ 17 BufferPoolController* controller_; 18 size_t oldMaxReservedSize_; 19 20 BufferPoolState(BufferPoolController* c, bool enable) 21 : controller_(c) 22 { 23 if (!cv::ocl::useOpenCL()) 24 { 25 throw ::perf::TestBase::PerfSkipTestException(); 26 } 27 oldMaxReservedSize_ = c->getMaxReservedSize(); 28 if (oldMaxReservedSize_ == (size_t)-1) 29 { 30 throw ::perf::TestBase::PerfSkipTestException(); 31 } 32 if (!enable) 33 { 34 c->setMaxReservedSize(0); 35 } 36 else 37 { 38 c->freeAllReservedBuffers(); 39 } 40 } 41 42 ~BufferPoolState() 43 { 44 controller_->setMaxReservedSize(oldMaxReservedSize_); 45 } 46}; 47 48typedef TestBaseWithParam<bool> BufferPoolFixture; 49 50OCL_PERF_TEST_P(BufferPoolFixture, BufferPool_UMatCreation100, Bool()) 51{ 52 BufferPoolState s(cv::ocl::getOpenCLAllocator()->getBufferPoolController(), GetParam()); 53 54 Size sz(1920, 1080); 55 56 OCL_TEST_CYCLE() 57 { 58 for (int i = 0; i < 100; i++) 59 { 60 UMat u(sz, CV_8UC1); 61 } 62 } 63 64 SANITY_CHECK_NOTHING(); 65} 66 67OCL_PERF_TEST_P(BufferPoolFixture, BufferPool_UMatCountNonZero100, Bool()) 68{ 69 BufferPoolState s(cv::ocl::getOpenCLAllocator()->getBufferPoolController(), GetParam()); 70 71 Size sz(1920, 1080); 72 73 OCL_TEST_CYCLE() 74 { 75 for (int i = 0; i < 100; i++) 76 { 77 UMat u(sz, CV_8UC1); 78 countNonZero(u); 79 } 80 } 81 82 SANITY_CHECK_NOTHING(); 83} 84 85OCL_PERF_TEST_P(BufferPoolFixture, BufferPool_UMatCanny10, Bool()) 86{ 87 BufferPoolState s(cv::ocl::getOpenCLAllocator()->getBufferPoolController(), GetParam()); 88 89 Size sz(1920, 1080); 90 91 int aperture = 3; 92 bool useL2 = false; 93 double thresh_low = 100; 94 double thresh_high = 120; 95 96 OCL_TEST_CYCLE() 97 { 98 for (int i = 0; i < 10; i++) 99 { 100 UMat src(sz, CV_8UC1); 101 UMat dst; 102 Canny(src, dst, thresh_low, thresh_high, aperture, useL2); 103 dst.getMat(ACCESS_READ); // complete async operations 104 } 105 } 106 107 SANITY_CHECK_NOTHING(); 108} 109 110OCL_PERF_TEST_P(BufferPoolFixture, BufferPool_UMatIntegral10, Bool()) 111{ 112 BufferPoolState s(cv::ocl::getOpenCLAllocator()->getBufferPoolController(), GetParam()); 113 114 Size sz(1920, 1080); 115 116 OCL_TEST_CYCLE() 117 { 118 for (int i = 0; i < 10; i++) 119 { 120 UMat src(sz, CV_32FC1); 121 UMat dst; 122 integral(src, dst); 123 dst.getMat(ACCESS_READ); // complete async operations 124 } 125 } 126 127 SANITY_CHECK_NOTHING(); 128} 129 130} } // namespace cvtest::ocl 131 132#endif // HAVE_OPENCL 133