]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - dense-linear-algebra-libraries/linalg.git/blob - blis/frame/2/trsv/bli_trsv.c
Consolidate all git repos of linalg into one.
[dense-linear-algebra-libraries/linalg.git] / blis / frame / 2 / trsv / bli_trsv.c
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 trsv_t* trsv_cntl_bs_ke_nrow_tcol;
38 extern trsv_t* trsv_cntl_bs_ke_ncol_trow;
39 extern trsv_t* trsv_cntl_ge_nrow_tcol;
40 extern trsv_t* trsv_cntl_ge_ncol_trow;
42 void bli_trsv( obj_t*  alpha,
43                obj_t*  a,
44                obj_t*  x )
45 {
46         trsv_t* trsv_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_trsv_check( alpha, a, x );
59         // Query the target datatypes of each object.
60         dt_targ_a = bli_obj_datatype( *a );
61         dt_targ_x = bli_obj_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                 if ( bli_obj_has_notrans( *a ) )
85                 {
86                         if ( bli_obj_is_row_stored( *a ) ) trsv_cntl = trsv_cntl_bs_ke_nrow_tcol;
87                         else                               trsv_cntl = trsv_cntl_bs_ke_ncol_trow;
88                 }
89                 else // if ( bli_obj_has_trans( *a ) )
90                 {
91                         if ( bli_obj_is_row_stored( *a ) ) trsv_cntl = trsv_cntl_bs_ke_ncol_trow;
92                         else                               trsv_cntl = trsv_cntl_bs_ke_nrow_tcol;
93                 }
94         }
95         else
96         {
97                 // Mark objects with unit stride as already being packed. This prevents
98                 // unnecessary packing from happening within the blocked algorithm.
99                 if ( a_has_unit_inc ) bli_obj_set_pack_schema( BLIS_PACKED_UNSPEC, *a );
100                 if ( x_has_unit_inc ) bli_obj_set_pack_schema( BLIS_PACKED_VECTOR, *x );
102                 // Here, we make a similar choice as above, except that (1) we look
103                 // at storage tilt, and (2) we choose a tree that performs blocking.
104                 if ( bli_obj_has_notrans( *a ) )
105                 {
106                         if ( bli_obj_is_row_tilted( *a ) ) trsv_cntl = trsv_cntl_ge_nrow_tcol;
107                         else                               trsv_cntl = trsv_cntl_ge_ncol_trow;
108                 }
109                 else // if ( bli_obj_has_trans( *a ) )
110                 {
111                         if ( bli_obj_is_row_tilted( *a ) ) trsv_cntl = trsv_cntl_ge_ncol_trow;
112                         else                               trsv_cntl = trsv_cntl_ge_nrow_tcol;
113                 }
114         }
117         // Invoke the internal back-end with the copy-cast of alpha and the
118         // chosen control tree.
119         bli_trsv_int( &alpha_local,
120                       a,
121                       x,
122                       trsv_cntl );
126 //
127 // Define BLAS-like interfaces with homogeneous-typed operands.
128 //
129 #undef  GENTFUNC
130 #define GENTFUNC( ctype, ch, opname, varname ) \
132 void PASTEMAC(ch,opname)( \
133                           uplo_t   uploa, \
134                           trans_t  transa, \
135                           diag_t   diaga, \
136                           dim_t    m, \
137                           ctype*   alpha, \
138                           ctype*   a, inc_t rs_a, inc_t cs_a, \
139                           ctype*   x, inc_t incx \
140                         ) \
141 { \
142         const num_t dt = PASTEMAC(ch,type); \
144         obj_t       alphao, ao, xo; \
146         inc_t       rs_x, cs_x; \
148         rs_x = incx; cs_x = m * incx; \
150         bli_obj_create_1x1_with_attached_buffer( dt, alpha, &alphao ); \
152         bli_obj_create_with_attached_buffer( dt, m, m, a, rs_a, cs_a, &ao ); \
153         bli_obj_create_with_attached_buffer( dt, m, 1, x, rs_x, cs_x, &xo ); \
155         bli_obj_set_uplo( uploa, ao ); \
156         bli_obj_set_conjtrans( transa, ao ); \
157         bli_obj_set_diag( diaga, ao ); \
159         bli_obj_set_struc( BLIS_TRIANGULAR, ao ); \
161         PASTEMAC0(opname)( &alphao, \
162                            &ao, \
163                            &xo ); \
166 INSERT_GENTFUNC_BASIC( trsv, trsv )
169 //
170 // Define BLAS-like interfaces with heterogeneous-typed operands.
171 //
172 #undef  GENTFUNC2U
173 #define GENTFUNC2U( ctype_a, ctype_x, ctype_ax, cha, chx, chax, opname, varname ) \
175 void PASTEMAC2(cha,chx,opname)( \
176                                 uplo_t    uploa, \
177                                 trans_t   transa, \
178                                 diag_t    diaga, \
179                                 dim_t     m, \
180                                 ctype_ax* alpha, \
181                                 ctype_a*  a, inc_t rs_a, inc_t cs_a, \
182                                 ctype_x*  x, inc_t incx \
183                               ) \
184 { \
185         bli_check_error_code( BLIS_NOT_YET_IMPLEMENTED ); \
188 INSERT_GENTFUNC2U_BASIC( trsv, trsv )
190 #ifdef BLIS_ENABLE_MIXED_DOMAIN_SUPPORT
191 INSERT_GENTFUNC2U_MIX_D( trsv, trsv )
192 #endif
194 #ifdef BLIS_ENABLE_MIXED_PRECISION_SUPPORT
195 INSERT_GENTFUNC2U_MIX_P( trsv, trsv )
196 #endif