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 
TestHypothesesGrow(std::string testName_,NCVTestSourceProvider<Ncv32u> & src_,Ncv32u rectWidth_,Ncv32u rectHeight_,Ncv32f rectScale_,Ncv32u maxLenSrc_,Ncv32u lenSrc_,Ncv32u maxLenDst_,Ncv32u lenDst_)46 TestHypothesesGrow::TestHypothesesGrow(std::string testName_, NCVTestSourceProvider<Ncv32u> &src_,
47                                        Ncv32u rectWidth_, Ncv32u rectHeight_, Ncv32f rectScale_,
48                                        Ncv32u maxLenSrc_, Ncv32u lenSrc_, Ncv32u maxLenDst_, Ncv32u lenDst_)
49     :
50     NCVTestProvider(testName_),
51     src(src_),
52     rectWidth(rectWidth_),
53     rectHeight(rectHeight_),
54     rectScale(rectScale_),
55     maxLenSrc(maxLenSrc_),
56     lenSrc(lenSrc_),
57     maxLenDst(maxLenDst_),
58     lenDst(lenDst_)
59 {
60 }
61 
62 
toString(std::ofstream & strOut)63 bool TestHypothesesGrow::toString(std::ofstream &strOut)
64 {
65     strOut << "rectWidth=" << rectWidth << std::endl;
66     strOut << "rectHeight=" << rectHeight << std::endl;
67     strOut << "rectScale=" << rectScale << std::endl;
68     strOut << "maxLenSrc=" << maxLenSrc << std::endl;
69     strOut << "lenSrc=" << lenSrc << std::endl;
70     strOut << "maxLenDst=" << maxLenDst << std::endl;
71     strOut << "lenDst=" << lenDst << std::endl;
72     return true;
73 }
74 
75 
init()76 bool TestHypothesesGrow::init()
77 {
78     return true;
79 }
80 
81 
process()82 bool TestHypothesesGrow::process()
83 {
84     NCVStatus ncvStat;
85     bool rcode = false;
86 
87     NCVVectorAlloc<Ncv32u> h_vecSrc(*this->allocatorCPU.get(), this->maxLenSrc);
88     ncvAssertReturn(h_vecSrc.isMemAllocated(), false);
89     NCVVectorAlloc<Ncv32u> d_vecSrc(*this->allocatorGPU.get(), this->maxLenSrc);
90     ncvAssertReturn(d_vecSrc.isMemAllocated(), false);
91 
92     NCVVectorAlloc<NcvRect32u> h_vecDst(*this->allocatorCPU.get(), this->maxLenDst);
93     ncvAssertReturn(h_vecDst.isMemAllocated(), false);
94     NCVVectorAlloc<NcvRect32u> d_vecDst(*this->allocatorGPU.get(), this->maxLenDst);
95     ncvAssertReturn(d_vecDst.isMemAllocated(), false);
96     NCVVectorAlloc<NcvRect32u> h_vecDst_d(*this->allocatorCPU.get(), this->maxLenDst);
97     ncvAssertReturn(h_vecDst_d.isMemAllocated(), false);
98 
99     NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
100 
101     NCV_SKIP_COND_BEGIN
102     ncvAssertReturn(this->src.fill(h_vecSrc), false);
103     memset(h_vecDst.ptr(), 0, h_vecDst.length() * sizeof(NcvRect32u));
104     NCVVectorReuse<Ncv32u> h_vecDst_as32u(h_vecDst.getSegment(), lenDst * sizeof(NcvRect32u) / sizeof(Ncv32u));
105     ncvAssertReturn(h_vecDst_as32u.isMemReused(), false);
106     ncvAssertReturn(this->src.fill(h_vecDst_as32u), false);
107     memcpy(h_vecDst_d.ptr(), h_vecDst.ptr(), h_vecDst.length() * sizeof(NcvRect32u));
108     NCV_SKIP_COND_END
109 
110     ncvStat = h_vecSrc.copySolid(d_vecSrc, 0);
111     ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
112     ncvStat = h_vecDst.copySolid(d_vecDst, 0);
113     ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
114     ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
115 
116     Ncv32u h_outElemNum_d = 0;
117     Ncv32u h_outElemNum_h = 0;
118     NCV_SKIP_COND_BEGIN
119     h_outElemNum_d = this->lenDst;
120     ncvStat = ncvGrowDetectionsVector_device(d_vecSrc, this->lenSrc,
121                                              d_vecDst, h_outElemNum_d, this->maxLenDst,
122                                              this->rectWidth, this->rectHeight, this->rectScale, 0);
123     ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
124     ncvStat = d_vecDst.copySolid(h_vecDst_d, 0);
125     ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
126     ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
127 
128     h_outElemNum_h = this->lenDst;
129     ncvStat = ncvGrowDetectionsVector_host(h_vecSrc, this->lenSrc,
130                                            h_vecDst, h_outElemNum_h, this->maxLenDst,
131                                            this->rectWidth, this->rectHeight, this->rectScale);
132     ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
133     NCV_SKIP_COND_END
134 
135     //bit-to-bit check
136     bool bLoopVirgin = true;
137 
138     NCV_SKIP_COND_BEGIN
139     if (h_outElemNum_d != h_outElemNum_h)
140     {
141         bLoopVirgin = false;
142     }
143     else
144     {
145         if (memcmp(h_vecDst.ptr(), h_vecDst_d.ptr(), this->maxLenDst * sizeof(NcvRect32u)))
146         {
147             bLoopVirgin = false;
148         }
149     }
150     NCV_SKIP_COND_END
151 
152     if (bLoopVirgin)
153     {
154         rcode = true;
155     }
156 
157     return rcode;
158 }
159 
160 
deinit()161 bool TestHypothesesGrow::deinit()
162 {
163     return true;
164 }
165