Path: blob/master/modules/core/perf/cuda/perf_gpumat.cpp
16358 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.13// Copyright (C) 2009, Willow Garage Inc., all rights reserved.14// Third party copyrights are property of their respective owners.15//16// Redistribution and use in source and binary forms, with or without modification,17// are permitted provided that the following conditions are met:18//19// * Redistribution's of source code must retain the above copyright notice,20// this list of conditions and the following disclaimer.21//22// * Redistribution's in binary form must reproduce the above copyright notice,23// this list of conditions and the following disclaimer in the documentation24// and/or other materials provided with the distribution.25//26// * The name of the copyright holders may not be used to endorse or promote products27// derived from this software without specific prior written permission.28//29// This software is provided by the copyright holders and contributors "as is" and30// any express or implied warranties, including, but not limited to, the implied31// warranties of merchantability and fitness for a particular purpose are disclaimed.32// In no event shall the Intel Corporation or contributors be liable for any direct,33// indirect, incidental, special, exemplary, or consequential damages34// (including, but not limited to, procurement of substitute goods or services;35// loss of use, data, or profits; or business interruption) however caused36// and on any theory of liability, whether in contract, strict liability,37// or tort (including negligence or otherwise) arising in any way out of38// the use of this software, even if advised of the possibility of such damage.39//40//M*/4142#include "../perf_precomp.hpp"4344#ifdef HAVE_CUDA4546#include "opencv2/core/cuda.hpp"47#include "opencv2/ts/cuda_perf.hpp"4849namespace opencv_test { namespace {50using namespace testing;51using namespace perf;5253//////////////////////////////////////////////////////////////////////54// SetTo5556PERF_TEST_P(Sz_Depth_Cn, CUDA_GpuMat_SetTo,57Combine(CUDA_TYPICAL_MAT_SIZES,58Values(CV_8U, CV_16U, CV_32F, CV_64F),59CUDA_CHANNELS_1_3_4))60{61const cv::Size size = GET_PARAM(0);62const int depth = GET_PARAM(1);63const int channels = GET_PARAM(2);6465const int type = CV_MAKE_TYPE(depth, channels);6667const cv::Scalar val(1, 2, 3, 4);6869if (PERF_RUN_CUDA())70{71cv::cuda::GpuMat dst(size, type);7273TEST_CYCLE() dst.setTo(val);74}75else76{77cv::Mat dst(size, type);7879TEST_CYCLE() dst.setTo(val);80}8182SANITY_CHECK_NOTHING();83}8485//////////////////////////////////////////////////////////////////////86// SetToMasked8788PERF_TEST_P(Sz_Depth_Cn, CUDA_GpuMat_SetToMasked,89Combine(CUDA_TYPICAL_MAT_SIZES,90Values(CV_8U, CV_16U, CV_32F, CV_64F),91CUDA_CHANNELS_1_3_4))92{93const cv::Size size = GET_PARAM(0);94const int depth = GET_PARAM(1);95const int channels = GET_PARAM(2);9697const int type = CV_MAKE_TYPE(depth, channels);9899cv::Mat src(size, type);100cv::Mat mask(size, CV_8UC1);101declare.in(src, mask, WARMUP_RNG);102103const cv::Scalar val(1, 2, 3, 4);104105if (PERF_RUN_CUDA())106{107cv::cuda::GpuMat dst(src);108const cv::cuda::GpuMat d_mask(mask);109110TEST_CYCLE() dst.setTo(val, d_mask);111}112else113{114cv::Mat dst = src;115116TEST_CYCLE() dst.setTo(val, mask);117}118119SANITY_CHECK_NOTHING();120}121122//////////////////////////////////////////////////////////////////////123// CopyToMasked124125PERF_TEST_P(Sz_Depth_Cn, CUDA_GpuMat_CopyToMasked,126Combine(CUDA_TYPICAL_MAT_SIZES,127Values(CV_8U, CV_16U, CV_32F, CV_64F),128CUDA_CHANNELS_1_3_4))129{130const cv::Size size = GET_PARAM(0);131const int depth = GET_PARAM(1);132const int channels = GET_PARAM(2);133134const int type = CV_MAKE_TYPE(depth, channels);135136cv::Mat src(size, type);137cv::Mat mask(size, CV_8UC1);138declare.in(src, mask, WARMUP_RNG);139140if (PERF_RUN_CUDA())141{142const cv::cuda::GpuMat d_src(src);143const cv::cuda::GpuMat d_mask(mask);144cv::cuda::GpuMat dst(d_src.size(), d_src.type(), cv::Scalar::all(0));145146TEST_CYCLE() d_src.copyTo(dst, d_mask);147}148else149{150cv::Mat dst(src.size(), src.type(), cv::Scalar::all(0));151152TEST_CYCLE() src.copyTo(dst, mask);153}154155SANITY_CHECK_NOTHING();156}157158//////////////////////////////////////////////////////////////////////159// ConvertTo160161DEF_PARAM_TEST(Sz_2Depth, cv::Size, MatDepth, MatDepth);162163PERF_TEST_P(Sz_2Depth, CUDA_GpuMat_ConvertTo,164Combine(CUDA_TYPICAL_MAT_SIZES,165Values(CV_8U, CV_16U, CV_32F, CV_64F),166Values(CV_8U, CV_16U, CV_32F, CV_64F)))167{168const cv::Size size = GET_PARAM(0);169const int depth1 = GET_PARAM(1);170const int depth2 = GET_PARAM(2);171172cv::Mat src(size, depth1);173declare.in(src, WARMUP_RNG);174175const double a = 0.5;176const double b = 1.0;177178if (PERF_RUN_CUDA())179{180const cv::cuda::GpuMat d_src(src);181cv::cuda::GpuMat dst;182183TEST_CYCLE() d_src.convertTo(dst, depth2, a, b);184}185else186{187cv::Mat dst;188189TEST_CYCLE() src.convertTo(dst, depth2, a, b);190}191192SANITY_CHECK_NOTHING();193}194195}} // namespace196#endif197198199