File: bli_cntx.h

package info (click to toggle)
python-cython-blis 1.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 43,676 kB
  • sloc: ansic: 645,510; sh: 2,354; asm: 1,466; python: 821; cpp: 585; makefile: 14
file content (724 lines) | stat: -rw-r--r-- 21,693 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
/*

   BLIS
   An object-based framework for developing high-performance BLAS-like
   libraries.

   Copyright (C) 2014, The University of Texas at Austin
   Copyright (C) 2016, Hewlett Packard Enterprise Development LP
   Copyright (C) 2019, Advanced Micro Devices, Inc.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions are
   met:
    - Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    - Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    - Neither the name(s) of the copyright holder(s) nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

#ifndef BLIS_CNTX_H
#define BLIS_CNTX_H


// Context object type (defined in bli_type_defs.h)

/*
typedef struct cntx_s
{
	blksz_t*  blkszs;
	bszid_t*  bmults;

	func_t*   l3_vir_ukrs;
	func_t*   l3_nat_ukrs;
	mbool_t*  l3_nat_ukrs_prefs;

	blksz_t*  l3_sup_thresh;
	void**    l3_sup_handlers;
	blksz_t*  l3_sup_blkszs;
	func_t*   l3_sup_kers;
	mbool_t*  l3_sup_kers_prefs;

	func_t*   l1f_kers;
	func_t*   l1v_kers;

	func_t*   packm_kers;
	func_t*   unpackm_kers;

	ind_t     method;

} cntx_t;
*/

// -----------------------------------------------------------------------------

//
// -- cntx_t query (fields only) -----------------------------------------------
//

BLIS_INLINE blksz_t* bli_cntx_blkszs_buf( cntx_t* cntx )
{
	return cntx->blkszs;
}
BLIS_INLINE bszid_t* bli_cntx_bmults_buf( cntx_t* cntx )
{
	return cntx->bmults;
}
BLIS_INLINE func_t* bli_cntx_l3_vir_ukrs_buf( cntx_t* cntx )
{
	return cntx->l3_vir_ukrs;
}
BLIS_INLINE func_t* bli_cntx_l3_nat_ukrs_buf( cntx_t* cntx )
{
	return cntx->l3_nat_ukrs;
}
BLIS_INLINE mbool_t* bli_cntx_l3_nat_ukrs_prefs_buf( cntx_t* cntx )
{
	return cntx->l3_nat_ukrs_prefs;
}
BLIS_INLINE blksz_t* bli_cntx_l3_sup_thresh_buf( cntx_t* cntx )
{
	return cntx->l3_sup_thresh;
}
BLIS_INLINE void** bli_cntx_l3_sup_handlers_buf( cntx_t* cntx )
{
	return cntx->l3_sup_handlers;
}
BLIS_INLINE blksz_t* bli_cntx_l3_sup_blkszs_buf( cntx_t* cntx )
{
	return cntx->l3_sup_blkszs;
}
BLIS_INLINE func_t* bli_cntx_l3_sup_kers_buf( cntx_t* cntx )
{
	return cntx->l3_sup_kers;
}
BLIS_INLINE mbool_t* bli_cntx_l3_sup_kers_prefs_buf( cntx_t* cntx )
{
	return cntx->l3_sup_kers_prefs;
}
BLIS_INLINE func_t* bli_cntx_l1f_kers_buf( cntx_t* cntx )
{
	return cntx->l1f_kers;
}
BLIS_INLINE func_t* bli_cntx_l1v_kers_buf( cntx_t* cntx )
{
	return cntx->l1v_kers;
}
BLIS_INLINE func_t* bli_cntx_packm_kers_buf( cntx_t* cntx )
{
	return cntx->packm_kers;
}
BLIS_INLINE func_t* bli_cntx_unpackm_kers_buf( cntx_t* cntx )
{
	return cntx->unpackm_kers;
}
BLIS_INLINE ind_t bli_cntx_method( cntx_t* cntx )
{
	return cntx->method;
}

// -----------------------------------------------------------------------------

//
// -- cntx_t modification (fields only) ----------------------------------------
//

BLIS_INLINE void bli_cntx_set_method( ind_t method, cntx_t* cntx )
{
	cntx->method = method;
}

