1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
*
* NVIDIA Corporation and its licensors retain all intellectual
* property and proprietary rights in and to this software and
* related documentation and any modifications thereto.
* Any use, reproduction, disclosure, or distribution of this
* software and related documentation without an express license
* agreement from NVIDIA Corporation is strictly prohibited.
*/
#include <math.h>
#include "TestTranspose.h"
template <class T>
TestTranspose<T>::TestTranspose(std::string testName, NCVTestSourceProvider<T> &src,
Ncv32u width, Ncv32u height)
:
NCVTestProvider(testName),
src(src),
width(width),
height(height)
{
}
template <class T>
bool TestTranspose<T>::toString(std::ofstream &strOut)
{
strOut << "sizeof(T)=" << sizeof(T) << std::endl;
strOut << "width=" << width << std::endl;
return true;
}
template <class T>
bool TestTranspose<T>::init()
{
return true;
}
template <class T>
bool TestTranspose<T>::process()
{
NCVStatus ncvStat;
bool rcode = false;
NcvSize32u srcSize(this->width, this->height);
NCVMatrixAlloc<T> d_img(*this->allocatorGPU.get(), this->width, this->height);
ncvAssertReturn(d_img.isMemAllocated(), false);
NCVMatrixAlloc<T> h_img(*this->allocatorCPU.get(), this->width, this->height);
ncvAssertReturn(h_img.isMemAllocated(), false);
NCVMatrixAlloc<T> d_dst(*this->allocatorGPU.get(), this->height, this->width);
ncvAssertReturn(d_dst.isMemAllocated(), false);
NCVMatrixAlloc<T> h_dst(*this->allocatorCPU.get(), this->height, this->width);
ncvAssertReturn(h_dst.isMemAllocated(), false);
NCVMatrixAlloc<T> h_dst_d(*this->allocatorCPU.get(), this->height, this->width);
ncvAssertReturn(h_dst_d.isMemAllocated(), false);
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
NCV_SKIP_COND_BEGIN
ncvAssertReturn(this->src.fill(h_img), false);
NCV_SKIP_COND_END
ncvStat = h_img.copySolid(d_img, 0);
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
NCV_SKIP_COND_BEGIN
if (sizeof(T) == sizeof(Ncv32u))
{
ncvStat = nppiStTranspose_32u_C1R((Ncv32u *)d_img.ptr(), d_img.pitch(),
(Ncv32u *)d_dst.ptr(), d_dst.pitch(),
NcvSize32u(this->width, this->height));
}
else if (sizeof(T) == sizeof(Ncv64u))
{
ncvStat = nppiStTranspose_64u_C1R((Ncv64u *)d_img.ptr(), d_img.pitch(),
(Ncv64u *)d_dst.ptr(), d_dst.pitch(),
NcvSize32u(this->width, this->height));
}
else
{
ncvAssertPrintReturn(false, "Incorrect transpose test instance", false);
}
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
NCV_SKIP_COND_END
ncvStat = d_dst.copySolid(h_dst_d, 0);
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
NCV_SKIP_COND_BEGIN
if (sizeof(T) == sizeof(Ncv32u))
{
ncvStat = nppiStTranspose_32u_C1R_host((Ncv32u *)h_img.ptr(), h_img.pitch(),
(Ncv32u *)h_dst.ptr(), h_dst.pitch(),
NcvSize32u(this->width, this->height));
}
else if (sizeof(T) == sizeof(Ncv64u))
{
ncvStat = nppiStTranspose_64u_C1R_host((Ncv64u *)h_img.ptr(), h_img.pitch(),
(Ncv64u *)h_dst.ptr(), h_dst.pitch(),
NcvSize32u(this->width, this->height));
}
else
{
ncvAssertPrintReturn(false, "Incorrect downsample test instance", false);
}
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
NCV_SKIP_COND_END
//bit-to-bit check
bool bLoopVirgin = true;
NCV_SKIP_COND_BEGIN
//const Ncv64f relEPS = 0.005;
for (Ncv32u i=0; bLoopVirgin && i < this->width; i++)
{
for (Ncv32u j=0; bLoopVirgin && j < this->height; j++)
{
if (h_dst.ptr()[h_dst.stride()*i+j] != h_dst_d.ptr()[h_dst_d.stride()*i+j])
{
bLoopVirgin = false;
}
}
}
NCV_SKIP_COND_END
if (bLoopVirgin)
{
rcode = true;
}
return rcode;
}
template <class T>
bool TestTranspose<T>::deinit()
{
return true;
}
template class TestTranspose<Ncv32u>;
template class TestTranspose<Ncv64u>;