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_var2f( obj_t* a,
38 obj_t* b,
39 obj_t* c,
40 trsm_t* cntl,
41 trsm_thrinfo_t* thread )
42 {
43 obj_t a_pack_s;
44 obj_t b1_pack_s, c1_pack_s;
46 obj_t b1, c1;
47 obj_t* a_pack = NULL;
48 obj_t* b1_pack = NULL;
49 obj_t* c1_pack = NULL;
51 dim_t i;
52 dim_t b_alg;
53 dim_t n_trans;
55 // Initialize pack objects for A that are passed into packm_init().
56 if( thread_am_ochief( thread ) ) {
57 bli_obj_init_pack( &a_pack_s );
59 // Initialize object for packing A.
60 bli_packm_init( a, &a_pack_s,
61 cntl_sub_packm_a( cntl ) );
63 // Scale C by beta (if instructed).
64 bli_scalm_int( &BLIS_ONE,
65 c,
66 cntl_sub_scalm( cntl ) );
67 }
68 a_pack = thread_obroadcast( thread, &a_pack_s );
70 // Initialize pack objects for B and C that are passed into packm_init().
71 if( thread_am_ichief( thread ) ) {
72 bli_obj_init_pack( &b1_pack_s );
73 bli_obj_init_pack( &c1_pack_s );
74 }
75 b1_pack = thread_ibroadcast( thread, &b1_pack_s );
76 c1_pack = thread_ibroadcast( thread, &c1_pack_s );
78 // Pack A (if instructed).
79 bli_packm_int( a, a_pack,
80 cntl_sub_packm_a( cntl ),
81 trmm_thread_sub_opackm( thread ) );
83 // Query dimension in partitioning direction.
84 n_trans = bli_obj_width_after_trans( *b );
85 dim_t start, end;
86 num_t datatype = bli_obj_execution_datatype( *a );
87 bli_get_range( thread, 0, n_trans,
88 bli_lcm( bli_info_get_default_nr( datatype ), bli_info_get_default_mr( datatype ) ),
89 &start, &end );
91 // Partition along the n dimension.
92 for ( i = start; i < end; i += b_alg )
93 {
94 // Determine the current algorithmic blocksize.
95 b_alg = bli_determine_blocksize_f( i, end, b,
96 cntl_blocksize( cntl ) );
98 // Acquire partitions for B1 and C1.
99 bli_acquire_mpart_l2r( BLIS_SUBPART1,
100 i, b_alg, b, &b1 );
101 bli_acquire_mpart_l2r( BLIS_SUBPART1,
102 i, b_alg, c, &c1 );
104 // Initialize objects for packing A1 and B1.
105 if( thread_am_ichief( thread ) ) {
106 bli_packm_init( &b1, b1_pack,
107 cntl_sub_packm_b( cntl ) );
108 bli_packm_init( &c1, c1_pack,
109 cntl_sub_packm_c( cntl ) );
110 }
111 thread_ibarrier( thread );
113 // Pack B1 (if instructed).
114 bli_packm_int( &b1, b1_pack,
115 cntl_sub_packm_b( cntl ),
116 trsm_thread_sub_ipackm( thread ) );
118 // Pack C1 (if instructed).
119 bli_packm_int( &c1, c1_pack,
120 cntl_sub_packm_c( cntl ),
121 trsm_thread_sub_ipackm( thread ) );
123 // Perform trsm subproblem.
124 bli_trsm_int( &BLIS_ONE,
125 a_pack,
126 b1_pack,
127 &BLIS_ONE,
128 c1_pack,
129 cntl_sub_trsm( cntl ),
130 trsm_thread_sub_trsm( thread ) );
132 // Unpack C1 (if C1 was packed).
133 bli_unpackm_int( c1_pack, &c1,
134 cntl_sub_unpackm_c( cntl ),
135 trsm_thread_sub_ipackm( thread ) );
136 }
138 // If any packing buffers were acquired within packm, release them back
139 // to the memory manager.
140 thread_obarrier( thread );
141 if( thread_am_ochief( thread ) )
142 bli_obj_release_pack( a_pack, cntl_sub_packm_a(cntl) );
143 if( thread_am_ichief( thread ) ) {
144 bli_obj_release_pack( b1_pack, cntl_sub_packm_b(cntl) );
145 bli_obj_release_pack( c1_pack, cntl_sub_packm_c(cntl));
146 }
147 }