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