TestHypothesesGrow.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // * Redistribution's in binary form must reproduce the above copyright notice,
  24. // this list of conditions and the following disclaimer in the documentation
  25. // and/or other materials provided with the distribution.
  26. //
  27. // * The name of the copyright holders may not be used to endorse or promote products
  28. // derived from this software without specific prior written permission.
  29. //
  30. // This software is provided by the copyright holders and contributors "as is" and
  31. // any express or implied warranties, including, but not limited to, the implied
  32. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  33. // In no event shall the Intel Corporation or contributors be liable for any direct,
  34. // indirect, incidental, special, exemplary, or consequential damages
  35. // (including, but not limited to, procurement of substitute goods or services;
  36. // loss of use, data, or profits; or business interruption) however caused
  37. // and on any theory of liability, whether in contract, strict liability,
  38. // or tort (including negligence or otherwise) arising in any way out of
  39. // the use of this software, even if advised of the possibility of such damage.
  40. //
  41. //M*/
  42. #include "test_precomp.hpp"
  43. TestHypothesesGrow::TestHypothesesGrow(std::string testName_, NCVTestSourceProvider<Ncv32u> &src_,
  44. Ncv32u rectWidth_, Ncv32u rectHeight_, Ncv32f rectScale_,
  45. Ncv32u maxLenSrc_, Ncv32u lenSrc_, Ncv32u maxLenDst_, Ncv32u lenDst_)
  46. :
  47. NCVTestProvider(testName_),
  48. src(src_),
  49. rectWidth(rectWidth_),
  50. rectHeight(rectHeight_),
  51. rectScale(rectScale_),
  52. maxLenSrc(maxLenSrc_),
  53. lenSrc(lenSrc_),
  54. maxLenDst(maxLenDst_),
  55. lenDst(lenDst_)
  56. {
  57. }
  58. bool TestHypothesesGrow::toString(std::ofstream &strOut)
  59. {
  60. strOut << "rectWidth=" << rectWidth << std::endl;
  61. strOut << "rectHeight=" << rectHeight << std::endl;
  62. strOut << "rectScale=" << rectScale << std::endl;
  63. strOut << "maxLenSrc=" << maxLenSrc << std::endl;
  64. strOut << "lenSrc=" << lenSrc << std::endl;
  65. strOut << "maxLenDst=" << maxLenDst << std::endl;
  66. strOut << "lenDst=" << lenDst << std::endl;
  67. return true;
  68. }
  69. bool TestHypothesesGrow::init()
  70. {
  71. return true;
  72. }
  73. bool TestHypothesesGrow::process()
  74. {
  75. NCVStatus ncvStat;
  76. bool rcode = false;
  77. NCVVectorAlloc<Ncv32u> h_vecSrc(*this->allocatorCPU.get(), this->maxLenSrc);
  78. ncvAssertReturn(h_vecSrc.isMemAllocated(), false);
  79. NCVVectorAlloc<Ncv32u> d_vecSrc(*this->allocatorGPU.get(), this->maxLenSrc);
  80. ncvAssertReturn(d_vecSrc.isMemAllocated(), false);
  81. NCVVectorAlloc<NcvRect32u> h_vecDst(*this->allocatorCPU.get(), this->maxLenDst);
  82. ncvAssertReturn(h_vecDst.isMemAllocated(), false);
  83. NCVVectorAlloc<NcvRect32u> d_vecDst(*this->allocatorGPU.get(), this->maxLenDst);
  84. ncvAssertReturn(d_vecDst.isMemAllocated(), false);
  85. NCVVectorAlloc<NcvRect32u> h_vecDst_d(*this->allocatorCPU.get(), this->maxLenDst);
  86. ncvAssertReturn(h_vecDst_d.isMemAllocated(), false);
  87. NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
  88. NCV_SKIP_COND_BEGIN
  89. ncvAssertReturn(this->src.fill(h_vecSrc), false);
  90. memset(h_vecDst.ptr(), 0, h_vecDst.length() * sizeof(NcvRect32u));
  91. NCVVectorReuse<Ncv32u> h_vecDst_as32u(h_vecDst.getSegment(), lenDst * sizeof(NcvRect32u) / sizeof(Ncv32u));
  92. ncvAssertReturn(h_vecDst_as32u.isMemReused(), false);
  93. ncvAssertReturn(this->src.fill(h_vecDst_as32u), false);
  94. memcpy(h_vecDst_d.ptr(), h_vecDst.ptr(), h_vecDst.length() * sizeof(NcvRect32u));
  95. NCV_SKIP_COND_END
  96. ncvStat = h_vecSrc.copySolid(d_vecSrc, 0);
  97. ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
  98. ncvStat = h_vecDst.copySolid(d_vecDst, 0);
  99. ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
  100. ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
  101. Ncv32u h_outElemNum_d = 0;
  102. Ncv32u h_outElemNum_h = 0;
  103. NCV_SKIP_COND_BEGIN
  104. h_outElemNum_d = this->lenDst;
  105. ncvStat = ncvGrowDetectionsVector_device(d_vecSrc, this->lenSrc,
  106. d_vecDst, h_outElemNum_d, this->maxLenDst,
  107. this->rectWidth, this->rectHeight, this->rectScale, 0);
  108. ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
  109. ncvStat = d_vecDst.copySolid(h_vecDst_d, 0);
  110. ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
  111. ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
  112. h_outElemNum_h = this->lenDst;
  113. ncvStat = ncvGrowDetectionsVector_host(h_vecSrc, this->lenSrc,
  114. h_vecDst, h_outElemNum_h, this->maxLenDst,
  115. this->rectWidth, this->rectHeight, this->rectScale);
  116. ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
  117. NCV_SKIP_COND_END
  118. //bit-to-bit check
  119. bool bLoopVirgin = true;
  120. NCV_SKIP_COND_BEGIN
  121. if (h_outElemNum_d != h_outElemNum_h)
  122. {
  123. bLoopVirgin = false;
  124. }
  125. else
  126. {
  127. if (memcmp(h_vecDst.ptr(), h_vecDst_d.ptr(), this->maxLenDst * sizeof(NcvRect32u)))
  128. {
  129. bLoopVirgin = false;
  130. }
  131. }
  132. NCV_SKIP_COND_END
  133. if (bLoopVirgin)
  134. {
  135. rcode = true;
  136. }
  137. return rcode;
  138. }
  139. bool TestHypothesesGrow::deinit()
  140. {
  141. return true;
  142. }