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 void bli_trsm_blk_var1f( obj_t* a,
38 obj_t* b,
39 obj_t* c,
40 trsm_t* cntl,
41 trsm_thrinfo_t* thread )
42 {
43 obj_t b_pack_s;
44 obj_t a1_pack_s;
46 obj_t a1, c1;
47 obj_t* b_pack = NULL;
48 obj_t* a1_pack = NULL;
50 #ifdef BLIS_ENABLE_C66X_EDMA
51 obj_t c2;
52 obj_t a1_dma_s;
53 obj_t *a1_dma = NULL;
54 #endif
56 dim_t i;
57 dim_t b_alg;
58 dim_t m_trans;
59 dim_t offA;
60 #ifdef BLIS_ENABLE_C66X_EDMA
61 dim_t b_alg_next;
62 #endif
64 // Initialize object for packing B.
65 if( thread_am_ochief( thread ) ) {
66 bli_obj_init_pack( &b_pack_s );
67 bli_packm_init( b, &b_pack_s,
68 cntl_sub_packm_b( cntl ) );
69 }
70 b_pack = thread_obroadcast( thread, &b_pack_s );
72 // Initialize object for packing B.
73 if( thread_am_ichief( thread ) ) {
74 #ifdef BLIS_ENABLE_C66X_EDMA
75 bli_obj_init_dma( &a1_dma_s );
76 #endif
77 bli_obj_init_pack( &a1_pack_s );
78 }
79 #ifdef BLIS_ENABLE_C66X_EDMA
80 a1_dma = thread_ibroadcast(thread, &a1_dma_s);
81 #endif
82 a1_pack = thread_ibroadcast( thread, &a1_pack_s );
84 // Pack B1 (if instructed).
85 bli_packm_int( b, b_pack,
86 cntl_sub_packm_b( cntl ),
87 trsm_thread_sub_opackm( thread ) );
89 // Set the default length of and offset to the non-zero part of A.
90 m_trans = bli_obj_length_after_trans( *a );
91 offA = 0;
93 // If A is lower triangular, we have to adjust where the non-zero part of
94 // A begins.
95 if ( bli_obj_is_lower( *a ) )
96 offA = bli_abs( bli_obj_diag_offset_after_trans( *a ) );
98 dim_t start, end;
99 num_t dt = bli_obj_execution_datatype( *a );
100 bli_get_range_t2b( thread, offA, m_trans,
101 //bli_lcm( bli_info_get_default_nr( BLIS_TRSM, dt ), bli_info_get_default_mr( BLIS_TRSM, dt ) ),
102 bli_info_get_default_mc( dt ),
103 &start, &end );
105 // Partition along the remaining portion of the m dimension.
106 for ( i = start; i < end; i += b_alg )
107 {
108 #ifdef BLIS_ENABLE_C66X_EDMA
109 if(i == start)
110 {
111 // Determine the current algorithmic blocksize.
112 b_alg = bli_determine_blocksize_f( i, end, a,
113 cntl_blocksize( cntl ) );
115 // Acquire partitions for A1 and C1.
116 bli_acquire_mpart_t2b( BLIS_SUBPART1,
117 i, b_alg, a, &a1 );
118 bli_acquire_mpart_t2b( BLIS_SUBPART1,
119 i, b_alg, c, &c1 );
121 if( thread_am_ichief( thread ) )
122 {
123 // DMA control leaf unrolling for A
124 //printf("Init DMA A2\n");
125 bli_dmam_init( &a1, a1_dma, cntl_sub_dmam_a( cntl ) );
126 }
127 bli_dmam_int( &a1, a1_dma, cntl_sub_dmam_a( cntl ), (dmam_thrinfo_t *) trsm_thread_sub_ipackm( thread ) );
128 }
129 else
130 {
131 b_alg = b_alg_next;
132 }
134 bli_dmam_wait(a1_dma, cntl_sub_dmam_a( cntl ), (dmam_thrinfo_t *) trsm_thread_sub_ipackm( thread ));
135 thread_ibarrier( thread );
137 // Initialize object for packing A1.
138 if( thread_am_ichief( thread ) ) {
139 bli_packm_init( a1_dma, a1_pack,
140 cntl_sub_packm_a( cntl ) );
141 }
142 thread_ibarrier( thread );
144 // Pack A1 (if instructed).
145 bli_packm_int( a1_dma, a1_pack,
146 cntl_sub_packm_a( cntl ),
147 trsm_thread_sub_ipackm( thread ) );
149 // printf("blk_var1: a: m %d n %d\n", bli_obj_length( a1 ), bli_obj_width( a1));
150 // printf("blk_var1: a: m_panel %d n_panel %d\n", bli_obj_panel_length( *a1_pack ), bli_obj_panel_width( *a1_pack ));
152 //Get the next partition and start DMA
153 if( (i+b_alg) < end ) //Making sure we aren't at the end of the matrix
154 {
155 b_alg_next = bli_determine_blocksize_f( i+b_alg, end, a,
156 cntl_blocksize( cntl ) );
158 // Acquire partitions for A1 and C1.
159 bli_acquire_mpart_t2b( BLIS_SUBPART1,
160 i+b_alg, b_alg_next, a, &a1 );
161 bli_acquire_mpart_t2b( BLIS_SUBPART1,
162 i+b_alg, b_alg_next, c, &c2 );
164 if( thread_am_ichief( thread ) )
165 {
166 // DMA control leaf unrolling for A
167 //printf("Init DMA A2\n");
168 bli_dmam_init( &a1, a1_dma, cntl_sub_dmam_a( cntl ) );
169 }
170 bli_dmam_int( &a1, a1_dma, cntl_sub_dmam_a( cntl ), (dmam_thrinfo_t *) trsm_thread_sub_ipackm( thread ) );
172 }
174 #else
175 // Determine the current algorithmic blocksize.
176 b_alg = bli_determine_blocksize_f( i, end, a,
177 cntl_blocksize( cntl ) );
179 // Acquire partitions for A1 and C1.
180 bli_acquire_mpart_t2b( BLIS_SUBPART1,
181 i, b_alg, a, &a1 );
182 bli_acquire_mpart_t2b( BLIS_SUBPART1,
183 i, b_alg, c, &c1 );
185 // Initialize object for packing A1.
186 if( thread_am_ichief( thread ) ) {
187 bli_packm_init( &a1, a1_pack,
188 cntl_sub_packm_a( cntl ) );
189 }
190 thread_ibarrier( thread );
192 // Pack A1 (if instructed).
193 bli_packm_int( &a1, a1_pack,
194 cntl_sub_packm_a( cntl ),
195 trsm_thread_sub_ipackm( thread ) );
196 #endif
197 // Perform trsm subproblem.
198 bli_trsm_int( &BLIS_ONE,
199 a1_pack,
200 b_pack,
201 &BLIS_ONE,
202 &c1,
203 cntl_sub_trsm( cntl ),
204 trsm_thread_sub_trsm( thread ) );
206 #ifdef BLIS_ENABLE_C66X_EDMA
207 bli_obj_alias_to(c2, c1);
208 #endif
209 }
211 // If any packing buffers were acquired within packm, release them back
212 // to the memory manager.
213 thread_obarrier( thread );
214 if( thread_am_ochief( thread ) )
215 bli_obj_release_pack( b_pack , cntl_sub_packm_b(cntl));
216 if( thread_am_ichief( thread ) )
217 {
218 #ifdef BLIS_ENABLE_C66X_EDMA
219 bli_obj_release_dma( a1_dma , cntl_sub_dmam_a(cntl));
220 bli_obj_release_emt_handle( a1_dma );
221 #endif
222 bli_obj_release_pack( a1_pack , cntl_sub_packm_a(cntl));
223 }
224 }