Debian Codegraph @

frame/3/old/bli_l3_sup_var1n2m.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) 2019, Advanced Micro Devices, Inc.
8
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(s) of the copyright holder(s) nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
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.
32
33 */
34
35 #include "blis.h"
36
37 #define FUNCPTR_T gemmsup_fp
38
39 typedef void (*FUNCPTR_T)
40 (
41 conj_t conja,
42 conj_t conjb,
43 dim_t m,
44 dim_t n,
45 dim_t k,
46 void* restrict alpha,
47 void* restrict a, inc_t rs_a, inc_t cs_a,
48 void* restrict b, inc_t rs_b, inc_t cs_b,
49 void* restrict beta,
50 void* restrict c, inc_t rs_c, inc_t cs_c,
51 stor3_t eff_id,
52 cntx_t* restrict cntx,
53 rntm_t* restrict rntm,
54 cntl_t* restrict cntl,
55 thrinfo_t* restrict thread
56 );
57
58 //
59 // -- var1n --------------------------------------------------------------------
60 //
61
62 static FUNCPTR_T GENARRAY(ftypes_var1n,gemmsup_ref_var1n);
63
64 void bli_gemmsup_ref_var1n
65 (
66 trans_t trans,
67 obj_t* alpha,
68 obj_t* a,
69 obj_t* b,
70 obj_t* beta,
71 obj_t* c,
72 stor3_t eff_id,
73 cntx_t* cntx,
74 rntm_t* rntm,
75 cntl_t* cntl,
76 thrinfo_t* thread
77 )
78 {
79 #if 0
80 obj_t at, bt;
81
82 bli_obj_alias_to( a, &at );
83 bli_obj_alias_to( b, &bt );
84
85 // Induce transpositions on A and/or B if either object is marked for
86 // transposition. We can induce "fast" transpositions since they objects
87 // are guaranteed to not have structure or be packed.
88 if ( bli_obj_has_trans( &at ) ) { bli_obj_induce_fast_trans( &at ); }
89 if ( bli_obj_has_trans( &bt ) ) { bli_obj_induce_fast_trans( &bt ); }
90
91 const num_t dt_exec = bli_obj_dt( c );
92
93 const conj_t conja = bli_obj_conj_status( a );
94 const conj_t conjb = bli_obj_conj_status( b );
95
96 const dim_t m = bli_obj_length( c );
97 const dim_t n = bli_obj_width( c );
98
99 const dim_t k = bli_obj_width( &at );
100
101 void* restrict buf_a = bli_obj_buffer_at_off( &at );
102 const inc_t rs_a = bli_obj_row_stride( &at );
103 const inc_t cs_a = bli_obj_col_stride( &at );
104
105 void* restrict buf_b = bli_obj_buffer_at_off( &bt );
106 const inc_t rs_b = bli_obj_row_stride( &bt );
107 const inc_t cs_b = bli_obj_col_stride( &bt );
108
109 void* restrict buf_c = bli_obj_buffer_at_off( c );
110 const inc_t rs_c = bli_obj_row_stride( c );
111 const inc_t cs_c = bli_obj_col_stride( c );
112
113 void* restrict buf_alpha = bli_obj_buffer_for_1x1( dt_exec, alpha );
114 void* restrict buf_beta = bli_obj_buffer_for_1x1( dt_exec, beta );
115
116 #else
117
118 const num_t dt_exec = bli_obj_dt( c );
119
120 const conj_t conja = bli_obj_conj_status( a );
121 const conj_t conjb = bli_obj_conj_status( b );
122
123 const dim_t m = bli_obj_length( c );
124 const dim_t n = bli_obj_width( c );
125 dim_t k;
126
127 void* restrict buf_a = bli_obj_buffer_at_off( a );
128 inc_t rs_a;
129 inc_t cs_a;
130
131 void* restrict buf_b = bli_obj_buffer_at_off( b );
132 inc_t rs_b;
133 inc_t cs_b;
134
135 if ( bli_obj_has_notrans( a ) )
136 {
137 k = bli_obj_width( a );
138
139 rs_a = bli_obj_row_stride( a );
140 cs_a = bli_obj_col_stride( a );
141 }
142 else // if ( bli_obj_has_trans( a ) )
143 {
144 // Assign the variables with an implicit transposition.
145 k = bli_obj_length( a );
146
147 rs_a = bli_obj_col_stride( a );
148 cs_a = bli_obj_row_stride( a );
149 }
150
151 if ( bli_obj_has_notrans( b ) )
152 {
153 rs_b = bli_obj_row_stride( b );
154 cs_b = bli_obj_col_stride( b );
155 }
156 else // if ( bli_obj_has_trans( b ) )
157 {
158 // Assign the variables with an implicit transposition.
159 rs_b = bli_obj_col_stride( b );
160 cs_b = bli_obj_row_stride( b );
161 }
162
163 void* restrict buf_c = bli_obj_buffer_at_off( c );
164 const inc_t rs_c = bli_obj_row_stride( c );
165 const inc_t cs_c = bli_obj_col_stride( c );
166
167 void* restrict buf_alpha = bli_obj_buffer_for_1x1( dt_exec, alpha );
168 void* restrict buf_beta = bli_obj_buffer_for_1x1( dt_exec, beta );
169
170 #endif
171
172 // Index into the type combination array to extract the correct
173 // function pointer.
174 FUNCPTR_T f = ftypes_var1n[dt_exec];
175
176 if ( bli_is_notrans( trans ) )
177 {
178 // Invoke the function.
179 f
180 (
181 conja,
182 conjb,
183 m,
184 n,
185 k,
186 buf_alpha,
187 buf_a, rs_a, cs_a,
188 buf_b, rs_b, cs_b,
189 buf_beta,
190 buf_c, rs_c, cs_c,
191 eff_id,
192 cntx,
193 rntm,
194 cntl,
195 thread
196 );
197 }
198 else
199 {
200 // Invoke the function (transposing the operation).
201 f
202 (
203 conjb, // swap the conj values.
204 conja,
205 n, // swap the m and n dimensions.
206 m,
207 k,
208 buf_alpha,
209 buf_b, cs_b, rs_b, // swap the positions of A and B.
210 buf_a, cs_a, rs_a, // swap the strides of A and B.
211 buf_beta,
212 buf_c, cs_c, rs_c, // swap the strides of C.
213 bli_stor3_trans( eff_id ), // transpose the stor3_t id.
214 cntx,
215 rntm,
216 cntl,
217 thread
218 );
219 }
220 }
221
222
223 #undef GENTFUNC
224 #define GENTFUNC( ctype, ch, varname ) \
225 \
226 void PASTEMAC(ch,varname) \
227 ( \
228 conj_t conja, \
229 conj_t conjb, \
230 dim_t m, \
231 dim_t n, \
232 dim_t k, \
233 void* restrict alpha, \
234 void* restrict a, inc_t rs_a, inc_t cs_a, \
235 void* restrict b, inc_t rs_b, inc_t cs_b, \
236 void* restrict beta, \
237 void* restrict c, inc_t rs_c, inc_t cs_c, \
238 stor3_t stor_id, \
239 cntx_t* restrict cntx, \
240 rntm_t* restrict rntm, \
241 cntl_t* restrict cntl, \
242 thrinfo_t* restrict thread \
243 ) \
244 { \
245 /* If m or n is zero, return immediately. */ \
246 if ( bli_zero_dim2( m, n ) ) return; \
247 \
248 /* If k < 1 or alpha is zero, scale by beta and return. */ \
249 if ( k < 1 || PASTEMAC(ch,eq0)( *(( ctype* )alpha) ) ) \
250 { \
251 PASTEMAC(ch,scalm) \
252 ( \
253 BLIS_NO_CONJUGATE, \
254 0, \
255 BLIS_NONUNIT_DIAG, \
256 BLIS_DENSE, \
257 m, n, \
258 beta, \
259 c, rs_c, cs_c \
260 ); \
261 return; \
262 } \
263 \
264 const num_t dt = PASTEMAC(ch,type); \
265 \
266 /* This transposition of the stor3_t id value is inherent to variant 1.
267 The reason: we assume that variant 2 is the "main" variant. The
268 consequence of this is that we assume that the millikernels that
269 iterate over m are registered to the kernel group associated with
270 the kernel preference. So, regardless of whether the mkernels are
271 row- or column-preferential, millikernels that iterate over n are
272 always placed in the slots for the opposite kernel group. */ \
273 stor_id = bli_stor3_trans( stor_id ); \
274 \
275 /* Query the context for various blocksizes. */ \
276 const dim_t NR = bli_cntx_get_l3_sup_blksz_def_dt( dt, BLIS_NR, cntx ); \
277 const dim_t MR = bli_cntx_get_l3_sup_blksz_def_dt( dt, BLIS_MR, cntx ); \
278 const dim_t NC0 = bli_cntx_get_l3_sup_blksz_def_dt( dt, BLIS_NC, cntx ); \
279 const dim_t MC0 = bli_cntx_get_l3_sup_blksz_def_dt( dt, BLIS_MC, cntx ); \
280 const dim_t KC0 = bli_cntx_get_l3_sup_blksz_def_dt( dt, BLIS_KC, cntx ); \
281 \
282 dim_t KC; \
283 if ( FALSE ) KC = KC0; \
284 else if ( stor_id == BLIS_RRC || \
285 stor_id == BLIS_CRC ) KC = KC0; \
286 else if ( m <= MR && n <= NR ) KC = KC0; \
287 else if ( m <= 2*MR && n <= 2*NR ) KC = KC0 / 2; \
288 else if ( m <= 3*MR && n <= 3*NR ) KC = (( KC0 / 3 ) / 4 ) * 4; \
289 else if ( m <= 4*MR && n <= 4*NR ) KC = KC0 / 4; \
290 else KC = (( KC0 / 5 ) / 4 ) * 4; \
291 \
292 /* Nudge NC up to a multiple of MR and MC up to a multiple of NR. */ \
293 const dim_t NC = bli_align_dim_to_mult( NC0, MR ); \
294 const dim_t MC = bli_align_dim_to_mult( MC0, NR ); \
295 \
296 /* Query the maximum blocksize for MR, which implies a maximum blocksize
297 extension for the final iteration. */ \
298 const dim_t MRM = bli_cntx_get_l3_sup_blksz_max_dt( dt, BLIS_MR, cntx ); \
299 const dim_t MRE = MRM - MR; \
300 \
301 /* Compute partitioning step values for each matrix of each loop. */ \
302 const inc_t jcstep_c = rs_c * NC; \
303 const inc_t jcstep_a = rs_a * NC; \
304 \
305 const inc_t pcstep_a = cs_a * KC; \
306 const inc_t pcstep_b = rs_b * KC; \
307 \
308 const inc_t icstep_c = cs_c * MC; \
309 const inc_t icstep_b = cs_b * MC; \
310 \
311 const inc_t jrstep_c = rs_c * MR; \
312 const inc_t jrstep_a = rs_a * MR; \
313 \
314 /*
315 const inc_t irstep_c = cs_c * NR; \
316 const inc_t irstep_b = cs_b * NR; \
317 */ \
318 \
319 /* Query the context for the sup microkernel address and cast it to its
320 function pointer type. */ \
321 PASTECH(ch,gemmsup_ker_ft) \
322 gemmsup_ker = bli_cntx_get_l3_sup_ker_dt( dt, stor_id, cntx ); \
323 \
324 ctype* restrict a_00 = a; \
325 ctype* restrict b_00 = b; \
326 ctype* restrict c_00 = c; \
327 ctype* restrict alpha_cast = alpha; \
328 ctype* restrict beta_cast = beta; \
329 \
330 ctype* restrict one = PASTEMAC(ch,1); \
331 \
332 auxinfo_t aux; \
333 \
334 /* Compute number of primary and leftover components of the outer
335 dimensions.
336 NOTE: Functionally speaking, we compute jc_iter as:
337 jc_iter = m / NC; if ( jc_left ) ++jc_iter;
338 However, this is implemented as:
339 jc_iter = ( m + NC - 1 ) / NC;
340 This avoids a branch at the cost of two additional integer instructions.
341 The pc_iter, mc_iter, nr_iter, and mr_iter variables are computed in
342 similar manner. */ \
343 const dim_t jc_iter = ( m + NC - 1 ) / NC; \
344 const dim_t jc_left = m % NC; \
345 \
346 const dim_t pc_iter = ( k + KC - 1 ) / KC; \
347 const dim_t pc_left = k % KC; \
348 \
349 const dim_t ic_iter = ( n + MC - 1 ) / MC; \
350 const dim_t ic_left = n % MC; \
351 \
352 const dim_t jc_inc = 1; \
353 const dim_t pc_inc = 1; \
354 const dim_t ic_inc = 1; \
355 const dim_t jr_inc = 1; \
356 /*
357 const dim_t ir_inc = 1; \
358 */ \
359 \
360 /* Loop over the m dimension (NC rows/columns at a time). */ \
361 for ( dim_t jj = 0; jj < jc_iter; jj += jc_inc ) \
362 { \
363 const dim_t nc_cur = ( bli_is_not_edge_f( jj, jc_iter, jc_left ) ? NC : jc_left ); \
364 \
365 ctype* restrict a_jc = a_00 + jj * jcstep_a; \
366 ctype* restrict c_jc = c_00 + jj * jcstep_c; \
367 \
368 dim_t jr_iter = ( nc_cur + MR - 1 ) / MR; \
369 dim_t jr_left = nc_cur % MR; \
370 \
371 /* An optimization: allow the last jr iteration to contain up to MRE
372 rows of C and A. (If MRE > MR, the mkernel has agreed to handle
373 these cases.) Note that this prevents us from declaring jr_iter and
374 jr_left as const. */ \
375 if ( 1 ) \
376 if ( MRE != 0 && 1 < jr_iter && jr_left != 0 && jr_left <= MRE ) \
377 { \
378 jr_iter--; jr_left += MR; \
379 } \
380 \
381 /* Loop over the k dimension (KC rows/columns at a time). */ \
382 for ( dim_t pp = 0; pp < pc_iter; pp += pc_inc ) \
383 { \
384 const dim_t kc_cur = ( bli_is_not_edge_f( pp, pc_iter, pc_left ) ? KC : pc_left ); \
385 \
386 ctype* restrict a_pc = a_jc + pp * pcstep_a; \
387 ctype* restrict b_pc = b_00 + pp * pcstep_b; \
388 \
389 /* Only apply beta to the first iteration of the pc loop. */ \
390 ctype* restrict beta_use = ( pp == 0 ? beta_cast : one ); \
391 \
392 /* Loop over the n dimension (MC rows at a time). */ \
393 for ( dim_t ii = 0; ii < ic_iter; ii += ic_inc ) \
394 { \
395 const dim_t mc_cur = ( bli_is_not_edge_f( ii, ic_iter, ic_left ) ? MC : ic_left ); \
396 \
397 ctype* restrict b_ic = b_pc + ii * icstep_b; \
398 ctype* restrict c_ic = c_jc + ii * icstep_c; \
399 \
400 /*
401 const dim_t ir_iter = ( mc_cur + NR - 1 ) / NR; \
402 const dim_t ir_left = mc_cur % NR; \
403 */ \
404 \
405 /* Loop over the m dimension (NR columns at a time). */ \
406 for ( dim_t j = 0; j < jr_iter; j += jr_inc ) \
407 { \
408 const dim_t nr_cur = ( bli_is_not_edge_f( j, jr_iter, jr_left ) ? MR : jr_left ); \
409 \
410 ctype* restrict a_jr = a_pc + j * jrstep_a; \
411 ctype* restrict c_jr = c_ic + j * jrstep_c; \
412 \
413 /* Loop over the n dimension (MR rows at a time). */ \
414 { \
415 /* Invoke the gemmsup millikernel. */ \
416 gemmsup_ker \
417 ( \
418 conja, \
419 conjb, \
420 nr_cur, /* Notice: nr_cur <= MR. */ \
421 mc_cur, /* Recall: mc_cur partitions the n dimension! */ \
422 kc_cur, \
423 alpha_cast, \
424 a_jr, rs_a, cs_a, \
425 b_ic, rs_b, cs_b, \
426 beta_use, \
427 c_jr, rs_c, cs_c, \
428 &aux, \
429 cntx \
430 ); \
431 } \
432 } \
433 } \
434 } \
435 } \
436 \
437 /*
438 PASTEMAC(ch,fprintm)( stdout, "gemmsup_ref_var2: b1", kc_cur, nr_cur, b_jr, rs_b, cs_b, "%4.1f", "" ); \
439 PASTEMAC(ch,fprintm)( stdout, "gemmsup_ref_var2: a1", mr_cur, kc_cur, a_ir, rs_a, cs_a, "%4.1f", "" ); \
440 PASTEMAC(ch,fprintm)( stdout, "gemmsup_ref_var2: c ", mr_cur, nr_cur, c_ir, rs_c, cs_c, "%4.1f", "" ); \
441 */ \
442 }
443
444 INSERT_GENTFUNC_BASIC0( gemmsup_ref_var1n )
445
446
447 //
448 // -- var2m --------------------------------------------------------------------
449 //
450
451 static FUNCPTR_T GENARRAY(ftypes_var2m,gemmsup_ref_var2m);
452
453 void bli_gemmsup_ref_var2m
454 (
455 trans_t trans,
456 obj_t* alpha,
457 obj_t* a,
458 obj_t* b,
459 obj_t* beta,
460 obj_t* c,
461 stor3_t eff_id,
462 cntx_t* cntx,
463 rntm_t* rntm,
464 cntl_t* cntl,
465 thrinfo_t* thread
466 )
467 {
468 #if 0
469 obj_t at, bt;
470
471 bli_obj_alias_to( a, &at );
472 bli_obj_alias_to( b, &bt );
473
474 // Induce transpositions on A and/or B if either object is marked for
475 // transposition. We can induce "fast" transpositions since they objects
476 // are guaranteed to not have structure or be packed.
477 if ( bli_obj_has_trans( &at ) ) { bli_obj_induce_fast_trans( &at ); }
478 if ( bli_obj_has_trans( &bt ) ) { bli_obj_induce_fast_trans( &bt ); }
479
480 const num_t dt_exec = bli_obj_dt( c );
481
482 const conj_t conja = bli_obj_conj_status( a );
483 const conj_t conjb = bli_obj_conj_status( b );
484
485 const dim_t m = bli_obj_length( c );
486 const dim_t n = bli_obj_width( c );
487
488 const dim_t k = bli_obj_width( &at );
489
490 void* restrict buf_a = bli_obj_buffer_at_off( &at );
491 const inc_t rs_a = bli_obj_row_stride( &at );
492 const inc_t cs_a = bli_obj_col_stride( &at );
493
494 void* restrict buf_b = bli_obj_buffer_at_off( &bt );
495 const inc_t rs_b = bli_obj_row_stride( &bt );
496 const inc_t cs_b = bli_obj_col_stride( &bt );
497
498 void* restrict buf_c = bli_obj_buffer_at_off( c );
499 const inc_t rs_c = bli_obj_row_stride( c );
500 const inc_t cs_c = bli_obj_col_stride( c );
501
502 void* restrict buf_alpha = bli_obj_buffer_for_1x1( dt_exec, alpha );
503 void* restrict buf_beta = bli_obj_buffer_for_1x1( dt_exec, beta );
504
505 #else
506 const num_t dt_exec = bli_obj_dt( c );
507
508 const conj_t conja = bli_obj_conj_status( a );
509 const conj_t conjb = bli_obj_conj_status( b );
510
511 const dim_t m = bli_obj_length( c );
512 const dim_t n = bli_obj_width( c );
513 dim_t k;
514
515 void* restrict buf_a = bli_obj_buffer_at_off( a );
516 inc_t rs_a;
517 inc_t cs_a;
518
519 void* restrict buf_b = bli_obj_buffer_at_off( b );
520 inc_t rs_b;
521 inc_t cs_b;
522
523 if ( bli_obj_has_notrans( a ) )
524 {
525 k = bli_obj_width( a );
526
527 rs_a = bli_obj_row_stride( a );
528 cs_a = bli_obj_col_stride( a );
529 }
530 else // if ( bli_obj_has_trans( a ) )
531 {
532 // Assign the variables with an implicit transposition.
533 k = bli_obj_length( a );
534
535 rs_a = bli_obj_col_stride( a );
536 cs_a = bli_obj_row_stride( a );
537 }
538
539 if ( bli_obj_has_notrans( b ) )
540 {
541 rs_b = bli_obj_row_stride( b );
542 cs_b = bli_obj_col_stride( b );
543 }
544 else // if ( bli_obj_has_trans( b ) )
545 {
546 // Assign the variables with an implicit transposition.
547 rs_b = bli_obj_col_stride( b );
548 cs_b = bli_obj_row_stride( b );
549 }
550
551 void* restrict buf_c = bli_obj_buffer_at_off( c );
552 const inc_t rs_c = bli_obj_row_stride( c );
553 const inc_t cs_c = bli_obj_col_stride( c );
554
555 void* restrict buf_alpha = bli_obj_buffer_for_1x1( dt_exec, alpha );
556 void* restrict buf_beta = bli_obj_buffer_for_1x1( dt_exec, beta );
557
558 #endif
559
560 // Index into the type combination array to extract the correct
561 // function pointer.
562 FUNCPTR_T f = ftypes_var2m[dt_exec];
563
564 if ( bli_is_notrans( trans ) )
565 {
566 // Invoke the function.
567 f
568 (
569 conja,
570 conjb,
571 m,
572 n,
573 k,
574 buf_alpha,
575 buf_a, rs_a, cs_a,
576 buf_b, rs_b, cs_b,
577 buf_beta,
578 buf_c, rs_c, cs_c,
579 eff_id,
580 cntx,
581 rntm,
582 cntl,
583 thread
584 );
585 }
586 else
587 {
588 // Invoke the function (transposing the operation).
589 f
590 (
591 conjb, // swap the conj values.
592 conja,
593 n, // swap the m and n dimensions.
594 m,
595 k,
596 buf_alpha,
597 buf_b, cs_b, rs_b, // swap the positions of A and B.
598 buf_a, cs_a, rs_a, // swap the strides of A and B.
599 buf_beta,
600 buf_c, cs_c, rs_c, // swap the strides of C.
601 bli_stor3_trans( eff_id ), // transpose the stor3_t id.
602 cntx,
603 rntm,
604 cntl,
605 thread
606 );
607 }
608 }
609
610
611 #undef GENTFUNC
612 #define GENTFUNC( ctype, ch, varname ) \
613 \
614 void PASTEMAC(ch,varname) \
615 ( \
616 conj_t conja, \
617 conj_t conjb, \
618 dim_t m, \
619 dim_t n, \
620 dim_t k, \
621 void* restrict alpha, \
622 void* restrict a, inc_t rs_a, inc_t cs_a, \
623 void* restrict b, inc_t rs_b, inc_t cs_b, \
624 void* restrict beta, \
625 void* restrict c, inc_t rs_c, inc_t cs_c, \
626 stor3_t stor_id, \
627 cntx_t* restrict cntx, \
628 rntm_t* restrict rntm, \
629 cntl_t* restrict cntl, \
630 thrinfo_t* restrict thread \
631 ) \
632 { \
633 /* If m or n is zero, return immediately. */ \
634 if ( bli_zero_dim2( m, n ) ) return; \
635 \
636 /* If k < 1 or alpha is zero, scale by beta and return. */ \
637 if ( k < 1 || PASTEMAC(ch,eq0)( *(( ctype* )alpha) ) ) \
638 { \
639 PASTEMAC(ch,scalm) \
640 ( \
641 BLIS_NO_CONJUGATE, \
642 0, \
643 BLIS_NONUNIT_DIAG, \
644 BLIS_DENSE, \
645 m, n, \
646 beta, \
647 c, rs_c, cs_c \
648 ); \
649 return; \
650 } \
651 \
652 const num_t dt = PASTEMAC(ch,type); \
653 \
654 /* Query the context for various blocksizes. */ \
655 const dim_t NR = bli_cntx_get_l3_sup_blksz_def_dt( dt, BLIS_NR, cntx ); \
656 const dim_t MR = bli_cntx_get_l3_sup_blksz_def_dt( dt, BLIS_MR, cntx ); \
657 const dim_t NC = bli_cntx_get_l3_sup_blksz_def_dt( dt, BLIS_NC, cntx ); \
658 const dim_t MC = bli_cntx_get_l3_sup_blksz_def_dt( dt, BLIS_MC, cntx ); \
659 const dim_t KC0 = bli_cntx_get_l3_sup_blksz_def_dt( dt, BLIS_KC, cntx ); \
660 \
661 dim_t KC; \
662 if ( stor_id == BLIS_RRR || \
663 stor_id == BLIS_CCC ) KC = KC0; \
664 else if ( stor_id == BLIS_RRC || \
665 stor_id == BLIS_CRC ) KC = KC0; \
666 else if ( m <= MR && n <= NR ) KC = KC0; \
667 else if ( m <= 2*MR && n <= 2*NR ) KC = KC0 / 2; \
668 else if ( m <= 3*MR && n <= 3*NR ) KC = (( KC0 / 3 ) / 4 ) * 4; \
669 else if ( m <= 4*MR && n <= 4*NR ) KC = KC0 / 4; \
670 else KC = (( KC0 / 5 ) / 4 ) * 4; \
671 \
672 /* Query the maximum blocksize for NR, which implies a maximum blocksize
673 extension for the final iteration. */ \
674 const dim_t NRM = bli_cntx_get_l3_sup_blksz_max_dt( dt, BLIS_NR, cntx ); \
675 const dim_t NRE = NRM - NR; \
676 \
677 /* Compute partitioning step values for each matrix of each loop. */ \
678 const inc_t jcstep_c = cs_c * NC; \
679 const inc_t jcstep_b = cs_b * NC; \
680 \
681 const inc_t pcstep_a = cs_a * KC; \
682 const inc_t pcstep_b = rs_b * KC; \
683 \
684 const inc_t icstep_c = rs_c * MC; \
685 const inc_t icstep_a = rs_a * MC; \
686 \
687 const inc_t jrstep_c = cs_c * NR; \
688 const inc_t jrstep_b = cs_b * NR; \
689 \
690 /*
691 const inc_t irstep_c = rs_c * MR; \
692 const inc_t irstep_a = rs_a * MR; \
693 */ \
694 \
695 /* Query the context for the sup microkernel address and cast it to its
696 function pointer type. */ \
697 PASTECH(ch,gemmsup_ker_ft) \
698 gemmsup_ker = bli_cntx_get_l3_sup_ker_dt( dt, stor_id, cntx ); \
699 \
700 ctype* restrict a_00 = a; \
701 ctype* restrict b_00 = b; \
702 ctype* restrict c_00 = c; \
703 ctype* restrict alpha_cast = alpha; \
704 ctype* restrict beta_cast = beta; \
705 \
706 ctype* restrict one = PASTEMAC(ch,1); \
707 \
708 auxinfo_t aux; \
709 \
710 /* Compute number of primary and leftover components of the outer
711 dimensions.
712 NOTE: Functionally speaking, we compute jc_iter as:
713 jc_iter = n / NC; if ( jc_left ) ++jc_iter;
714 However, this is implemented as:
715 jc_iter = ( n + NC - 1 ) / NC;
716 This avoids a branch at the cost of two additional integer instructions.
717 The pc_iter, mc_iter, nr_iter, and mr_iter variables are computed in
718 similar manner. */ \
719 const dim_t jc_iter = ( n + NC - 1 ) / NC; \
720 const dim_t jc_left = n % NC; \
721 \
722 const dim_t pc_iter = ( k + KC - 1 ) / KC; \
723 const dim_t pc_left = k % KC; \
724 \
725 const dim_t ic_iter = ( m + MC - 1 ) / MC; \
726 const dim_t ic_left = m % MC; \
727 \
728 const dim_t jc_inc = 1; \
729 const dim_t pc_inc = 1; \
730 const dim_t ic_inc = 1; \
731 const dim_t jr_inc = 1; \
732 /*
733 const dim_t ir_inc = 1; \
734 */ \
735 \
736 /* Loop over the n dimension (NC rows/columns at a time). */ \
737 for ( dim_t jj = 0; jj < jc_iter; jj += jc_inc ) \
738 { \
739 const dim_t nc_cur = ( bli_is_not_edge_f( jj, jc_iter, jc_left ) ? NC : jc_left ); \
740 \
741 ctype* restrict b_jc = b_00 + jj * jcstep_b; \
742 ctype* restrict c_jc = c_00 + jj * jcstep_c; \
743 \
744 dim_t jr_iter = ( nc_cur + NR - 1 ) / NR; \
745 dim_t jr_left = nc_cur % NR; \
746 \
747 /* An optimization: allow the last jr iteration to contain up to NRE
748 columns of C and B. (If NRE > NR, the mkernel has agreed to handle
749 these cases.) Note that this prevents us from declaring jr_iter and
750 jr_left as const. */ \
751 if ( 1 ) \
752 if ( NRE != 0 && 1 < jr_iter && jr_left != 0 && jr_left <= NRE ) \
753 { \
754 jr_iter--; jr_left += NR; \
755 } \
756 \
757 /* Loop over the k dimension (KC rows/columns at a time). */ \
758 for ( dim_t pp = 0; pp < pc_iter; pp += pc_inc ) \
759 { \
760 const dim_t kc_cur = ( bli_is_not_edge_f( pp, pc_iter, pc_left ) ? KC : pc_left ); \
761 \
762 ctype* restrict a_pc = a_00 + pp * pcstep_a; \
763 ctype* restrict b_pc = b_jc + pp * pcstep_b; \
764 \
765 /* Only apply beta to the first iteration of the pc loop. */ \
766 ctype* restrict beta_use = ( pp == 0 ? beta_cast : one ); \
767 \
768 /* Loop over the m dimension (MC rows at a time). */ \
769 for ( dim_t ii = 0; ii < ic_iter; ii += ic_inc ) \
770 { \
771 const dim_t mc_cur = ( bli_is_not_edge_f( ii, ic_iter, ic_left ) ? MC : ic_left ); \
772 \
773 ctype* restrict a_ic = a_pc + ii * icstep_a; \
774 ctype* restrict c_ic = c_jc + ii * icstep_c; \
775 \
776 /*
777 const dim_t ir_iter = ( mc_cur + MR - 1 ) / MR; \
778 const dim_t ir_left = mc_cur % MR; \
779 */ \
780 \
781 /* Loop over the n dimension (NR columns at a time). */ \
782 for ( dim_t j = 0; j < jr_iter; j += jr_inc ) \
783 { \
784 const dim_t nr_cur = ( bli_is_not_edge_f( j, jr_iter, jr_left ) ? NR : jr_left ); \
785 \
786 ctype* restrict b_jr = b_pc + j * jrstep_b; \
787 ctype* restrict c_jr = c_ic + j * jrstep_c; \
788 \
789 /* Loop over the m dimension (MR rows at a time). */ \
790 { \
791 /* Invoke the gemmsup millikernel. */ \
792 gemmsup_ker \
793 ( \
794 conja, \
795 conjb, \
796 mc_cur, \
797 nr_cur, \
798 kc_cur, \
799 alpha_cast, \
800 a_ic, rs_a, cs_a, \
801 b_jr, rs_b, cs_b, \
802 beta_use, \
803 c_jr, rs_c, cs_c, \
804 &aux, \
805 cntx \
806 ); \
807 } \
808 } \
809 } \
810 } \
811 } \
812 \
813 /*
814 PASTEMAC(ch,fprintm)( stdout, "gemmsup_ref_var2: b1", kc_cur, nr_cur, b_jr, rs_b, cs_b, "%4.1f", "" ); \
815 PASTEMAC(ch,fprintm)( stdout, "gemmsup_ref_var2: a1", mr_cur, kc_cur, a_ir, rs_a, cs_a, "%4.1f", "" ); \
816 PASTEMAC(ch,fprintm)( stdout, "gemmsup_ref_var2: c ", mr_cur, nr_cur, c_ir, rs_c, cs_c, "%4.1f", "" ); \
817 */ \
818 }
819
820 INSERT_GENTFUNC_BASIC0( gemmsup_ref_var2m )
821