move CUDA core tests to core module

pull/3531/head
Vladislav Vinogradov 10 years ago
parent 53862687d5
commit 1be1a28920
  1. 41
      modules/core/perf/cuda/perf_gpumat.cpp
  2. 83
      modules/core/test/cuda/test_buffer_pool.cpp
  3. 35
      modules/core/test/cuda/test_gpumat.cpp
  4. 6
      modules/core/test/cuda/test_opengl.cpp
  5. 7
      modules/core/test/cuda/test_stream.cpp
  6. 114
      modules/cuda/perf/perf_buffer_pool.cpp

@ -40,7 +40,12 @@
//
//M*/
#include "perf_precomp.hpp"
#include "../perf_precomp.hpp"
#ifdef HAVE_CUDA
#include "opencv2/core/cuda.hpp"
#include "opencv2/ts/cuda_perf.hpp"
using namespace std;
using namespace testing;
@ -49,7 +54,7 @@ using namespace perf;
//////////////////////////////////////////////////////////////////////
// SetTo
PERF_TEST_P(Sz_Depth_Cn, MatOp_SetTo,
PERF_TEST_P(Sz_Depth_Cn, CUDA_GpuMat_SetTo,
Combine(CUDA_TYPICAL_MAT_SIZES,
Values(CV_8U, CV_16U, CV_32F, CV_64F),
CUDA_CHANNELS_1_3_4))
@ -67,23 +72,21 @@ PERF_TEST_P(Sz_Depth_Cn, MatOp_SetTo,
cv::cuda::GpuMat dst(size, type);
TEST_CYCLE() dst.setTo(val);
CUDA_SANITY_CHECK(dst);
}
else
{
cv::Mat dst(size, type);
TEST_CYCLE() dst.setTo(val);
CPU_SANITY_CHECK(dst);
}
SANITY_CHECK_NOTHING();
}
//////////////////////////////////////////////////////////////////////
// SetToMasked
PERF_TEST_P(Sz_Depth_Cn, MatOp_SetToMasked,
PERF_TEST_P(Sz_Depth_Cn, CUDA_GpuMat_SetToMasked,
Combine(CUDA_TYPICAL_MAT_SIZES,
Values(CV_8U, CV_16U, CV_32F, CV_64F),
CUDA_CHANNELS_1_3_4))
@ -106,23 +109,21 @@ PERF_TEST_P(Sz_Depth_Cn, MatOp_SetToMasked,
const cv::cuda::GpuMat d_mask(mask);
TEST_CYCLE() dst.setTo(val, d_mask);
CUDA_SANITY_CHECK(dst, 1e-10);
}
else
{
cv::Mat dst = src;
TEST_CYCLE() dst.setTo(val, mask);
CPU_SANITY_CHECK(dst);
}
SANITY_CHECK_NOTHING();
}
//////////////////////////////////////////////////////////////////////
// CopyToMasked
PERF_TEST_P(Sz_Depth_Cn, MatOp_CopyToMasked,
PERF_TEST_P(Sz_Depth_Cn, CUDA_GpuMat_CopyToMasked,
Combine(CUDA_TYPICAL_MAT_SIZES,
Values(CV_8U, CV_16U, CV_32F, CV_64F),
CUDA_CHANNELS_1_3_4))
@ -144,17 +145,15 @@ PERF_TEST_P(Sz_Depth_Cn, MatOp_CopyToMasked,
cv::cuda::GpuMat dst(d_src.size(), d_src.type(), cv::Scalar::all(0));
TEST_CYCLE() d_src.copyTo(dst, d_mask);
CUDA_SANITY_CHECK(dst, 1e-10);
}
else
{
cv::Mat dst(src.size(), src.type(), cv::Scalar::all(0));
TEST_CYCLE() src.copyTo(dst, mask);
CPU_SANITY_CHECK(dst);
}
SANITY_CHECK_NOTHING();
}
//////////////////////////////////////////////////////////////////////
@ -162,7 +161,7 @@ PERF_TEST_P(Sz_Depth_Cn, MatOp_CopyToMasked,
DEF_PARAM_TEST(Sz_2Depth, cv::Size, MatDepth, MatDepth);
PERF_TEST_P(Sz_2Depth, MatOp_ConvertTo,
PERF_TEST_P(Sz_2Depth, CUDA_GpuMat_ConvertTo,
Combine(CUDA_TYPICAL_MAT_SIZES,
Values(CV_8U, CV_16U, CV_32F, CV_64F),
Values(CV_8U, CV_16U, CV_32F, CV_64F)))
@ -183,15 +182,15 @@ PERF_TEST_P(Sz_2Depth, MatOp_ConvertTo,
cv::cuda::GpuMat dst;
TEST_CYCLE() d_src.convertTo(dst, depth2, a, b);
CUDA_SANITY_CHECK(dst, 1e-10);
}
else
{
cv::Mat dst;
TEST_CYCLE() src.convertTo(dst, depth2, a, b);
CPU_SANITY_CHECK(dst);
}
SANITY_CHECK_NOTHING();
}
#endif

@ -40,13 +40,13 @@
//
//M*/
#include "test_precomp.hpp"
#include "../test_precomp.hpp"
#ifdef HAVE_CUDA
#include "opencv2/cudaarithm.hpp"
#include "opencv2/cudawarping.hpp"
#include "opencv2/core/cuda.hpp"
#include "opencv2/core/private.cuda.hpp"
#include "opencv2/ts/cuda_test.hpp"
using namespace testing;
using namespace cv;
@ -54,65 +54,64 @@ using namespace cv::cuda;
struct BufferPoolTest : TestWithParam<DeviceInfo>
{
};
namespace
{
void func1(const GpuMat& src, GpuMat& dst, Stream& stream)
void RunSimpleTest(Stream& stream, HostMem& dst_1, HostMem& dst_2)
{
BufferPool pool(stream);
GpuMat buf = pool.getBuffer(src.size(), CV_32FC(src.channels()));
src.convertTo(buf, CV_32F, 1.0 / 255.0, stream);
{
GpuMat buf0 = pool.getBuffer(Size(640, 480), CV_8UC1);
EXPECT_FALSE( buf0.empty() );
cuda::exp(buf, dst, stream);
}
void func2(const GpuMat& src, GpuMat& dst, Stream& stream)
{
BufferPool pool(stream);
buf0.setTo(Scalar::all(0), stream);
GpuMat buf1 = pool.getBuffer(saturate_cast<int>(src.rows * 0.5), saturate_cast<int>(src.cols * 0.5), src.type());
GpuMat buf1 = pool.getBuffer(Size(640, 480), CV_8UC1);
EXPECT_FALSE( buf1.empty() );
cuda::resize(src, buf1, Size(), 0.5, 0.5, cv::INTER_NEAREST, stream);
buf0.convertTo(buf1, buf1.type(), 1.0, 1.0, stream);
GpuMat buf2 = pool.getBuffer(buf1.size(), CV_32FC(buf1.channels()));
buf1.download(dst_1, stream);
}
func1(buf1, buf2, stream);
{
GpuMat buf2 = pool.getBuffer(Size(1280, 1024), CV_32SC1);
EXPECT_FALSE( buf2.empty() );
GpuMat buf3 = pool.getBuffer(src.size(), buf2.type());
buf2.setTo(Scalar::all(2), stream);
cuda::resize(buf2, buf3, src.size(), 0, 0, cv::INTER_NEAREST, stream);
buf2.download(dst_2, stream);
}
}
buf3.convertTo(dst, CV_8U, stream);
void CheckSimpleTest(HostMem& dst_1, HostMem& dst_2)
{
EXPECT_MAT_NEAR(Mat(Size(640, 480), CV_8UC1, Scalar::all(1)), dst_1, 0.0);
EXPECT_MAT_NEAR(Mat(Size(1280, 1024), CV_32SC1, Scalar::all(2)), dst_2, 0.0);
}
}
};
CUDA_TEST_P(BufferPoolTest, SimpleUsage)
CUDA_TEST_P(BufferPoolTest, FromNullStream)
{
DeviceInfo devInfo = GetParam();
setDevice(devInfo.deviceID());
HostMem dst_1, dst_2;
GpuMat src(200, 200, CV_8UC1);
GpuMat dst;
RunSimpleTest(Stream::Null(), dst_1, dst_2);
Stream stream;
func2(src, dst, stream);
CheckSimpleTest(dst_1, dst_2);
}
stream.waitForCompletion();
CUDA_TEST_P(BufferPoolTest, From2Streams)
{
HostMem dst1_1, dst1_2;
HostMem dst2_1, dst2_2;
GpuMat buf, buf1, buf2, buf3;
GpuMat dst_gold;
Stream stream1, stream2;
RunSimpleTest(stream1, dst1_1, dst1_2);
RunSimpleTest(stream2, dst2_1, dst2_2);
cuda::resize(src, buf1, Size(), 0.5, 0.5, cv::INTER_NEAREST);
buf1.convertTo(buf, CV_32F, 1.0 / 255.0);
cuda::exp(buf, buf2);
cuda::resize(buf2, buf3, src.size(), 0, 0, cv::INTER_NEAREST);
buf3.convertTo(dst_gold, CV_8U);
stream1.waitForCompletion();
stream2.waitForCompletion();
ASSERT_MAT_NEAR(dst_gold, dst, 0);
CheckSimpleTest(dst1_1, dst1_2);
CheckSimpleTest(dst2_1, dst2_2);
}
INSTANTIATE_TEST_CASE_P(CUDA_Stream, BufferPoolTest, ALL_DEVICES);

