perf_channels.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
  14. // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // @Authors
  18. // Fangfang Bai, fangfang@multicorewareinc.com
  19. // Jin Ma, jin@multicorewareinc.com
  20. //
  21. // Redistribution and use in source and binary forms, with or without modification,
  22. // are permitted provided that the following conditions are met:
  23. //
  24. // * Redistribution's of source code must retain the above copyright notice,
  25. // this list of conditions and the following disclaimer.
  26. //
  27. // * Redistribution's in binary form must reproduce the above copyright notice,
  28. // this list of conditions and the following disclaimer in the documentation
  29. // and/or other materials provided with the distribution.
  30. //
  31. // * The name of the copyright holders may not be used to endorse or promote products
  32. // derived from this software without specific prior written permission.
  33. //
  34. // This software is provided by the copyright holders and contributors as is and
  35. // any express or implied warranties, including, but not limited to, the implied
  36. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  37. // In no event shall the Intel Corporation or contributors be liable for any direct,
  38. // indirect, incidental, special, exemplary, or consequential damages
  39. // (including, but not limited to, procurement of substitute goods or services;
  40. // loss of use, data, or profits; or business interruption) however caused
  41. // and on any theory of liability, whether in contract, strict liability,
  42. // or tort (including negligence or otherwise) arising in any way out of
  43. // the use of this software, even if advised of the possibility of such damage.
  44. //
  45. //M*/
  46. #include "../perf_precomp.hpp"
  47. #include "opencv2/ts/ocl_perf.hpp"
  48. #ifdef HAVE_OPENCL
  49. namespace opencv_test {
  50. namespace ocl {
  51. ///////////// Merge////////////////////////
  52. typedef tuple<Size, MatDepth, int> MergeParams;
  53. typedef TestBaseWithParam<MergeParams> MergeFixture;
  54. OCL_PERF_TEST_P(MergeFixture, Merge,
  55. ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8U, CV_32F), Values(2, 3)))
  56. {
  57. const MergeParams params = GetParam();
  58. const Size srcSize = get<0>(params);
  59. const int depth = get<1>(params), cn = get<2>(params), dtype = CV_MAKE_TYPE(depth, cn);
  60. checkDeviceMaxMemoryAllocSize(srcSize, dtype);
  61. UMat dst(srcSize, dtype);
  62. vector<UMat> src(cn);
  63. for (vector<UMat>::iterator i = src.begin(), end = src.end(); i != end; ++i)
  64. {
  65. i->create(srcSize, CV_MAKE_TYPE(depth, 1));
  66. declare.in(*i, WARMUP_RNG);
  67. }
  68. declare.out(dst);
  69. OCL_TEST_CYCLE() cv::merge(src, dst);
  70. SANITY_CHECK(dst);
  71. }
  72. ///////////// Split ////////////////////////
  73. typedef MergeParams SplitParams;
  74. typedef TestBaseWithParam<SplitParams> SplitFixture;
  75. OCL_PERF_TEST_P(SplitFixture, Split,
  76. ::testing::Combine(OCL_TEST_SIZES, OCL_PERF_ENUM(CV_8U, CV_32F), Values(2, 3)))
  77. {
  78. const SplitParams params = GetParam();
  79. const Size srcSize = get<0>(params);
  80. const int depth = get<1>(params), cn = get<2>(params), type = CV_MAKE_TYPE(depth, cn);
  81. ASSERT_TRUE(cn == 3 || cn == 2);
  82. checkDeviceMaxMemoryAllocSize(srcSize, type);
  83. UMat src(srcSize, type);
  84. std::vector<UMat> dst(cn, UMat(srcSize, CV_MAKE_TYPE(depth, 1)));
  85. declare.in(src, WARMUP_RNG);
  86. for (int i = 0; i < cn; ++i)
  87. declare.in(dst[i]);
  88. OCL_TEST_CYCLE() cv::split(src, dst);
  89. ASSERT_EQ(cn, (int)dst.size());
  90. if (cn == 2)
  91. {
  92. UMat & dst0 = dst[0], & dst1 = dst[1];
  93. SANITY_CHECK(dst0);
  94. SANITY_CHECK(dst1);
  95. }
  96. else
  97. {
  98. UMat & dst0 = dst[0], & dst1 = dst[1], & dst2 = dst[2];
  99. SANITY_CHECK(dst0);
  100. SANITY_CHECK(dst1);
  101. SANITY_CHECK(dst2);
  102. }
  103. }
  104. ///////////// MixChannels ////////////////////////
  105. typedef tuple<Size, MatDepth> MixChannelsParams;
  106. typedef TestBaseWithParam<MixChannelsParams> MixChannelsFixture;
  107. OCL_PERF_TEST_P(MixChannelsFixture, MixChannels,
  108. ::testing::Combine(Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
  109. OCL_PERF_ENUM(CV_8U, CV_32F)))
  110. {
  111. const MixChannelsParams params = GetParam();
  112. const Size srcSize = get<0>(params);
  113. const int depth = get<1>(params), type = CV_MAKE_TYPE(depth, 2), n = 2;
  114. checkDeviceMaxMemoryAllocSize(srcSize, type);
  115. std::vector<UMat> src(n), dst(n);
  116. for (int i = 0; i < n; ++i)
  117. {
  118. src[i] = UMat(srcSize, type);
  119. dst[i] = UMat(srcSize, type);
  120. declare.in(src[i], WARMUP_RNG).out(dst[i]);
  121. }
  122. int fromTo[] = { 1,2, 2,0, 0,3, 3,1 };
  123. OCL_TEST_CYCLE() cv::mixChannels(src, dst, fromTo, 4);
  124. UMat & dst0 = dst[0], & dst1 = dst[1];
  125. SANITY_CHECK(dst0);
  126. SANITY_CHECK(dst1);
  127. }
  128. ///////////// InsertChannel ////////////////////////
  129. typedef tuple<cv::Size, MatDepth> Size_MatDepth_t;
  130. typedef TestBaseWithParam<Size_MatDepth_t> Size_MatDepth;
  131. typedef Size_MatDepth InsertChannelFixture;
  132. OCL_PERF_TEST_P(InsertChannelFixture, InsertChannel,
  133. ::testing::Combine(Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
  134. OCL_PERF_ENUM(CV_8U, CV_32F)))
  135. {
  136. const Size_MatDepth_t params = GetParam();
  137. const Size srcSize = get<0>(params);
  138. const int depth = get<1>(params), type = CV_MAKE_TYPE(depth, 3);
  139. checkDeviceMaxMemoryAllocSize(srcSize, type);
  140. UMat src(srcSize, depth), dst(srcSize, type, Scalar::all(17));
  141. declare.in(src, WARMUP_RNG).out(dst);
  142. OCL_TEST_CYCLE() cv::insertChannel(src, dst, 1);
  143. SANITY_CHECK(dst);
  144. }
  145. ///////////// ExtractChannel ////////////////////////
  146. typedef Size_MatDepth ExtractChannelFixture;
  147. OCL_PERF_TEST_P(ExtractChannelFixture, ExtractChannel,
  148. ::testing::Combine(Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
  149. OCL_PERF_ENUM(CV_8U, CV_32F)))
  150. {
  151. const Size_MatDepth_t params = GetParam();
  152. const Size srcSize = get<0>(params);
  153. const int depth = get<1>(params), type = CV_MAKE_TYPE(depth, 3);
  154. checkDeviceMaxMemoryAllocSize(srcSize, type);
  155. UMat src(srcSize, type), dst(srcSize, depth);
  156. declare.in(src, WARMUP_RNG).out(dst);
  157. OCL_TEST_CYCLE() cv::extractChannel(src, dst, 1);
  158. SANITY_CHECK(dst);
  159. }
  160. } } // namespace opencv_test::ocl
  161. #endif // HAVE_OPENCL