1 /*
2
3 BLIS
4 An object-based framework for developing high-performance BLAS-like
5 libraries.
6
7 Copyright (C) 2014, The University of Texas at Austin
8
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(s) of the copyright holder(s) nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
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.
32
33 */
34
35 #include "blis.h"
36
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;
41
bli_her_front(obj_t * alpha,obj_t * x,obj_t * c,cntx_t * cntx)42 void bli_her_front
43 (
44 obj_t* alpha,
45 obj_t* x,
46 obj_t* c,
47 cntx_t* cntx
48 )
49 {
50 her_t* her_cntl;
51 num_t dt_targ_x;
52 //num_t dt_targ_c;
53 bool x_has_unit_inc;
54 bool c_has_unit_inc;
55 obj_t alpha_local;
56 num_t dt_alpha;
57
58 // Check parameters.
59 if ( bli_error_checking_is_enabled() )
60 bli_her_check( alpha, x, c );
61
62
63 // Query the target datatypes of each object.
64 dt_targ_x = bli_obj_target_dt( x );
65 //dt_targ_c = bli_obj_target_dt( c );
66
67 // Determine whether each operand with unit stride.
68 x_has_unit_inc = ( bli_obj_vector_inc( x ) == 1 );
69 c_has_unit_inc = ( bli_obj_is_row_stored( c ) ||
70 bli_obj_is_col_stored( c ) );
71
72
73 // Create object to hold a copy-cast of alpha.
74 dt_alpha = dt_targ_x;
75 bli_obj_scalar_init_detached_copy_of( dt_alpha,
76 BLIS_NO_CONJUGATE,
77 alpha,
78 &alpha_local );
79
80
81 // If all operands have unit stride, we choose a control tree for calling
82 // the unblocked implementation directly without any blocking.
83 if ( x_has_unit_inc &&
84 c_has_unit_inc )
85 {
86 // We use two control trees to handle the four cases corresponding to
87 // combinations of upper/lower triangular storage and row/column-storage.
88 // The row-stored lower triangular and column-stored upper triangular
89 // trees are identical. Same for the remaining two trees.
90 if ( bli_obj_is_lower( c ) )
91 {
92 if ( bli_obj_is_row_stored( c ) ) her_cntl = her_cntl_bs_ke_lrow_ucol;
93 else her_cntl = her_cntl_bs_ke_lcol_urow;
94 }
95 else // if ( bli_obj_is_upper( c ) )
96 {
97 if ( bli_obj_is_row_stored( c ) ) her_cntl = her_cntl_bs_ke_lcol_urow;
98 else her_cntl = her_cntl_bs_ke_lrow_ucol;
99 }
100 }
101 else
102 {
103 // Mark objects with unit stride as already being packed. This prevents
104 // unnecessary packing from happening within the blocked algorithm.
105 if ( x_has_unit_inc ) bli_obj_set_pack_schema( BLIS_PACKED_VECTOR, x );
106 if ( c_has_unit_inc ) bli_obj_set_pack_schema( BLIS_PACKED_UNSPEC, c );
107
108 // Here, we make a similar choice as above, except that (1) we look
109 // at storage tilt, and (2) we choose a tree that performs blocking.
110 if ( bli_obj_is_lower( c ) )
111 {
112 if ( bli_obj_is_row_stored( c ) ) her_cntl = her_cntl_ge_lrow_ucol;
113 else her_cntl = her_cntl_ge_lcol_urow;
114 }
115 else // if ( bli_obj_is_upper( c ) )
116 {
117 if ( bli_obj_is_row_stored( c ) ) her_cntl = her_cntl_ge_lcol_urow;
118 else her_cntl = her_cntl_ge_lrow_ucol;
119 }
120 }
121
122 // Invoke the internal back-end with the copy-cast scalar and the
123 // chosen control tree. Set conjh to BLIS_CONJUGATE to invoke the
124 // Hermitian (and not symmetric) algorithms.
125 bli_her_int( BLIS_CONJUGATE,
126 &alpha_local,
127 x,
128 c,
129 cntx,
130 her_cntl );
131 }
132
133
134 //
135 // Define BLAS-like interfaces with homogeneous-typed operands.
136 //
137 #undef GENTFUNCR
138 #define GENTFUNCR( ctype, ctype_r, ch, chr, opname ) \
139 \
140 void PASTEMAC(ch,opname) \
141 ( \
142 uplo_t uploc, \
143 conj_t conjx, \
144 dim_t m, \
145 ctype_r* alpha, \
146 ctype* x, inc_t incx, \
147 ctype* c, inc_t rs_c, inc_t cs_c, \
148 cntx_t* cntx \
149 ) \
150 { \
151 const num_t dt_r = PASTEMAC(chr,type); \
152 const num_t dt = PASTEMAC(ch,type); \
153 \
154 obj_t alphao, xo, co; \
155 \
156 inc_t rs_x, cs_x; \
157 \
158 rs_x = incx; cs_x = m * incx; \
159 \
160 bli_obj_create_1x1_with_attached_buffer( dt_r, alpha, &alphao ); \
161 \
162 bli_obj_create_with_attached_buffer( dt, m, 1, x, rs_x, cs_x, &xo ); \
163 bli_obj_create_with_attached_buffer( dt, m, m, c, rs_c, cs_c, &co ); \
164 \
165 bli_obj_set_conj( conjx, &xo ); \
166 bli_obj_set_uplo( uploc, &co ); \
167 \
168 bli_obj_set_struc( BLIS_HERMITIAN, &co ); \
169 \
170 PASTEMAC0(opname)( &alphao, \
171 &xo, \
172 &co, \
173 cntx ); \
174 }
175
176 INSERT_GENTFUNCR_BASIC0( her_front )
177
178