// -----------------------------------------------------------------------------

//
// -- cntx_t query (complex) ---------------------------------------------------
//

BLIS_INLINE blksz_t* bli_cntx_get_blksz( bszid_t bs_id, cntx_t* cntx )
{
	blksz_t* blkszs = bli_cntx_blkszs_buf( cntx );
	blksz_t* blksz  = &blkszs[ bs_id ];

	// Return the address of the blksz_t identified by bs_id.
	return blksz;
}

BLIS_INLINE dim_t bli_cntx_get_blksz_def_dt( num_t dt, bszid_t bs_id, cntx_t* cntx )
{
	blksz_t* blksz  = bli_cntx_get_blksz( bs_id, cntx );
	dim_t    bs_dt  = bli_blksz_get_def( dt, blksz );

	// Return the main (default) blocksize value for the datatype given.
	return bs_dt;
}

BLIS_INLINE dim_t bli_cntx_get_blksz_max_dt( num_t dt, bszid_t bs_id, cntx_t* cntx )
{
	blksz_t* blksz  = bli_cntx_get_blksz( bs_id, cntx );
	dim_t    bs_dt  = bli_blksz_get_max( dt, blksz );

	// Return the auxiliary (maximum) blocksize value for the datatype given.
	return bs_dt;
}

BLIS_INLINE bszid_t bli_cntx_get_bmult_id( bszid_t bs_id, cntx_t* cntx )
{
	bszid_t* restrict bmults = bli_cntx_bmults_buf( cntx );
	bszid_t           bm_id  = bmults[ bs_id ];

	return bm_id;
}

BLIS_INLINE blksz_t* bli_cntx_get_bmult( bszid_t bs_id, cntx_t* cntx )
{
	bszid_t           bm_id  = bli_cntx_get_bmult_id( bs_id, cntx );
	blksz_t* restrict bmult  = bli_cntx_get_blksz( bm_id, cntx );

	return bmult;
}

BLIS_INLINE dim_t bli_cntx_get_bmult_dt( num_t dt, bszid_t bs_id, cntx_t* cntx )
{
	blksz_t* bmult  = bli_cntx_get_bmult( bs_id, cntx );
	dim_t    bm_dt  = bli_blksz_get_def( dt, bmult );

	return bm_dt;
}

// -----------------------------------------------------------------------------

BLIS_INLINE func_t* bli_cntx_get_l3_vir_ukrs( l3ukr_t ukr_id, cntx_t* cntx )
{
	func_t* funcs = bli_cntx_l3_vir_ukrs_buf( cntx );
	func_t* func  = &funcs[ ukr_id ];

	return func;
}

BLIS_INLINE void_fp bli_cntx_get_l3_vir_ukr_dt( num_t dt, l3ukr_t ukr_id, cntx_t* cntx )
{
	func_t* func = bli_cntx_get_l3_vir_ukrs( ukr_id, cntx );

	return bli_func_get_dt( dt, func );
}

BLIS_INLINE func_t* bli_cntx_get_l3_nat_ukrs( l3ukr_t ukr_id, cntx_t* cntx )
{
	func_t* funcs = bli_cntx_l3_nat_ukrs_buf( cntx );
	func_t* func  = &funcs[ ukr_id ];

	return func;
}

BLIS_INLINE void_fp bli_cntx_get_l3_nat_ukr_dt( num_t dt, l3ukr_t ukr_id, cntx_t* cntx )
{
	func_t* func = bli_cntx_get_l3_nat_ukrs( ukr_id, cntx );

	return bli_func_get_dt( dt, func );
}

// -----------------------------------------------------------------------------

BLIS_INLINE mbool_t* bli_cntx_get_l3_nat_ukr_prefs( l3ukr_t ukr_id, cntx_t* cntx )
{
	mbool_t* mbools = bli_cntx_l3_nat_ukrs_prefs_buf( cntx );
	mbool_t* mbool  = &mbools[ ukr_id ];

	return mbool;
}

