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 #include <iostream>
19 #include <string.h>
20 #include <clBLAS.h>
21 
22 #include <common.h>
23 
24 cl_context
getQueueContext(cl_command_queue commandQueue,cl_int * error)25 getQueueContext(cl_command_queue commandQueue, cl_int *error)
26 {
27     cl_int err;
28     cl_context ctx = NULL;
29 
30     err = clGetCommandQueueInfo(commandQueue, CL_QUEUE_CONTEXT,
31         sizeof(cl_context), &ctx, NULL);
32     if (error != NULL) {
33         *error = err;
34     }
35     return ctx;
36 }
37 
38 cl_int
waitForSuccessfulFinish(cl_uint numCommandQueues,cl_command_queue * commandQueues,cl_event * events)39 waitForSuccessfulFinish(
40     cl_uint numCommandQueues,
41     cl_command_queue *commandQueues,
42     cl_event *events)
43 {
44     cl_int err = CL_SUCCESS;
45     cl_uint i;
46 
47     for (i = 0; i < numCommandQueues; i++) {
48         cl_int e;
49         cl_int status;
50 
51         e = clFinish(commandQueues[i]);
52         if ((events != NULL) && (events[i] != NULL)) {
53             if (e == CL_SUCCESS) {
54         status = CL_COMPLETE;
55                 e = clGetEventInfo(events[i], CL_EVENT_COMMAND_EXECUTION_STATUS,
56             sizeof(status), &status, NULL);
57                 if ((e == CL_SUCCESS) && (status < 0)) {
58                     e = -status;
59         }
60         }
61             clReleaseEvent(events[i]);
62     }
63 
64         if (err == CL_SUCCESS) {
65             err = e;
66 }
67     }
68 
69     return err;
70 }
71 
72 cl_int
flushAll(cl_uint numCommandQueues,cl_command_queue * commandQueues)73 flushAll(
74     cl_uint numCommandQueues,
75     cl_command_queue *commandQueues)
76 {
77     cl_int err;
78     cl_uint i;
79 
80     for (i = 0; i < numCommandQueues; i++) {
81         err = clFlush(commandQueues[i]);
82         if (err != CL_SUCCESS) {
83             return err;
84         }
85     }
86 
87     return CL_SUCCESS;
88 }
89 
90 void
printTestParams(clblasOrder order,clblasTranspose transA,clblasTranspose transB,size_t M,size_t N,size_t K,bool useAlpha,ComplexLong alpha,size_t offA,size_t lda,size_t offB,size_t ldb,bool useBeta,ComplexLong beta,size_t offC,size_t ldc)91 printTestParams(
92     clblasOrder order,
93     clblasTranspose transA,
94     clblasTranspose transB,
95     size_t M,
96     size_t N,
97     size_t K,
98     bool useAlpha,
99     ComplexLong alpha,
100     size_t offA,
101     size_t lda,
102     size_t offB,
103     size_t ldb,
104     bool useBeta,
105     ComplexLong beta,
106     size_t offC,
107     size_t ldc)
108 {
109     ::std::cerr
110         << orderStr(order) << ", "
111         << transStr(transA) << ", "
112         << transStr(transB) << ", "
113         << "M = " << M << ", "
114         << "N = " << N << ", "
115         << "K = " << K << ", "
116         << "offA = " << offA << ", "
117         << "offB = " << offB << ", "
118         << "offC = " << offC << ", "
119         << "lda = " << lda << ", "
120         << "ldb = " << ldb << ", "
121         << "ldc = " << ldc;
122     if (useAlpha) {
123         ::std::cerr << ", "
124           << "alpha = (" << alpha.re << "," << alpha.imag << ")";
125     }
126     if (useBeta) {
127         ::std::cerr << ", "
128           << "beta = (" << beta.re << "," << beta.imag << ")";
129     }
130     ::std::cerr << std::endl;
131 }
132 
133 void
printTestParams(clblasOrder order,clblasSide side,clblasUplo uplo,clblasTranspose transA,clblasDiag diag,size_t M,size_t N,bool useAlpha,ComplexLong alpha,size_t offA,size_t lda,size_t offB,size_t ldb)134 printTestParams(
135     clblasOrder order,
136     clblasSide side,
137     clblasUplo uplo,
138     clblasTranspose transA,
139     clblasDiag diag,
140     size_t M,
141     size_t N,
142     bool useAlpha,
143     ComplexLong alpha,
144     size_t offA,
145     size_t lda,
146     size_t offB,
147     size_t ldb)
148 {
149     ::std::cerr << orderStr(order) << ", " << sideStr(side) << ", " <<
150         uploStr(uplo) << ", " << transStr(transA) << ", " <<
151         diagStr(diag) << ::std::endl;
152     ::std::cerr << "M = " << M << ", N = " << N << ::std::endl;
153     ::std::cerr << "offA = " << offA << ", offB = " << offB << ::std::endl;
154     ::std::cerr << "lda = " << lda << ", ldb = " << ldb << ::std::endl;
155     if (useAlpha) {
156         ::std::cerr << "alpha = (" << alpha.re << "," << alpha.imag
157             << ")" << ::std::endl;
158     }
159 }
160 
161 //SYR
162 void
printTestParams(clblasOrder order,clblasUplo uplo,size_t N,double alpha,size_t offx,int incx,size_t offa,size_t lda)163 printTestParams(
164     clblasOrder order,
165     clblasUplo uplo,
166     size_t N,
167 	double alpha,
168     size_t offx,
169     int incx,
170     size_t offa,
171     size_t lda)
172 {
173 	::std::cerr << orderStr(order) << ", " << uploStr(uplo) << ::std::endl;
174 	::std::cerr << "N = " << N << ", offx = " << offx << ", incx = " << incx << ::std::endl;
175 	::std::cerr << "offa = " << offa << ::std::endl;
176     if( lda )
177         ::std::cerr << ", lda = " << lda << ::std::endl;
178 	::std::cerr << "alpha = " << alpha << ::std::endl;
179 }
180 
181 //SPR
182 void
printTestParams(clblasOrder order,clblasUplo uplo,size_t N,double alpha,size_t offx,int incx,size_t offa)183 printTestParams(
184     clblasOrder order,
185     clblasUplo uplo,
186     size_t N,
187     double alpha,
188     size_t offx,
189     int incx,
190     size_t offa)
191 {
192     ::std::cerr << orderStr(order) << ", " << uploStr(uplo) << ::std::endl;
193     ::std::cerr << "N = " << N << ", offx = " << offx << ", incx = " << incx << ::std::endl;
194     ::std::cerr << "offa = " << offa << ::std::endl;
195     ::std::cerr << "alpha = " << alpha << ::std::endl;
196 }
197 
198 //SYR2
199 void
printTestParams(clblasOrder order,clblasUplo uplo,size_t N,double alpha,size_t offx,int incx,size_t offy,int incy,size_t offa,size_t lda)200 printTestParams(
201 	clblasOrder order,
202 	clblasUplo  uplo,
203 	size_t N,
204 	double alpha,
205 	size_t offx,
206 	int incx,
207 	size_t offy,
208 	int incy,
209 	size_t offa,
210 	size_t lda)
211 {
212 	::std::cerr << orderStr(order) << ", " << uploStr(uplo) << ::std::endl;
213 	::std::cerr << "N = " << N << ", offx = " << offx << ", incx = " << incx << ::std::endl;
214 	::std::cerr << "offy = " << offy << ", incy = " << incy << ::std::endl;
215 	::std::cerr << "offa = " << offa << ::std::endl;
216     if( lda )
217         ::std::cerr << ", lda = " << lda << ::std::endl;
218 	::std::cerr << "alpha = " << alpha << ::std::endl;
219 }
220 
221 //copy, dot, swap, dotc
222 
223 void
printTestParams(size_t N,size_t offx,int incx,size_t offy,int incy)224 printTestParams(
225     size_t N,
226     size_t offx,
227     int incx,
228     size_t offy,
229     int incy)
230 {
231 
232     ::std::cerr << "N = " << N << ", offx = " << offx << ", incx = " << incx << ::std::endl;
233     ::std::cerr << "offy = " << offy << ", incy = " << incy << ::std::endl;
234 }
235 
236 //HER2
237 void
printTestParams(clblasOrder order,clblasUplo uplo,size_t N,bool useAlpha,cl_float2 alpha,size_t offx,int incx,size_t offy,int incy,size_t offa,size_t lda)238 printTestParams(
239     clblasOrder order,
240     clblasUplo  uplo,
241     size_t N,
242     bool useAlpha,
243     cl_float2 alpha,
244     size_t offx,
245     int incx,
246     size_t offy,
247     int incy,
248     size_t offa,
249     size_t lda)
250 {
251     ::std::cerr << orderStr(order) << ", " << uploStr(uplo) << ::std::endl;
252     ::std::cerr << "N = " << N << ", offx = " << offx << ", incx = " << incx << ::std::endl;
253     ::std::cerr << "offy = " << offy << ", incy = " << incy << ::std::endl;
254     ::std::cerr << "offa = " << offa << ::std::endl;
255     if( lda )
256         ::std::cerr << ", lda = " << lda << ::std::endl;
257         if(useAlpha)
258     ::std::cerr << "alpha = (" << CREAL(alpha) << ", " << CIMAG(alpha) << ")" << ::std::endl;
259 }
260 
261 //HEMV
262 void
printTestParams(clblasOrder order,clblasUplo uplo,size_t N,ComplexLong alpha,size_t offa,size_t lda,size_t offx,int incx,ComplexLong beta,size_t offy,int incy)263 printTestParams(
264     clblasOrder order,
265     clblasUplo  uplo,
266     size_t N,
267     ComplexLong alpha,
268     size_t offa,
269     size_t lda,
270     size_t offx,
271     int incx,
272     ComplexLong beta,
273     size_t offy,
274     int incy)
275 {
276     ::std::cerr << orderStr(order) << ", " << uploStr(uplo) << ::std::endl;
277     ::std::cerr << "N = " << N << ", offx = " << offx << ", incx = " << incx << ::std::endl;
278     ::std::cerr << "offy = " << offy << ", incy = " << incy << ::std::endl;
279     ::std::cerr << "offa = " << offa;
280     if( lda )
281         ::std::cerr << ", lda = " << lda;
282     ::std::cerr << ::std::endl << "alpha = (" << alpha.re << "," << alpha.imag << ")" << ::std::endl;
283     ::std::cerr << "beta = (" << beta.re << "," << beta.imag << ")" << ::std::endl;
284 }
285 //SYMM , HEMM
286 void
printTestParams(clblasOrder order,clblasSide side,clblasUplo uplo,size_t M,size_t N,bool useAlpha,ComplexLong alpha,bool useBeta,ComplexLong beta,size_t lda,size_t ldb,size_t ldc,size_t offa,size_t offb,size_t offc)287 printTestParams(
288     clblasOrder order,
289     clblasSide side,
290     clblasUplo uplo,
291     size_t M,
292     size_t N,
293     bool useAlpha,
294     ComplexLong alpha,
295     bool useBeta,
296     ComplexLong beta,
297     size_t lda,
298     size_t ldb,
299     size_t ldc,
300     size_t offa,
301     size_t offb,
302     size_t offc )
303 {
304     ::std::cerr << orderStr(order) << ", " << sideStr(side) << ", " << uploStr(uplo) << ::std::endl;
305     ::std::cerr << "M = " << M << ", N = " << N << ::std::endl;
306     ::std::cerr << "lda = " << lda << ", ldb = " << ldb << ", ldc = " << ldc<< ::std::endl;
307     if (useAlpha) {
308         ::std::cerr << "alpha = (" << alpha.re << "," << alpha.imag << ")" << ::std::endl; }
309 	 if (useBeta) {
310         ::std::cerr << "beta = (" << beta.re << "," << beta.imag  << ")" << ::std::endl; }
311 	::std::cerr << "offa = " << offa << ", offb = " << offb << ", offc = " << offc<< ::std::endl;
312 
313 }
314 
315 //xHEMM
316 void
printTestParams(clblasOrder order,clblasSide side,clblasUplo uplo,size_t M,size_t N,bool useAlpha,cl_float2 alpha,bool useBeta,cl_float2 beta,size_t lda,size_t ldb,size_t ldc,size_t offa,size_t offb,size_t offc)317 printTestParams(
318     clblasOrder order,
319     clblasSide side,
320     clblasUplo uplo,
321     size_t M,
322     size_t N,
323     bool useAlpha,
324     cl_float2 alpha,
325     bool useBeta,
326     cl_float2 beta,
327     size_t lda,
328     size_t ldb,
329     size_t ldc,
330     size_t offa,
331     size_t offb,
332     size_t offc )
333 {
334     ::std::cerr << orderStr(order) << ", " << sideStr(side) << ", " << uploStr(uplo) << ::std::endl;
335     ::std::cerr << "M = " << M << ", N = " << N << ::std::endl;
336     ::std::cerr << "lda = " << lda << ", ldb = " << ldb << ", ldc = " << ldc<< ::std::endl;
337     if (useAlpha) {
338         ::std::cerr << "alpha = (" << CREAL(alpha) << "," << CIMAG(alpha) << ")" << ::std::endl; }
339          if (useBeta) {
340         ::std::cerr << "beta = (" << CREAL(beta) << "," << CIMAG(beta)  << ")" << ::std::endl; }
341         ::std::cerr << "offa = " << offa << ", offb = " << offb << ", offc = " << offc<< ::std::endl;
342 
343 }
344 
345 
346 
347 void
printTestParams(clblasOrder order,size_t M,size_t N,bool useAlpha,ComplexLong alpha,size_t lda,int incx,int incy,size_t offa,size_t offx,size_t offy)348 printTestParams(
349     clblasOrder order,
350     size_t M,
351     size_t N,
352     bool useAlpha,
353     ComplexLong alpha,
354     size_t lda,
355     int incx,
356     int incy,
357     size_t offa,
358     size_t offx,
359     size_t offy )
360 {
361     ::std::cerr << orderStr(order) << ", " << ::std::endl;
362     ::std::cerr << "M = " << M << ", N = " << N << ::std::endl;
363     ::std::cerr << "lda = " << lda << ", incx = " << incx << ", incy = " << incy<< ::std::endl;
364     if (useAlpha) {
365         ::std::cerr << "alpha = (" << alpha.re << "," << alpha.imag << ")" << ::std::endl; }
366         ::std::cerr << "offa = " << offa << ", offx = " << offx << ", offy = " << offy << ::std::endl;
367 
368 }
369 
370 // xGBMV
371 void
printTestParams(clblasOrder order,clblasTranspose transA,size_t M,size_t N,size_t KL,size_t KU,ComplexLong alpha,size_t offa,size_t lda,size_t offx,int incx,ComplexLong beta,size_t offy,int incy)372 printTestParams(
373     clblasOrder order,
374     clblasTranspose transA,
375     size_t M,
376     size_t N,
377     size_t KL,
378     size_t KU,
379     ComplexLong alpha,
380     size_t offa,
381     size_t lda,
382     size_t offx,
383     int incx,
384     ComplexLong beta,
385     size_t offy,
386     int incy)
387 {
388     ::std::cerr << orderStr(order) << ", " << transStr(transA) << ", " << ::std::endl;
389     ::std::cerr << "M = " << M << ", N = " << N << ", KL = " << KL << ", KU = " << KU << ::std::endl;
390     ::std::cerr << "lda = " << lda << ", incx = " << incx << ", incy = " << incy<< ::std::endl;
391     ::std::cerr << "offa = " << offa << ", offx = " << offx << ", offy = " << offy << ::std::endl;
392     ::std::cerr << "alpha = (" << alpha.re << "," << alpha.imag << ")" << ::std::endl;
393     ::std::cerr << "beta = (" << beta.re << "," << beta.imag << ")" << ::std::endl;
394 }
395 
396 //HBMV
397 //SBMV
398 
399 void
printTestParams(clblasOrder order,clblasUplo uplo,size_t N,size_t K,ComplexLong alpha,size_t offa,size_t lda,size_t offx,int incx,ComplexLong beta,size_t offy,int incy)400 printTestParams(
401     clblasOrder order,
402     clblasUplo uplo,
403     size_t N,
404     size_t K,
405     ComplexLong alpha,
406     size_t offa,
407     size_t lda,
408     size_t offx,
409     int incx,
410     ComplexLong beta,
411     size_t offy,
412     int incy)
413 {
414     ::std::cerr << orderStr(order) << ", " << uploStr(uplo) << ", " << ::std::endl;
415     ::std::cerr << ", N = " << N << ", K = " << K << ::std::endl;
416     ::std::cerr << "lda = " << lda << ", incx = " << incx << ", incy = " << incy<< ::std::endl;
417     ::std::cerr << "offa = " << offa << ", offx = " << offx << ", offy = " << offy << ::std::endl;
418     ::std::cerr << "alpha = (" << alpha.re << "," << alpha.imag << ")" << ::std::endl;
419     ::std::cerr << "beta = (" << beta.re << "," << beta.imag << ")" << ::std::endl;
420 }
421 
422 
423 //xTBMV
424 void
printTestParams(clblasOrder order,clblasUplo uplo,clblasTranspose transA,clblasDiag diag,size_t N,size_t KLU,size_t offA,size_t lda,size_t offx,int incx,size_t offy,int incy)425 printTestParams(
426     clblasOrder order,
427     clblasUplo uplo,
428     clblasTranspose transA,
429     clblasDiag diag,
430     size_t N,
431     size_t KLU,
432     size_t offA,
433     size_t lda,
434     size_t offx,
435     int incx,
436     size_t offy,
437     int incy)
438 {
439     ::std::cerr << orderStr(order) << ", " << uploStr(uplo) << ", " << transStr(transA) << ", " << diagStr(diag) << ::std::endl;
440     ::std::cerr << ", N = " << N << ", KL or KU = " << KLU << ::std::endl;
441     ::std::cerr << "lda = " << lda << ", incx = " << incx << ", incy = " << incy<< ::std::endl;
442     ::std::cerr << "offa = " << offA << ", offx = " << offx << ", offy = " << offy << ::std::endl;
443 }
444 
445 //HER
446 void
printTestParams(clblasOrder order,clblasUplo uplo,size_t N,bool useAlpha,ComplexLong alpha,size_t lda,int incx,size_t offa,size_t offx)447 printTestParams(
448     clblasOrder order,
449     clblasUplo uplo,
450     size_t N,
451     bool useAlpha,
452     ComplexLong alpha,
453     size_t lda,
454     int incx,
455     size_t offa,
456     size_t offx)
457 {
458     ::std::cerr << orderStr(order) << ", " << ::std::endl;
459     ::std::cerr << uploStr(uplo) << ", " << ::std::endl;
460     ::std::cerr << " N = " << N << ::std::endl;
461     ::std::cerr << "lda = " << lda << ", incx = " << incx << ::std::endl;
462     if (useAlpha) {
463         ::std::cerr << "alpha = (" << alpha.re << "," << alpha.imag << ")" << ::std::endl; }
464         ::std::cerr << "offa = " << offa << ", offx = " << offx << ::std::endl;
465 
466 }
467 
468 
469 void
printTestParams(clblasOrder order,clblasUplo uplo,clblasTranspose transA,clblasDiag diag,size_t N,size_t lda,int incx,size_t offa,size_t offx)470 printTestParams(
471     clblasOrder order,
472     clblasUplo uplo,
473     clblasTranspose transA,
474     clblasDiag diag,
475     size_t N,
476     size_t lda,
477     int incx,
478 	size_t offa,
479 	size_t offx)
480 {
481     ::std::cerr << orderStr(order) << ", " << uploStr(uplo) << ", " << transStr(transA)
482 				<< ", " <<diagStr(diag) << ::std::endl;
483     ::std::cerr << " N = " << N << ::std::endl;
484     ::std::cerr << "lda = " << lda << ", incx = " << incx << ::std::endl;
485 	::std::cerr << "offa = " << offa << ", offx = " << offx << ::std::endl;
486 }
487 
488 //xTPMV
489 void
printTestParams(clblasOrder order,clblasUplo uplo,clblasTranspose transA,clblasDiag diag,size_t N,int incx,size_t offa,size_t offx)490 printTestParams(
491     clblasOrder order,
492     clblasUplo uplo,
493     clblasTranspose transA,
494     clblasDiag diag,
495     size_t N,
496     int incx,
497     size_t offa,
498     size_t offx)
499 {
500     ::std::cerr << orderStr(order) << ", " << uploStr(uplo) << ", " << transStr(transA)
501                 << ", " <<diagStr(diag) << ::std::endl;
502     ::std::cerr << " N = " << N << ::std::endl;
503     ::std::cerr << " incx = " << incx << ::std::endl;
504     ::std::cerr << "offa = " << offa << ", offx = " << offx << ::std::endl;
505 }
506 
507 
508 void
printTestParams(clblasOrder order,clblasTranspose transA,size_t M,size_t N,bool useAlpha,ComplexLong alpha,size_t offA,size_t lda,int incx,bool useBeta,ComplexLong beta,int incy)509 printTestParams(
510     clblasOrder order,
511     clblasTranspose transA,
512     size_t M,
513     size_t N,
514     bool useAlpha,
515     ComplexLong alpha,
516     size_t offA,
517     size_t lda,
518     int incx,
519     bool useBeta,
520     ComplexLong beta,
521     int incy)
522 {
523     ::std::cerr << orderStr(order) << ", " << transStr(transA) << ::std::endl;
524     ::std::cerr << "M = " << M << ", N = " << N << ::std::endl;
525     ::std::cerr << "offA = " << offA << ::std::endl;
526     ::std::cerr << "lda = " << lda << ::std::endl;
527     if (useAlpha) {
528         ::std::cerr << "alpha = (" << alpha.re << "," << alpha.imag
529             << ")" << ::std::endl;
530     }
531     if (useBeta) {
532         ::std::cerr << "beta = (" << beta.re << "," << beta.imag
533             << ")" << ::std::endl;
534     }
535     ::std::cerr << "incx = " << incx << ", incy = " << incy << ::std::endl;
536 }
537 
538 void
printTestParams(clblasOrder order,clblasUplo uplo,size_t N,bool useAlpha,ComplexLong alpha,size_t offA,size_t lda,int incx,bool useBeta,ComplexLong beta,int incy)539 printTestParams(
540     clblasOrder order,
541     clblasUplo uplo,
542     size_t N,
543     bool useAlpha,
544     ComplexLong alpha,
545     size_t offA,
546     size_t lda,
547     int incx,
548     bool useBeta,
549     ComplexLong beta,
550     int incy)
551 {
552     ::std::cerr << orderStr(order) << ", " << uploStr(uplo) << ::std::endl;
553     ::std::cerr << "N = " << N << ::std::endl;
554     ::std::cerr << "offA = " << offA << ::std::endl;
555     if( lda )
556     ::std::cerr << "lda = " << lda << ::std::endl;
557     if (useAlpha) {
558         ::std::cerr << "alpha = (" << alpha.re << "," << alpha.imag
559             << ")" << ::std::endl;
560     }
561     if (useBeta) {
562         ::std::cerr << "beta = (" << beta.re << "," << beta.imag
563             << ")" << ::std::endl;
564     }
565     ::std::cerr << "incx = " << incx << ", incy = " << incy << ::std::endl;
566 }
567 
568 void
printTestParams(clblasOrder order,clblasUplo uplo,clblasTranspose transA,size_t N,size_t K,bool useAlpha,ComplexLong alpha,size_t offA,size_t lda,size_t offB,size_t ldb,bool useBeta,ComplexLong beta,size_t offC,size_t ldc)569 printTestParams(
570     clblasOrder order,
571     clblasUplo uplo,
572     clblasTranspose transA,
573     size_t N,
574     size_t K,
575     bool useAlpha,
576     ComplexLong alpha,
577     size_t offA,
578     size_t lda,
579     size_t offB,
580     size_t ldb,
581     bool useBeta,
582     ComplexLong beta,
583     size_t offC,
584     size_t ldc)
585 {
586     ::std::cerr << orderStr(order) << ", " << uploStr(uplo)
587         << ", " << transStr(transA) << ::std::endl;
588     ::std::cerr << "N = " << N << ", K = " << K << ::std::endl;
589     ::std::cerr << "offA = " << offA << ", offB = " << offB
590             << ", offC = " << offC << ::std::endl;
591     ::std::cerr << "lda = " << lda << ", ldb = " << ldb
592         << ", ldc = " << ldc << ::std::endl;
593     if (useAlpha) {
594         ::std::cerr << "alpha = (" << alpha.re << "," << alpha.imag
595             << ")" << ::std::endl;
596     }
597     if (useBeta) {
598         ::std::cerr << "beta = (" << beta.re << "," << beta.imag
599             << ")" << ::std::endl;
600     }
601 }
602 
603 void
printTestParams(clblasOrder order,clblasUplo uplo,clblasTranspose transA,size_t N,size_t K,bool useAlpha,ComplexLong alpha,size_t offA,size_t lda,bool useBeta,ComplexLong beta,size_t offC,size_t ldc)604 printTestParams(
605     clblasOrder order,
606     clblasUplo uplo,
607     clblasTranspose transA,
608     size_t N,
609     size_t K,
610     bool useAlpha,
611     ComplexLong alpha,
612     size_t offA,
613     size_t lda,
614     bool useBeta,
615     ComplexLong beta,
616     size_t offC,
617     size_t ldc)
618 {
619     ::std::cerr << orderStr(order) << ", " << uploStr(uplo)
620         << ", " << transStr(transA) << ::std::endl;
621     ::std::cerr << "N = " << N << ", K = " << K << ::std::endl;
622     ::std::cerr << "offA = " << offA << ", offC = " << offC << ::std::endl;
623     ::std::cerr << "lda = " << lda << ", ldc = " << ldc << ::std::endl;
624     if (useAlpha) {
625         ::std::cerr << "alpha = (" << alpha.re << "," << alpha.imag
626             << ")" << ::std::endl;
627     }
628     if (useBeta) {
629         ::std::cerr << "beta = (" << beta.re << "," << beta.imag
630             << ")" << ::std::endl;
631     }
632 }
633 
634 //For scal
635 void
printTestParams(size_t N,ComplexLong alpha,size_t offx,int incx)636 printTestParams(
637     size_t N,
638     ComplexLong alpha,
639     size_t offx,
640     int incx)
641 {
642     ::std::cerr << "N = " << N << ", alpha = (" << alpha.re << "," << alpha.imag << ")" << ::std::endl;
643     ::std::cerr << "offx = " << offx << ", incx = " << incx << ::std::endl;
644 }
645 
646 //For axpy
647 void
printTestParams(size_t N,ComplexLong alpha,size_t offx,int incx,size_t offy,int incy)648 printTestParams(
649     size_t N,
650     ComplexLong alpha,
651     size_t offx,
652     int incx,
653     size_t offy,
654     int incy)
655 {
656     ::std::cerr << "N = " << N << ", alpha = (" << alpha.re << "," << alpha.imag << ")" << ::std::endl;
657     ::std::cerr << "offx = " << offx << ", incx = " << incx << ::std::endl;
658     ::std::cerr << "offy = " << offy << ", incy = " << incy << ::std::endl;
659 }
660 
661 
662 //xROT
663 void
printTestParams(size_t N,size_t offx,int incx,size_t offy,int incy,ComplexLong C,ComplexLong S)664 printTestParams(
665     size_t N,
666     size_t offx,
667     int incx,
668 	size_t offy,
669 	int incy,
670 	ComplexLong C,
671 	ComplexLong S)
672 {
673     ::std::cerr << "N = " << N << ::std::endl;
674 	::std::cerr << "C = (" << C.re << "," << C.imag << ")" << ",S = (" << S.re << "," << S.imag << ")" << ::std::endl;
675     ::std::cerr << "offx = " << offx << ", incx = " << incx << ", offy = "<< offy << ", incy = " << incy <<  ::std::endl;
676 }
677 
678 // xROTG
679 void
printTestParams(size_t offSA,size_t offSB,size_t offC,size_t offS)680 printTestParams(size_t offSA, size_t offSB, size_t offC, size_t offS)
681 {
682     ::std::cerr << "offSA = " << offSA << ", offSB = " << offSB << ", offC = " << offC << ",offS = " << offS << std::endl;
683 }
684 
685 //xROTM
686 void
printTestParams(size_t N,size_t offx,int incx,size_t offy,int incy,size_t offParam,ComplexLong sflagParam)687 printTestParams(size_t N, size_t offx, int incx, size_t offy, int incy, size_t offParam, ComplexLong sflagParam)
688 {
689     ::std::cerr << "N = " << N << ", offx = " << offx << ", incx = " << incx << ", offy = " << offy
690                 << ", incy = " << incy << ", offParam = " << offParam << ", PARAM[0] = " << sflagParam.re << std::endl;
691 }
692 
693 //xROTMG
694 void
printTestParams(int offX,int offY,int offD1,int offD2,int offParam,ComplexLong sflagParam)695 printTestParams(int offX, int offY, int offD1, int offD2, int offParam, ComplexLong sflagParam)
696 {
697     ::std::cerr << "offX = " << offX << ", offY = " << offY << ", offD1 = " << offD1 << ", offD2 = " << offD2
698                 << ", offParam = " << offParam << ", PARAM[0] = " << sflagParam.re << std::endl;
699 }
700 
701 
702 // xNRM2, xASUM, iXAMAX
703 void
printTestParams(size_t N,size_t offx,int incx)704 printTestParams(
705     size_t N,
706     size_t offx,
707     int incx)
708 {
709     ::std::cerr << "N = " << N << ", offx = " << offx << ", incx = " << incx << ::std::endl;
710 }
711 
712 const char*
orderStr(clblasOrder order)713 orderStr(clblasOrder order)
714 {
715     switch (order) {
716     case clblasColumnMajor:
717         return "clblasColumnMajor";
718     case clblasRowMajor:
719         return "clblasRowMajor";
720     default:
721         return NULL;
722     }
723 }
724 
725 const char*
sideStr(clblasSide side)726 sideStr(clblasSide side)
727 {
728     switch (side) {
729     case clblasLeft:
730         return "clblasLeft";
731     case clblasRight:
732         return "clblasRight";
733     default:
734         return NULL;
735     }
736 }
737 
738 const char*
uploStr(clblasUplo uplo)739 uploStr(clblasUplo uplo)
740 {
741     switch (uplo) {
742     case clblasUpper:
743         return "clblasUpper";
744     case clblasLower:
745         return "clblasLower";
746     default:
747         return NULL;
748     }
749 }
750 
751 const char*
transStr(clblasTranspose trans)752 transStr(clblasTranspose trans)
753 {
754     switch (trans) {
755     case clblasNoTrans:
756         return "clblasNoTrans";
757     case clblasTrans:
758         return "clblasTrans";
759     case clblasConjTrans:
760         return "clblasConjTrans";
761     default:
762         return NULL;
763     }
764 }
765 
766 const char*
diagStr(clblasDiag diag)767 diagStr(clblasDiag diag)
768 {
769     switch (diag) {
770     case clblasNonUnit:
771         return "clblasNonUnit";
772     case clblasUnit:
773         return "clblasUnit";
774     default:
775         return NULL;
776     }
777 }
778 
779 char
encodeTranspose(clblasTranspose value)780 encodeTranspose(clblasTranspose value)
781 {
782     switch (value) {
783     case clblasNoTrans:      return 'N';
784     case clblasTrans:        return 'T';
785     case clblasConjTrans:    return 'C';
786     }
787     return '\0';
788 }
789 
790 char
encodeUplo(clblasUplo value)791 encodeUplo(clblasUplo value)
792 {
793     switch (value) {
794     case clblasUpper:  return 'U';
795     case clblasLower:  return 'L';
796     }
797     return '\0';
798 }
799 
800 char
encodeDiag(clblasDiag value)801 encodeDiag(clblasDiag value)
802 {
803     switch (value) {
804     case clblasUnit:       return 'U';
805     case clblasNonUnit:    return 'N';
806     }
807     return '\0';
808 }
809 
810 char
encodeSide(clblasSide value)811 encodeSide(clblasSide value)
812 {
813     switch (value) {
814     case clblasLeft:   return 'L';
815     case clblasRight:  return 'R';
816     }
817     return '\0';
818 }
819 
820 int
functionBlasLevel(BlasFunctionID funct)821 functionBlasLevel(BlasFunctionID funct) {
822     switch (funct) {
823 
824     case FN_SSCAL:
825     case FN_DSCAL:
826     case FN_CSCAL:
827     case FN_ZSCAL:
828     case FN_CSSCAL:
829     case FN_ZDSCAL:
830 
831     case FN_SSWAP:
832     case FN_DSWAP:
833     case FN_CSWAP:
834     case FN_ZSWAP:
835 
836     case FN_SAXPY:
837     case FN_DAXPY:
838     case FN_CAXPY:
839     case FN_ZAXPY:
840 
841 	case FN_SDOT:
842     case FN_DDOT:
843     case FN_CDOTU:
844     case FN_ZDOTU:
845     case FN_CDOTC:
846     case FN_ZDOTC:
847 
848 	case FN_SCOPY:
849     case FN_DCOPY:
850     case FN_CCOPY:
851     case FN_ZCOPY:
852 
853     case FN_SROTG:
854     case FN_DROTG:
855     case FN_CROTG:
856     case FN_ZROTG:
857 
858     case FN_SROT:
859     case FN_DROT:
860     case FN_CSROT:
861     case FN_ZDROT:
862 
863     case FN_SASUM:
864     case FN_DASUM:
865     case FN_SCASUM:
866     case FN_DZASUM:
867 
868     case FN_SROTM:
869     case FN_DROTM:
870 
871     case FN_SROTMG:
872     case FN_DROTMG:
873 
874     case FN_SNRM2:
875     case FN_DNRM2:
876     case FN_SCNRM2:
877     case FN_DZNRM2:
878 
879     case FN_iSAMAX:
880     case FN_iDAMAX:
881     case FN_iCAMAX:
882     case FN_iZAMAX:
883 
884     return 1;
885 
886     case FN_SGEMV:
887     case FN_DGEMV:
888     case FN_CGEMV:
889     case FN_ZGEMV:
890 
891     case FN_SSYMV:
892     case FN_DSYMV:
893     case FN_SSPMV:
894     case FN_DSPMV:
895 
896     case FN_STRMV:
897     case FN_DTRMV:
898     case FN_CTRMV:
899     case FN_ZTRMV:
900 
901     case FN_STPMV:
902     case FN_DTPMV:
903     case FN_CTPMV:
904     case FN_ZTPMV:
905 
906     case FN_STRSV:
907     case FN_DTRSV:
908     case FN_CTRSV:
909     case FN_ZTRSV:
910 
911     case FN_STPSV:
912     case FN_DTPSV:
913     case FN_CTPSV:
914     case FN_ZTPSV:
915 
916     case FN_SGER:
917     case FN_DGER:
918     case FN_CGERU:
919     case FN_ZGERU:
920     case FN_CGERC:
921     case FN_ZGERC:
922 
923     case FN_CHER:
924     case FN_ZHER:
925     case FN_CHER2:
926     case FN_ZHER2:
927 
928     case FN_CHPR:
929     case FN_ZHPR:
930     case FN_CHPR2:
931     case FN_ZHPR2:
932 
933 	case FN_SSYR:
934 	case FN_DSYR:
935     case FN_SSPR:
936 	case FN_DSPR:
937 
938 	case FN_SSYR2:
939 	case FN_DSYR2:
940     case FN_SSPR2:
941 	case FN_DSPR2:
942 
943 	case FN_CHEMV:
944 	case FN_ZHEMV:
945     case FN_CHPMV:
946     case FN_ZHPMV:
947 
948     case FN_SGBMV:
949 	case FN_DGBMV:
950 	case FN_CGBMV:
951 	case FN_ZGBMV:
952 
953 	case FN_STBMV:
954 	case FN_DTBMV:
955 	case FN_CTBMV:
956 	case FN_ZTBMV:
957 
958 	case FN_SSBMV:
959 	case FN_DSBMV:
960 
961 	case FN_CHBMV:
962 	case FN_ZHBMV:
963 
964 	case FN_STBSV:
965 	case FN_DTBSV:
966 	case FN_CTBSV:
967 	case FN_ZTBSV:
968 
969     return 2;
970 
971 	case FN_CHEMM:
972     case FN_ZHEMM:
973 
974     case FN_SSYMM:
975     case FN_DSYMM:
976     case FN_CSYMM:
977     case FN_ZSYMM:
978 
979     case FN_SGEMM:
980     case FN_DGEMM:
981     case FN_CGEMM:
982     case FN_ZGEMM:
983 
984     case FN_SGEMM_2:
985     case FN_DGEMM_2:
986     case FN_CGEMM_2:
987     case FN_ZGEMM_2:
988 
989     case FN_STRMM:
990     case FN_DTRMM:
991     case FN_CTRMM:
992     case FN_ZTRMM:
993 
994     case FN_STRSM:
995     case FN_DTRSM:
996     case FN_CTRSM:
997     case FN_ZTRSM:
998 
999     case FN_SSYR2K:
1000     case FN_DSYR2K:
1001     case FN_CSYR2K:
1002     case FN_ZSYR2K:
1003 
1004     case FN_SSYRK:
1005     case FN_DSYRK:
1006     case FN_CSYRK:
1007     case FN_ZSYRK:
1008 
1009 	case FN_CHERK:
1010 	case FN_ZHERK:
1011 	case FN_CHER2K:
1012 	case FN_ZHER2K:
1013 
1014         return 3;
1015     default:
1016         return 0;
1017     }
1018 }
1019