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 Copyright (C) 2019, Advanced Micro Devices, Inc.
9
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are
12 met:
13 - Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15 - Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18 - Neither the name(s) of the copyright holder(s) nor the names of its
19 contributors may be used to endorse or promote products derived
20 from this software without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34 */
35
36 #include "blis.h"
37
38 // --- BLIS to BLAS/LAPACK mappings --------------------------------------------
39
bli_param_map_blis_to_netlib_side(side_t side,char * blas_side)40 void bli_param_map_blis_to_netlib_side( side_t side, char* blas_side )
41 {
42 if ( side == BLIS_LEFT ) *blas_side = 'L';
43 else if ( side == BLIS_RIGHT ) *blas_side = 'R';
44 else
45 {
46 bli_check_error_code( BLIS_INVALID_SIDE );
47 }
48 }
49
bli_param_map_blis_to_netlib_uplo(uplo_t uplo,char * blas_uplo)50 void bli_param_map_blis_to_netlib_uplo( uplo_t uplo, char* blas_uplo )
51 {
52 if ( uplo == BLIS_LOWER ) *blas_uplo = 'L';
53 else if ( uplo == BLIS_UPPER ) *blas_uplo = 'U';
54 else
55 {
56 bli_check_error_code( BLIS_INVALID_UPLO );
57 }
58 }
59
bli_param_map_blis_to_netlib_trans(trans_t trans,char * blas_trans)60 void bli_param_map_blis_to_netlib_trans( trans_t trans, char* blas_trans )
61 {
62 if ( trans == BLIS_NO_TRANSPOSE ) *blas_trans = 'N';
63 else if ( trans == BLIS_TRANSPOSE ) *blas_trans = 'T';
64 else if ( trans == BLIS_CONJ_TRANSPOSE ) *blas_trans = 'C';
65 else
66 {
67 bli_check_error_code( BLIS_INVALID_TRANS );
68 }
69 }
70
bli_param_map_blis_to_netlib_diag(diag_t diag,char * blas_diag)71 void bli_param_map_blis_to_netlib_diag( diag_t diag, char* blas_diag )
72 {
73 if ( diag == BLIS_NONUNIT_DIAG ) *blas_diag = 'N';
74 else if ( diag == BLIS_UNIT_DIAG ) *blas_diag = 'U';
75 else
76 {
77 bli_check_error_code( BLIS_INVALID_DIAG );
78 }
79 }
80
bli_param_map_blis_to_netlib_machval(machval_t machval,char * blas_machval)81 void bli_param_map_blis_to_netlib_machval( machval_t machval, char* blas_machval )
82 {
83 if ( machval == BLIS_MACH_EPS ) *blas_machval = 'E';
84 else if ( machval == BLIS_MACH_SFMIN ) *blas_machval = 'S';
85 else if ( machval == BLIS_MACH_BASE ) *blas_machval = 'B';
86 else if ( machval == BLIS_MACH_PREC ) *blas_machval = 'P';
87 else if ( machval == BLIS_MACH_NDIGMANT ) *blas_machval = 'N';
88 else if ( machval == BLIS_MACH_RND ) *blas_machval = 'R';
89 else if ( machval == BLIS_MACH_EMIN ) *blas_machval = 'M';
90 else if ( machval == BLIS_MACH_RMIN ) *blas_machval = 'U';
91 else if ( machval == BLIS_MACH_EMAX ) *blas_machval = 'L';
92 else if ( machval == BLIS_MACH_RMAX ) *blas_machval = 'O';
93 else
94 {
95 bli_check_error_code( BLIS_INVALID_MACHVAL );
96 }
97 }
98
99
100 // --- BLAS/LAPACK to BLIS mappings --------------------------------------------
101
102 // NOTE: These functions were converted into static functions. Please see this
103 // file's corresponding header for those definitions.
104
105
106 // --- BLIS char to BLIS mappings ----------------------------------------------
107
bli_param_map_char_to_blis_side(char side,side_t * blis_side)108 void bli_param_map_char_to_blis_side( char side, side_t* blis_side )
109 {
110 if ( side == 'l' || side == 'L' ) *blis_side = BLIS_LEFT;
111 else if ( side == 'r' || side == 'R' ) *blis_side = BLIS_RIGHT;
112 else
113 {
114 bli_check_error_code( BLIS_INVALID_SIDE );
115 }
116 }
117
bli_param_map_char_to_blis_uplo(char uplo,uplo_t * blis_uplo)118 void bli_param_map_char_to_blis_uplo( char uplo, uplo_t* blis_uplo )
119 {
120 if ( uplo == 'l' || uplo == 'L' ) *blis_uplo = BLIS_LOWER;
121 else if ( uplo == 'u' || uplo == 'U' ) *blis_uplo = BLIS_UPPER;
122 else if ( uplo == 'e' || uplo == 'E' ) *blis_uplo = BLIS_DENSE;
123 else
124 {
125 bli_check_error_code( BLIS_INVALID_UPLO );
126 }
127 }
128
bli_param_map_char_to_blis_trans(char trans,trans_t * blis_trans)129 void bli_param_map_char_to_blis_trans( char trans, trans_t* blis_trans )
130 {
131 if ( trans == 'n' || trans == 'N' ) *blis_trans = BLIS_NO_TRANSPOSE;
132 else if ( trans == 't' || trans == 'T' ) *blis_trans = BLIS_TRANSPOSE;
133 else if ( trans == 'c' || trans == 'C' ) *blis_trans = BLIS_CONJ_NO_TRANSPOSE;
134 else if ( trans == 'h' || trans == 'H' ) *blis_trans = BLIS_CONJ_TRANSPOSE;
135 else
136 {
137 bli_check_error_code( BLIS_INVALID_TRANS );
138 }
139 }
140
bli_param_map_char_to_blis_conj(char conj,conj_t * blis_conj)141 void bli_param_map_char_to_blis_conj( char conj, conj_t* blis_conj )
142 {
143 if ( conj == 'n' || conj == 'N' ) *blis_conj = BLIS_NO_CONJUGATE;
144 else if ( conj == 'c' || conj == 'C' ) *blis_conj = BLIS_CONJUGATE;
145 else
146 {
147 bli_check_error_code( BLIS_INVALID_CONJ );
148 }
149 }
150
bli_param_map_char_to_blis_diag(char diag,diag_t * blis_diag)151 void bli_param_map_char_to_blis_diag( char diag, diag_t* blis_diag )
152 {
153 if ( diag == 'n' || diag == 'N' ) *blis_diag = BLIS_NONUNIT_DIAG;
154 else if ( diag == 'u' || diag == 'U' ) *blis_diag = BLIS_UNIT_DIAG;
155 else
156 {
157 bli_check_error_code( BLIS_INVALID_DIAG );
158 }
159 }
160
bli_param_map_char_to_blis_dt(char dt,num_t * blis_dt)161 void bli_param_map_char_to_blis_dt( char dt, num_t* blis_dt )
162 {
163 if ( dt == 's' ) *blis_dt = BLIS_FLOAT;
164 else if ( dt == 'd' ) *blis_dt = BLIS_DOUBLE;
165 else if ( dt == 'c' ) *blis_dt = BLIS_SCOMPLEX;
166 else if ( dt == 'z' ) *blis_dt = BLIS_DCOMPLEX;
167 else if ( dt == 'i' ) *blis_dt = BLIS_INT;
168 else
169 {
170 bli_check_error_code( BLIS_INVALID_DATATYPE );
171 }
172 }
173
174
175 // --- BLIS to BLIS char mappings ----------------------------------------------
176
bli_param_map_blis_to_char_side(side_t blis_side,char * side)177 void bli_param_map_blis_to_char_side( side_t blis_side, char* side )
178 {
179 if ( blis_side == BLIS_LEFT ) *side = 'l';
180 else if ( blis_side == BLIS_RIGHT ) *side = 'r';
181 else
182 {
183 bli_check_error_code( BLIS_INVALID_SIDE );
184 }
185 }
186
bli_param_map_blis_to_char_uplo(uplo_t blis_uplo,char * uplo)187 void bli_param_map_blis_to_char_uplo( uplo_t blis_uplo, char* uplo )
188 {
189 if ( blis_uplo == BLIS_LOWER ) *uplo = 'l';
190 else if ( blis_uplo == BLIS_UPPER ) *uplo = 'u';
191 else
192 {
193 bli_check_error_code( BLIS_INVALID_UPLO );
194 }
195 }
196
bli_param_map_blis_to_char_trans(trans_t blis_trans,char * trans)197 void bli_param_map_blis_to_char_trans( trans_t blis_trans, char* trans )
198 {
199 if ( blis_trans == BLIS_NO_TRANSPOSE ) *trans = 'n';
200 else if ( blis_trans == BLIS_TRANSPOSE ) *trans = 't';
201 else if ( blis_trans == BLIS_CONJ_NO_TRANSPOSE ) *trans = 'c';
202 else if ( blis_trans == BLIS_CONJ_TRANSPOSE ) *trans = 'h';
203 else
204 {
205 bli_check_error_code( BLIS_INVALID_TRANS );
206 }
207 }
208
bli_param_map_blis_to_char_conj(conj_t blis_conj,char * conj)209 void bli_param_map_blis_to_char_conj( conj_t blis_conj, char* conj )
210 {
211 if ( blis_conj == BLIS_NO_CONJUGATE ) *conj = 'n';
212 else if ( blis_conj == BLIS_CONJUGATE ) *conj = 'c';
213 else
214 {
215 bli_check_error_code( BLIS_INVALID_CONJ );
216 }
217 }
218
bli_param_map_blis_to_char_diag(diag_t blis_diag,char * diag)219 void bli_param_map_blis_to_char_diag( diag_t blis_diag, char* diag )
220 {
221 if ( blis_diag == BLIS_NONUNIT_DIAG ) *diag = 'n';
222 else if ( blis_diag == BLIS_UNIT_DIAG ) *diag = 'u';
223 else
224 {
225 bli_check_error_code( BLIS_INVALID_DIAG );
226 }
227 }
228
bli_param_map_blis_to_char_dt(num_t blis_dt,char * dt)229 void bli_param_map_blis_to_char_dt( num_t blis_dt, char* dt )
230 {
231 if ( blis_dt == BLIS_FLOAT ) *dt = 's';
232 else if ( blis_dt == BLIS_DOUBLE ) *dt = 'd';
233 else if ( blis_dt == BLIS_SCOMPLEX ) *dt = 'c';
234 else if ( blis_dt == BLIS_DCOMPLEX ) *dt = 'z';
235 else if ( blis_dt == BLIS_INT ) *dt = 'i';
236 else
237 {
238 bli_check_error_code( BLIS_INVALID_DATATYPE );
239 }
240 }
241
242