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_gemm_blk_var2f( obj_t* a,
38 obj_t* b,
39 obj_t* c,
40 gemm_t* cntl,
41 gemm_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 // printf("blk var 2\n");
57 if( thread_am_ochief( thread ) ) {
58 // Initialize object for packing A
59 bli_obj_init_pack( &a_pack_s );
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 gemm_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 // bli_get_range( thread, 0, n_trans,
87 // bli_determine_reg_blocksize( b, cntl_blocksize( cntl ) ),
88 // &start, &end );
90 bli_get_range_l2r( thread, 0, n_trans,
91 bli_determine_reg_blocksize( b, cntl_blocksize( cntl ) ),
92 &start, &end );
94 // Partition along the n dimension.
95 for ( i = start; i < end; i += b_alg )
96 {
97 // Determine the current algorithmic blocksize.
98 // NOTE: Use of b (for execution datatype) is intentional!
99 // This causes the right blocksize to be used if c and a are
100 // complex and b is real.
101 b_alg = bli_determine_blocksize_f( i, end, b,
102 cntl_blocksize( cntl ) );
104 // Acquire partitions for B1 and C1.
105 bli_acquire_mpart_l2r( BLIS_SUBPART1,
106 i, b_alg, b, &b1 );
107 bli_acquire_mpart_l2r( BLIS_SUBPART1,
108 i, b_alg, c, &c1 );
110 // Initialize objects for packing A1 and B1.
111 if( thread_am_ichief( thread ) ) {
112 bli_packm_init( &b1, b1_pack,
113 cntl_sub_packm_b( cntl ) );
114 bli_packm_init( &c1, c1_pack,
115 cntl_sub_packm_c( cntl ) );
116 }
117 thread_ibarrier( thread );
119 // Pack B1 (if instructed).
120 bli_packm_int( &b1, b1_pack,
121 cntl_sub_packm_b( cntl ),
122 gemm_thread_sub_ipackm( thread ) );
124 // Pack C1 (if instructed).
125 bli_packm_int( &c1, c1_pack,
126 cntl_sub_packm_c( cntl ),
127 gemm_thread_sub_ipackm( thread ) );
129 // Perform gemm subproblem.
130 bli_gemm_int( &BLIS_ONE,
131 a_pack,
132 b1_pack,
133 &BLIS_ONE,
134 c1_pack,
135 cntl_sub_gemm( cntl ),
136 gemm_thread_sub_gemm( thread ) );
138 // Unpack C1 (if C1 was packed).
139 // Currently must be done by 1 thread
140 bli_unpackm_int( c1_pack, &c1,
141 cntl_sub_unpackm_c( cntl ),
142 gemm_thread_sub_ipackm( thread ) );
143 }
145 // If any packing buffers were acquired within packm, release them back
146 // to the memory manager.
147 thread_obarrier( thread );
148 if( thread_am_ochief( thread ) )
149 bli_obj_release_pack( a_pack, cntl_sub_packm_a( cntl ) );
150 if( thread_am_ichief( thread ) ) {
151 bli_obj_release_pack( b1_pack, cntl_sub_packm_b( cntl ) );
152 bli_obj_release_pack( c1_pack, cntl_sub_packm_c( cntl ) );
153 }
154 // printf("blk var 2 done\n");
155 }