Debian Codegraph @

src/lapack/dec/q/lqut/vars/flamec/test/time_LQ_UT.c

raw
1 /*
2
3 Copyright (C) 2014, The University of Texas at Austin
4
5 This file is part of libflame and is available under the 3-Clause
6 BSD license, which can be found in the LICENSE file at the top-level
7 directory, or at http://opensource.org/licenses/BSD-3-Clause
8
9 */
10 #include "FLAME.h"
11
12 #define FLA_ALG_REFERENCE 0
13 #define FLA_ALG_BLOCKED 1
14 #define FLA_ALG_UNBLOCKED 2
15 #define FLA_ALG_UNB_OPT1 3
16
17 extern fla_gemm_t* fla_gemm_cntl_blas;
18 extern fla_trmm_t* fla_trmm_cntl_blas;
19 extern fla_trsm_t* fla_trsm_cntl_blas;
20 extern fla_copyt_t* fla_copyt_cntl_blas;
21 extern fla_axpyt_t* fla_axpyt_cntl_blas;
22
23 FLA_Error REF_LQ_UT( FLA_Obj A, FLA_Obj t );
24 void time_LQ(
25 int variant, int type, int n_repeats, int m, int n, int nb_alg,
26 FLA_Obj A, FLA_Obj t, FLA_Obj T, FLA_Obj TT, FLA_Obj w, FLA_Obj W, FLA_Obj WW, FLA_Obj b, FLA_Obj b_ref,
27 double *dtime, double *diff, double *gflops );
28
29
30 void time_LQ(
31 int variant, int type, int n_repeats, int m, int n, int nb_alg,
32 FLA_Obj A, FLA_Obj t, FLA_Obj T, FLA_Obj TT, FLA_Obj w, FLA_Obj W, FLA_Obj WW, FLA_Obj b, FLA_Obj b_ref,
33 double *dtime, double *diff, double *gflops )
34 {
35 int
36 irep;
37 int nb_alg_sm;
38
39 double
40 dtime_old = 1.0e9;
41
42 FLA_Obj
43 A_save, b_save, norm;
44
45 fla_blocksize_t* bp_la;
46 fla_blocksize_t* bp_sm;
47 fla_apqut_t* cntl_apqut;
48 fla_lqut_t* cntl_lqut_unb;
49 fla_lqut_t* cntl_lqut_var1;
50 fla_lqut_t* cntl_lqut_var2;
51
52 nb_alg_sm = max( nb_alg/4, 1 );
53
54 bp_la = FLA_Blocksize_create( nb_alg, nb_alg, nb_alg, nb_alg );
55 bp_sm = FLA_Blocksize_create( nb_alg_sm, nb_alg_sm, nb_alg_sm, nb_alg_sm );
56
57 cntl_apqut = FLA_Cntl_apqut_obj_create( FLA_FLAT,
58 FLA_BLOCKED_VARIANT1,
59 bp_la,
60 NULL,
61 fla_trmm_cntl_blas,
62 fla_trmm_cntl_blas,
63 fla_gemm_cntl_blas,
64 fla_gemm_cntl_blas,
65 fla_trsm_cntl_blas,
66 fla_copyt_cntl_blas,
67 fla_axpyt_cntl_blas );
68 cntl_lqut_unb = FLA_Cntl_lqut_obj_create( FLA_FLAT,
69 FLA_UNB_OPT_VARIANT1,
70 NULL,
71 NULL,
72 NULL );
73 cntl_lqut_var1 = FLA_Cntl_lqut_obj_create( FLA_FLAT,
74 FLA_BLOCKED_VARIANT1,
75 bp_la,
76 cntl_lqut_unb,
77 cntl_apqut );
78 cntl_lqut_var2 = FLA_Cntl_lqut_obj_create( FLA_FLAT,
79 FLA_BLOCKED_VARIANT2,
80 bp_la,
81 cntl_lqut_unb,
82 cntl_apqut );
83
84 FLA_Obj_create_conf_to( FLA_NO_TRANSPOSE, A, &A_save );
85 FLA_Obj_create_conf_to( FLA_NO_TRANSPOSE, b, &b_save );
86
87 if ( FLA_Obj_is_single_precision( A ) )
88 FLA_Obj_create( FLA_FLOAT, 1, 1, 0, 0, &norm );
89 else
90 FLA_Obj_create( FLA_DOUBLE, 1, 1, 0, 0, &norm );
91
92 FLA_Copy_external( A, A_save );
93 FLA_Copy_external( b, b_save );
94
95
96 for ( irep = 0 ; irep < n_repeats; irep++ ){
97
98 FLA_Copy_external( A_save, A );
99
100 *dtime = FLA_Clock();
101
102 switch( variant )
103 {
104
105 case 0:
106 REF_LQ_UT( A, t );
107 break;
108
109 case 1:
110 {
111 // Time variant 1
112 switch( type ){
113 case FLA_ALG_UNBLOCKED:
114 FLA_LQ_UT_unb_var1( A, T );
115 break;
116 case FLA_ALG_UNB_OPT1:
117 FLA_LQ_UT_opt_var1( A, T );
118 break;
119 case FLA_ALG_BLOCKED:
120 FLA_LQ_UT_internal( A, T, cntl_lqut_var1 );
121 break;
122 default:
123 printf("trouble\n");
124 }
125
126 break;
127 }
128
129 case 2:
130 {
131 // Time variant 2
132 switch( type ){
133 case FLA_ALG_UNBLOCKED:
134 FLA_LQ_UT_unb_var2( A, t );
135 break;
136 case FLA_ALG_UNB_OPT1:
137 FLA_LQ_UT_opt_var2( A, t );
138 break;
139 case FLA_ALG_BLOCKED:
140 FLA_LQ_UT_internal( A, TT, cntl_lqut_var2 );
141 break;
142 default:
143 printf("trouble\n");
144 }
145
146 break;
147 }
148
149 }
150
151 *dtime = FLA_Clock() - *dtime;
152 dtime_old = min( *dtime, dtime_old );
153
154 }
155
156 FLA_Cntl_obj_free( cntl_apqut );
157 FLA_Cntl_obj_free( cntl_lqut_unb );
158 FLA_Cntl_obj_free( cntl_lqut_var1 );
159 FLA_Cntl_obj_free( cntl_lqut_var2 );
160 FLA_Blocksize_free( bp_sm );
161 FLA_Blocksize_free( bp_la );
162
163 if ( variant == 0 )
164 {
165 FLA_Copy_external( b, b_ref );
166 FLA_Trsm_external( FLA_LEFT, FLA_LOWER_TRIANGULAR, FLA_NO_TRANSPOSE,
167 FLA_NONUNIT_DIAG, FLA_ONE, A, b );
168
169 if ( FLA_Obj_is_real( A ) )
170 FLA_Apply_Q_blk_external( FLA_LEFT, FLA_TRANSPOSE, FLA_ROWWISE, A, t, b );
171 else
172 FLA_Apply_Q_blk_external( FLA_LEFT, FLA_CONJ_TRANSPOSE, FLA_ROWWISE, A, t, b );
173
174 FLA_Gemv_external( FLA_NO_TRANSPOSE, FLA_MINUS_ONE, A_save, b, FLA_ONE, b_ref );
175 FLA_Nrm2_external( b_ref, norm );
176 if ( FLA_Obj_is_single_precision( A ) )
177 *diff = *(FLA_FLOAT_PTR(norm));
178 else
179 *diff = *(FLA_DOUBLE_PTR(norm));
180 }
181 else
182 {
183 FLA_Copy_external( b, b_ref );
184
185 if ( variant == 1 )
186 FLA_LQ_UT_solve( A, T, b_ref, b );
187 else if ( variant == 2 && type == FLA_ALG_BLOCKED )
188 FLA_LQ_UT_solve( A, TT, b_ref, b );
189 else if ( variant == 2 && type != FLA_ALG_BLOCKED )
190 FLA_LQ_UT_solve( A, t, b_ref, b );
191
192 FLA_Gemv_external( FLA_NO_TRANSPOSE, FLA_MINUS_ONE, A_save, b, FLA_ONE, b_ref );
193 FLA_Nrm2_external( b_ref, norm );
194 FLA_Obj_extract_real_scalar( norm, diff );
195 }
196
197 /*
198 if ( type == FLA_ALG_UNBLOCKED )
199 {
200 FLA_Obj AT, T2;
201
202 FLA_Obj_show( "A_orig", A_save, "%10.3e + %10.3e ", "" );
203
204 FLA_Obj_show( "LQ(A)", A, "%10.3e + %10.3e ", "" );
205 FLA_Obj_show( "T ", T, "%10.3e + %10.3e ", "" );
206
207 FLA_Obj_create_copy_of( FLA_CONJ_TRANSPOSE, A_save, &AT );
208 FLA_Obj_create_copy_of( FLA_NO_TRANSPOSE, T, &T2 );
209
210 FLA_QR_UT_unb_var1( AT, T2 );
211 FLA_Transpose( AT );
212
213 FLA_Obj_show( "(QR(A^T))^T", AT, "%10.3e + %10.3e ", "" );
214 FLA_Obj_show( "T ", T2, "%10.3e + %10.3e ", "" );
215
216 FLA_Obj_free( &AT );
217 FLA_Obj_free( &T2 );
218 }
219 */
220
221 *gflops = 2.0 * n * n * (m - n/3.0) /
222 dtime_old / 1e9;
223
224 if ( FLA_Obj_is_complex( A ) )
225 *gflops *= 4.0;
226
227 *dtime = dtime_old;
228
229 FLA_Copy_external( A_save, A );
230 FLA_Copy_external( b_save, b );
231
232 FLA_Obj_free( &A_save );
233 FLA_Obj_free( &b_save );
234 FLA_Obj_free( &norm );
235 }
236