mirror of https://github.com/opencv/opencv.git
Merge pull request #2192 from alalek:buffer_pool
commit
42ac3123ec
10 changed files with 479 additions and 14 deletions
@ -0,0 +1,26 @@ |
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
//
|
||||
// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
|
||||
|
||||
#ifndef __OPENCV_CORE_BUFFER_POOL_HPP__ |
||||
#define __OPENCV_CORE_BUFFER_POOL_HPP__ |
||||
|
||||
namespace cv |
||||
{ |
||||
|
||||
class BufferPoolController |
||||
{ |
||||
protected: |
||||
~BufferPoolController() { } |
||||
public: |
||||
virtual size_t getReservedSize() const = 0; |
||||
virtual size_t getMaxReservedSize() const = 0; |
||||
virtual void setMaxReservedSize(size_t size) = 0; |
||||
virtual void freeAllReservedBuffers() = 0; |
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif // __OPENCV_CORE_BUFFER_POOL_HPP__
|
@ -0,0 +1,132 @@ |
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
//
|
||||
// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
|
||||
|
||||
#include "perf_precomp.hpp" |
||||
#include "opencv2/ts/ocl_perf.hpp" |
||||
|
||||
#ifdef HAVE_OPENCL |
||||
|
||||
namespace cvtest { |
||||
namespace ocl { |
||||
|
||||
struct BufferPoolState |
||||
{ |
||||
BufferPoolController* controller_; |
||||
size_t oldMaxReservedSize_; |
||||
|
||||
BufferPoolState(BufferPoolController* c, bool enable) |
||||
: controller_(c) |
||||
{ |
||||
if (!cv::ocl::useOpenCL()) |
||||
{ |
||||
throw ::perf::TestBase::PerfSkipTestException(); |
||||
} |
||||
oldMaxReservedSize_ = c->getMaxReservedSize(); |
||||
if (oldMaxReservedSize_ == (size_t)-1) |
||||
{ |
||||
throw ::perf::TestBase::PerfSkipTestException(); |
||||
} |
||||
if (!enable) |
||||
{ |
||||
c->setMaxReservedSize(0); |
||||
} |
||||
else |
||||
{ |
||||
c->freeAllReservedBuffers(); |
||||
} |
||||
} |
||||
|
||||
~BufferPoolState() |
||||
{ |
||||
controller_->setMaxReservedSize(oldMaxReservedSize_); |
||||
} |
||||
}; |
||||
|
||||
typedef TestBaseWithParam<bool> BufferPoolFixture; |
||||
|
||||
OCL_PERF_TEST_P(BufferPoolFixture, BufferPool_UMatCreation100, Bool()) |
||||
{ |
||||
BufferPoolState s(cv::ocl::getOpenCLAllocator()->getBufferPoolController(), GetParam()); |
||||
|
||||
Size sz(1920, 1080); |
||||
|
||||
OCL_TEST_CYCLE() |
||||
{ |
||||
for (int i = 0; i < 100; i++) |
||||
{ |
||||
UMat u(sz, CV_8UC1); |
||||
} |
||||
} |
||||
|
||||
SANITY_CHECK_NOTHING() |
||||
} |
||||
|
||||
OCL_PERF_TEST_P(BufferPoolFixture, BufferPool_UMatCountNonZero100, Bool()) |
||||
{ |
||||
BufferPoolState s(cv::ocl::getOpenCLAllocator()->getBufferPoolController(), GetParam()); |
||||
|
||||
Size sz(1920, 1080); |
||||
|
||||
OCL_TEST_CYCLE() |
||||
{ |
||||
for (int i = 0; i < 100; i++) |
||||
{ |
||||
UMat u(sz, CV_8UC1); |
||||
countNonZero(u); |
||||
} |
||||
} |
||||
|
||||
SANITY_CHECK_NOTHING() |
||||
} |
||||
|
||||
OCL_PERF_TEST_P(BufferPoolFixture, BufferPool_UMatCanny10, Bool()) |
||||
{ |
||||
BufferPoolState s(cv::ocl::getOpenCLAllocator()->getBufferPoolController(), GetParam()); |
||||
|
||||
Size sz(1920, 1080); |
||||
|
||||
int aperture = 3; |
||||
bool useL2 = false; |
||||
double thresh_low = 100; |
||||
double thresh_high = 120; |
||||
|
||||
OCL_TEST_CYCLE() |
||||
{ |
||||
for (int i = 0; i < 10; i++) |
||||
{ |
||||
UMat src(sz, CV_8UC1); |
||||
UMat dst; |
||||
Canny(src, dst, thresh_low, thresh_high, aperture, useL2); |
||||
dst.getMat(ACCESS_READ); // complete async operations
|
||||
} |
||||
} |
||||
|
||||
SANITY_CHECK_NOTHING() |
||||
} |
||||
|
||||
OCL_PERF_TEST_P(BufferPoolFixture, BufferPool_UMatIntegral10, Bool()) |
||||
{ |
||||
BufferPoolState s(cv::ocl::getOpenCLAllocator()->getBufferPoolController(), GetParam()); |
||||
|
||||
Size sz(1920, 1080); |
||||
|
||||
OCL_TEST_CYCLE() |
||||
{ |
||||
for (int i = 0; i < 10; i++) |
||||
{ |
||||
UMat src(sz, CV_32FC1); |
||||
UMat dst; |
||||
integral(src, dst); |
||||
dst.getMat(ACCESS_READ); // complete async operations
|
||||
} |
||||
} |
||||
|
||||
SANITY_CHECK_NOTHING() |
||||
} |
||||
|
||||
} } // namespace cvtest::ocl
|
||||
|
||||
#endif // HAVE_OPENCL
|
@ -0,0 +1,28 @@ |
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
//
|
||||
// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
|
||||
|
||||
#ifndef __OPENCV_CORE_BUFFER_POOL_IMPL_HPP__ |
||||
#define __OPENCV_CORE_BUFFER_POOL_IMPL_HPP__ |
||||
|
||||
#include "opencv2/core/bufferpool.hpp" |
||||
|
||||
namespace cv { |
||||
|
||||
class DummyBufferPoolController : public BufferPoolController |
||||
{ |
||||
public: |
||||
DummyBufferPoolController() { } |
||||
virtual ~DummyBufferPoolController() { } |
||||
|
||||
virtual size_t getReservedSize() const { return (size_t)-1; } |
||||
virtual size_t getMaxReservedSize() const { return (size_t)-1; } |
||||
virtual void setMaxReservedSize(size_t size) { (void)size; } |
||||
virtual void freeAllReservedBuffers() { } |
||||
}; |
||||
|
||||
} // namespace
|
||||
|
||||
#endif // __OPENCV_CORE_BUFFER_POOL_IMPL_HPP__
|
Loading…
Reference in new issue