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 her_t* her_cntl_bs_ke_lrow_ucol;
38 extern her_t* her_cntl_bs_ke_lcol_urow;
39 extern her_t* her_cntl_ge_lrow_ucol;
40 extern her_t* her_cntl_ge_lcol_urow;
42 void bli_her( obj_t* alpha,
43 obj_t* x,
44 obj_t* c )
45 {
46 her_t* her_cntl;
47 num_t dt_targ_x;
48 //num_t dt_targ_c;
49 bool_t x_has_unit_inc;
50 bool_t c_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_her_check( BLIS_CONJUGATE, alpha, x, c );
59 // Query the target datatypes of each object.
60 dt_targ_x = bli_obj_target_datatype( *x );
61 //dt_targ_c = bli_obj_target_datatype( *c );
63 // Determine whether each operand with unit stride.
64 x_has_unit_inc = ( bli_obj_vector_inc( *x ) == 1 );
65 c_has_unit_inc = ( bli_obj_is_row_stored( *c ) ||
66 bli_obj_is_col_stored( *c ) );
69 // Create object to hold a copy-cast of alpha.
70 dt_alpha = dt_targ_x;
71 bli_obj_scalar_init_detached_copy_of( dt_alpha,
72 BLIS_NO_CONJUGATE,
73 alpha,
74 &alpha_local );
77 // If all operands have unit stride, we choose a control tree for calling
78 // the unblocked implementation directly without any blocking.
79 if ( x_has_unit_inc &&
80 c_has_unit_inc )
81 {
82 // We use two control trees to handle the four cases corresponding to
83 // combinations of upper/lower triangular storage and row/column-storage.
84 // The row-stored lower triangular and column-stored upper triangular
85 // trees are identical. Same for the remaining two trees.
86 if ( bli_obj_is_lower( *c ) )
87 {
88 if ( bli_obj_is_row_stored( *c ) ) her_cntl = her_cntl_bs_ke_lrow_ucol;
89 else her_cntl = her_cntl_bs_ke_lcol_urow;
90 }
91 else // if ( bli_obj_is_upper( *c ) )
92 {
93 if ( bli_obj_is_row_stored( *c ) ) her_cntl = her_cntl_bs_ke_lcol_urow;
94 else her_cntl = her_cntl_bs_ke_lrow_ucol;
95 }
96 }
97 else
98 {
99 // Mark objects with unit stride as already being packed. This prevents
100 // unnecessary packing from happening within the blocked algorithm.
101 if ( x_has_unit_inc ) bli_obj_set_pack_schema( BLIS_PACKED_VECTOR, *x );
102 if ( c_has_unit_inc ) bli_obj_set_pack_schema( BLIS_PACKED_UNSPEC, *c );
104 // Here, we make a similar choice as above, except that (1) we look
105 // at storage tilt, and (2) we choose a tree that performs blocking.
106 if ( bli_obj_is_lower( *c ) )
107 {
108 if ( bli_obj_is_row_stored( *c ) ) her_cntl = her_cntl_ge_lrow_ucol;
109 else her_cntl = her_cntl_ge_lcol_urow;
110 }
111 else // if ( bli_obj_is_upper( *c ) )
112 {
113 if ( bli_obj_is_row_stored( *c ) ) her_cntl = her_cntl_ge_lcol_urow;
114 else her_cntl = her_cntl_ge_lrow_ucol;
115 }
116 }
119 // Invoke the internal back-end with the copy-cast scalar and the
120 // chosen control tree. Set conjh to BLIS_CONJUGATE to invoke the
121 // Hermitian (and not symmetric) algorithms.
122 bli_her_int( BLIS_CONJUGATE,
123 &alpha_local,
124 x,
125 c,
126 her_cntl );
127 }
130 //
131 // Define BLAS-like interfaces with homogeneous-typed operands.
132 //
133 #undef GENTFUNCR
134 #define GENTFUNCR( ctype, ctype_r, ch, chr, opname, varname ) \
135 \
136 void PASTEMAC(ch,opname)( \
137 uplo_t uploc, \
138 conj_t conjx, \
139 dim_t m, \
140 ctype_r* alpha, \
141 ctype* x, inc_t incx, \
142 ctype* c, inc_t rs_c, inc_t cs_c \
143 ) \
144 { \
145 const num_t dt_r = PASTEMAC(chr,type); \
146 const num_t dt = PASTEMAC(ch,type); \
147 \
148 obj_t alphao, xo, co; \
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_r, alpha, &alphao ); \
155 \
156 bli_obj_create_with_attached_buffer( dt, m, 1, x, rs_x, cs_x, &xo ); \
157 bli_obj_create_with_attached_buffer( dt, m, m, c, rs_c, cs_c, &co ); \
158 \
159 bli_obj_set_conj( conjx, xo ); \
160 bli_obj_set_uplo( uploc, co ); \
161 \
162 bli_obj_set_struc( BLIS_HERMITIAN, co ); \
163 \
164 PASTEMAC0(opname)( &alphao, \
165 &xo, \
166 &co ); \
167 }
169 INSERT_GENTFUNCR_BASIC( her, her )
172 //
173 // Define BLAS-like interfaces with heterogeneous-typed operands.
174 //
175 #undef GENTFUNC2R
176 #define GENTFUNC2R( ctype_x, ctype_c, ctype_xr, chx, chc, chxr, opname, varname ) \
177 \
178 void PASTEMAC2(chx,chc,opname)( \
179 uplo_t uploc, \
180 conj_t conjx, \
181 dim_t m, \
182 ctype_xr* alpha, \
183 ctype_x* x, inc_t incx, \
184 ctype_c* c, inc_t rs_c, inc_t cs_c \
185 ) \
186 { \
187 bli_check_error_code( BLIS_NOT_YET_IMPLEMENTED ); \
188 }
190 INSERT_GENTFUNC2R_BASIC( her, her )
192 #ifdef BLIS_ENABLE_MIXED_DOMAIN_SUPPORT
193 INSERT_GENTFUNC2R_MIX_D( her, her )
194 #endif
196 #ifdef BLIS_ENABLE_MIXED_PRECISION_SUPPORT
197 INSERT_GENTFUNC2R_MIX_P( her, her )
198 #endif