1 #include "test_precomp.hpp"
2 #include "opencv2/ts/ocl_test.hpp"
3
4 #ifdef HAVE_IPP_A
5 #include "opencv2/core/ippasync.hpp"
6
7 using namespace cv;
8 using namespace std;
9 using namespace cvtest;
10
11 namespace cvtest {
12 namespace ocl {
13
PARAM_TEST_CASE(IPPAsync,MatDepth,Channels,hppAccelType)14 PARAM_TEST_CASE(IPPAsync, MatDepth, Channels, hppAccelType)
15 {
16 int type;
17 int cn;
18 int depth;
19 hppAccelType accelType;
20
21 Mat matrix, result;
22 hppiMatrix * hppMat;
23 hppAccel accel;
24 hppiVirtualMatrix * virtMatrix;
25 hppStatus sts;
26
27 virtual void SetUp()
28 {
29 type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
30 depth = GET_PARAM(0);
31 cn = GET_PARAM(1);
32 accelType = GET_PARAM(2);
33 }
34
35 virtual void generateTestData()
36 {
37 Size matrix_Size = randomSize(2, 100);
38 const double upValue = 100;
39
40 matrix = randomMat(matrix_Size, type, -upValue, upValue);
41 }
42
43 void Near(double threshold = 0.0)
44 {
45 EXPECT_MAT_NEAR(matrix, result, threshold);
46 }
47 };
48
TEST_P(IPPAsync,accuracy)49 TEST_P(IPPAsync, accuracy)
50 {
51 sts = hppCreateInstance(accelType, 0, &accel);
52 if (sts!=HPP_STATUS_NO_ERROR) printf("hppStatus = %d\n",sts);
53 CV_Assert(sts==HPP_STATUS_NO_ERROR);
54
55 virtMatrix = hppiCreateVirtualMatrices(accel, 2);
56
57 for (int j = 0; j < test_loop_times; j++)
58 {
59 generateTestData();
60 hppMat = hpp::getHpp(matrix,accel);
61
62 hppScalar a = 3;
63
64 sts = hppiAddC(accel, hppMat, a, 0, virtMatrix[0]);
65 CV_Assert(sts==HPP_STATUS_NO_ERROR);
66 sts = hppiSubC(accel, virtMatrix[0], a, 0, virtMatrix[1]);
67 CV_Assert(sts==HPP_STATUS_NO_ERROR);
68
69 sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
70 CV_Assert(sts==HPP_STATUS_NO_ERROR);
71
72 result = hpp::getMat(virtMatrix[1], accel, cn);
73
74 Near(5.0e-6);
75
76 sts = hppiFreeMatrix(hppMat);
77 CV_Assert(sts==HPP_STATUS_NO_ERROR);
78 }
79
80 sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
81 CV_Assert(sts==HPP_STATUS_NO_ERROR);
82 sts = hppDeleteInstance(accel);
83 CV_Assert(sts==HPP_STATUS_NO_ERROR);
84 }
85
PARAM_TEST_CASE(IPPAsyncShared,Channels,hppAccelType)86 PARAM_TEST_CASE(IPPAsyncShared, Channels, hppAccelType)
87 {
88 int cn;
89 int type;
90 hppAccelType accelType;
91
92 Mat matrix, result;
93 hppiMatrix* hppMat;
94 hppAccel accel;
95 hppiVirtualMatrix * virtMatrix;
96 hppStatus sts;
97
98 virtual void SetUp()
99 {
100 cn = GET_PARAM(0);
101 accelType = GET_PARAM(1);
102 type=CV_MAKE_TYPE(CV_8U, GET_PARAM(0));
103 }
104
105 virtual void generateTestData()
106 {
107 Size matrix_Size = randomSize(2, 100);
108 hpp32u pitch, size;
109 const int upValue = 100;
110
111 sts = hppQueryMatrixAllocParams(accel, (hpp32u)(matrix_Size.width*cn), (hpp32u)matrix_Size.height, HPP_DATA_TYPE_8U, &pitch, &size);
112
113 if (pitch!=0 && size!=0)
114 {
115 uchar *pData = (uchar*)_aligned_malloc(size, 4096);
116
117 for (int j=0; j<matrix_Size.height; j++)
118 for(int i=0; i<matrix_Size.width*cn; i++)
119 pData[i+j*pitch] = rand()%upValue;
120
121 matrix = Mat(matrix_Size.height, matrix_Size.width, type, pData, pitch);
122 }
123
124 matrix = randomMat(matrix_Size, type, 0, upValue);
125 }
126
127 void Near(double threshold = 0.0)
128 {
129 EXPECT_MAT_NEAR(matrix, result, threshold);
130 }
131 };
132
TEST_P(IPPAsyncShared,accuracy)133 TEST_P(IPPAsyncShared, accuracy)
134 {
135 sts = hppCreateInstance(accelType, 0, &accel);
136 if (sts!=HPP_STATUS_NO_ERROR) printf("hppStatus = %d\n",sts);
137 CV_Assert(sts==HPP_STATUS_NO_ERROR);
138
139 virtMatrix = hppiCreateVirtualMatrices(accel, 2);
140
141 for (int j = 0; j < test_loop_times; j++)
142 {
143 generateTestData();
144 hppMat = hpp::getHpp(matrix,accel);
145
146 hppScalar a = 3;
147
148 sts = hppiAddC(accel, hppMat, a, 0, virtMatrix[0]);
149 CV_Assert(sts==HPP_STATUS_NO_ERROR);
150 sts = hppiSubC(accel, virtMatrix[0], a, 0, virtMatrix[1]);
151 CV_Assert(sts==HPP_STATUS_NO_ERROR);
152
153 sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
154 CV_Assert(sts==HPP_STATUS_NO_ERROR);
155
156 result = hpp::getMat(virtMatrix[1], accel, cn);
157
158 Near(0);
159
160 sts = hppiFreeMatrix(hppMat);
161 CV_Assert(sts==HPP_STATUS_NO_ERROR);
162 }
163
164 sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
165 CV_Assert(sts==HPP_STATUS_NO_ERROR);
166 sts = hppDeleteInstance(accel);
167 CV_Assert(sts==HPP_STATUS_NO_ERROR);
168 }
169
170 INSTANTIATE_TEST_CASE_P(IppATest, IPPAsyncShared, Combine(Values(1, 2, 3, 4),
171 Values( HPP_ACCEL_TYPE_CPU, HPP_ACCEL_TYPE_GPU)));
172
173 INSTANTIATE_TEST_CASE_P(IppATest, IPPAsync, Combine(Values(CV_8U, CV_16U, CV_16S, CV_32F),
174 Values(1, 2, 3, 4),
175 Values( HPP_ACCEL_TYPE_CPU, HPP_ACCEL_TYPE_GPU)));
176
177 }
178 }
179 #endif