61e407a8fe5098d84f7e9143e7e062cb6094d88e
[profile/ivi/opencv.git] / modules / core / test / test_ippasync.cpp
1 #include "test_precomp.hpp"
2 #include "opencv2/ts/ocl_test.hpp"
3
4 #include "opencv2/core/ippasync.hpp"
5
6 using namespace cv;
7 using namespace std;
8 using namespace cvtest;
9
10 namespace cvtest {
11 namespace ocl {
12
13 PARAM_TEST_CASE(IPPAsync, MatDepth, Channels, hppAccelType)
14 {
15     int type;
16     int cn;
17     int depth;
18     hppAccelType accelType;
19
20     Mat matrix, result;
21     Ptr<hppiMatrix> hppMat;
22     hppAccel accel;
23     hppiVirtualMatrix * virtMatrix;
24     hppStatus sts;
25
26     virtual void SetUp()
27     {
28         type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
29         depth = GET_PARAM(0);
30         cn = GET_PARAM(1);
31         accelType = GET_PARAM(2);
32     }
33
34     virtual void generateTestData()
35     {
36         Size matrix_Size = randomSize(2, 100);
37         const double upValue = 100;
38
39         matrix = randomMat(matrix_Size, type, -upValue, upValue);
40     }
41
42     void Near(double threshold = 0.0)
43     {
44         EXPECT_MAT_NEAR(matrix, result, threshold);
45     }
46 };
47
48 TEST_P(IPPAsync, accuracy)
49 {
50     if (depth==CV_32S || depth==CV_64F)
51         return;
52     
53     sts = hppCreateInstance(accelType, 0, &accel);
54     CV_Assert(sts==HPP_STATUS_NO_ERROR);
55     virtMatrix = hppiCreateVirtualMatrices(accel, 2);
56
57     for (int j = 0; j < test_loop_times; j++)
58     {
59         generateTestData();
60         hppMat = hpp::getHpp(matrix);
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
77     sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
78     CV_Assert(sts==HPP_STATUS_NO_ERROR);
79     sts = hppDeleteInstance(accel);
80     CV_Assert(sts==HPP_STATUS_NO_ERROR);
81 }
82
83 TEST_P(IPPAsync, conversion)
84 {
85     sts = hppCreateInstance(accelType, 0, &accel);
86     CV_Assert(sts==HPP_STATUS_NO_ERROR);
87     virtMatrix = hppiCreateVirtualMatrices(accel, 1);
88
89     for (int j = 0; j < test_loop_times; j++)
90     {
91         generateTestData();
92         hppMat = hpp::getHpp(matrix);
93
94         sts = hppiCopy (accel, hppMat, virtMatrix[0]);
95         CV_Assert(sts==HPP_STATUS_NO_ERROR);
96
97         sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
98         CV_Assert(sts==HPP_STATUS_NO_ERROR);
99         
100         result = hpp::getMat(virtMatrix[0], accel, cn);
101
102         Near();
103     }
104
105     sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
106     CV_Assert(sts==HPP_STATUS_NO_ERROR);
107     sts = hppDeleteInstance(accel);
108     CV_Assert(sts==HPP_STATUS_NO_ERROR);
109 }
110
111 INSTANTIATE_TEST_CASE_P(IppATest, IPPAsync, Combine(Values(CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F),
112                                                    Values(1, 2, 3, 4),
113                                                    Values( HPP_ACCEL_TYPE_CPU, HPP_ACCEL_TYPE_GPU)));
114
115 }
116 }