Commit b51a1a7d authored by Vadim Pisarevsky's avatar Vadim Pisarevsky Committed by OpenCV Buildbot

Merge pull request #895 from bitwangyaoyao:2.4_perf

parents 389be676 04399a27
......@@ -3,5 +3,5 @@ if(NOT HAVE_OPENCL)
endif()
set(the_description "OpenCL-accelerated Computer Vision")
ocv_define_module(ocl opencv_core opencv_imgproc opencv_features2d opencv_objdetect opencv_video)
ocv_define_module(ocl opencv_core opencv_imgproc opencv_features2d opencv_objdetect opencv_video opencv_calib3d)
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wshadow)
This diff is collapsed.
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -68,7 +69,7 @@ void blendLinearGold(const cv::Mat &img1, const cv::Mat &img2, const cv::Mat &we
}
}
}
TEST(blend)
PERFTEST(blend)
{
Mat src1, src2, weights1, weights2, dst;
ocl::oclMat d_src1, d_src2, d_weights1, d_weights2, d_dst;
......@@ -102,9 +103,12 @@ TEST(blend)
ocl::blendLinear(d_src1, d_src2, d_weights1, d_weights2, d_dst);
WARMUP_OFF;
cv::Mat ocl_mat;
d_dst.download(ocl_mat);
TestSystem::instance().setAccurate(ExpectedMatNear(dst, ocl_mat, 1.f));
GPU_ON;
ocl::blendLinear(d_src1, d_src2, d_weights1, d_weights2, d_dst);
;
GPU_OFF;
GPU_FULL_ON;
......
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -45,7 +46,7 @@
#include "precomp.hpp"
//////////////////// BruteForceMatch /////////////////
TEST(BruteForceMatcher)
PERFTEST(BruteForceMatcher)
{
Mat trainIdx_cpu;
Mat distance_cpu;
......@@ -66,6 +67,7 @@ TEST(BruteForceMatcher)
gen(train, size, desc_len, CV_32F, 0, 1);
// Output
vector< vector<DMatch> > matches(2);
vector< vector<DMatch> > d_matches(2);
// Init GPU matcher
ocl::BruteForceMatcher_OCL_base d_matcher(ocl::BruteForceMatcher_OCL_base::L2Dist);
......@@ -86,9 +88,11 @@ TEST(BruteForceMatcher)
d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
WARMUP_OFF;
d_matcher.match(d_query, d_train, d_matches[0]);
TestSystem::instance().setAccurate(AssertEQ<size_t>(d_matches[0].size(), matches[0].size()));
GPU_ON;
d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
;
GPU_OFF;
GPU_FULL_ON;
......@@ -111,15 +115,16 @@ TEST(BruteForceMatcher)
GPU_ON;
d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, 2);
;
GPU_OFF;
GPU_FULL_ON;
d_query.upload(query);
d_train.upload(train);
d_matcher.knnMatch(d_query, d_train, matches, 2);
d_matcher.knnMatch(d_query, d_train, d_matches, 2);
GPU_FULL_OFF;
TestSystem::instance().setAccurate(AssertEQ<size_t>(d_matches[0].size(), matches[0].size()));
SUBTEST << size << "; radiusMatch";
float max_distance = 2.0f;
......@@ -138,13 +143,14 @@ TEST(BruteForceMatcher)
GPU_ON;
d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, max_distance);
;
GPU_OFF;
GPU_FULL_ON;
d_query.upload(query);
d_train.upload(train);
d_matcher.radiusMatch(d_query, d_train, matches, max_distance);
d_matcher.radiusMatch(d_query, d_train, d_matches, max_distance);
GPU_FULL_OFF;
TestSystem::instance().setAccurate(AssertEQ<size_t>(d_matches[0].size(), matches[0].size()));
}
}
\ No newline at end of file
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -45,7 +46,7 @@
#include "precomp.hpp"
///////////// Canny ////////////////////////
TEST(Canny)
PERFTEST(Canny)
{
Mat img = imread(abspath("aloeL.jpg"), CV_LOAD_IMAGE_GRAYSCALE);
......@@ -70,9 +71,10 @@ TEST(Canny)
ocl::Canny(d_img, d_buf, d_edges, 50.0, 100.0);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExceptedMatSimilar(edges, d_edges, 2e-2));
GPU_ON;
ocl::Canny(d_img, d_buf, d_edges, 50.0, 100.0);
;
GPU_OFF;
GPU_FULL_ON;
......
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -45,7 +46,7 @@
#include "precomp.hpp"
///////////// cvtColor////////////////////////
TEST(cvtColor)
PERFTEST(cvtColor)
{
Mat src, dst;
ocl::oclMat d_src, d_dst;
......@@ -72,9 +73,12 @@ TEST(cvtColor)
ocl::cvtColor(d_src, d_dst, CV_RGBA2GRAY, 4);
WARMUP_OFF;
cv::Mat ocl_mat;
d_dst.download(ocl_mat);
TestSystem::instance().setAccurate(ExceptedMatSimilar(dst, ocl_mat, 1e-5));
GPU_ON;
ocl::cvtColor(d_src, d_dst, CV_RGBA2GRAY, 4);
;
GPU_OFF;
GPU_FULL_ON;
......
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -45,7 +46,7 @@
#include "precomp.hpp"
///////////// columnSum////////////////////////
TEST(columnSum)
PERFTEST(columnSum)
{
Mat src, dst;
ocl::oclMat d_src, d_dst;
......@@ -58,12 +59,13 @@ TEST(columnSum)
CPU_ON;
dst.create(src.size(), src.type());
for (int j = 0; j < src.cols; j++)
dst.at<float>(0, j) = src.at<float>(0, j);
for (int i = 1; i < src.rows; ++i)
{
for (int j = 0; j < src.cols; ++j)
{for (int j = 0; j < src.cols; ++j)
{
dst.at<float>(i, j) = src.at<float>(i, j) += src.at<float>(i - 1, j);
dst.at<float>(i, j) = dst.at<float>(i - 1 , j) + src.at<float>(i , j);
}
}
......@@ -74,9 +76,12 @@ TEST(columnSum)
ocl::columnSum(d_src, d_dst);
WARMUP_OFF;
cv::Mat ocl_mat;
d_dst.download(ocl_mat);
TestSystem::instance().setAccurate(ExpectedMatNear(dst, ocl_mat, 5e-1));
GPU_ON;
ocl::columnSum(d_src, d_dst);
;
GPU_OFF;
GPU_FULL_ON;
......
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -45,13 +46,13 @@
#include "precomp.hpp"
///////////// dft ////////////////////////
TEST(dft)
PERFTEST(dft)
{
Mat src, dst;
ocl::oclMat d_src, d_dst;
int all_type[] = {CV_32FC1, CV_32FC2};
std::string type_name[] = {"CV_32FC1", "CV_32FC2"};
int all_type[] = {CV_32FC2};
std::string type_name[] = {"CV_32FC2"};
for (int size = Min_Size; size <= Max_Size; size *= Multiple)
{
......@@ -73,9 +74,10 @@ TEST(dft)
ocl::dft(d_src, d_dst, Size(size, size));
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(dst, cv::Mat(d_dst), src.size().area() * 1e-4));
GPU_ON;
ocl::dft(d_src, d_dst, Size(size, size));
;
GPU_OFF;
GPU_FULL_ON;
......
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -45,7 +46,7 @@
#include "precomp.hpp"
///////////// Blur////////////////////////
TEST(Blur)
PERFTEST(Blur)
{
Mat src1, dst;
ocl::oclMat d_src1, d_dst;
......@@ -77,9 +78,10 @@ TEST(Blur)
ocl::blur(d_src1, d_dst, ksize, Point(-1, -1), bordertype);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(cv::Mat(d_dst), dst, 1.0));
GPU_ON;
ocl::blur(d_src1, d_dst, ksize, Point(-1, -1), bordertype);
;
GPU_OFF;
GPU_FULL_ON;
......@@ -92,7 +94,7 @@ TEST(Blur)
}
}
///////////// Laplacian////////////////////////
TEST(Laplacian)
PERFTEST(Laplacian)
{
Mat src1, dst;
ocl::oclMat d_src1, d_dst;
......@@ -123,9 +125,10 @@ TEST(Laplacian)
ocl::Laplacian(d_src1, d_dst, -1, ksize, 1);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(cv::Mat(d_dst), dst, 1e-5));
GPU_ON;
ocl::Laplacian(d_src1, d_dst, -1, ksize, 1);
;
GPU_OFF;
GPU_FULL_ON;
......@@ -139,7 +142,7 @@ TEST(Laplacian)
}
///////////// Erode ////////////////////
TEST(Erode)
PERFTEST(Erode)
{
Mat src, dst, ker;
ocl::oclMat d_src, d_dst;
......@@ -168,9 +171,10 @@ TEST(Erode)
ocl::erode(d_src, d_dst, ker);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(cv::Mat(d_dst), dst, 1e-5));
GPU_ON;
ocl::erode(d_src, d_dst, ker);
;
GPU_OFF;
GPU_FULL_ON;
......@@ -184,7 +188,7 @@ TEST(Erode)
}
///////////// Sobel ////////////////////////
TEST(Sobel)
PERFTEST(Sobel)
{
Mat src, dst;
ocl::oclMat d_src, d_dst;
......@@ -214,9 +218,10 @@ TEST(Sobel)
ocl::Sobel(d_src, d_dst, -1, dx, dy);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(cv::Mat(d_dst), dst, 1));
GPU_ON;
ocl::Sobel(d_src, d_dst, -1, dx, dy);
;
GPU_OFF;
GPU_FULL_ON;
......@@ -229,7 +234,7 @@ TEST(Sobel)
}
}
///////////// Scharr ////////////////////////
TEST(Scharr)
PERFTEST(Scharr)
{
Mat src, dst;
ocl::oclMat d_src, d_dst;
......@@ -259,9 +264,10 @@ TEST(Scharr)
ocl::Scharr(d_src, d_dst, -1, dx, dy);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(cv::Mat(d_dst), dst, 1));
GPU_ON;
ocl::Scharr(d_src, d_dst, -1, dx, dy);
;
GPU_OFF;
GPU_FULL_ON;
......@@ -275,7 +281,7 @@ TEST(Scharr)
}
///////////// GaussianBlur ////////////////////////
TEST(GaussianBlur)
PERFTEST(GaussianBlur)
{
Mat src, dst;
int all_type[] = {CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4};
......@@ -288,6 +294,8 @@ TEST(GaussianBlur)
SUBTEST << size << 'x' << size << "; " << type_name[j] ;
gen(src, size, size, all_type[j], 0, 256);
dst = src;
dst.setTo(0);
GaussianBlur(src, dst, Size(9, 9), 0);
......@@ -303,9 +311,11 @@ TEST(GaussianBlur)
ocl::GaussianBlur(d_src, d_dst, Size(9, 9), 0);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(cv::Mat(d_dst), dst, 1.0));
GPU_ON;
ocl::GaussianBlur(d_src, d_dst, Size(9, 9), 0);
;
GPU_OFF;
GPU_FULL_ON;
......@@ -319,7 +329,7 @@ TEST(GaussianBlur)
}
///////////// filter2D////////////////////////
TEST(filter2D)
PERFTEST(filter2D)
{
Mat src;
......@@ -339,7 +349,8 @@ TEST(filter2D)
Mat kernel;
gen(kernel, ksize, ksize, CV_32FC1, 0.0, 1.0);
Mat dst;
Mat dst(src);
dst.setTo(0);
cv::filter2D(src, dst, -1, kernel);
CPU_ON;
......@@ -347,15 +358,18 @@ TEST(filter2D)
CPU_OFF;
ocl::oclMat d_src(src);
ocl::oclMat d_dst;
ocl::oclMat d_dst(d_src);
d_dst.setTo(0);
WARMUP_ON;
ocl::filter2D(d_src, d_dst, -1, kernel);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(cv::Mat(d_dst), dst, 1e-5));
GPU_ON;
ocl::filter2D(d_src, d_dst, -1, kernel);
;
GPU_OFF;
GPU_FULL_ON;
......
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -45,7 +46,7 @@
#include "precomp.hpp"
///////////// gemm ////////////////////////
TEST(gemm)
PERFTEST(gemm)
{
Mat src1, src2, src3, dst;
ocl::oclMat d_src1, d_src2, d_src3, d_dst;
......@@ -71,10 +72,10 @@ TEST(gemm)
WARMUP_ON;
ocl::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(cv::Mat(d_dst), dst, src1.cols * src1.rows * 1e-4));
GPU_ON;
ocl::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst);
;
GPU_OFF;
GPU_FULL_ON;
......
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -82,7 +83,7 @@ public:
}
}
TEST(Haar)
PERFTEST(Haar)
{
Mat img = imread(abspath("basketball1.png"), CV_LOAD_IMAGE_GRAYSCALE);
......@@ -106,6 +107,8 @@ TEST(Haar)
1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
CPU_OFF;
vector<Rect> oclfaces;
ocl::CascadeClassifier_GPU faceCascade;
if (!faceCascade.load(abspath("haarcascade_frontalface_alt.xml")))
......@@ -115,24 +118,24 @@ TEST(Haar)
ocl::oclMat d_img(img);
faces.clear();
WARMUP_ON;
faceCascade.detectMultiScale(d_img, faces,
faceCascade.detectMultiScale(d_img, oclfaces,
1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
WARMUP_OFF;
//Testing whether the expected is equal to the actual.
TestSystem::instance().setAccurate(ExpectedEQ<vector<Rect>::size_type, vector<Rect>::size_type>(faces.size(), oclfaces.size()));
faces.clear();
GPU_ON;
faceCascade.detectMultiScale(d_img, faces,
faceCascade.detectMultiScale(d_img, oclfaces,
1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
;
GPU_OFF;
GPU_FULL_ON;
d_img.upload(img);
faceCascade.detectMultiScale(d_img, faces,
faceCascade.detectMultiScale(d_img, oclfaces,
1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
GPU_FULL_OFF;
}
\ No newline at end of file
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -45,7 +46,13 @@
#include "precomp.hpp"
///////////// HOG////////////////////////
TEST(HOG)
bool match_rect(cv::Rect r1, cv::Rect r2, int threshold)
{
return ((abs(r1.x - r2.x) < threshold) && (abs(r1.y - r2.y) < threshold) &&
(abs(r1.width - r2.width) < threshold) && (abs(r1.height - r2.height) < threshold));
}
PERFTEST(HOG)
{
Mat src = imread(abspath("road.png"), cv::IMREAD_GRAYSCALE);
......@@ -58,6 +65,7 @@ TEST(HOG)
cv::HOGDescriptor hog;
hog.setSVMDetector(hog.getDefaultPeopleDetector());
std::vector<cv::Rect> found_locations;
std::vector<cv::Rect> d_found_locations;
SUBTEST << 768 << 'x' << 576 << "; road.png";
......@@ -73,12 +81,78 @@ TEST(HOG)
d_src.upload(src);
WARMUP_ON;
ocl_hog.detectMultiScale(d_src, found_locations);
ocl_hog.detectMultiScale(d_src, d_found_locations);
WARMUP_OFF;
// Ground-truth rectangular people window
cv::Rect win1_64x128(231, 190, 72, 144);
cv::Rect win2_64x128(621, 156, 97, 194);
cv::Rect win1_48x96(238, 198, 63, 126);
cv::Rect win2_48x96(619, 161, 92, 185);
cv::Rect win3_48x96(488, 136, 56, 112);
// Compare whether ground-truth windows are detected and compare the number of windows detected.
std::vector<int> d_comp(4);
std::vector<int> comp(4);
for(int i = 0; i < (int)d_comp.size(); i++)
{
d_comp[i] = 0;
comp[i] = 0;
}
int threshold = 10;
int val = 32;
d_comp[0] = (int)d_found_locations.size();
comp[0] = (int)found_locations.size();
cv::Size winSize = hog.winSize;
if (winSize == cv::Size(48, 96))
{
for(int i = 0; i < (int)d_found_locations.size(); i++)
{
if (match_rect(d_found_locations[i], win1_48x96, threshold))
d_comp[1] = val;
if (match_rect(d_found_locations[i], win2_48x96, threshold))
d_comp[2] = val;
if (match_rect(d_found_locations[i], win3_48x96, threshold))
d_comp[3] = val;
}
for(int i = 0; i < (int)found_locations.size(); i++)
{
if (match_rect(found_locations[i], win1_48x96, threshold))
comp[1] = val;
if (match_rect(found_locations[i], win2_48x96, threshold))
comp[2] = val;
if (match_rect(found_locations[i], win3_48x96, threshold))
comp[3] = val;
}
}
else if (winSize == cv::Size(64, 128))
{
for(int i = 0; i < (int)d_found_locations.size(); i++)
{
if (match_rect(d_found_locations[i], win1_64x128, threshold))
d_comp[1] = val;
if (match_rect(d_found_locations[i], win2_64x128, threshold))
d_comp[2] = val;
}
for(int i = 0; i < (int)found_locations.size(); i++)
{
if (match_rect(found_locations[i], win1_64x128, threshold))
comp[1] = val;
if (match_rect(found_locations[i], win2_64x128, threshold))
comp[2] = val;
}
}
cv::Mat ocl_mat;
ocl_mat = cv::Mat(d_comp);
ocl_mat.convertTo(ocl_mat, cv::Mat(comp).type());
TestSystem::instance().setAccurate(ExpectedMatNear(ocl_mat, cv::Mat(comp), 3));
GPU_ON;
ocl_hog.detectMultiScale(d_src, found_locations);
;
GPU_OFF;
GPU_FULL_ON;
......
This diff is collapsed.
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -52,7 +53,7 @@
// ocl::oclMat d_src(src), d_templ(templ), d_dst;
// ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR);
//}
TEST(matchTemplate)
PERFTEST(matchTemplate)
{
//InitMatchTemplate();
......@@ -89,9 +90,10 @@ TEST(matchTemplate)
ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(dst, cv::Mat(d_dst), templ.rows * templ.cols * 1e-1));
GPU_ON;
ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR);
;
GPU_OFF;
GPU_FULL_ON;
......@@ -129,9 +131,10 @@ TEST(matchTemplate)
ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR_NORMED);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(dst, cv::Mat(d_dst), templ.rows * templ.cols * 1e-1));
GPU_ON;
ocl::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR_NORMED);
;
GPU_OFF;
GPU_FULL_ON;
......
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -45,7 +46,7 @@
#include "precomp.hpp"
///////////// ConvertTo////////////////////////
TEST(ConvertTo)
PERFTEST(ConvertTo)
{
Mat src, dst;
ocl::oclMat d_src, d_dst;
......@@ -76,9 +77,11 @@ TEST(ConvertTo)
d_src.convertTo(d_dst, CV_32FC1);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(dst, cv::Mat(d_dst), 0.0));
GPU_ON;
d_src.convertTo(d_dst, CV_32FC1);
;
GPU_OFF;
GPU_FULL_ON;
......@@ -91,7 +94,7 @@ TEST(ConvertTo)
}
}
///////////// copyTo////////////////////////
TEST(copyTo)
PERFTEST(copyTo)
{
Mat src, dst;
ocl::oclMat d_src, d_dst;
......@@ -122,9 +125,11 @@ TEST(copyTo)
d_src.copyTo(d_dst);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(dst, cv::Mat(d_dst), 0.0));
GPU_ON;
d_src.copyTo(d_dst);
;
GPU_OFF;
GPU_FULL_ON;
......@@ -137,7 +142,7 @@ TEST(copyTo)
}
}
///////////// setTo////////////////////////
TEST(setTo)
PERFTEST(setTo)
{
Mat src, dst;
Scalar val(1, 2, 3, 4);
......@@ -166,9 +171,11 @@ TEST(setTo)
d_src.setTo(val);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(src, cv::Mat(d_src), 1.0));
GPU_ON;
d_src.setTo(val);
;
GPU_OFF;
GPU_FULL_ON;
......
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -45,7 +46,7 @@
#include "precomp.hpp"
///////////// norm////////////////////////
TEST(norm)
PERFTEST(norm)
{
Mat src, buf;
ocl::oclMat d_src, d_buf;
......@@ -71,9 +72,10 @@ TEST(norm)
ocl::norm(d_src, d_buf, NORM_INF);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(src, cv::Mat(d_buf), .5));
GPU_ON;
ocl::norm(d_src, d_buf, NORM_INF);
;
GPU_OFF;
GPU_FULL_ON;
......
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -45,7 +46,7 @@
#include "precomp.hpp"
///////////// pyrDown //////////////////////
TEST(pyrDown)
PERFTEST(pyrDown)
{
Mat src, dst;
int all_type[] = {CV_8UC1, CV_8UC4};
......@@ -72,9 +73,11 @@ TEST(pyrDown)
ocl::pyrDown(d_src, d_dst);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(dst, cv::Mat(d_dst), dst.depth() == CV_32F ? 1e-4f : 1.0f));
GPU_ON;
ocl::pyrDown(d_src, d_dst);
;
GPU_OFF;
GPU_FULL_ON;
......
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -45,7 +46,7 @@
#include "precomp.hpp"
///////////// PyrLKOpticalFlow ////////////////////////
TEST(PyrLKOpticalFlow)
PERFTEST(PyrLKOpticalFlow)
{
std::string images1[] = {"rubberwhale1.png", "aloeL.jpg"};
std::string images2[] = {"rubberwhale2.png", "aloeR.jpg"};
......@@ -115,9 +116,14 @@ TEST(PyrLKOpticalFlow)
d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status, &d_err);
WARMUP_OFF;
std::vector<cv::Point2f> ocl_nextPts(d_nextPts.cols);
std::vector<unsigned char> ocl_status(d_status.cols);
TestSystem::instance().setAccurate(AssertEQ<size_t>(nextPts.size(), ocl_nextPts.size()));
TestSystem::instance().setAccurate(AssertEQ<size_t>(status.size(), ocl_status.size()));
GPU_ON;
d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status, &d_err);
;
GPU_OFF;
GPU_FULL_ON;
......
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -45,7 +46,7 @@
#include "precomp.hpp"
///////////// pyrUp ////////////////////////
TEST(pyrUp)
PERFTEST(pyrUp)
{
Mat src, dst;
int all_type[] = {CV_8UC1, CV_8UC4};
......@@ -72,9 +73,10 @@ TEST(pyrUp)
ocl::pyrUp(d_src, d_dst);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(dst, cv::Mat(d_dst), (src.depth() == CV_32F ? 1e-4f : 1.0)));
GPU_ON;
ocl::pyrUp(d_src, d_dst);
;
GPU_OFF;
GPU_FULL_ON;
......
......@@ -16,6 +16,7 @@
//
// @Authors
// Fangfang Bai, fangfang@multicorewareinc.com
// Jin Ma, jin@multicorewareinc.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
......@@ -45,7 +46,7 @@
#include "precomp.hpp"
///////////// Merge////////////////////////
TEST(Merge)
PERFTEST(Merge)
{
Mat dst;
ocl::oclMat d_dst;
......@@ -84,9 +85,10 @@ TEST(Merge)
ocl::merge(d_src, d_dst);
WARMUP_OFF;
TestSystem::instance().setAccurate(ExpectedMatNear(cv::Mat(dst), cv::Mat(d_dst), 0.0));
GPU_ON;
ocl::merge(d_src, d_dst);
;
GPU_OFF;
GPU_FULL_ON;
......@@ -105,7 +107,7 @@ TEST(Merge)
}
///////////// Split////////////////////////
TEST(Split)
PERFTEST(Split)
{
//int channels = 4;
int all_type[] = {CV_8UC1, CV_32FC1};
......@@ -135,9 +137,23 @@ TEST(Split)
ocl::split(d_src, d_dst);
WARMUP_OFF;
if(d_dst.size() == dst.size())
{
TestSystem::instance().setAccurate(1);
for(size_t i = 0; i < dst.size(); i++)
{
if(ExpectedMatNear(dst[i], cv::Mat(d_dst[i]), 0.0) == 0)
{
TestSystem::instance().setAccurate(0);
break;
}
}
}else
TestSystem::instance().setAccurate(0);
GPU_ON;
ocl::split(d_src, d_dst);
;
GPU_OFF;
GPU_FULL_ON;
......
This diff is collapsed.
......@@ -50,10 +50,15 @@
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/ocl/ocl.hpp"
#include "opencv2/ts/ts.hpp"
#include "opencv2/ts/ts_perf.hpp"
#include "opencv2/ts/ts_gtest.h"
#define Min_Size 1000
#define Max_Size 4000
......@@ -64,6 +69,8 @@ using namespace std;
using namespace cv;
void gen(Mat &mat, int rows, int cols, int type, Scalar low, Scalar high);
void gen(Mat &mat, int rows, int cols, int type, int low, int high, int n);
string abspath(const string &relpath);
int CV_CDECL cvErrorCallback(int, const char *, const char *, const char *, int, void *);
typedef struct
......@@ -76,6 +83,50 @@ COOR do_meanShift(int x0, int y0, uchar *sptr, uchar *dptr, int sstep,
void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi,
int sp, int sr, cv::TermCriteria crit);
template<class T1, class T2>
int ExpectedEQ(T1 expected, T2 actual)
{
if(expected == actual)
return 1;
return 0;
}
template<class T1>
int EeceptDoubleEQ(T1 expected, T1 actual)
{
testing::internal::Double lhs(expected);
testing::internal::Double rhs(actual);
if (lhs.AlmostEquals(rhs))
{
return 1;
}
return 0;
}
template<class T>
int AssertEQ(T expected, T actual)
{
if(expected == actual)
{
return 1;
}
return 0;
}
int ExceptDoubleNear(double val1, double val2, double abs_error);
bool match_rect(cv::Rect r1, cv::Rect r2, int threshold);
double checkNorm(const cv::Mat &m);
double checkNorm(const cv::Mat &m1, const cv::Mat &m2);
double checkSimilarity(const cv::Mat &m1, const cv::Mat &m2);
int ExpectedMatNear(cv::Mat dst, cv::Mat cpu_dst, double eps);
int ExceptedMatSimilar(cv::Mat dst, cv::Mat cpu_dst, double eps);
class Runnable
{
public:
......@@ -171,6 +222,16 @@ public:
return cur_iter_idx_ >= cpu_num_iters_;
}
int get_cur_iter_idx()
{
return cur_iter_idx_;
}
int get_cpu_num_iters()
{
return cpu_num_iters_;
}
bool warmupStop()
{
return cur_warmup_idx_++ >= gpu_warmup_iters_;
......@@ -252,6 +313,16 @@ public:
itname_changed_ = true;
}
void setAccurate(int is_accurate = -1)
{
is_accurate_ = is_accurate;
}
std::stringstream &getCurSubtestDescription()
{
return cur_subtest_description_;
}
private:
TestSystem():
cur_subtest_is_empty_(true), cpu_elapsed_(0),
......@@ -261,7 +332,8 @@ private:
speedup_full_faster_count_(0), speedup_full_slower_count_(0), speedup_full_equal_count_(0), is_list_mode_(false),
num_iters_(10), cpu_num_iters_(2),
gpu_warmup_iters_(1), cur_iter_idx_(0), cur_warmup_idx_(0),
record_(0), recordname_("performance"), itname_changed_(true)
record_(0), recordname_("performance"), itname_changed_(true),
is_accurate_(-1)
{
cpu_times_.reserve(num_iters_);
gpu_times_.reserve(num_iters_);
......@@ -277,20 +349,22 @@ private:
cur_subtest_description_.str("");
cur_subtest_is_empty_ = true;
cur_iter_idx_ = 0;
cur_warmup_idx_ = 0;
cpu_times_.clear();
gpu_times_.clear();
gpu_full_times_.clear();
is_accurate_ = -1;
}
double meanTime(const std::vector<int64> &samples);
void printHeading();
void printSummary();
void printMetrics(double cpu_time, double gpu_time = 0.0f, double gpu_full_time = 0.0f, double speedup = 0.0f, double fullspeedup = 0.0f);
void printMetrics(int is_accurate, double cpu_time, double gpu_time = 0.0f, double gpu_full_time = 0.0f, double speedup = 0.0f, double fullspeedup = 0.0f);
void writeHeading();
void writeSummary();
void writeMetrics(double cpu_time, double gpu_time = 0.0f, double gpu_full_time = 0.0f,
void writeMetrics(int is_accurate, double cpu_time, double gpu_time = 0.0f, double gpu_full_time = 0.0f,
double speedup = 0.0f, double fullspeedup = 0.0f,
double gpu_min = 0.0f, double gpu_max = 0.0f, double std_dev = 0.0f);
......@@ -340,6 +414,8 @@ private:
std::string recordname_;
std::string itname_;
bool itname_changed_;
int is_accurate_;
};
......@@ -353,7 +429,7 @@ struct name##_init: Runnable { \
void name##_init::run()
#define TEST(name) \
#define PERFTEST(name) \
struct name##_test: Runnable { \
name##_test(): Runnable(#name) { \
TestSystem::instance().addTest(this); \
......@@ -375,7 +451,7 @@ struct name##_test: Runnable { \
while (!TestSystem::instance().stop()) { \
TestSystem::instance().gpuOn()
#define GPU_OFF \
ocl::finish(); \
ocl::finish();\
TestSystem::instance().gpuOff(); \
} TestSystem::instance().gpuComplete()
......@@ -389,5 +465,5 @@ struct name##_test: Runnable { \
#define WARMUP_ON \
while (!TestSystem::instance().warmupStop()) {
#define WARMUP_OFF \
ocl::finish(); \
ocl::finish();\
} TestSystem::instance().warmupComplete()
......@@ -74,7 +74,7 @@ TEST_P(Gemm, Accuracy)
cv::gemm(a, b, 1.0, c, 1.0, dst, flags);
cv::ocl::gemm(cv::ocl::oclMat(a), cv::ocl::oclMat(b), 1.0, cv::ocl::oclMat(c), 1.0, ocl_dst, flags);
EXPECT_MAT_NEAR(dst, ocl_dst, mat_size.area() * 1e-4, "");
EXPECT_MAT_NEAR(dst, ocl_dst, mat_size.area() * 1e-4);
}
INSTANTIATE_TEST_CASE_P(ocl_gemm, Gemm, testing::Combine(
......
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