Debian Codegraph @

frame/3/trsm/bli_trsm_blk_var1.c

raw symbols SCIP
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) 2018 - 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 //#define PRINT
39
40 void bli_trsm_blk_var1
41 (
42 const obj_t* a,
43 const obj_t* b,
44 const obj_t* c,
45 const cntx_t* cntx,
46 const cntl_t* cntl,
47 thrinfo_t* thread_par
48 )
49 {
50 obj_t ap, cp;
51 bli_obj_alias_to( a, &ap );
52 bli_obj_alias_to( c, &cp );
53
54 // Determine the direction in which to partition (forwards or backwards).
55 const dir_t direct = bli_part_cntl_direct( cntl );
56
57 // Prune any zero region that exists along the partitioning dimension.
58 bli_l3_prune_unref_mparts_m( &ap, b, &cp );
59
60 // Isolate the diagonal block A11 and its corresponding row panel C1.
61 const dim_t kc = bli_obj_width_after_trans( &ap );
62 obj_t a11, c1;
63 bli_acquire_mpart_mdim( direct, BLIS_SUBPART1,
64 0, kc, &ap, &a11 );
65 bli_acquire_mpart_mdim( direct, BLIS_SUBPART1,
66 0, kc, &cp, &c1 );
67
68 // All threads iterate over the entire diagonal block A11.
69 thrinfo_t* thread_pre = bli_thrinfo_sub_node( 0, thread_par );
70 dim_t my_start = 0, my_end = kc;
71
72 #ifdef PRINT
73 printf( "bli_trsm_blk_var1(): a11 is %d x %d at offsets (%3d, %3d)\n",
74 (int)bli_obj_length( &a11 ), (int)bli_obj_width( &a11 ),
75 (int)bli_obj_row_off( &a11 ), (int)bli_obj_col_off( &a11 ) );
76 printf( "bli_trsm_blk_var1(): entering trsm subproblem loop.\n" );
77 #endif
78
79 // Partition along the m dimension for the trsm subproblem.
80 dim_t b_alg;
81 for ( dim_t i = my_start; i < my_end; i += b_alg )
82 {
83 b_alg = bli_determine_blocksize( direct, i, my_end,
84 bli_part_cntl_blksz_alg( cntl ),
85 bli_part_cntl_blksz_max( cntl ) );
86
87 // Acquire partitions for A1 and C1.
88 obj_t a11_1, c1_1;
89 bli_acquire_mpart_mdim( direct, BLIS_SUBPART1,
90 i, b_alg, &a11, &a11_1 );
91 bli_acquire_mpart_mdim( direct, BLIS_SUBPART1,
92 i, b_alg, &c1, &c1_1 );
93
94 #ifdef PRINT
95 printf( "bli_trsm_blk_var1(): a11_1 is %d x %d at offsets (%3d, %3d)\n",
96 (int)bli_obj_length( &a11_1 ), (int)bli_obj_width( &a11_1 ),
97 (int)bli_obj_row_off( &a11_1 ), (int)bli_obj_col_off( &a11_1 ) );
98 #endif
99
100 // Perform trsm subproblem.
101 bli_l3_int
102 (
103 &a11_1,
104 b,
105 &c1_1,
106 cntx,
107 bli_cntl_sub_node( 0, cntl ),
108 thread_pre
109 );
110 }
111
112 #ifdef PRINT
113 printf( "bli_trsm_blk_var1(): finishing trsm subproblem loop.\n" );
114 #endif
115
116 // We must execute a barrier here because the upcoming rank-k update
117 // requires the packed matrix B to be fully updated by the trsm
118 // subproblem.
119 bli_thrinfo_barrier( thread_par );
120
121 // Isolate the remaining part of the column panel matrix A, which we do by
122 // acquiring the subpartition ahead of A11 (that is, A21 or A01, depending
123 // on whether we are moving forwards or backwards, respectively).
124 obj_t ax1, cx1;
125 bli_acquire_mpart_mdim( direct, BLIS_SUBPART1A,
126 0, kc, &ap, &ax1 );
127 bli_acquire_mpart_mdim( direct, BLIS_SUBPART1A,
128 0, kc, &cp, &cx1 );
129
130 #ifdef PRINT
131 printf( "bli_trsm_blk_var1(): ax1 is %d x %d at offsets (%3d, %3d)\n",
132 (int)bli_obj_length( &ax1 ), (int)bli_obj_width( &ax1 ),
133 (int)bli_obj_row_off( &ax1 ), (int)bli_obj_col_off( &ax1 ) );
134 #endif
135
136 // Determine the current thread's subpartition range for the gemm
137 // subproblem over Ax1.
138 thrinfo_t* thread = bli_thrinfo_sub_node( 1, thread_par );
139 bli_thread_range_mdim
140 (
141 direct,
142 bli_part_cntl_blksz_mult( cntl ),
143 bli_part_cntl_use_weighted( cntl ),
144 thread, &ax1, b, &cx1,
145 &my_start, &my_end
146 );
147
148 #ifdef PRINT
149 printf( "bli_trsm_blk_var1(): entering gemm subproblem loop (%d->%d).\n", (int)my_start, (int)my_end );
150 #endif
151
152 // Partition along the m dimension for the gemm subproblem.
153 for ( dim_t i = my_start; i < my_end; i += b_alg )
154 {
155 // Determine the current algorithmic blocksize.
156 b_alg = bli_determine_blocksize( direct, i, my_end,
157 bli_part_cntl_blksz_alg( cntl ),
158 bli_part_cntl_blksz_max( cntl ) );
159
160 // Acquire partitions for A1 and C1.
161 obj_t a11, c1;
162 bli_acquire_mpart_mdim( direct, BLIS_SUBPART1,
163 i, b_alg, &ax1, &a11 );
164 bli_acquire_mpart_mdim( direct, BLIS_SUBPART1,
165 i, b_alg, &cx1, &c1 );
166
167 #ifdef PRINT
168 printf( "bli_trsm_blk_var1(): a11 is %d x %d at offsets (%3d, %3d)\n",
169 (int)bli_obj_length( &a11 ), (int)bli_obj_width( &a11 ),
170 (int)bli_obj_row_off( &a11 ), (int)bli_obj_col_off( &a11 ) );
171 #endif
172
173 // Perform gemm subproblem. (Note that we use the same backend
174 // function as before, since we're calling the same macrokernel.)
175 bli_l3_int
176 (
177 &a11,
178 b,
179 &c1,
180 cntx,
181 bli_cntl_sub_node( 1, cntl ),
182 thread
183 );
184 }
185 #ifdef PRINT
186 printf( "bli_trsm_blk_var1(): finishing gemm subproblem loop.\n" );
187 #endif
188 }
189