1 /*********************************************************************/
2 /* Copyright 2009, 2010 The University of Texas at Austin. */
3 /* All rights reserved. */
5 /* Redistribution and use in source and binary forms, with or */
6 /* without modification, are permitted provided that the following */
7 /* conditions are met: */
9 /* 1. Redistributions of source code must retain the above */
10 /* copyright notice, this list of conditions and the following */
13 /* 2. Redistributions in binary form must reproduce the above */
14 /* copyright notice, this list of conditions and the following */
15 /* disclaimer in the documentation and/or other materials */
16 /* provided with the distribution. */
18 /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
19 /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
20 /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
21 /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
23 /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
24 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
25 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
26 /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
27 /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
28 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
29 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
30 /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
31 /* POSSIBILITY OF SUCH DAMAGE. */
33 /* The views and conclusions contained in the software and */
34 /* documentation are those of the authors and should not be */
35 /* interpreted as representing official policies, either expressed */
36 /* or implied, of The University of Texas at Austin. */
37 /*********************************************************************/
42 #ifdef FUNCTION_PROFILE
43 #include "functable.h"
47 #define ERROR_NAME "QGEMV "
49 #define ERROR_NAME "DGEMV "
51 #define ERROR_NAME "SGEMV "
55 static int (*gemv_thread[])(BLASLONG, BLASLONG, FLOAT, FLOAT *, BLASLONG, FLOAT * , BLASLONG, FLOAT *, BLASLONG, FLOAT *, int) = {
57 qgemv_thread_n, qgemv_thread_t,
59 dgemv_thread_n, dgemv_thread_t,
61 sgemv_thread_n, sgemv_thread_t,
68 void NAME(char *TRANS, blasint *M, blasint *N,
69 FLOAT *ALPHA, FLOAT *a, blasint *LDA,
70 FLOAT *x, blasint *INCX,
71 FLOAT *BETA, FLOAT *y, blasint *INCY){
87 int (*gemv[])(BLASLONG, BLASLONG, BLASLONG, FLOAT, FLOAT *, BLASLONG, FLOAT * , BLASLONG, FLOAT *, BLASLONG, FLOAT *) = {
103 if (trans == 'N') i = 0;
104 if (trans == 'T') i = 1;
105 if (trans == 'R') i = 0;
106 if (trans == 'C') i = 1;
108 if (incy == 0) info = 11;
109 if (incx == 0) info = 8;
110 if (lda < MAX(1, m)) info = 6;
118 BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
124 void CNAME(enum CBLAS_ORDER order,
125 enum CBLAS_TRANSPOSE TransA,
126 blasint m, blasint n,
128 FLOAT *a, blasint lda,
129 FLOAT *x, blasint incx,
131 FLOAT *y, blasint incy){
135 int trans, buffer_size;
141 int (*gemv[])(BLASLONG, BLASLONG, BLASLONG, FLOAT, FLOAT *, BLASLONG, FLOAT * , BLASLONG, FLOAT *, BLASLONG, FLOAT *) = {
150 if (order == CblasColMajor) {
151 if (TransA == CblasNoTrans) trans = 0;
152 if (TransA == CblasTrans) trans = 1;
153 if (TransA == CblasConjNoTrans) trans = 0;
154 if (TransA == CblasConjTrans) trans = 1;
158 if (incy == 0) info = 11;
159 if (incx == 0) info = 8;
160 if (lda < MAX(1, m)) info = 6;
163 if (trans < 0) info = 1;
167 if (order == CblasRowMajor) {
168 if (TransA == CblasNoTrans) trans = 1;
169 if (TransA == CblasTrans) trans = 0;
170 if (TransA == CblasConjNoTrans) trans = 1;
171 if (TransA == CblasConjTrans) trans = 0;
179 if (incy == 0) info = 11;
180 if (incx == 0) info = 8;
181 if (lda < MAX(1, m)) info = 6;
184 if (trans < 0) info = 1;
189 BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
194 //printf("m=%d, n=%d, trans=%d, incx=%d, incy=%d, alpha=%f, beta=%f\n", m, n, trans, incx, incy, alpha, beta);
195 if ((m==0) || (n==0)) return;
202 if (beta != ONE) SCAL_K(leny, 0, 0, beta, y, blasabs(incy), NULL, 0, NULL, 0);
204 if (alpha == ZERO) return;
208 FUNCTION_PROFILE_START();
210 if (incx < 0) x -= (lenx - 1) * incx;
211 if (incy < 0) y -= (leny - 1) * incy;
213 buffer_size = m + n + 128 / sizeof(FLOAT);
215 buffer_size += 160 / sizeof(FLOAT) ;
218 buffer_size = (buffer_size + 3) & ~3;
219 STACK_ALLOC(buffer_size, FLOAT, buffer);
223 if ( 1L * m * n < 2304L * GEMM_MULTITHREAD_THRESHOLD )
226 nthreads = num_cpu_avail(2);
231 (gemv[(int)trans])(m, n, 0, alpha, a, lda, x, incx, y, incy, buffer);
236 (gemv_thread[(int)trans])(m, n, alpha, a, lda, x, incx, y, incy, buffer, nthreads);
242 FUNCTION_PROFILE_END(1, m * n + m + n, 2 * m * n);