@ -40,16 +40,19 @@
//
//M*/
#include "test_precomp.hpp"
#include "../test_precomp.hpp"
#ifdef HAVE_CUDA
#include "opencv2/core/cuda.hpp"
#include "opencv2/ts/cuda_test.hpp"
using namespace cvtest;
////////////////////////////////////////////////////////////////////////////////
// SetTo
PARAM_TEST_CASE(SetTo, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
PARAM_TEST_CASE(GpuMat_SetTo, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
{
cv::cuda::DeviceInfo devInfo;
cv::Size size;
@ -67,7 +70,7 @@ PARAM_TEST_CASE(SetTo, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
}
};
CUDA_TEST_P(SetTo, Zero)
CUDA_TEST_P(GpuMat_SetTo, Zero)
{
cv::Scalar zero = cv::Scalar::all(0);
@ -77,7 +80,7 @@ CUDA_TEST_P(SetTo, Zero)
EXPECT_MAT_NEAR(cv::Mat::zeros(size, type), mat, 0.0);
}
CUDA_TEST_P(SetTo, SameVal)
CUDA_TEST_P(GpuMat_SetTo, SameVal)
{
cv::Scalar val = cv::Scalar::all(randomDouble(0.0, 255.0));
@ -102,7 +105,7 @@ CUDA_TEST_P(SetTo, SameVal)
}
}
CUDA_TEST_P(SetTo, DifferentVal)
CUDA_TEST_P(GpuMat_SetTo, DifferentVal)
{
cv::Scalar val = randomScalar(0.0, 255.0);
@ -127,7 +130,7 @@ CUDA_TEST_P(SetTo, DifferentVal)
}
}
CUDA_TEST_P(SetTo, Masked)
CUDA_TEST_P(GpuMat_SetTo, Masked)
{
cv::Scalar val = randomScalar(0.0, 255.0);
cv::Mat mat_gold = randomMat(size, type);
@ -156,7 +159,7 @@ CUDA_TEST_P(SetTo, Masked)
}
}
INSTANTIATE_TEST_CASE_P(CUDA_GpuMat, SetTo, testing::Combine(
INSTANTIATE_TEST_CASE_P(CUDA, GpuMat_SetTo, testing::Combine(
ALL_DEVICES,
DIFFERENT_SIZES,
ALL_TYPES,
@ -165,7 +168,7 @@ INSTANTIATE_TEST_CASE_P(CUDA_GpuMat, SetTo, testing::Combine(
////////////////////////////////////////////////////////////////////////////////
// CopyTo
PARAM_TEST_CASE(CopyTo, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
PARAM_TEST_CASE(GpuMat_CopyTo, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
{
cv::cuda::DeviceInfo devInfo;
cv::Size size;
@ -184,7 +187,7 @@ PARAM_TEST_CASE(CopyTo, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
}
};
CUDA_TEST_P(CopyTo, WithOutMask)
CUDA_TEST_P(GpuMat_CopyTo, WithOutMask)
{
cv::Mat src = randomMat(size, type);
@ -195,7 +198,7 @@ CUDA_TEST_P(CopyTo, WithOutMask)
EXPECT_MAT_NEAR(src, dst, 0.0);
}
CUDA_TEST_P(CopyTo, Masked)
CUDA_TEST_P(GpuMat_CopyTo, Masked)
{
cv::Mat src = randomMat(size, type);
cv::Mat mask = randomMat(size, CV_8UC1, 0.0, 2.0);
@ -226,7 +229,7 @@ CUDA_TEST_P(CopyTo, Masked)
}
}
INSTANTIATE_TEST_CASE_P(CUDA_GpuMat, CopyTo, testing::Combine(
INSTANTIATE_TEST_CASE_P(CUDA, GpuMat_CopyTo, testing::Combine(
ALL_DEVICES,
DIFFERENT_SIZES,
ALL_TYPES,
@ -235,7 +238,7 @@ INSTANTIATE_TEST_CASE_P(CUDA_GpuMat, CopyTo, testing::Combine(
////////////////////////////////////////////////////////////////////////////////
// ConvertTo
PARAM_TEST_CASE(ConvertTo, cv::cuda::DeviceInfo, cv::Size, MatDepth, MatDepth, UseRoi)
PARAM_TEST_CASE(GpuMat_ConvertTo, cv::cuda::DeviceInfo, cv::Size, MatDepth, MatDepth, UseRoi)
{
cv::cuda::DeviceInfo devInfo;
cv::Size size;
@ -255,7 +258,7 @@ PARAM_TEST_CASE(ConvertTo, cv::cuda::DeviceInfo, cv::Size, MatDepth, MatDepth, U
}
};
CUDA_TEST_P(ConvertTo, WithOutScaling)
CUDA_TEST_P(GpuMat_ConvertTo, WithOutScaling)
{
cv::Mat src = randomMat(size, depth1);
@ -285,7 +288,7 @@ CUDA_TEST_P(ConvertTo, WithOutScaling)
}
}
CUDA_TEST_P(ConvertTo, WithScaling)
CUDA_TEST_P(GpuMat_ConvertTo, WithScaling)
{
cv::Mat src = randomMat(size, depth1);
double a = randomDouble(0.0, 1.0);
@ -317,7 +320,7 @@ CUDA_TEST_P(ConvertTo, WithScaling)
}
}
INSTANTIATE_TEST_CASE_P(CUDA_GpuMat, ConvertTo, testing::Combine(
INSTANTIATE_TEST_CASE_P(CUDA, GpuMat_ConvertTo, testing::Combine(
ALL_DEVICES,
DIFFERENT_SIZES,
ALL_DEPTH,
@ -356,6 +359,6 @@ CUDA_TEST_P(EnsureSizeIsEnough, BufferReuse)
EXPECT_EQ(reinterpret_cast<intptr_t>(old.data), reinterpret_cast<intptr_t>(buffer.data));
}
INSTANTIATE_TEST_CASE_P(CUDA_GpuMat, EnsureSizeIsEnough, ALL_DEVICES);
INSTANTIATE_TEST_CASE_P(CUDA, EnsureSizeIsEnough, ALL_DEVICES);
#endif // HAVE_CUDA

@ -40,10 +40,14 @@
//
//M*/
#include "test_precomp.hpp"
#include "../test_precomp.hpp"
#if defined(HAVE_CUDA) && defined(HAVE_OPENGL)
#include "opencv2/core/cuda.hpp"
#include "opencv2/core/opengl.hpp"
#include "opencv2/ts/cuda_test.hpp"
using namespace cvtest;
/////////////////////////////////////////////

@ -40,13 +40,14 @@
//
//M*/
#include "test_precomp.hpp"
#include "../test_precomp.hpp"
#ifdef HAVE_CUDA
#include <cuda_runtime.h>
#if CUDART_VERSION >= 5000
#include "opencv2/core/cuda.hpp"
#include "opencv2/ts/cuda_test.hpp"
using namespace cvtest;
@ -130,6 +131,4 @@ CUDA_TEST_P(Async, Convert)
INSTANTIATE_TEST_CASE_P(CUDA_Stream, Async, ALL_DEVICES);
#endif // CUDART_VERSION >= 5000
#endif // HAVE_CUDA

@ -1,114 +0,0 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "perf_precomp.hpp"
#ifdef HAVE_CUDA
#include "opencv2/cudaarithm.hpp"
#include "opencv2/core/private.cuda.hpp"
using namespace testing;
using namespace perf;
using namespace cv;
using namespace cv::cuda;
namespace
{
void func1(const GpuMat& src, GpuMat& dst, Stream& stream)
{
BufferPool pool(stream);
GpuMat buf = pool.getBuffer(src.size(), CV_32FC(src.channels()));
src.convertTo(buf, CV_32F, 1.0 / 255.0, stream);
cuda::exp(buf, dst, stream);
}
void func2(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream)
{
BufferPool pool(stream);
GpuMat buf1 = pool.getBuffer(src1.size(), CV_32FC(src1.channels()));
func1(src1, buf1, stream);
GpuMat buf2 = pool.getBuffer(src2.size(), CV_32FC(src2.channels()));
func1(src2, buf2, stream);
cuda::add(buf1, buf2, dst, noArray(), -1, stream);
}
}
PERF_TEST_P(Sz, BufferPool, CUDA_TYPICAL_MAT_SIZES)
{
static bool first = true;
const Size size = GetParam();
const bool useBufferPool = PERF_RUN_CUDA();
Mat host_src(size, CV_8UC1);
declare.in(host_src, WARMUP_RNG);
GpuMat src1(host_src), src2(host_src);
GpuMat dst;
setBufferPoolUsage(useBufferPool);
if (useBufferPool && first)
{
setBufferPoolConfig(-1, 25 * 1024 * 1024, 2);
first = false;
}
TEST_CYCLE()
{
func2(src1, src2, dst, Stream::Null());
}
Mat h_dst(dst);
SANITY_CHECK(h_dst);
}
#endif
Loading…
Cancel
Save