BLIS_INLINE bool bli_cntx_get_l3_nat_ukr_prefs_dt( num_t dt, l3ukr_t ukr_id, cntx_t* cntx )
{
	mbool_t* mbool = bli_cntx_get_l3_nat_ukr_prefs( ukr_id, cntx );

	return ( bool )bli_mbool_get_dt( dt, mbool );
}

// -----------------------------------------------------------------------------

BLIS_INLINE blksz_t* bli_cntx_get_l3_sup_thresh( threshid_t thresh_id, cntx_t* cntx )
{
	blksz_t* threshs = bli_cntx_l3_sup_thresh_buf( cntx );
	blksz_t* thresh  = &threshs[ thresh_id ];

	// Return the address of the blksz_t identified by thresh_id.
	return thresh;
}

BLIS_INLINE dim_t bli_cntx_get_l3_sup_thresh_dt( num_t dt, threshid_t thresh_id, cntx_t* cntx )
{
	blksz_t* threshs   = bli_cntx_get_l3_sup_thresh( thresh_id, cntx );
	dim_t    thresh_dt = bli_blksz_get_def( dt, threshs );

	// Return the main (default) threshold value for the datatype given.
	return thresh_dt;
}

BLIS_INLINE bool bli_cntx_l3_sup_thresh_is_met( num_t dt, dim_t m, dim_t n, dim_t k, cntx_t* cntx )
{
	if ( m < bli_cntx_get_l3_sup_thresh_dt( dt, BLIS_MT, cntx ) ) return TRUE;
	if ( n < bli_cntx_get_l3_sup_thresh_dt( dt, BLIS_NT, cntx ) ) return TRUE;
	if ( k < bli_cntx_get_l3_sup_thresh_dt( dt, BLIS_KT, cntx ) ) return TRUE;

	return FALSE;
}

// -----------------------------------------------------------------------------

BLIS_INLINE void* bli_cntx_get_l3_sup_handler( opid_t op, cntx_t* cntx )
{
	void** funcs = bli_cntx_l3_sup_handlers_buf( cntx );
	void*  func  = funcs[ op ];

	return func;
}

// -----------------------------------------------------------------------------

BLIS_INLINE blksz_t* bli_cntx_get_l3_sup_blksz( bszid_t bs_id, cntx_t* cntx )
{
	blksz_t* blkszs = bli_cntx_l3_sup_blkszs_buf( cntx );
	blksz_t* blksz  = &blkszs[ bs_id ];

	// Return the address of the blksz_t identified by bs_id.
	return blksz;
}

BLIS_INLINE dim_t bli_cntx_get_l3_sup_blksz_def_dt( num_t dt, bszid_t bs_id, cntx_t* cntx )
{
	blksz_t* blksz  = bli_cntx_get_l3_sup_blksz( bs_id, cntx );
	dim_t    bs_dt  = bli_blksz_get_def( dt, blksz );

	// Return the main (default) blocksize value for the datatype given.
	return bs_dt;
}

BLIS_INLINE dim_t bli_cntx_get_l3_sup_blksz_max_dt( num_t dt, bszid_t bs_id, cntx_t* cntx )
{
	blksz_t* blksz  = bli_cntx_get_l3_sup_blksz( bs_id, cntx );
	dim_t    bs_dt  = bli_blksz_get_max( dt, blksz );

	// Return the auxiliary (maximum) blocksize value for the datatype given.
	return bs_dt;
}

// -----------------------------------------------------------------------------

BLIS_INLINE func_t* bli_cntx_get_l3_sup_kers( stor3_t stor_id, cntx_t* cntx )
{
	func_t* funcs = bli_cntx_l3_sup_kers_buf( cntx );
	func_t* func  = &funcs[ stor_id ];

	return func;
}

BLIS_INLINE void* bli_cntx_get_l3_sup_ker_dt( num_t dt, stor3_t stor_id, cntx_t* cntx )
{
	func_t* func = bli_cntx_get_l3_sup_kers( stor_id, cntx );

	return bli_func_get_dt( dt, func );
}

// -----------------------------------------------------------------------------

BLIS_INLINE mbool_t* bli_cntx_get_l3_sup_ker_prefs( stor3_t stor_id, cntx_t* cntx )
{
	mbool_t* mbools = bli_cntx_l3_sup_kers_prefs_buf( cntx );
	mbool_t* mbool  = &mbools[ stor_id ];

	return mbool;
}

