This source file includes following definitions.
- SetUp
- checkMemSet
- CUDA_TEST_P
- checkConvert
- CUDA_TEST_P
- CUDA_TEST_P
#include "test_precomp.hpp"
#ifdef HAVE_CUDA
#include <cuda_runtime.h>
#include "opencv2/core/cuda.hpp"
#include "opencv2/ts/cuda_test.hpp"
using namespace cvtest;
struct Async : testing::TestWithParam<cv::cuda::DeviceInfo>
{
cv::cuda::HostMem src;
cv::cuda::GpuMat d_src;
cv::cuda::HostMem dst;
cv::cuda::GpuMat d_dst;
virtual void SetUp()
{
cv::cuda::DeviceInfo devInfo = GetParam();
cv::cuda::setDevice(devInfo.deviceID());
src = cv::cuda::HostMem(cv::cuda::HostMem::PAGE_LOCKED);
cv::Mat m = randomMat(cv::Size(128, 128), CV_8UC1);
m.copyTo(src);
}
};
void checkMemSet(int status, void* userData)
{
ASSERT_EQ(cudaSuccess, status);
Async* test = reinterpret_cast<Async*>(userData);
cv::cuda::HostMem src = test->src;
cv::cuda::HostMem dst = test->dst;
cv::Mat dst_gold = cv::Mat::zeros(src.size(), src.type());
ASSERT_MAT_NEAR(dst_gold, dst, 0);
}
CUDA_TEST_P(Async, MemSet)
{
cv::cuda::Stream stream;
d_dst.upload(src);
d_dst.setTo(cv::Scalar::all(0), stream);
d_dst.download(dst, stream);
Async* test = this;
stream.enqueueHostCallback(checkMemSet, test);
stream.waitForCompletion();
}
void checkConvert(int status, void* userData)
{
ASSERT_EQ(cudaSuccess, status);
Async* test = reinterpret_cast<Async*>(userData);
cv::cuda::HostMem src = test->src;
cv::cuda::HostMem dst = test->dst;
cv::Mat dst_gold;
src.createMatHeader().convertTo(dst_gold, CV_32S);
ASSERT_MAT_NEAR(dst_gold, dst, 0);
}
CUDA_TEST_P(Async, Convert)
{
cv::cuda::Stream stream;
d_src.upload(src, stream);
d_src.convertTo(d_dst, CV_32S, stream);
d_dst.download(dst, stream);
Async* test = this;
stream.enqueueHostCallback(checkConvert, test);
stream.waitForCompletion();
}
CUDA_TEST_P(Async, HostMemAllocator)
{
cv::cuda::Stream stream;
cv::Mat h_dst;
h_dst.allocator = cv::cuda::HostMem::getAllocator();
d_src.upload(src, stream);
d_src.convertTo(d_dst, CV_32S, stream);
d_dst.download(h_dst, stream);
stream.waitForCompletion();
cv::Mat dst_gold;
src.createMatHeader().convertTo(dst_gold, CV_32S);
ASSERT_MAT_NEAR(dst_gold, h_dst, 0);
}
INSTANTIATE_TEST_CASE_P(CUDA_Stream, Async, ALL_DEVICES);
#endif