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 extern trmv_t* trmv_cntl_bs_ke_nrow_tcol;
38 extern trmv_t* trmv_cntl_bs_ke_ncol_trow;
39 extern trmv_t* trmv_cntl_ge_nrow_tcol;
40 extern trmv_t* trmv_cntl_ge_ncol_trow;
42 void bli_trmv( obj_t* alpha,
43 obj_t* a,
44 obj_t* x )
45 {
46 trmv_t* trmv_cntl;
47 num_t dt_targ_a;
48 num_t dt_targ_x;
49 bool_t a_has_unit_inc;
50 bool_t x_has_unit_inc;
51 obj_t alpha_local;
52 num_t dt_alpha;
54 // Check parameters.
55 if ( bli_error_checking_is_enabled() )
56 bli_trmv_check( alpha, a, x );
59 // Query the target datatypes of each object.
60 dt_targ_a = bli_obj_target_datatype( *a );
61 dt_targ_x = bli_obj_target_datatype( *x );
63 // Determine whether each operand with unit stride.
64 a_has_unit_inc = ( bli_obj_is_row_stored( *a ) ||
65 bli_obj_is_col_stored( *a ) );
66 x_has_unit_inc = ( bli_obj_vector_inc( *x ) == 1 );
69 // Create an object to hold a copy-cast of alpha. Notice that we use
70 // the type union of the target datatypes of a and x to prevent any
71 // unnecessary loss of information during the computation.
72 dt_alpha = bli_datatype_union( dt_targ_a, dt_targ_x );
73 bli_obj_scalar_init_detached_copy_of( dt_alpha,
74 BLIS_NO_CONJUGATE,
75 alpha,
76 &alpha_local );
79 // If all operands have unit stride, we choose a control tree for calling
80 // the unblocked implementation directly without any blocking.
81 if ( a_has_unit_inc &&
82 x_has_unit_inc )
83 {
84 // We use two control trees to handle the four cases corresponding to
85 // combinations of transposition and row/column-storage.
86 // The row-stored without transpose and column-stored with transpose
87 // trees are identical. Same for the remaining two trees.
88 if ( bli_obj_has_notrans( *a ) )
89 {
90 if ( bli_obj_is_row_stored( *a ) ) trmv_cntl = trmv_cntl_bs_ke_nrow_tcol;
91 else trmv_cntl = trmv_cntl_bs_ke_ncol_trow;
92 }
93 else // if ( bli_obj_has_trans( *a ) )
94 {
95 if ( bli_obj_is_row_stored( *a ) ) trmv_cntl = trmv_cntl_bs_ke_ncol_trow;
96 else trmv_cntl = trmv_cntl_bs_ke_nrow_tcol;
97 }
98 }
99 else
100 {
101 // Mark objects with unit stride as already being packed. This prevents
102 // unnecessary packing from happening within the blocked algorithm.
103 if ( a_has_unit_inc ) bli_obj_set_pack_schema( BLIS_PACKED_UNSPEC, *a );
104 if ( x_has_unit_inc ) bli_obj_set_pack_schema( BLIS_PACKED_VECTOR, *x );
106 // Here, we make a similar choice as above, except that (1) we look
107 // at storage tilt, and (2) we choose a tree that performs blocking.
108 if ( bli_obj_has_notrans( *a ) )
109 {
110 if ( bli_obj_is_row_tilted( *a ) ) trmv_cntl = trmv_cntl_ge_nrow_tcol;
111 else trmv_cntl = trmv_cntl_ge_ncol_trow;
112 }
113 else // if ( bli_obj_has_trans( *a ) )
114 {
115 if ( bli_obj_is_row_tilted( *a ) ) trmv_cntl = trmv_cntl_ge_ncol_trow;
116 else trmv_cntl = trmv_cntl_ge_nrow_tcol;
117 }
118 }
121 // Invoke the internal back-end with the copy-cast of alpha and the
122 // chosen control tree.
123 bli_trmv_int( &alpha_local,
124 a,
125 x,
126 trmv_cntl );
127 }
130 //
131 // Define BLAS-like interfaces with homogeneous-typed operands.
132 //
133 #undef GENTFUNC
134 #define GENTFUNC( ctype, ch, opname, varname ) \
135 \
136 void PASTEMAC(ch,opname)( \
137 uplo_t uploa, \
138 trans_t transa, \
139 diag_t diaga, \
140 dim_t m, \
141 ctype* alpha, \
142 ctype* a, inc_t rs_a, inc_t cs_a, \
143 ctype* x, inc_t incx \
144 ) \
145 { \
146 const num_t dt = PASTEMAC(ch,type); \
147 \
148 obj_t alphao, ao, xo; \
149 \
150 inc_t rs_x, cs_x; \
151 \
152 rs_x = incx; cs_x = m * incx; \
153 \
154 bli_obj_create_1x1_with_attached_buffer( dt, alpha, &alphao ); \
155 \
156 bli_obj_create_with_attached_buffer( dt, m, m, a, rs_a, cs_a, &ao ); \
157 bli_obj_create_with_attached_buffer( dt, m, 1, x, rs_x, cs_x, &xo ); \
158 \
159 bli_obj_set_uplo( uploa, ao ); \
160 bli_obj_set_conjtrans( transa, ao ); \
161 bli_obj_set_diag( diaga, ao ); \
162 \
163 bli_obj_set_struc( BLIS_TRIANGULAR, ao ); \
164 \
165 PASTEMAC0(opname)( &alphao, \
166 &ao, \
167 &xo ); \
168 }
170 INSERT_GENTFUNC_BASIC( trmv, trmv )
173 //
174 // Define BLAS-like interfaces with heterogeneous-typed operands.
175 //
176 #undef GENTFUNC2U
177 #define GENTFUNC2U( ctype_a, ctype_x, ctype_ax, cha, chx, chax, opname, varname ) \
178 \
179 void PASTEMAC2(cha,chx,opname)( \
180 uplo_t uploa, \
181 trans_t transa, \
182 diag_t diaga, \
183 dim_t m, \
184 ctype_ax* alpha, \
185 ctype_a* a, inc_t rs_a, inc_t cs_a, \
186 ctype_x* x, inc_t incx \
187 ) \
188 { \
189 bli_check_error_code( BLIS_NOT_YET_IMPLEMENTED ); \
190 }
192 INSERT_GENTFUNC2U_BASIC( trmv, trmv )
194 #ifdef BLIS_ENABLE_MIXED_DOMAIN_SUPPORT
195 INSERT_GENTFUNC2U_MIX_D( trmv, trmv )
196 #endif
198 #ifdef BLIS_ENABLE_MIXED_PRECISION_SUPPORT
199 INSERT_GENTFUNC2U_MIX_P( trmv, trmv )
200 #endif