BLIS_INLINE bool bli_cntx_get_l3_sup_ker_prefs_dt( num_t dt, stor3_t stor_id, cntx_t* cntx )
{
	mbool_t* mbool = bli_cntx_get_l3_sup_ker_prefs( stor_id, cntx );

	return ( bool )bli_mbool_get_dt( dt, mbool );
}

// -----------------------------------------------------------------------------

BLIS_INLINE func_t* bli_cntx_get_l1f_kers( l1fkr_t ker_id, cntx_t* cntx )
{
	func_t* funcs = bli_cntx_l1f_kers_buf( cntx );
	func_t* func  = &funcs[ ker_id ];

	return func;
}

BLIS_INLINE void_fp bli_cntx_get_l1f_ker_dt( num_t dt, l1fkr_t ker_id, cntx_t* cntx )
{
	func_t* func = bli_cntx_get_l1f_kers( ker_id, cntx );

	return bli_func_get_dt( dt, func );
}

// -----------------------------------------------------------------------------

BLIS_INLINE func_t* bli_cntx_get_l1v_kers( l1vkr_t ker_id, cntx_t* cntx )
{
	func_t* funcs = bli_cntx_l1v_kers_buf( cntx );
	func_t* func  = &funcs[ ker_id ];

	return func;
}

BLIS_INLINE void_fp bli_cntx_get_l1v_ker_dt( num_t dt, l1vkr_t ker_id, cntx_t* cntx )
{
	func_t* func = bli_cntx_get_l1v_kers( ker_id, cntx );

	return bli_func_get_dt( dt, func );
}

// -----------------------------------------------------------------------------

BLIS_INLINE func_t* bli_cntx_get_packm_kers( l1mkr_t ker_id, cntx_t* cntx )
{
	func_t* func = NULL;

	// Only index to the requested packm func_t if the packm kernel being
	// requested is one that is explicitly supported.
	if ( 0 <= ( gint_t )ker_id &&
	          ( gint_t )ker_id < BLIS_NUM_PACKM_KERS )
	{
		func_t* funcs = bli_cntx_packm_kers_buf( cntx );

		func = &funcs[ ker_id ];
	}

	return func;
}

BLIS_INLINE void_fp bli_cntx_get_packm_ker_dt( num_t dt, l1mkr_t ker_id, cntx_t* cntx )
{
	void_fp fp = NULL;

	// Only query the context for the packm func_t (and then extract the
	// datatype-specific function pointer) if the packm kernel being
	// requested is one that is explicitly supported.
	if ( 0 <= ( gint_t )ker_id &&
	          ( gint_t )ker_id < BLIS_NUM_PACKM_KERS )
	{
		func_t* func = bli_cntx_get_packm_kers( ker_id, cntx );

		fp = bli_func_get_dt( dt, func );
	}

	return fp;
}

BLIS_INLINE func_t* bli_cntx_get_unpackm_kers( l1mkr_t ker_id, cntx_t* cntx )
{
	func_t* func = NULL;

	// Only index to the requested unpackm func_t if the unpackm kernel being
	// requested is one that is explicitly supported.
	if ( 0 <= ( gint_t )ker_id &&
	          ( gint_t )ker_id < BLIS_NUM_UNPACKM_KERS )
	{
		func_t* funcs = bli_cntx_unpackm_kers_buf( cntx );

		func = &funcs[ ker_id ];
	}

	return func;
}

BLIS_INLINE void_fp bli_cntx_get_unpackm_ker_dt( num_t dt, l1mkr_t ker_id, cntx_t* cntx )
{
	void_fp fp = NULL;

	// Only query the context for the unpackm func_t (and then extract the
	// datatype-specific function pointer) if the unpackm kernel being
	// requested is one that is explicitly supported.
	if ( 0 <= ( gint_t )ker_id &&
	          ( gint_t )ker_id < BLIS_NUM_UNPACKM_KERS )
	{
		func_t* func = bli_cntx_get_unpackm_kers( ker_id, cntx );

		fp = bli_func_get_dt( dt, func );
	}

	return fp;
}

