1 /* ************************************************************************
2 * Copyright 2013 Advanced Micro Devices, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 * ************************************************************************/
16
17
18
19 #if !defined(HER_PACKED)
20 #ifndef HER_H
21 #define HER_H
22 #else
23 #define DUPLICIT
24 #endif
25 #endif
26
27 #ifndef DUPLICIT
28
29 #include <gtest/gtest.h>
30 #include <clBLAS.h>
31 #include <common.h>
32 #include <BlasBase.h>
33 #include <blas-random.h>
34 #include <blas-math.h>
35
36 using ::testing::TestWithParam;
37
38 #ifndef HER_PACKED
39 class HER : public TestWithParam<
40 #else
41 class HPR : public TestWithParam<
42 #endif
43
44 ::std::tr1::tuple<
45 clblasOrder, // order
46 clblasUplo, // uplo
47 int, // N
48 double, //alpha
49 int, // lda
50 int, //incx
51 int, // offx
52 int, // offa //FIX_ME.. gtest not allowing to add more parameters
53 int // numCommandQueues
54 > > {
55 public:
getParams(TestParams * params)56 void getParams(TestParams *params)
57 {
58 params->order = order;
59 params->uplo = uplo;
60 params->N = N;
61 params->alpha.re = (long)alpha;
62 params->lda = lda;
63 params->incx = incx;
64 params->offa = offa;
65 params->offBX = offx;
66 params->numCommandQueues = numCommandQueues;
67 }
68
69 protected:
SetUp()70 virtual void SetUp()
71 {
72 order = ::std::tr1::get<0>(GetParam());
73 uplo = ::std::tr1::get<1>(GetParam());
74 N = ::std::tr1::get<2>(GetParam());
75 alpha = ::std::tr1::get<3>(GetParam());
76 lda = ::std::tr1::get<4>(GetParam());
77 incx = ::std::tr1::get<5>(GetParam());
78 offa = ::std::tr1::get<6>(GetParam());
79 offx = ::std::tr1::get<7>(GetParam());
80 numCommandQueues = ::std::tr1::get<8>(GetParam());
81
82 #ifndef HER_PACKED
83 lda = ::std::max( lda, N );
84 #else
85 lda =0;
86 #endif
87
88 base = ::clMath::BlasBase::getInstance();
89 seed = base->seed();
90
91 useNumCommandQueues = base->useNumCommandQueues();
92 if (useNumCommandQueues) {
93 numCommandQueues = base->numCommandQueues();
94 }
95
96 if (base->useN()) {
97 N = base->N();
98 }
99
100 printTestParams(order, uplo, N, alpha,
101 offx, incx, offa, lda );
102
103 ::std::cerr << "seed = " << seed << ::std::endl;
104 ::std::cerr << "queues = " << numCommandQueues << ::std::endl;
105 }
106
107 clblasOrder order;
108 clblasUplo uplo;
109 size_t N;
110 size_t lda;
111 int incx;
112 size_t offa, offx;
113 unsigned int seed;
114 double alpha;
115 ComplexLong paramAlpha;
116 size_t rowsA, columnsA;
117 ::clMath::BlasBase *base;
118 bool useNumCommandQueues;
119 cl_uint numCommandQueues;
120 };
121
122 #ifndef RANDOM_HER
123 #define RANDOM_HER
124
125 template <typename T>
126 static void
randomHerMatrices(clblasOrder order,clblasUplo uplo,size_t N,T * alpha,T * A,size_t lda,T * X,int incx)127 randomHerMatrices(
128 clblasOrder order,
129 clblasUplo uplo,
130 size_t N,
131 T *alpha,
132 T *A,
133 size_t lda,
134 T *X,
135 int incx
136 )
137 {
138 size_t i, j;
139 size_t lengthX;
140 cl_double bound, max;
141
142 // bound is calculated by solving the equation (alpha*x^2 + x - UPPER_BOUND) < 0
143 bound = UPPER_BOUND<T>();
144 if(module(CREAL(*alpha)) > (sqrt(bound) / (2.0)))
145 *alpha = random<T>((sqrt(bound) / (2.0)));
146
147 max = module(CREAL(*alpha));
148 bound = bound / max / 2.0;
149 bound = sqrt( ((((1.0) / max) / (4.0)) / max) + bound) - ((1.0) / ((2.0) * max));
150
151 if( lda )
152 {
153 for (i = 0; i < N; i++) {
154 for (j = 0; j < N; j++) {
155 setElement<T>(order, clblasNoTrans, i, j, A, lda, random<T>(bound));
156 }
157 }
158 } else {
159 for (i = 0; i < N; i++) {
160 for (j = 0; j < N; j++) {
161 setElementPacked<T>(order, clblasNoTrans, uplo, i, j, A, N, random<T>(bound));
162 }
163 }
164 }
165
166 lengthX = 1 + ((N - 1) * abs(incx));
167 if (X != NULL) {
168 for (i = 0; i < lengthX; i++) {
169 X[i] = random<T>(bound);
170 }
171 }
172 }
173 #endif // RANDOM_HER
174
175 #endif // HER_H_
176