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"
36 #include "assert.h"
38 void bli_setup_herk_thrinfo_node( herk_thrinfo_t* thread,
39 thread_comm_t* ocomm, dim_t ocomm_id,
40 thread_comm_t* icomm, dim_t icomm_id,
41 dim_t n_way, dim_t work_id,
42 packm_thrinfo_t* opackm,
43 packm_thrinfo_t* ipackm,
44 herk_thrinfo_t* sub_herk )
45 {
46 thread->ocomm = ocomm;
47 thread->ocomm_id = ocomm_id;
48 thread->icomm = icomm;
49 thread->icomm_id = icomm_id;
50 thread->n_way = n_way;
51 thread->work_id = work_id;
52 thread->opackm = opackm;
53 thread->ipackm = ipackm;
54 thread->sub_herk = sub_herk;
55 }
57 void bli_setup_herk_single_threaded_info( herk_thrinfo_t* thread )
58 {
59 thread->ocomm = &BLIS_SINGLE_COMM;
60 thread->ocomm_id = 0;
61 thread->icomm = &BLIS_SINGLE_COMM;
62 thread->icomm_id = 0;
63 thread->n_way = 1;
64 thread->work_id = 0;
65 thread->opackm = &BLIS_PACKM_SINGLE_THREADED;
66 thread->ipackm = &BLIS_PACKM_SINGLE_THREADED;
67 thread->sub_herk = thread;
68 }
70 herk_thrinfo_t* bli_create_herk_thrinfo_node( thread_comm_t* ocomm, dim_t ocomm_id,
71 thread_comm_t* icomm, dim_t icomm_id,
72 dim_t n_way, dim_t work_id,
73 packm_thrinfo_t* opackm,
74 packm_thrinfo_t* ipackm,
75 herk_thrinfo_t* sub_herk )
76 {
77 herk_thrinfo_t* thread = ( herk_thrinfo_t* ) bli_malloc( sizeof( herk_thrinfo_t ) );
78 bli_setup_herk_thrinfo_node( thread, ocomm, ocomm_id,
79 icomm, icomm_id,
80 n_way, work_id,
81 opackm,
82 ipackm,
83 sub_herk );
84 return thread;
85 }
87 void bli_herk_thrinfo_free( herk_thrinfo_t* thread)
88 {
89 if( thread == NULL ) return;
91 // Free Communicators
92 if( thread_am_ochief( thread ) )
93 bli_free_communicator( thread->ocomm );
95 if (thread->sub_herk == NULL)
96 bli_free_communicator( thread->icomm );
98 // Free Sub Thrinfos
99 bli_packm_thrinfo_free( thread->opackm );
100 bli_packm_thrinfo_free( thread->ipackm );
101 bli_herk_thrinfo_free( thread->sub_herk );
102 bli_free( thread );
104 return;
105 }
106 void bli_herk_thrinfo_free_paths( herk_thrinfo_t** threads, dim_t num )
107 {
108 for( int i = 0; i < num; i++)
109 bli_herk_thrinfo_free( threads[i] );
110 bli_free( threads );
111 }
113 herk_thrinfo_t** bli_create_herk_thrinfo_paths( )
114 {
116 #ifdef BLIS_ENABLE_MULTITHREADING
117 dim_t jc_way = bli_read_nway_from_env( "BLIS_JC_NT" );
118 // dim_t kc_way = bli_read_nway_from_env( "BLIS_KC_NT" );
119 dim_t kc_way = 1;
120 dim_t ic_way = bli_read_nway_from_env( "BLIS_IC_NT" );
121 dim_t jr_way = bli_read_nway_from_env( "BLIS_JR_NT" );
122 dim_t ir_way = bli_read_nway_from_env( "BLIS_IR_NT" );
123 #else
124 dim_t jc_way = 1;
125 dim_t kc_way = 1;
126 dim_t ic_way = 1;
127 dim_t jr_way = 1;
128 dim_t ir_way = 1;
129 #endif
131 dim_t global_num_threads = jc_way * kc_way * ic_way * jr_way * ir_way;
132 assert( global_num_threads != 0 );
134 dim_t jc_nt = kc_way * ic_way * jr_way * ir_way;
135 dim_t kc_nt = ic_way * jr_way * ir_way;
136 dim_t ic_nt = jr_way * ir_way;
137 dim_t jr_nt = ir_way;
138 dim_t ir_nt = 1;
141 herk_thrinfo_t** paths = (herk_thrinfo_t**) bli_malloc( global_num_threads * sizeof( herk_thrinfo_t* ) );
143 thread_comm_t* global_comm = bli_create_communicator( global_num_threads );
144 for( int a = 0; a < jc_way; a++ )
145 {
146 thread_comm_t* jc_comm = bli_create_communicator( jc_nt );
147 for( int b = 0; b < kc_way; b++ )
148 {
149 thread_comm_t* kc_comm = bli_create_communicator( kc_nt );
150 for( int c = 0; c < ic_way; c++ )
151 {
152 thread_comm_t* ic_comm = bli_create_communicator( ic_nt );
153 for( int d = 0; d < jr_way; d++ )
154 {
155 thread_comm_t* jr_comm = bli_create_communicator( jr_nt );
156 for( int e = 0; e < ir_way; e++)
157 {
158 thread_comm_t* ir_comm = bli_create_communicator( ir_nt );
159 dim_t ir_comm_id = 0;
160 dim_t jr_comm_id = e*ir_nt + ir_comm_id;
161 dim_t ic_comm_id = d*jr_nt + jr_comm_id;
162 dim_t kc_comm_id = c*ic_nt + ic_comm_id;
163 dim_t jc_comm_id = b*kc_nt + kc_comm_id;
164 dim_t global_comm_id = a*jc_nt + jc_comm_id;
166 herk_thrinfo_t* ir_info = bli_create_herk_thrinfo_node( jr_comm, jr_comm_id,
167 ir_comm, ir_comm_id,
168 ir_way, e,
169 NULL, NULL, NULL);
171 herk_thrinfo_t* jr_info = bli_create_herk_thrinfo_node( ic_comm, ic_comm_id,
172 jr_comm, jr_comm_id,
173 jr_way, d,
174 NULL, NULL, ir_info);
176 /* packm_thrinfo_t* packb = bli_create_packm_thread_info( kc_comm, kc_comm_id,
177 ic_comm, ic_comm_id,
178 kc_nt, kc_comm_id );
180 packm_thrinfo_t* packa = bli_create_packm_thread_info( ic_comm, ic_comm_id,
181 jr_comm, jr_comm_id,
182 ic_nt, ic_comm_id );*/
184 //blk_var_1
185 packm_thrinfo_t* pack_ic_in = bli_create_packm_thread_info( ic_comm, ic_comm_id,
186 jr_comm, jr_comm_id,
187 ic_nt, ic_comm_id );
189 packm_thrinfo_t* pack_ic_out = bli_create_packm_thread_info( kc_comm, kc_comm_id,
190 ic_comm, ic_comm_id,
191 kc_nt, kc_comm_id );
193 herk_thrinfo_t* ic_info = bli_create_herk_thrinfo_node( kc_comm, kc_comm_id,
194 ic_comm, ic_comm_id,
195 ic_way, c,
196 pack_ic_out, pack_ic_in, jr_info);
198 packm_thrinfo_t* pack_kc_in = bli_create_packm_thread_info( kc_comm, kc_comm_id,
199 ic_comm, ic_comm_id,
200 kc_nt, kc_comm_id );
202 packm_thrinfo_t* pack_kc_out = bli_create_packm_thread_info( jc_comm, jc_comm_id,
203 jc_comm, jc_comm_id,
204 jc_nt, jc_comm_id );
207 herk_thrinfo_t* kc_info = bli_create_herk_thrinfo_node( jc_comm, jc_comm_id,
208 kc_comm, kc_comm_id,
209 kc_way, b,
210 pack_kc_out, pack_kc_in, ic_info);
211 //blk_var_2
212 packm_thrinfo_t* pack_jc_in = bli_create_packm_thread_info( jc_comm, jc_comm_id,
213 kc_comm, kc_comm_id,
214 jc_nt, jc_comm_id );
216 packm_thrinfo_t* pack_jc_out = bli_create_packm_thread_info( global_comm, global_comm_id,
217 jc_comm, jc_comm_id,
218 global_num_threads, global_comm_id );
221 herk_thrinfo_t* jc_info = bli_create_herk_thrinfo_node( global_comm, global_comm_id,
222 jc_comm, jc_comm_id,
223 jc_way, a,
224 pack_jc_out, pack_jc_in, kc_info);
226 paths[global_comm_id] = jc_info;
227 }
228 }
229 }
230 }
231 }
232 return paths;
233 }