// -----------------------------------------------------------------------------

BLIS_INLINE bool bli_cntx_l3_nat_ukr_prefers_rows_dt( num_t dt, l3ukr_t ukr_id, cntx_t* cntx )
{
	const bool prefs = bli_cntx_get_l3_nat_ukr_prefs_dt( dt, ukr_id, cntx );

	// A ukernel preference of TRUE means the ukernel prefers row storage.
	return ( bool )
	       ( prefs == TRUE );
}

BLIS_INLINE bool bli_cntx_l3_nat_ukr_prefers_cols_dt( num_t dt, l3ukr_t ukr_id, cntx_t* cntx )
{
	const bool prefs = bli_cntx_get_l3_nat_ukr_prefs_dt( dt, ukr_id, cntx );

	// A ukernel preference of FALSE means the ukernel prefers column storage.
	return ( bool )
	       ( prefs == FALSE );
}

BLIS_INLINE bool bli_cntx_l3_nat_ukr_prefers_storage_of( obj_t* obj, l3ukr_t ukr_id, cntx_t* cntx )
{
	// Note that we use the computation datatype, which may differ from the
	// storage datatype of C (when performing a mixed datatype operation).
	const num_t dt    = bli_obj_comp_dt( obj );
	const bool  ukr_prefers_rows
	                  = bli_cntx_l3_nat_ukr_prefers_rows_dt( dt, ukr_id, cntx );
	const bool  ukr_prefers_cols
	                  = bli_cntx_l3_nat_ukr_prefers_cols_dt( dt, ukr_id, cntx );
	bool        r_val = FALSE;

	if      ( bli_obj_is_row_stored( obj ) && ukr_prefers_rows ) r_val = TRUE;
	else if ( bli_obj_is_col_stored( obj ) && ukr_prefers_cols ) r_val = TRUE;

	return r_val;
}

BLIS_INLINE bool bli_cntx_l3_nat_ukr_dislikes_storage_of( obj_t* obj, l3ukr_t ukr_id, cntx_t* cntx )
{
	return ( bool )
	       !bli_cntx_l3_nat_ukr_prefers_storage_of( obj, ukr_id, cntx );
}

// -----------------------------------------------------------------------------

BLIS_INLINE bool bli_cntx_l3_vir_ukr_prefers_rows_dt( num_t dt, l3ukr_t ukr_id, cntx_t* cntx )
{
	// For induced methods, return the ukernel storage preferences of the
	// corresponding real micro-kernel.
	// NOTE: This projection to real domain becomes unnecessary if you
	// set the exec_dt for 1m to the real projection of the storage
	// datatype.
	if ( bli_cntx_method( cntx ) != BLIS_NAT )
	    dt = bli_dt_proj_to_real( dt );

	return bli_cntx_l3_nat_ukr_prefers_rows_dt( dt, ukr_id, cntx );
}

BLIS_INLINE bool bli_cntx_l3_vir_ukr_prefers_cols_dt( num_t dt, l3ukr_t ukr_id, cntx_t* cntx )
{
	// For induced methods, return the ukernel storage preferences of the
	// corresponding real micro-kernel.
	// NOTE: This projection to real domain becomes unnecessary if you
	// set the exec_dt for 1m to the real projection of the storage
	// datatype.
	if ( bli_cntx_method( cntx ) != BLIS_NAT )
	    dt = bli_dt_proj_to_real( dt );

	return bli_cntx_l3_nat_ukr_prefers_cols_dt( dt, ukr_id, cntx );
}

BLIS_INLINE bool bli_cntx_l3_vir_ukr_prefers_storage_of( obj_t* obj, l3ukr_t ukr_id, cntx_t* cntx )
{
	// Note that we use the computation datatype, which may differ from the
	// storage datatype of C (when performing a mixed datatype operation).
	const num_t dt    = bli_obj_comp_dt( obj );
	const bool  ukr_prefers_rows
	                  = bli_cntx_l3_vir_ukr_prefers_rows_dt( dt, ukr_id, cntx );
	const bool  ukr_prefers_cols
	                  = bli_cntx_l3_vir_ukr_prefers_cols_dt( dt, ukr_id, cntx );
	bool        r_val = FALSE;

	if      ( bli_obj_is_row_stored( obj ) && ukr_prefers_rows ) r_val = TRUE;
	else if ( bli_obj_is_col_stored( obj ) && ukr_prefers_cols ) r_val = TRUE;

	return r_val;
}

