Commit 8009b515 authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

added performance tests for gpu module

parent 3206945b
......@@ -217,3 +217,6 @@ if(BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test)
# install(TARGETS ${the_test_target} RUNTIME DESTINATION bin COMPONENT main)
#endif()
endif()
define_opencv_perf_test(${name})
......@@ -596,8 +596,8 @@ namespace cv
////////////////////////////// Image processing //////////////////////////////
//! DST[x,y] = SRC[xmap[x,y],ymap[x,y]] with bilinear interpolation.
//! supports CV_32FC1 map type
//! DST[x,y] = SRC[xmap[x,y],ymap[x,y]]
//! supports only CV_32FC1 map type
CV_EXPORTS void remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap,
int interpolation, int borderMode = BORDER_CONSTANT, const Scalar& borderValue = Scalar(),
Stream& stream = Stream::Null());
......
This diff is collapsed.
#include "perf_precomp.hpp"
PERF_TEST_P(DevInfo_Size_MatType_KernelSize, boxFilter, testing::Combine(testing::ValuesIn(devices()),
testing::Values(GPU_TYPICAL_MAT_SIZES),
testing::Values(CV_8UC1, CV_8UC4),
testing::Values(3, 5, 7)))
{
DeviceInfo devInfo = std::tr1::get<0>(GetParam());
Size size = std::tr1::get<1>(GetParam());
int type = std::tr1::get<2>(GetParam());
int ksize = std::tr1::get<3>(GetParam());
setDevice(devInfo.deviceID());
Mat src_host(size, type);
declare.in(src_host, WARMUP_RNG);
GpuMat src(src_host);
GpuMat dst(size, type);
Ptr<FilterEngine_GPU> filter = createBoxFilter_GPU(type, type, Size(ksize, ksize));
declare.time(0.5).iterations(100);
SIMPLE_TEST_CYCLE()
{
filter->apply(src, dst);
}
Mat dst_host = dst;
SANITY_CHECK(dst_host);
}
PERF_TEST_P(DevInfo_Size_MatType_MorphOp_KernelSize, morphologyFilter, testing::Combine(testing::ValuesIn(devices()),
testing::Values(GPU_TYPICAL_MAT_SIZES),
testing::Values(CV_8UC1, CV_8UC4),
testing::Values((int)MORPH_ERODE, (int)MORPH_DILATE),
testing::Values(3, 5, 7)))
{
DeviceInfo devInfo = std::tr1::get<0>(GetParam());
Size size = std::tr1::get<1>(GetParam());
int type = std::tr1::get<2>(GetParam());
int op = std::tr1::get<3>(GetParam());
int ksize = std::tr1::get<4>(GetParam());
setDevice(devInfo.deviceID());
Mat src_host(size, type);
declare.in(src_host, WARMUP_RNG);
GpuMat src(src_host);
GpuMat dst(size, type);
Ptr<FilterEngine_GPU> filter = createMorphologyFilter_GPU(op, type, Mat::ones(ksize, ksize, CV_8U));
declare.time(0.5).iterations(100);
SIMPLE_TEST_CYCLE()
{
filter->apply(src, dst);
}
Mat dst_host = dst;
SANITY_CHECK(dst_host);
}
PERF_TEST_P(DevInfo_Size_MatType_KernelSize, linearFilter, testing::Combine(testing::ValuesIn(devices()),
testing::Values(GPU_TYPICAL_MAT_SIZES),
testing::Values(CV_8UC1, CV_8UC4),
testing::Values(3, 5, 7)))
{
DeviceInfo devInfo = std::tr1::get<0>(GetParam());
Size size = std::tr1::get<1>(GetParam());
int type = std::tr1::get<2>(GetParam());
int ksize = std::tr1::get<3>(GetParam());
setDevice(devInfo.deviceID());
Mat src_host(size, type);
declare.in(src_host, WARMUP_RNG);
GpuMat src(src_host);
GpuMat dst(size, type);
Ptr<FilterEngine_GPU> filter = createLinearFilter_GPU(type, type, Mat::ones(ksize, ksize, CV_8U));
declare.time(1.0).iterations(100);
SIMPLE_TEST_CYCLE()
{
filter->apply(src, dst);
}
Mat dst_host = dst;
SANITY_CHECK(dst_host);
}
PERF_TEST_P(DevInfo_Size_MatType_KernelSize_BorderMode, separableLinearFilter, testing::Combine(testing::ValuesIn(devices()),
testing::Values(GPU_TYPICAL_MAT_SIZES),
testing::Values(CV_8UC1, CV_8UC4, CV_16SC1, CV_16SC3, CV_32FC1),
testing::Values(3, 5, 7),
testing::Values((int)BORDER_REFLECT101, (int)BORDER_CONSTANT)))
{
DeviceInfo devInfo = std::tr1::get<0>(GetParam());
Size size = std::tr1::get<1>(GetParam());
int type = std::tr1::get<2>(GetParam());
int ksize = std::tr1::get<3>(GetParam());
int borderMode = std::tr1::get<4>(GetParam());
setDevice(devInfo.deviceID());
Mat src_host(size, type);
declare.in(src_host, WARMUP_RNG);
GpuMat src(src_host);
GpuMat dst(size, type);
Mat kernel = getGaussianKernel(ksize, 0.5, CV_32F);
Ptr<FilterEngine_GPU> filter = createSeparableLinearFilter_GPU(type, type, kernel, kernel, Point(-1,-1), borderMode);
declare.time(1.0).iterations(100);
SIMPLE_TEST_CYCLE()
{
filter->apply(src, dst, Rect(0, 0, src.cols, src.rows));
}
Mat dst_host = dst;
SANITY_CHECK(dst_host);
}
This diff is collapsed.
#include "perf_precomp.hpp"
#ifdef HAVE_CUDA
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
cvtest::TS::ptr()->init("gpu");
Regression::Init("gpu");
TestBase::Init(argc, argv);
return RUN_ALL_TESTS();
}
#else
int main(int argc, char** argv)
{
printf("OpenCV was built without CUDA support\n");
return 0;
}
#endif
#include "perf_precomp.hpp"
PERF_TEST_P(DevInfo_Size_MatType, merge, testing::Combine(testing::ValuesIn(devices()),
testing::Values(GPU_TYPICAL_MAT_SIZES),
testing::Values(CV_8UC1, CV_16UC1, CV_32FC1)))
{
DeviceInfo devInfo = std::tr1::get<0>(GetParam());
Size size = std::tr1::get<1>(GetParam());
int type = std::tr1::get<2>(GetParam());
setDevice(devInfo.deviceID());
const int num_channels = 4;
vector<GpuMat> src(num_channels);
for (int i = 0; i < num_channels; ++i)
src[i] = GpuMat(size, type, cv::Scalar::all(i));
GpuMat dst(size, CV_MAKETYPE(type, num_channels));
declare.time(0.5).iterations(100);
SIMPLE_TEST_CYCLE()
{
merge(src, dst);
}
Mat dst_host = dst;
SANITY_CHECK(dst_host);
}
PERF_TEST_P(DevInfo_Size_MatType, split, testing::Combine(testing::ValuesIn(devices()),
testing::Values(GPU_TYPICAL_MAT_SIZES),
testing::Values(CV_8UC1, CV_16UC1, CV_32FC1)))
{
DeviceInfo devInfo = std::tr1::get<0>(GetParam());
Size size = std::tr1::get<1>(GetParam());
int type = std::tr1::get<2>(GetParam());
setDevice(devInfo.deviceID());
const int num_channels = 4;
GpuMat src(size, CV_MAKETYPE(type, num_channels), cv::Scalar(1, 2, 3, 4));
vector<GpuMat> dst(num_channels);
for (int i = 0; i < num_channels; ++i)
dst[i] = GpuMat(size, type);
declare.time(0.5).iterations(100);
SIMPLE_TEST_CYCLE()
{
split(src, dst);
}
vector<Mat> dst_host(dst.size());
for (size_t i = 0; i < dst.size(); ++i)
dst[i].download(dst_host[i]);
SANITY_CHECK(dst_host);
}
PERF_TEST_P(DevInfo_Size_MatType, setTo, testing::Combine(testing::ValuesIn(devices()),
testing::Values(GPU_TYPICAL_MAT_SIZES),
testing::Values(CV_8UC1, CV_8UC4, CV_32FC1)))
{
DeviceInfo devInfo = std::tr1::get<0>(GetParam());
Size size = std::tr1::get<1>(GetParam());
int type = std::tr1::get<2>(GetParam());
setDevice(devInfo.deviceID());
GpuMat src(size, type);
Scalar val(1, 2, 3, 4);
declare.time(0.5).iterations(100);
SIMPLE_TEST_CYCLE()
{
src.setTo(val);
}
Mat src_host = src;
SANITY_CHECK(src_host);
}
PERF_TEST_P(DevInfo_Size_MatType, setToMasked, testing::Combine(testing::ValuesIn(devices()),
testing::Values(GPU_TYPICAL_MAT_SIZES),
testing::Values(CV_8UC1, CV_8UC4, CV_32FC1)))
{
DeviceInfo devInfo = std::tr1::get<0>(GetParam());
Size size = std::tr1::get<1>(GetParam());
int type = std::tr1::get<2>(GetParam());
setDevice(devInfo.deviceID());
Mat src_host(size, type);
declare.in(src_host, WARMUP_RNG);
GpuMat src(src_host);
Scalar val(1, 2, 3, 4);
Mat mask_host(size, CV_8UC1);
randu(mask_host, 0.0, 2.0);
GpuMat mask(mask_host);
declare.time(0.5).iterations(100);
SIMPLE_TEST_CYCLE()
{
src.setTo(val, mask);
}
src_host = src;
SANITY_CHECK(src_host);
}
PERF_TEST_P(DevInfo_Size_MatType, copyToMasked, testing::Combine(testing::ValuesIn(devices()),
testing::Values(GPU_TYPICAL_MAT_SIZES),
testing::Values(CV_8UC1, CV_8UC4, CV_32FC1)))
{
DeviceInfo devInfo = std::tr1::get<0>(GetParam());
Size size = std::tr1::get<1>(GetParam());
int type = std::tr1::get<2>(GetParam());
setDevice(devInfo.deviceID());
Mat src_host(size, type);
declare.in(src_host, WARMUP_RNG);
GpuMat src(src_host);
GpuMat dst(size, type);
Mat mask_host(size, CV_8UC1);
randu(mask_host, 0.0, 2.0);
GpuMat mask(mask_host);
declare.time(0.5).iterations(100);
SIMPLE_TEST_CYCLE()
{
src.copyTo(dst, mask);
}
Mat dst_host = dst;
SANITY_CHECK(dst_host);
}
PERF_TEST_P(DevInfo_Size_MatType_MatType, convertTo, testing::Combine(testing::ValuesIn(devices()),
testing::Values(GPU_TYPICAL_MAT_SIZES),
testing::Values(CV_8UC1, CV_16UC1, CV_32FC1),
testing::Values(CV_8UC1, CV_16UC1, CV_32FC1)))
{
DeviceInfo devInfo = std::tr1::get<0>(GetParam());
Size size = std::tr1::get<1>(GetParam());
int type1 = std::tr1::get<2>(GetParam());
int type2 = std::tr1::get<3>(GetParam());
setDevice(devInfo.deviceID());
Mat src_host(size, type1);
declare.in(src_host, WARMUP_RNG);
GpuMat src(src_host);
GpuMat dst(size, type2);
double a = 0.5;
double b = 1.0;
declare.time(0.5).iterations(100);
SIMPLE_TEST_CYCLE()
{
src.convertTo(dst, type2, a, b);
}
Mat dst_host = dst;
SANITY_CHECK(dst_host);
}
#include "perf_precomp.hpp"
#ifndef __OPENCV_PERF_PRECOMP_HPP__
#define __OPENCV_PERF_PRECOMP_HPP__
#include <cstdio>
#include <iostream>
#include "cvconfig.h"
#include "opencv2/ts/ts.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"
#include "perf_utility.hpp"
#if GTEST_CREATE_SHARED_LIBRARY
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
#endif
#endif
#include "perf_precomp.hpp"
using namespace std;
using namespace cv::gpu;
Mat readImage(const string& fileName, int flags)
{
return imread(string(cvtest::TS::ptr()->get_data_path()) + fileName, flags);
}
bool supportFeature(const DeviceInfo& info, FeatureSet feature)
{
return TargetArchs::builtWith(feature) && info.supports(feature);
}
const vector<DeviceInfo>& devices()
{
static vector<DeviceInfo> devs;
static bool first = true;
if (first)
{
int deviceCount = getCudaEnabledDeviceCount();
devs.reserve(deviceCount);
for (int i = 0; i < deviceCount; ++i)
{
DeviceInfo info(i);
if (info.isCompatible())
devs.push_back(info);
}
first = false;
}
return devs;
}
vector<DeviceInfo> devices(FeatureSet feature)
{
const vector<DeviceInfo>& d = devices();
vector<DeviceInfo> devs_filtered;
if (TargetArchs::builtWith(feature))
{
devs_filtered.reserve(d.size());
for (size_t i = 0, size = d.size(); i < size; ++i)
{
const DeviceInfo& info = d[i];
if (info.supports(feature))
devs_filtered.push_back(info);
}
}
return devs_filtered;
}
void cv::gpu::PrintTo(const DeviceInfo& info, ostream* os)
{
*os << info.name();
}
void PrintTo(const CvtColorInfo& info, ::std::ostream* os)
{
static const char* str[] =
{
"BGR2BGRA",
"BGRA2BGR",
"BGR2RGBA",
"RGBA2BGR",
"BGR2RGB",
"BGRA2RGBA",
"BGR2GRAY",
"RGB2GRAY",
"GRAY2BGR",
"GRAY2BGRA",
"BGRA2GRAY",
"RGBA2GRAY",
"BGR2BGR565",
"RGB2BGR565",
"BGR5652BGR",
"BGR5652RGB",
"BGRA2BGR565",
"RGBA2BGR565",
"BGR5652BGRA",
"BGR5652RGBA",
"GRAY2BGR565",
"BGR5652GRAY",
"BGR2BGR555",
"RGB2BGR555",
"BGR5552BGR",
"BGR5552RGB",
"BGRA2BGR555",
"RGBA2BGR555",
"BGR5552BGRA",
"BGR5552RGBA",
"GRAY2BGR555",
"BGR5552GRAY",
"BGR2XYZ",
"RGB2XYZ",
"XYZ2BGR",
"XYZ2RGB",
"BGR2YCrCb",
"RGB2YCrCb",
"YCrCb2BGR",
"YCrCb2RGB",
"BGR2HSV",
"RGB2HSV",
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
"BGR2HLS",
"RGB2HLS",
"HSV2BGR",
"HSV2RGB",
0,
0,
0,
0,
"HLS2BGR",
"HLS2RGB",
0,
0,
0,
0,
"BGR2HSV_FULL",
"RGB2HSV_FULL",
"BGR2HLS_FULL",
"RGB2HLS_FULL",
"HSV2BGR_FULL",
"HSV2RGB_FULL",
"HLS2BGR_FULL",
"HLS2RGB_FULL",
0,
0,
0,
0,
0,
0,
0,
0,
"BGR2YUV",
"RGB2YUV",
"YUV2BGR",
"YUV2RGB",
0,
0,
0,
0,
0,
0,
0,
0
};
*os << str[info.code];
}
#ifndef __OPENCV_PERF_GPU_UTILITY_HPP__
#define __OPENCV_PERF_GPU_UTILITY_HPP__
#include <iosfwd>
#include "opencv2/ts/ts.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"
using namespace std;
using namespace cv;
using namespace cv::gpu;
using namespace perf;
enum {HORIZONTAL_AXIS = 0, VERTICAL_AXIS = 1, BOTH_AXIS = -1};
CV_ENUM(MorphOp, MORPH_ERODE, MORPH_DILATE)
CV_ENUM(BorderMode, BORDER_REFLECT101, BORDER_REPLICATE, BORDER_CONSTANT, BORDER_REFLECT, BORDER_WRAP)
CV_ENUM(FlipCode, HORIZONTAL_AXIS, VERTICAL_AXIS, BOTH_AXIS)
CV_ENUM(CmpOp, CMP_EQ, CMP_GT, CMP_GE, CMP_LT, CMP_LE, CMP_NE)
CV_ENUM(Interpolation, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC)
CV_ENUM(MatchMethod, TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED)
struct CvtColorInfo
{
int scn;
int dcn;
int code;
explicit CvtColorInfo(int scn_=0, int dcn_=0, int code_=0) : scn(scn_), dcn(dcn_), code(code_) {}
};
typedef TestBaseWithParam<DeviceInfo> DevInfo;
typedef TestBaseWithParam< std::tr1::tuple<DeviceInfo, Size> > DevInfo_Size;
typedef TestBaseWithParam< std::tr1::tuple<DeviceInfo, MatType> > DevInfo_MatType;
typedef TestBaseWithParam< std::tr1::tuple<DeviceInfo, Size, MatType> > DevInfo_Size_MatType;
typedef TestBaseWithParam< std::tr1::tuple<DeviceInfo, Size, MatType, MatType> > DevInfo_Size_MatType_MatType;
typedef TestBaseWithParam< std::tr1::tuple<DeviceInfo, Size, MatType, int> > DevInfo_Size_MatType_KernelSize;
typedef TestBaseWithParam< std::tr1::tuple<DeviceInfo, Size, MatType, MorphOp, int> > DevInfo_Size_MatType_MorphOp_KernelSize;
typedef TestBaseWithParam< std::tr1::tuple<DeviceInfo, Size, MatType, int, BorderMode> > DevInfo_Size_MatType_KernelSize_BorderMode;
typedef TestBaseWithParam< std::tr1::tuple<DeviceInfo, Size, MatType, FlipCode> > DevInfo_Size_MatType_FlipCode;
typedef TestBaseWithParam< std::tr1::tuple<DeviceInfo, Size, MatType, CmpOp> > DevInfo_Size_MatType_CmpOp;
typedef TestBaseWithParam< std::tr1::tuple<DeviceInfo, Size, MatType, Interpolation> > DevInfo_Size_MatType_Interpolation;
typedef TestBaseWithParam< std::tr1::tuple<DeviceInfo, Size, MatType, Interpolation, double> > DevInfo_Size_MatType_Interpolation_SizeCoeff;
typedef TestBaseWithParam< std::tr1::tuple<DeviceInfo, Size, MatType, Interpolation, BorderMode> > DevInfo_Size_MatType_Interpolation_BorderMode;
typedef TestBaseWithParam< std::tr1::tuple<DeviceInfo, Size, MatType, CvtColorInfo> > DevInfo_Size_MatType_CvtColorInfo;
typedef TestBaseWithParam< std::tr1::tuple<DeviceInfo, Size, MatType, MatchMethod> > DevInfo_Size_MatType_MatchMethod;
const cv::Size sz1800x1500 = cv::Size(1800, 1500);
const cv::Size sz4700x3000 = cv::Size(4700, 3000);
#define GPU_TYPICAL_MAT_SIZES szXGA, szSXGA, sz720p, sz1080p, sz1800x1500, sz4700x3000
//! read image from testdata folder.
Mat readImage(const string& fileName, int flags = CV_LOAD_IMAGE_COLOR);
//! return true if device supports specified feature and gpu module was built with support the feature.
bool supportFeature(const cv::gpu::DeviceInfo& info, cv::gpu::FeatureSet feature);
//! return all devices compatible with current gpu module build.
const std::vector<cv::gpu::DeviceInfo>& devices();
//! return all devices compatible with current gpu module build which support specified feature.
std::vector<cv::gpu::DeviceInfo> devices(cv::gpu::FeatureSet feature);
namespace cv
{
namespace gpu
{
void PrintTo(const DeviceInfo& info, ::std::ostream* os);
}
}
void PrintTo(const CvtColorInfo& info, ::std::ostream* os);
#endif // __OPENCV_PERF_GPU_UTILITY_HPP__
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment