TestTranspose.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. template <class T>
  44. TestTranspose<T>::TestTranspose(std::string testName_, NCVTestSourceProvider<T> &src_,
  45. Ncv32u width_, Ncv32u height_)
  46. :
  47. NCVTestProvider(testName_),
  48. src(src_),
  49. width(width_),
  50. height(height_)
  51. {
  52. }
  53. template <class T>
  54. bool TestTranspose<T>::toString(std::ofstream &strOut)
  55. {
  56. strOut << "sizeof(T)=" << sizeof(T) << std::endl;
  57. strOut << "width=" << width << std::endl;
  58. return true;
  59. }
  60. template <class T>
  61. bool TestTranspose<T>::init()
  62. {
  63. return true;
  64. }
  65. template <class T>
  66. bool TestTranspose<T>::process()
  67. {
  68. NCVStatus ncvStat;
  69. bool rcode = false;
  70. NcvSize32u srcSize(this->width, this->height);
  71. NCVMatrixAlloc<T> d_img(*this->allocatorGPU.get(), this->width, this->height);
  72. ncvAssertReturn(d_img.isMemAllocated(), false);
  73. NCVMatrixAlloc<T> h_img(*this->allocatorCPU.get(), this->width, this->height);
  74. ncvAssertReturn(h_img.isMemAllocated(), false);
  75. NCVMatrixAlloc<T> d_dst(*this->allocatorGPU.get(), this->height, this->width);
  76. ncvAssertReturn(d_dst.isMemAllocated(), false);
  77. NCVMatrixAlloc<T> h_dst(*this->allocatorCPU.get(), this->height, this->width);
  78. ncvAssertReturn(h_dst.isMemAllocated(), false);
  79. NCVMatrixAlloc<T> h_dst_d(*this->allocatorCPU.get(), this->height, this->width);
  80. ncvAssertReturn(h_dst_d.isMemAllocated(), false);
  81. NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
  82. NCV_SKIP_COND_BEGIN
  83. ncvAssertReturn(this->src.fill(h_img), false);
  84. NCV_SKIP_COND_END
  85. ncvStat = h_img.copySolid(d_img, 0);
  86. ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
  87. NCV_SKIP_COND_BEGIN
  88. if (sizeof(T) == sizeof(Ncv32u))
  89. {
  90. ncvStat = nppiStTranspose_32u_C1R((Ncv32u *)d_img.ptr(), d_img.pitch(),
  91. (Ncv32u *)d_dst.ptr(), d_dst.pitch(),
  92. NcvSize32u(this->width, this->height));
  93. }
  94. else if (sizeof(T) == sizeof(Ncv64u))
  95. {
  96. ncvStat = nppiStTranspose_64u_C1R((Ncv64u *)d_img.ptr(), d_img.pitch(),
  97. (Ncv64u *)d_dst.ptr(), d_dst.pitch(),
  98. NcvSize32u(this->width, this->height));
  99. }
  100. else
  101. {
  102. ncvAssertPrintReturn(false, "Incorrect transpose test instance", false);
  103. }
  104. ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
  105. NCV_SKIP_COND_END
  106. ncvStat = d_dst.copySolid(h_dst_d, 0);
  107. ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
  108. NCV_SKIP_COND_BEGIN
  109. if (sizeof(T) == sizeof(Ncv32u))
  110. {
  111. ncvStat = nppiStTranspose_32u_C1R_host((Ncv32u *)h_img.ptr(), h_img.pitch(),
  112. (Ncv32u *)h_dst.ptr(), h_dst.pitch(),
  113. NcvSize32u(this->width, this->height));
  114. }
  115. else if (sizeof(T) == sizeof(Ncv64u))
  116. {
  117. ncvStat = nppiStTranspose_64u_C1R_host((Ncv64u *)h_img.ptr(), h_img.pitch(),
  118. (Ncv64u *)h_dst.ptr(), h_dst.pitch(),
  119. NcvSize32u(this->width, this->height));
  120. }
  121. else
  122. {
  123. ncvAssertPrintReturn(false, "Incorrect downsample test instance", false);
  124. }
  125. ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
  126. NCV_SKIP_COND_END
  127. //bit-to-bit check
  128. bool bLoopVirgin = true;
  129. NCV_SKIP_COND_BEGIN
  130. //const Ncv64f relEPS = 0.005;
  131. for (Ncv32u i=0; bLoopVirgin && i < this->width; i++)
  132. {
  133. for (Ncv32u j=0; bLoopVirgin && j < this->height; j++)
  134. {
  135. if (h_dst.ptr()[h_dst.stride()*i+j] != h_dst_d.ptr()[h_dst_d.stride()*i+j])
  136. {
  137. bLoopVirgin = false;
  138. }
  139. }
  140. }
  141. NCV_SKIP_COND_END
  142. if (bLoopVirgin)
  143. {
  144. rcode = true;
  145. }
  146. return rcode;
  147. }
  148. template <class T>
  149. bool TestTranspose<T>::deinit()
  150. {
  151. return true;
  152. }
  153. template class TestTranspose<Ncv32u>;
  154. template class TestTranspose<Ncv64u>;