BLIS_INLINE bool bli_cntx_l3_vir_ukr_dislikes_storage_of( obj_t* obj, l3ukr_t ukr_id, cntx_t* cntx )
{
	return ( bool )
	       !bli_cntx_l3_vir_ukr_prefers_storage_of( obj, ukr_id, cntx );
}

// -----------------------------------------------------------------------------

BLIS_INLINE bool bli_cntx_l3_sup_ker_prefers_rows_dt( num_t dt, stor3_t stor_id, cntx_t* cntx )
{
	const bool prefs = bli_cntx_get_l3_sup_ker_prefs_dt( dt, stor_id, cntx );

	// A ukernel preference of TRUE means the ukernel prefers row storage.
	return ( bool )
	       ( prefs == TRUE );
}

BLIS_INLINE bool bli_cntx_l3_sup_ker_prefers_cols_dt( num_t dt, stor3_t stor_id, cntx_t* cntx )
{
	const bool prefs = bli_cntx_get_l3_sup_ker_prefs_dt( dt, stor_id, cntx );

	// A ukernel preference of FALSE means the ukernel prefers column storage.
	return ( bool )
	       ( prefs == FALSE );
}

#if 0
// NOTE: These static functions aren't needed yet.

BLIS_INLINE bool bli_cntx_l3_sup_ker_prefers_storage_of( obj_t* obj, stor3_t stor_id, cntx_t* cntx )
{
	const num_t dt    = bli_obj_dt( obj );
	const bool  ukr_prefers_rows
	                  = bli_cntx_l3_sup_ker_prefers_rows_dt( dt, stor_id, cntx );
	const bool  ukr_prefers_cols
	                  = bli_cntx_l3_sup_ker_prefers_cols_dt( dt, stor_id, cntx );
	bool        r_val = FALSE;

	if      ( bli_obj_is_row_stored( obj ) && ukr_prefers_rows ) r_val = TRUE;
	else if ( bli_obj_is_col_stored( obj ) && ukr_prefers_cols ) r_val = TRUE;

	return r_val;
}

BLIS_INLINE bool bli_cntx_l3_sup_ker_dislikes_storage_of( obj_t* obj, stor3_t stor_id, cntx_t* cntx )
{
	return ( bool )
	       !bli_cntx_l3_sup_ker_prefers_storage_of( obj, stor_id, cntx );
}
#endif

// -----------------------------------------------------------------------------

//
// -- cntx_t modification (complex) --------------------------------------------
//

// NOTE: The framework does not use any of the following functions. We provide
// them in order to facilitate creating/modifying custom contexts.

BLIS_INLINE void bli_cntx_set_blksz( bszid_t bs_id, blksz_t* blksz, bszid_t mult_id, cntx_t* cntx )
{
	blksz_t* blkszs = bli_cntx_blkszs_buf( cntx );
	bszid_t* bmults = bli_cntx_bmults_buf( cntx );

	blkszs[ bs_id ] = *blksz;
	bmults[ bs_id ] = mult_id;
}

BLIS_INLINE void bli_cntx_set_blksz_def_dt( num_t dt, bszid_t bs_id, dim_t bs, cntx_t* cntx )
{
	blksz_t* blkszs = bli_cntx_blkszs_buf( cntx );
	blksz_t* blksz  = &blkszs[ bs_id ];

	bli_blksz_set_def( bs, dt, blksz );
}

BLIS_INLINE void bli_cntx_set_blksz_max_dt( num_t dt, bszid_t bs_id, dim_t bs, cntx_t* cntx )
{
	blksz_t* blkszs = bli_cntx_blkszs_buf( cntx );
	blksz_t* blksz  = &blkszs[ bs_id ];

	bli_blksz_set_max( bs, dt, blksz );
}

