1 /*
3 BLIS
4 An object-based framework for developing high-performance BLAS-like
5 libraries.
7 Copyright (C) 2014, The University of Texas at Austin
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are
11 met:
12 - Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14 - Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
17 - Neither the name of The University of Texas at Austin nor the names
18 of its contributors may be used to endorse or promote products
19 derived from this software without specific prior written permission.
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
35 #include "blis.h"
37 #define FUNCPTR_T gemv_fp
39 typedef void (*FUNCPTR_T)(
40 trans_t transa,
41 conj_t conjx,
42 dim_t m,
43 dim_t n,
44 void* alpha,
45 void* a, inc_t rs_a, inc_t cs_a,
46 void* x, inc_t incx,
47 void* beta,
48 void* y, inc_t incy
49 );
51 // If some mixed datatype functions will not be compiled, we initialize
52 // the corresponding elements of the function array to NULL.
53 #ifdef BLIS_ENABLE_MIXED_PRECISION_SUPPORT
54 static FUNCPTR_T GENARRAY3_ALL(ftypes,gemv_unb_var1);
55 #else
56 #ifdef BLIS_ENABLE_MIXED_DOMAIN_SUPPORT
57 static FUNCPTR_T GENARRAY3_EXT(ftypes,gemv_unb_var1);
58 #else
59 static FUNCPTR_T GENARRAY3_MIN(ftypes,gemv_unb_var1);
60 #endif
61 #endif
64 void bli_gemv_unb_var1( obj_t* alpha,
65 obj_t* a,
66 obj_t* x,
67 obj_t* beta,
68 obj_t* y,
69 gemv_t* cntl )
70 {
71 num_t dt_a = bli_obj_datatype( *a );
72 num_t dt_x = bli_obj_datatype( *x );
73 num_t dt_y = bli_obj_datatype( *y );
75 trans_t transa = bli_obj_conjtrans_status( *a );
76 conj_t conjx = bli_obj_conj_status( *x );
78 dim_t m = bli_obj_length( *a );
79 dim_t n = bli_obj_width( *a );
81 void* buf_a = bli_obj_buffer_at_off( *a );
82 inc_t rs_a = bli_obj_row_stride( *a );
83 inc_t cs_a = bli_obj_col_stride( *a );
85 void* buf_x = bli_obj_buffer_at_off( *x );
86 inc_t incx = bli_obj_vector_inc( *x );
88 void* buf_y = bli_obj_buffer_at_off( *y );
89 inc_t incy = bli_obj_vector_inc( *y );
91 num_t dt_alpha;
92 void* buf_alpha;
94 num_t dt_beta;
95 void* buf_beta;
97 FUNCPTR_T f;
99 // The datatype of alpha MUST be the type union of a and x. This is to
100 // prevent any unnecessary loss of information during computation.
101 dt_alpha = bli_datatype_union( dt_a, dt_x );
102 buf_alpha = bli_obj_buffer_for_1x1( dt_alpha, *alpha );
104 // The datatype of beta MUST be the same as the datatype of y.
105 dt_beta = dt_y;
106 buf_beta = bli_obj_buffer_for_1x1( dt_beta, *beta );
108 // Index into the type combination array to extract the correct
109 // function pointer.
110 f = ftypes[dt_a][dt_x][dt_y];
112 // Invoke the function.
113 f( transa,
114 conjx,
115 m,
116 n,
117 buf_alpha,
118 buf_a, rs_a, cs_a,
119 buf_x, incx,
120 buf_beta,
121 buf_y, incy );
122 }
125 #undef GENTFUNC3U12
126 #define GENTFUNC3U12( ctype_a, ctype_x, ctype_y, ctype_ax, cha, chx, chy, chax, varname, kername ) \
127 \
128 void PASTEMAC3(cha,chx,chy,varname)( \
129 trans_t transa, \
130 conj_t conjx, \
131 dim_t m, \
132 dim_t n, \
133 void* alpha, \
134 void* a, inc_t rs_a, inc_t cs_a, \
135 void* x, inc_t incx, \
136 void* beta, \
137 void* y, inc_t incy \
138 ) \
139 { \
140 ctype_ax* alpha_cast = alpha; \
141 ctype_y* beta_cast = beta; \
142 ctype_a* a_cast = a; \
143 ctype_x* x_cast = x; \
144 ctype_y* y_cast = y; \
145 ctype_a* a1t; \
146 ctype_x* x1; \
147 ctype_y* psi1; \
148 dim_t i; \
149 dim_t n_elem, n_iter; \
150 inc_t rs_at, cs_at; \
151 conj_t conja; \
152 \
153 if ( bli_zero_dim2( m, n ) ) return; \
154 \
155 bli_set_dims_incs_with_trans( transa, \
156 m, n, rs_a, cs_a, \
157 n_iter, n_elem, rs_at, cs_at ); \
158 \
159 conja = bli_extract_conj( transa ); \
160 \
161 for ( i = 0; i < n_iter; ++i ) \
162 { \
163 a1t = a_cast + (i )*rs_at + (0 )*cs_at; \
164 x1 = x_cast + (0 )*incy; \
165 psi1 = y_cast + (i )*incy; \
166 \
167 /* psi1 = beta * psi1 + alpha * a1t * x1; */ \
168 PASTEMAC3(cha,chx,chy,kername)( conja, \
169 conjx, \
170 n_elem, \
171 alpha_cast, \
172 a1t, cs_at, \
173 x1, incx, \
174 beta_cast, \
175 psi1 ); \
176 } \
177 }
179 // Define the basic set of functions unconditionally, and then also some
180 // mixed datatype functions if requested.
181 INSERT_GENTFUNC3U12_BASIC( gemv_unb_var1, DOTXV_KERNEL )
183 #ifdef BLIS_ENABLE_MIXED_DOMAIN_SUPPORT
184 INSERT_GENTFUNC3U12_MIX_D( gemv_unb_var1, DOTXV_KERNEL )
185 #endif
187 #ifdef BLIS_ENABLE_MIXED_PRECISION_SUPPORT
188 INSERT_GENTFUNC3U12_MIX_P( gemv_unb_var1, DOTXV_KERNEL )
189 #endif