BLIS_INLINE void bli_cntx_set_l3_vir_ukr( l3ukr_t ukr_id, func_t* func, cntx_t* cntx )
{
	func_t* funcs = bli_cntx_l3_vir_ukrs_buf( cntx );

	funcs[ ukr_id ] = *func;
}

BLIS_INLINE void bli_cntx_set_l3_nat_ukr( l3ukr_t ukr_id, func_t* func, cntx_t* cntx )
{
	func_t* funcs = bli_cntx_l3_nat_ukrs_buf( cntx );

	funcs[ ukr_id ] = *func;
}

BLIS_INLINE void bli_cntx_set_l3_nat_ukr_prefs( l3ukr_t ukr_id, mbool_t* prefs, cntx_t* cntx )
{
	mbool_t* mbools = bli_cntx_l3_nat_ukrs_prefs_buf( cntx );

	mbools[ ukr_id ] = *prefs;
}

BLIS_INLINE void bli_cntx_set_l1f_ker( l1fkr_t ker_id, func_t* func, cntx_t* cntx )
{
	func_t* funcs = bli_cntx_l1f_kers_buf( cntx );

	funcs[ ker_id ] = *func;
}

BLIS_INLINE void bli_cntx_set_l1v_ker( l1vkr_t ker_id, func_t* func, cntx_t* cntx )
{
	func_t* funcs = bli_cntx_l1v_kers_buf( cntx );

	funcs[ ker_id ] = *func;
}

BLIS_INLINE void bli_cntx_set_packm_ker( l1mkr_t ker_id, func_t* func, cntx_t* cntx )
{
	func_t* funcs = bli_cntx_get_packm_kers( ker_id, cntx );

	funcs[ ker_id ] = *func;
}

BLIS_INLINE void bli_cntx_set_packm_ker_dt( void_fp fp, num_t dt, l1mkr_t ker_id, cntx_t* cntx )
{
	func_t* func = ( func_t* )bli_cntx_get_packm_kers( ker_id, cntx );

	bli_func_set_dt( fp, dt, func );
}

BLIS_INLINE void bli_cntx_set_unpackm_ker( l1mkr_t ker_id, func_t* func, cntx_t* cntx )
{
	func_t* funcs = bli_cntx_get_unpackm_kers( ker_id, cntx );

	funcs[ ker_id ] = *func;
}

BLIS_INLINE void bli_cntx_set_unpackm_ker_dt( void_fp fp, num_t dt, l1mkr_t ker_id, cntx_t* cntx )
{
	func_t* func = ( func_t* )bli_cntx_get_unpackm_kers( ker_id, cntx );

	bli_func_set_dt( fp, dt, func );
}

// -----------------------------------------------------------------------------

// Function prototypes

BLIS_EXPORT_BLIS void bli_cntx_clear( cntx_t* cntx );

BLIS_EXPORT_BLIS void bli_cntx_set_blkszs( ind_t method, dim_t n_bs, ... );

BLIS_EXPORT_BLIS void bli_cntx_set_ind_blkszs( ind_t method, num_t dt, dim_t n_bs, ... );

BLIS_EXPORT_BLIS void bli_cntx_set_l3_nat_ukrs( dim_t n_ukrs, ... );
BLIS_EXPORT_BLIS void bli_cntx_set_l3_vir_ukrs( dim_t n_ukrs, ... );

BLIS_EXPORT_BLIS void bli_cntx_set_l3_sup_thresh( dim_t n_thresh, ... );
BLIS_EXPORT_BLIS void bli_cntx_set_l3_sup_handlers( dim_t n_ops, ... );
BLIS_EXPORT_BLIS void bli_cntx_set_l3_sup_blkszs( dim_t n_bs, ... );
BLIS_EXPORT_BLIS void bli_cntx_set_l3_sup_kers( dim_t n_ukrs, ... );

BLIS_EXPORT_BLIS void bli_cntx_set_l1f_kers( dim_t n_kers, ... );
BLIS_EXPORT_BLIS void bli_cntx_set_l1v_kers( dim_t n_kers, ... );
BLIS_EXPORT_BLIS void bli_cntx_set_packm_kers( dim_t n_kers, ... );

BLIS_EXPORT_BLIS void bli_cntx_print( cntx_t* cntx );


#endif