-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathsm1xx_common.inl
More file actions
797 lines (741 loc) · 42.1 KB
/
Copy pathsm1xx_common.inl
File metadata and controls
797 lines (741 loc) · 42.1 KB
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
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
/***************************************************************************************************
* Copyright (c) 2023 - 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. Neither the name of the copyright holder 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.
*
**************************************************************************************************/
#pragma once
#include "cutlass/gemm/gemm.h"
#include "cutlass/gemm/kernel/sm100_tile_scheduler.hpp"
#include "cutlass/gemm/dispatch_policy.hpp" // KernelSchedule1Sm, KernelSchedule2Sm
#include "cutlass/gemm/collective/builders/sm90_common.inl" // detail::sm90_cluster_shape_to_tma_atom()
#include "cutlass/numeric_types.h" // all numeric types
#include "cutlass/detail/dependent_false.hpp" // detail::dependent_false
#include "cutlass/pipeline/pipeline.hpp"
#include "cutlass/detail/layout.hpp" // cutlass::detail::get_input_alignment_bits()
#include "cutlass/layout/matrix.h" // cutlass::layout::RowMajor, cutlass::layout::ColumnMajor
#include "cutlass/fast_math.h" // cutlass::round_up, cutlass::const_max
#include "cutlass/arch/arch.h"
#include "cute/atom/mma_traits_sm100.hpp" // UMMA::Layout_MN_SW*
#include "cute/atom/copy_traits_sm100_tma.hpp" // SM100_TMA_*SM_LOAD_*
#include "cute/arch/tmem_allocator_sm100.hpp"
#include "cute/arch/mma_sm100_desc.hpp" // cute::UMMA::Major
#include "cute/arch/mma_sm100_umma.hpp" // SM100_*MMA_SS_*
#include "cute/numeric/integral_constant.hpp" // is_static_v, cute::integral_constant
#include "cute/util/type_traits.hpp" // cute::alignment_of_v
/////////////////////////////////////////////////////////////////////////////////////////////////
namespace cutlass::gemm::collective {
// Forward Declaration
struct KernelScheduleAuto;
/////////////////////////////////////////////////////////////////////////////////////////////////
namespace detail {
// Maps input element to umma element
template <class Element, bool IsF8F6F4 = true>
constexpr auto
sm1xx_kernel_input_element_to_mma_input_element() {
if constexpr (cute::is_same_v<Element, float>) {
return cutlass::tfloat32_t{};
}
else if constexpr (cute::is_same_v<Element, cutlass::float_e2m1_t> && IsF8F6F4) {
return cutlass::detail::float_e2m1_unpacksmem_t{};
}
else if constexpr (cute::is_same_v<Element, cutlass::float_e3m2_t> && IsF8F6F4) {
return cutlass::detail::float_e3m2_unpacksmem_t{};
}
else if constexpr (cute::is_same_v<Element, cutlass::float_e2m3_t> && IsF8F6F4) {
return cutlass::detail::float_e2m3_unpacksmem_t{};
}
else if constexpr (cute::is_same_v<Element, cutlass::type_erased_dynamic_float4_t> && IsF8F6F4) {
return cutlass::detail::type_erased_dynamic_float4_unpacksmem_t{};
}
else if constexpr (cute::is_same_v<Element, cutlass::type_erased_dynamic_float6_t> && IsF8F6F4) {
return cutlass::detail::type_erased_dynamic_float6_unpacksmem_t{};
}
else {
return Element{};
}
}
// Maps 2.x A matrix layout tag to respective UMMA major mode enum
template <class Layout>
constexpr cute::UMMA::Major
tag_to_umma_major_A() {
using LayoutA = cute::remove_pointer_t<Layout>;
if constexpr (cute::is_same_v<LayoutA, cutlass::layout::RowMajor>) {
return cute::UMMA::Major::K;
}
else if constexpr (cute::is_same_v<LayoutA, cutlass::layout::ColumnMajor>) {
return cute::UMMA::Major::MN;
}
else if constexpr (cutlass::detail::is_major<0, LayoutA>()) {
return cute::UMMA::Major::MN;
}
else if constexpr (cutlass::detail::is_major<1, LayoutA>()) {
return cute::UMMA::Major::K;
}
else {
static_assert(sizeof(LayoutA) == 0, "Invalid layout.");
}
}
// Maps 2.x B matrix layout tag to respective UMMA major mode enum
template <class Layout>
constexpr cute::UMMA::Major
tag_to_umma_major_B() {
using LayoutB = cute::remove_pointer_t<Layout>;
if constexpr (cute::is_same_v<LayoutB, cutlass::layout::RowMajor>) {
return cute::UMMA::Major::MN;
}
else if constexpr (cute::is_same_v<LayoutB, cutlass::layout::ColumnMajor>) {
return cute::UMMA::Major::K;
}
else if constexpr (cutlass::detail::is_major<0, LayoutB>()) {
return cute::UMMA::Major::MN;
}
else if constexpr (cutlass::detail::is_major<1, LayoutB>()) {
return cute::UMMA::Major::K;
}
else {
static_assert(sizeof(LayoutB) == 0, "Invalid layout.");
}
}
template<class BuilderScheduleTag>
constexpr uint32_t find_vector_size() {
if constexpr (cute::is_same_v<BuilderScheduleTag, KernelTmaWarpSpecialized1SmNvf4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelTmaWarpSpecialized2SmNvf4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelPtrArrayTmaWarpSpecialized1SmNvf4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelPtrArrayTmaWarpSpecialized2SmNvf4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelTmaWarpSpecializedNvf4Sm120> ||
cute::is_same_v<BuilderScheduleTag, KernelTmaWarpSpecializedPingpongNvf4Sm120>
) {
return 16;
}
else if constexpr (cute::is_same_v<BuilderScheduleTag, KernelSparseTmaWarpSpecialized1SmNvf4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelSparseTmaWarpSpecialized2SmNvf4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelTmaWarpSpecialized1SmMxf4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelTmaWarpSpecialized2SmMxf4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelTmaWarpSpecialized1SmMxf8f6f4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelTmaWarpSpecialized2SmMxf8f6f4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelPtrArrayTmaWarpSpecialized1SmMxf4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelPtrArrayTmaWarpSpecialized2SmMxf4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelPtrArrayTmaWarpSpecialized1SmMxf8f6f4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelPtrArrayTmaWarpSpecialized2SmMxf8f6f4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelSparseTmaWarpSpecializedNvf4Sm120>) {
return 32;
}
else if constexpr (cute::is_same_v<BuilderScheduleTag, KernelSparseTmaWarpSpecialized1SmMxf8f6f4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelSparseTmaWarpSpecialized2SmMxf8f6f4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelSparseTmaWarpSpecialized1SmMxf4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelSparseTmaWarpSpecialized2SmMxf4Sm100> ||
cute::is_same_v<BuilderScheduleTag, KernelSparseTmaWarpSpecializedMxf8f6f4Sm120> ||
cute::is_same_v<BuilderScheduleTag, KernelSparseTmaWarpSpecializedMxf8f6f4Acc2x4Sm120> ||
cute::is_same_v<BuilderScheduleTag, KernelSparseTmaWarpSpecializedMxf4Sm120>) {
return 64;
}
else {
return 32;
}
}
/**
* @brief Check for F8F6F4 alignment requirement
*
* @tparam TileShape_MNK (MmaAtomShape_M, MmaAtomShape_N, TileShape_K)
* @tparam ClusterShape_MNK (cluster_M, cluster_N, cluster_K)
* @tparam BuilderScheduleTag Builder tag
*/
template<
class ElementAMma,
class ElementBMma,
class TileShape_MNK,
class ClusterShape_MNK,
class LayoutA,
class LayoutB,
bool IsSparse,
bool Is2sm = false
>
constexpr bool sm1xx_gemm_check_for_f8f6f4_mix8bit_requirement(){
// * 1SM Dense
// * A_K(t) : TileShape_K % 128 == 0
// * A_M(n) : TileShape_M % 128 == 0
// * B_N(t) : TileSize_N % 128 == 0
// * B_K(n) : TileSize_K % 128 == 0
//
// * 2SM Dense
// * A_K(t) : TileShape_K % 128 == 0
// * A_M(n) : TileShape_M % 128 == 0
// * B_N(t) : TileSize_N % 256 == 0
// each sm load half the data along tile_n (split vertically), each sm needs to be 128 elts aligned.
// full tile_n needs to be 256 elts aligned
// * B_K(n) : TileShape_K % 128 == 0
//
// * 1SM Sparse
// * A_K(t) : TileShape_K % 256 == 0
// num of physical elems needs to be 128 elts aligned
// num of logical elems needs to be 256 elts aligned
// * A_M(n) : TileShape_M % 128 == 0
// * B_N(t) : TileSize_N % 128 == 0
// * B_K(n) : TileSize_K % 128 == 0
//
// * 2SM Sparse
// * A_K(t) : TileShape_K % 256 == 0
// num of physical elems needs to be 128 elts aligned
// num of logical elems needs to be 256 elts aligned
// * A_M(n) : TileShape_M % 128 == 0
// * B_N(t) : TileSize_N % 256 == 0
// each sm load half the data along tile_n (split vertically), each sm needs to be 128 elts aligned.
// full tile_n needs to be 256 elts aligned
// * B_K(n) : TileShape_K % 128 == 0
//
// * Valid TileShape_MNK Dense
// * Notation:
// mma_instruction_tile_shape-cta_tile_shape
// * s128x128x64
// s128x128x32_128x128x128_nn YES
// s128x128x32_128x128x128_nt YES
// s128x128x32_128x128x128_tn YES
// s128x128x32_128x128x128_tt YES
// * s128x256x64
// s128x256x32_128x256x128_nn YES
// s128x256x32_128x256x128_nt YES
// s128x256x32_128x256x128_tn YES
// s128x256x32_128x256x128_tt YES
// * s256x128x64
// s256x128x32_256x128x128_nn YES
// s256x128x32_256x128x128_nt NO (2SM B_N TileSize_N % 256 != 0)
// s256x128x32_256x128x128_tn YES
// s256x128x32_256x128x128_tt NO (2SM B_N TileSize_N % 256 != 0)
// * s256x256x64
// s256x256x32_256x256x128_nn YES
// s256x256x32_256x256x128_nt YES
// s256x256x32_256x256x128_tn YES
// s256x256x32_256x256x128_tt YES
//
// * Valid TileShape_MNK Sparse
// * s128x128x64
// s128x128x64_128x128x128_nn YES
// s128x128x64_128x128x128_nt YES
// s128x128x64_128x128x128_tn NO (A_K TileShape_K % 256 != 0)
// s128x128x64_128x128x128_tt NO (A_K TileShape_K % 256 != 0)
// s128x128x64_128x128x256_nn YES
// s128x128x64_128x128x256_nt YES
// s128x128x64_128x128x256_tn YES
// s128x128x64_128x128x256_tt YES
// * s128x256x64
// s128x256x64_128x256x128_nn YES
// s128x256x64_128x256x128_nt YES
// s128x256x64_128x256x128_tn NO (A_K TileShape_K % 256 != 0)
// s128x256x64_128x256x128_tt NO (A_K TileShape_K % 256 != 0)
// s128x256x64_128x256x256_nn YES
// s128x256x64_128x256x256_nt YES
// s128x256x64_128x256x256_tn YES
// s128x256x64_128x256x256_tt YES
// * s256x128x64
// s256x128x64_128x128x128_nn YES
// s256x128x64_128x128x128_nt NO (2SM B_N TileSize_N % 256 != 0)
// s256x128x64_128x128x128_tn NO (A_K TileShape_K % 256 != 0)
// s256x128x64_128x128x128_tt NO (A_K TileShape_K % 256 != 0)
// s256x128x64_128x128x256_nn YES
// s256x128x64_128x128x256_nt NO (2SM B_N TileSize_N % 256 != 0)
// s256x128x64_128x128x256_tn YES
// s256x128x64_128x128x256_tt NO (2SM B_N TileSize_N % 256 != 0)
// * s256x256x64
// s256x256x64_128x256x128_nn YES
// s256x256x64_128x256x128_nt YES
// s256x256x64_128x256x128_tn NO (A_K TileShape_K % 256 != 0)
// s256x256x64_128x256x128_tt NO (A_K TileShape_K % 256 != 0)
// s256x256x64_128x256x256_nn YES
// s256x256x64_128x256x256_nt YES
// s256x256x64_128x256x256_tn YES
// s256x256x64_128x256x256_tt YES
[[maybe_unused]] constexpr int TileShape_M = Is2sm ? size<0>(TileShape_MNK{}) / 2 : size<0>(TileShape_MNK{});
[[maybe_unused]] constexpr int TileShape_N = size<1>(TileShape_MNK{});
[[maybe_unused]] constexpr int TileShape_K = size<2>(TileShape_MNK{});
constexpr bool is_b_unpack_f4_f6 = cute::is_same_v<ElementBMma, cutlass::detail::float_e2m1_unpacksmem_t> ||
cute::is_same_v<ElementBMma, cutlass::detail::float_e3m2_unpacksmem_t> ||
cute::is_same_v<ElementBMma, cutlass::detail::float_e2m3_unpacksmem_t> ||
cute::is_same_v<ElementBMma, cutlass::detail::type_erased_dynamic_float4_unpacksmem_t> ||
cute::is_same_v<ElementBMma, cutlass::detail::type_erased_dynamic_float6_unpacksmem_t>;
// For sparse, this is ElementAMmaRaw
constexpr bool is_a_unpack_f4_f6 = cute::is_same_v<ElementAMma, cutlass::detail::float_e2m1_unpacksmem_t> ||
cute::is_same_v<ElementAMma, cutlass::detail::float_e3m2_unpacksmem_t> ||
cute::is_same_v<ElementAMma, cutlass::detail::float_e2m3_unpacksmem_t> ||
cute::is_same_v<ElementAMma, cutlass::detail::type_erased_dynamic_float4_unpacksmem_t> ||
cute::is_same_v<ElementAMma, cutlass::detail::type_erased_dynamic_float6_unpacksmem_t>;
[[maybe_unused]] constexpr bool is_b_n_major = cute::is_same_v<LayoutB, cutlass::layout::RowMajor>;
[[maybe_unused]] constexpr bool is_b_k_major = not is_b_n_major;
[[maybe_unused]] constexpr bool is_a_m_major = cute::is_same_v<LayoutA, cutlass::layout::ColumnMajor>;
[[maybe_unused]] constexpr bool is_a_k_major = not is_a_m_major;
// 2SM
if constexpr (Is2sm) {
if constexpr (IsSparse) {
constexpr bool valid_a = !is_a_unpack_f4_f6 || (is_a_k_major ?
TileShape_K % 256 == 0:
TileShape_M % 128 == 0);
constexpr bool valid_b = !is_b_unpack_f4_f6 || (is_b_n_major ?
TileShape_N % 256 == 0:
TileShape_K % 128 == 0);
return valid_a && valid_b;
}
else {
constexpr bool valid_a = !is_a_unpack_f4_f6 || (is_a_k_major ?
TileShape_K % 128 == 0 :
TileShape_M % 128 == 0);
constexpr bool valid_b = !is_b_unpack_f4_f6 || (is_b_n_major ?
TileShape_N % 256 == 0:
TileShape_K % 128 == 0);
return valid_a && valid_b;
}
}
// 1SM
else {
if constexpr (IsSparse) {
constexpr bool valid_a = !is_a_unpack_f4_f6 || (is_a_k_major ?
TileShape_K % 256 == 0:
TileShape_M % 128 == 0);
constexpr bool valid_b = !is_b_unpack_f4_f6 || (is_b_n_major ?
TileShape_N % 128 == 0 :
TileShape_K % 128 == 0);
return valid_a && valid_b;
}
else {
constexpr bool valid_a = !is_a_unpack_f4_f6 || (is_a_k_major ?
TileShape_K % 128 == 0 :
TileShape_M % 128 == 0);
constexpr bool valid_b = !is_b_unpack_f4_f6 || (is_b_n_major ?
TileShape_N % 128 == 0 :
TileShape_K % 128 == 0);
return valid_a && valid_b;
}
}
}
template <class ElementA, int AlignmentA, class ElementB, int AlignmentB, class BuilderScheduleTag>
constexpr bool
sm1xx_gemm_is_aligned() {
// Only support dense gemm alignment check
constexpr bool is_f8f6f4_subbytes = cute::sizeof_bits_v<ElementA> < 8 || cute::sizeof_bits_v<ElementB> < 8;
return ((cute::sizeof_bits_v<ElementA> * AlignmentA) % cutlass::detail::get_input_alignment_bits<ElementA, is_f8f6f4_subbytes>() == 0) &&
((cute::sizeof_bits_v<ElementB> * AlignmentB) % cutlass::detail::get_input_alignment_bits<ElementB, is_f8f6f4_subbytes>() == 0);
}
template <class ElementA, int AlignmentA, class ElementB, int AlignmentB, class BuilderScheduleTag>
constexpr bool
sm1xx_blockscaled_gemm_is_aligned() {
// Only support blocksscaled gemm alignment check
constexpr bool is_mxf8f6f4_subbytes = (cute::sizeof_bits_v<ElementA> < 8 || cute::sizeof_bits_v<ElementB> < 8) &&
(cute::is_base_of_v<KernelScheduleMxf8f6f4Sm100, BuilderScheduleTag> ||
cute::is_base_of_v<KernelScheduleMxf8f6f4Sm120, BuilderScheduleTag> );
return ((cute::sizeof_bits_v<ElementA> * AlignmentA) % cutlass::detail::get_input_alignment_bits<ElementA, is_mxf8f6f4_subbytes>() == 0) &&
((cute::sizeof_bits_v<ElementB> * AlignmentB) % cutlass::detail::get_input_alignment_bits<ElementB, is_mxf8f6f4_subbytes>() == 0);
}
template <class ElementA, int AlignmentA, class GmemLayoutATag, class ElementB, int AlignmentB, class BuilderScheduleTag>
constexpr bool
sm1xx_sparse_gemm_is_aligned() {
// Only support sparse gemm alignment check
constexpr bool is_f8f6f4_subbytes = cute::sizeof_bits_v<ElementA> < 8 || cute::sizeof_bits_v<ElementB> < 8;
constexpr int a_k_major_compress_factor = cutlass::gemm::detail::is_k_major_A<GmemLayoutATag>() ? 2 : 1;
return ((cute::sizeof_bits_v<ElementA> * AlignmentA / a_k_major_compress_factor) %
cutlass::detail::get_input_alignment_bits<ElementA, is_f8f6f4_subbytes>() == 0) &&
((cute::sizeof_bits_v<ElementB> * AlignmentB) % cutlass::detail::get_input_alignment_bits<ElementB, is_f8f6f4_subbytes>() == 0);
}
template <class ElementA, int AlignmentA, class GmemLayoutATag, class ElementB, int AlignmentB, class BuilderScheduleTag>
constexpr bool
sm1xx_blockscaled_sparse_gemm_is_aligned() {
// Only support blocksscaled sparse gemm alignment check
constexpr bool is_mxf8f6f4_subbytes = (cute::sizeof_bits_v<ElementA> < 8 || cute::sizeof_bits_v<ElementB> < 8) &&
(cute::is_base_of_v<KernelScheduleSparseMxf8f6f4Sm100, BuilderScheduleTag> ||
cute::is_base_of_v<KernelScheduleSparseMxf8f6f4Sm120, BuilderScheduleTag>);
constexpr int a_k_major_compress_factor = cutlass::gemm::detail::is_k_major_A<GmemLayoutATag>() ? 2 : 1;
return ((cute::sizeof_bits_v<ElementA> * AlignmentA / a_k_major_compress_factor) %
cutlass::detail::get_input_alignment_bits<ElementA, is_mxf8f6f4_subbytes>() == 0) &&
((cute::sizeof_bits_v<ElementB> * AlignmentB) % cutlass::detail::get_input_alignment_bits<ElementB, is_mxf8f6f4_subbytes>() == 0);
}
template<class CollectiveEpilogue>
constexpr int
compute_carveout_from_epi() {
constexpr int tensor_alignment = cutlass::const_max(128, cute::alignment_of_v<typename CollectiveEpilogue::TensorStorage>);
constexpr int pipeline_alignment = 16;
return cutlass::round_up(sizeof(typename CollectiveEpilogue::TensorStorage), tensor_alignment) +
cutlass::round_up(sizeof(typename CollectiveEpilogue::PipelineStorage), pipeline_alignment);
}
namespace blockscaled {
enum class BlockScaledInstr {
MXF4_NVF4,
MXF4F6F8
};
template <class BuilderScheduleTag, class T>
struct blockscaled_type {};
template <class BuilderScheduleTag, class T, class SF>
struct blockscaled_type<BuilderScheduleTag, cute::tuple<T,SF>> {
using sf_type = SF;
using data_type = T;
static constexpr uint32_t SfVectorSize = detail::find_vector_size<BuilderScheduleTag>();
};
template <class BuilderScheduleTag, class T, class SF, int SfVectorSize_>
struct blockscaled_type<BuilderScheduleTag, cute::tuple<T,SF, cute::Int<SfVectorSize_>>> {
using sf_type = SF;
using data_type = T;
static constexpr uint32_t SfVectorSize = SfVectorSize_;
};
template <class BuilderScheduleTag, class T>
struct blockscaled_type<BuilderScheduleTag, cutlass::mx_float6_t<T>> {
using sf_type = cutlass::float_ue8m0_t;
using data_type = T;
static constexpr uint32_t SfVectorSize =
(cute::is_base_of_v<KernelScheduleBlockScaledSparseGemmSm100, BuilderScheduleTag> ||
cute::is_base_of_v<KernelScheduleBlockScaledSparseGemmSm120, BuilderScheduleTag>) ? 64 : 32;
};
template <class BuilderScheduleTag, class T>
struct blockscaled_type<BuilderScheduleTag, cutlass::mx_float4_t<T>> {
using sf_type = cutlass::float_ue8m0_t;
using data_type = T;
static constexpr uint32_t SfVectorSize =
(cute::is_base_of_v<KernelScheduleBlockScaledSparseGemmSm100, BuilderScheduleTag> ||
cute::is_base_of_v<KernelScheduleBlockScaledSparseGemmSm120, BuilderScheduleTag>) ? 64 : 32;
};
template <class BuilderScheduleTag, class T>
struct blockscaled_type<BuilderScheduleTag, nv_float4_t<T>> {
using sf_type = cutlass::float_ue4m3_t;
using data_type = T;
static constexpr uint32_t SfVectorSize =
(cute::is_base_of_v<KernelScheduleBlockScaledSparseGemmSm100, BuilderScheduleTag> ||
cute::is_base_of_v<KernelScheduleBlockScaledSparseGemmSm120, BuilderScheduleTag>) ? 32 : 16;
};
template <class BuilderScheduleTag, class T>
struct blockscaled_type<BuilderScheduleTag, cutlass::mx_float8_t<T>> {
using sf_type = cutlass::float_ue8m0_t;
using data_type = T;
static constexpr uint32_t SfVectorSize =
(cute::is_base_of_v<KernelScheduleBlockScaledSparseGemmSm100, BuilderScheduleTag> ||
cute::is_base_of_v<KernelScheduleBlockScaledSparseGemmSm120, BuilderScheduleTag>) ? 64 : 32;
};
template <
class BuilderScheduleTag,
class ElementPairA, class ElementPairB,
UMMA::Major UmmaMajorA, UMMA::Major UmmaMajorB
>
CUTLASS_HOST_DEVICE
static constexpr bool
check_input_datatypes() {
using ElementSFA = typename detail::blockscaled::blockscaled_type<BuilderScheduleTag, ElementPairA>::sf_type;
using ElementSFB = typename detail::blockscaled::blockscaled_type<BuilderScheduleTag, ElementPairB>::sf_type;
using ElementA = typename detail::blockscaled::blockscaled_type<BuilderScheduleTag, ElementPairA>::data_type;
using ElementB = typename detail::blockscaled::blockscaled_type<BuilderScheduleTag, ElementPairB>::data_type;
constexpr uint32_t SfVectorSizeA = detail::blockscaled::blockscaled_type<BuilderScheduleTag, ElementPairA>::SfVectorSize;
constexpr uint32_t SfVectorSizeB = detail::blockscaled::blockscaled_type<BuilderScheduleTag, ElementPairB>::SfVectorSize;
auto is_auto_instr_selection_policy = [&]() {
return ((cute::is_same_v<BuilderScheduleTag, KernelScheduleAuto>)
// SM100 BS
|| (cute::is_same_v<BuilderScheduleTag, KernelScheduleBlockScaledGemmSm100>)
|| (cute::is_same_v<BuilderScheduleTag, KernelTmaWarpSpecialized1SmBlockScaledSm100>)
|| (cute::is_same_v<BuilderScheduleTag, KernelTmaWarpSpecialized2SmBlockScaledSm100>)
// SM100 BS ptr_array
|| (cute::is_same_v<BuilderScheduleTag, KernelSchedulePtrArrayBlockScaledGemmSm100>)
|| (cute::is_same_v<BuilderScheduleTag, KernelPtrArrayTmaWarpSpecialized1SmBlockScaledSm100>)
|| (cute::is_same_v<BuilderScheduleTag, KernelPtrArrayTmaWarpSpecialized2SmBlockScaledSm100>)
// SM100 BSSP
|| (cute::is_same_v<BuilderScheduleTag, KernelScheduleBlockScaledSparseGemmSm100>)
|| (cute::is_same_v<BuilderScheduleTag, KernelSparseTmaWarpSpecialized1SmBlockScaledSm100>)
|| (cute::is_same_v<BuilderScheduleTag, KernelSparseTmaWarpSpecialized2SmBlockScaledSm100>)
// SM120 BS
|| (cute::is_same_v<BuilderScheduleTag, KernelScheduleBlockScaledGemmSm120>)
|| (cute::is_same_v<BuilderScheduleTag, KernelTmaWarpSpecializedPingpong>)
|| (cute::is_same_v<BuilderScheduleTag, KernelTmaWarpSpecializedCooperative>)
// SM120 BS ptr_array
|| (cute::is_same_v<BuilderScheduleTag, KernelPtrArrayTmaWarpSpecializedPingpong>)
|| (cute::is_same_v<BuilderScheduleTag, KernelPtrArrayTmaWarpSpecializedCooperative>)
// SM120 BSSP
|| (cute::is_same_v<BuilderScheduleTag, KernelScheduleBlockScaledSparseGemmSm120>)
);
};
static_assert(cute::is_same_v<ElementSFA, ElementSFB>, "Scale factor types for A and B should be the same.");
static_assert((SfVectorSizeA == SfVectorSizeB), "Scale factor vector size for A and B should be the same.");
if constexpr ((SfVectorSizeA == 0) || (SfVectorSizeB == 0)) {
static_assert(!is_auto_instr_selection_policy(), "Auto instr selection isn't valid if scale factor vector size can't be determined from the types");
}
static_assert(cute::is_same_v<ElementSFA, cutlass::float_ue8m0_t>
|| cute::is_same_v<ElementSFA, cutlass::float_ue4m3_t>, "Incorrect scale factor type");
if constexpr (((sizeof_bits_v<ElementA> == 4 || sizeof_bits_v<ElementA> == 6 || sizeof_bits_v<ElementA> == 8) &&
(sizeof_bits_v<ElementB> == 4 || sizeof_bits_v<ElementB> == 6 || sizeof_bits_v<ElementB> == 8) ) && // A and B are 4, 6, or 8 bit types and
(!(sizeof_bits_v<ElementA> == 4 && sizeof_bits_v<ElementB> == 4) ) // A and B are not both 4 bit types
) {
///////////////////////////////////////////////////////////////////////
// Mixed Precision FP4, FP6, FP8 case. -> MX_F4F6F8 instructions
///////////////////////////////////////////////////////////////////////
// 1. Check Scale factor data type
static_assert(cute::is_same_v<ElementSFA, cutlass::float_ue8m0_t>, "MX_F4F6F8 only supports ue8m0 SF type");
// 2. Check whether A and B type combinations are valid or not
static_assert(
( // If runtime datatypes are used, then both A and B should be runtime data type
(
cute::is_same_v<ElementA, cutlass::type_erased_dynamic_float8_t> ||
cute::is_same_v<ElementA, cutlass::type_erased_dynamic_float6_t> ||
cute::is_same_v<ElementA, cutlass::type_erased_dynamic_float4_t>
) &&
(
cute::is_same_v<ElementB, cutlass::type_erased_dynamic_float8_t> ||
cute::is_same_v<ElementB, cutlass::type_erased_dynamic_float6_t> ||
cute::is_same_v<ElementB, cutlass::type_erased_dynamic_float4_t>
)
) ||
( // Valid (explicit) A and B type pairs
(
cute::is_same_v<ElementA, cutlass::float_e2m1_t> ||
cute::is_same_v<ElementA, cutlass::float_e2m3_t> ||
cute::is_same_v<ElementA, cutlass::float_e3m2_t> ||
cute::is_same_v<ElementA, cutlass::float_e4m3_t> ||
cute::is_same_v<ElementA, cutlass::float_e5m2_t>
) &&
(
cute::is_same_v<ElementB, cutlass::float_e2m1_t> ||
cute::is_same_v<ElementB, cutlass::float_e2m3_t> ||
cute::is_same_v<ElementB, cutlass::float_e3m2_t> ||
cute::is_same_v<ElementB, cutlass::float_e4m3_t> ||
cute::is_same_v<ElementB, cutlass::float_e5m2_t>
)
), "Incorrect types for A and B for MX_F4F6F8"
);
// 3. Check Scale factor vector size is valid.
// SfVectorSize = 32 for blockscaled dense gemm and ptr array blockscaled dense gemm
// SfVectorSize = 64 for blockscaled sparse gemm
static_assert(
((SfVectorSizeA == 32 && cute::is_same_v<KernelScheduleAuto, BuilderScheduleTag>)
|| (SfVectorSizeA == 32 && cute::is_same_v<KernelTmaWarpSpecializedPingpong, BuilderScheduleTag>)
|| (SfVectorSizeA == 32 && cute::is_same_v<KernelTmaWarpSpecializedCooperative, BuilderScheduleTag>)
|| (SfVectorSizeA == 32 && cute::is_base_of_v<KernelScheduleBlockScaledGemmSm100, BuilderScheduleTag>)
|| (SfVectorSizeA == 32 && cute::is_base_of_v<KernelSchedulePtrArrayBlockScaledGemmSm100, BuilderScheduleTag>)
|| (SfVectorSizeA == 64 && cute::is_base_of_v<KernelScheduleBlockScaledSparseGemmSm100, BuilderScheduleTag>)
|| (SfVectorSizeA == 32 && cute::is_base_of_v<KernelScheduleBlockScaledGemmSm120, BuilderScheduleTag>)
|| (SfVectorSizeA == 64 && cute::is_base_of_v<KernelScheduleBlockScaledSparseGemmSm120, BuilderScheduleTag>)
), "Incorrect SfVectorSize for MX_F4F6F8 is deduced.");
// 4. Check the kernel policy. Kernel policy should be either auto or *MXf8f6f4*
static_assert((cute::is_base_of_v<KernelScheduleMxf8f6f4Sm100, BuilderScheduleTag>
|| cute::is_base_of_v<KernelSchedulePtrArrayMxf8f6f4Sm100, BuilderScheduleTag>
|| cute::is_base_of_v<KernelScheduleSparseMxf8f6f4Sm100, BuilderScheduleTag>
|| cute::is_base_of_v<KernelScheduleMxf8f6f4Sm120, BuilderScheduleTag>
|| cute::is_base_of_v<KernelScheduleSparseMxf8f6f4Sm120, BuilderScheduleTag>
|| is_auto_instr_selection_policy()), "Incorrect Kernel Schedule Policy for Mx_F4F6F8 type inputs.");
return true;
}
else if constexpr ((sizeof_bits_v<ElementA> == 4 && sizeof_bits_v<ElementB> == 4)) {
///////////////////////////////////////////////////////////////////////
// A and B are both 4 bit types
// There are multiple block scaled tcgen05.mma instructions supporting F4 types.
///////////////////////////////////////////////////////////////////////
// 1. Check Scale factor data type
static_assert(cute::is_same_v<ElementSFA, cutlass::float_ue8m0_t>
|| cute::is_same_v<ElementSFA, cutlass::float_ue4m3_t>
, "MXNV_F4 supports ue8m0 and ue4m3 SF types");
// 2. Check whether A and B type combinations are valid or not
static_assert(
( // If runtime datatypes are used, then both A and B should be runtime data type
cute::is_same_v<ElementA, cutlass::type_erased_dynamic_float4_t> &&
cute::is_same_v<ElementB, cutlass::type_erased_dynamic_float4_t>
) ||
( // Valid (explicit) A and B type pairs
(
cute::is_same_v<ElementA, cutlass::float_e2m1_t>
) &&
(
cute::is_same_v<ElementB, cutlass::float_e2m1_t>
)
), "Incorrect types for A and B for MXNV_F4");
// 3. Skip checking the scale factor vector size. Will be checked later for specific Kernel Schedule policies.
// 4. Check the kernel policy.
static_assert((cute::is_base_of_v<KernelScheduleMxf8f6f4Sm100, BuilderScheduleTag> ||
cute::is_base_of_v<KernelScheduleMxNvf4Sm100, BuilderScheduleTag> ||
cute::is_base_of_v<KernelSchedulePtrArrayMxf8f6f4Sm100, BuilderScheduleTag> ||
cute::is_base_of_v<KernelSchedulePtrArrayMxNvf4Sm100, BuilderScheduleTag> ||
cute::is_base_of_v<KernelScheduleSparseMxf8f6f4Sm100, BuilderScheduleTag> ||
cute::is_base_of_v<KernelScheduleSparseMxNvf4Sm100, BuilderScheduleTag> ||
cute::is_base_of_v<KernelScheduleMxf8f6f4Sm120, BuilderScheduleTag> ||
cute::is_base_of_v<KernelScheduleMxNvf4Sm120, BuilderScheduleTag> ||
cute::is_base_of_v<KernelScheduleSparseMxf8f6f4Sm120, BuilderScheduleTag> ||
cute::is_base_of_v<KernelScheduleSparseMxNvf4Sm120, BuilderScheduleTag> ||
is_auto_instr_selection_policy()), "Incorrect Kernel Schedule Policy for F4 type inputs.");
// If a policy is specified, do more checks
if constexpr (cute::is_base_of_v<KernelScheduleMxf8f6f4Sm100, BuilderScheduleTag>
|| cute::is_base_of_v<KernelSchedulePtrArrayMxf8f6f4Sm100, BuilderScheduleTag>
|| cute::is_base_of_v<KernelScheduleSparseMxf8f6f4Sm100, BuilderScheduleTag>
|| cute::is_base_of_v<KernelScheduleMxf8f6f4Sm120, BuilderScheduleTag>
|| cute::is_base_of_v<KernelScheduleSparseMxf8f6f4Sm120, BuilderScheduleTag>) {
// Perform additional checks. Only subset of FP4 and scale factor types are supported.
static_assert(cute::is_same_v<ElementSFA, cutlass::float_ue8m0_t>, "MX_F4F6F8 only supports ue8m0 SF type");
static_assert((cute::is_same_v<ElementA, cutlass::type_erased_dynamic_float4_t> &&
cute::is_same_v<ElementB, cutlass::type_erased_dynamic_float4_t>) ||
(cute::is_same_v<ElementA, cutlass::float_e2m1_t> &&
cute::is_same_v<ElementB, cutlass::float_e2m1_t>), "Incorrect types for A and B for MX_F4F6F8");
static_assert(detail::find_vector_size<BuilderScheduleTag>() == SfVectorSizeA,
"Kernel Schedule policy doesn't match the scale factor vector size.");
return true;
}
else if constexpr (cute::is_base_of_v<KernelScheduleMxNvf4Sm100, BuilderScheduleTag>
|| cute::is_base_of_v<KernelSchedulePtrArrayMxNvf4Sm100, BuilderScheduleTag>
|| cute::is_base_of_v<KernelScheduleSparseMxNvf4Sm100, BuilderScheduleTag>
|| cute::is_base_of_v<KernelScheduleMxNvf4Sm120, BuilderScheduleTag>
|| cute::is_base_of_v<KernelScheduleSparseMxNvf4Sm120, BuilderScheduleTag>) {
static_assert((UmmaMajorA == UMMA::Major::K && UmmaMajorB == UMMA::Major::K), "MX/NV_F4 only supports RowMajor A, and ColMajorB");
static_assert(detail::find_vector_size<BuilderScheduleTag>() == SfVectorSizeA,
"Kernel Schedule policy doesn't match the scale factor vector size.");
return true;
}
else { // auto policy
// If the scale factor type is ue4m3 or the scale factor vector size is 16 -> only MXF4_NVF4 instruction can support it
// For MXF4_NVF4, the layouts should be RowMajor A, and ColMajorB
static_assert(is_auto_instr_selection_policy(), "Kernel Schedule policy should be auto");
if constexpr (SfVectorSizeA == 16 || SfVectorSizeB == 16
|| cute::is_same_v<ElementSFA, cutlass::float_ue4m3_t>
) { // Only MXF4NVF4 can support these types
static_assert((UmmaMajorA == UMMA::Major::K && UmmaMajorB == UMMA::Major::K), "NV_F4 only supports RowMajor A, and ColMajorB");
return true;
}
return true;
}
}
else {
return false;
}
return false;
}
template <
class TileShape_MNK, // (MmaAtomShape_M, MmaAtomShape_N, CtaTileShapeK)
class ClusterShape_MNK,
class BuilderScheduleTag
>
CUTLASS_HOST_DEVICE
static constexpr bool
is_2sm() {
// 2SM kernel schedule is requested
if constexpr (cute::is_base_of_v<KernelSchedule2Sm, BuilderScheduleTag>) { return true; }
// 1SM kernel schedule is requested
else if constexpr (cute::is_base_of_v<KernelSchedule1Sm, BuilderScheduleTag>) { return false; }
// auto schedule is used.
else {
if constexpr (!cute::is_static_v<ClusterShape_MNK>) {
// If the cluster shape is dynamic, we can't guarantee 2x1. Default to 1sm.
// If tile shape M is 256, throw an error. M=256 is only supported by 2SM instructions.
static_assert(get<0>(TileShape_MNK{}) != 256, "If M=256, auto policy can't create 2sm kernels. Specify a 2SM policy");
return false;
}
else if constexpr (cute::is_static_v<ClusterShape_MNK> && cute::get<0>(ClusterShape_MNK{}) % 2 == 0) {
// We need to check the TileShape
if constexpr (get<0>(TileShape_MNK{}) == 256) {
return true;
}
else if constexpr (get<0>(TileShape_MNK{}) == 128) {
return false;
}
else {
static_assert(get<0>(TileShape_MNK{}) == 0, "Unsupported M dimension for TileShape_MNK.");
}
}
else { return false;}
}
}
template <
class ElementPairA,
class ElementPairB,
class ElementAccumulator,
UMMA::Major UmmaMajorA,
UMMA::Major UmmaMajorB,
class BuilderScheduleTag
>
CUTLASS_HOST_DEVICE
static constexpr auto
select_instr() {
using ElementSFA = typename detail::blockscaled::blockscaled_type<BuilderScheduleTag, ElementPairA>::sf_type;
using ElementSFB = typename detail::blockscaled::blockscaled_type<BuilderScheduleTag, ElementPairB>::sf_type;
using ElementA = typename detail::blockscaled::blockscaled_type<BuilderScheduleTag, ElementPairA>::data_type;
using ElementB = typename detail::blockscaled::blockscaled_type<BuilderScheduleTag, ElementPairB>::data_type;
constexpr uint32_t SfVectorSizeA = detail::blockscaled::blockscaled_type<BuilderScheduleTag, ElementPairA>::SfVectorSize;
constexpr uint32_t SfVectorSizeB = detail::blockscaled::blockscaled_type<BuilderScheduleTag, ElementPairB>::SfVectorSize;
constexpr int SfVectorSize = SfVectorSizeA > SfVectorSizeB ? SfVectorSizeA : SfVectorSizeB;
using ElementSF = ElementSFA;
if constexpr (cute::is_base_of_v<KernelScheduleMxf8f6f4Sm100, BuilderScheduleTag>
|| cute::is_base_of_v<KernelSchedulePtrArrayMxf8f6f4Sm100, BuilderScheduleTag>
|| cute::is_base_of_v<KernelScheduleSparseMxf8f6f4Sm100, BuilderScheduleTag>
|| cute::is_base_of_v<KernelScheduleMxf8f6f4Sm120, BuilderScheduleTag>
|| cute::is_base_of_v<KernelScheduleSparseMxf8f6f4Sm120, BuilderScheduleTag>) {
return detail::blockscaled::BlockScaledInstr::MXF4F6F8;
}
else if constexpr (cute::is_base_of_v<KernelScheduleMxNvf4Sm100, BuilderScheduleTag>
|| cute::is_base_of_v<KernelSchedulePtrArrayMxNvf4Sm100, BuilderScheduleTag>
|| cute::is_base_of_v<KernelScheduleSparseMxNvf4Sm100, BuilderScheduleTag>
|| cute::is_base_of_v<KernelScheduleMxNvf4Sm120, BuilderScheduleTag>
|| cute::is_base_of_v<KernelScheduleSparseMxNvf4Sm120, BuilderScheduleTag>) {
return detail::blockscaled::BlockScaledInstr::MXF4_NVF4;
}
else {
// Auto scheduling
if constexpr ((sizeof_bits_v<ElementA> >= 6 && sizeof_bits_v<ElementA> <= 8) &&
(sizeof_bits_v<ElementB> >= 6 && sizeof_bits_v<ElementB> <= 8)) {
// These types can only be supported by MX_F8F6F4 instruction
static_assert(
(SfVectorSize == 32 && cute::is_same_v<KernelScheduleAuto, BuilderScheduleTag>)
|| (SfVectorSize == 32 && cute::is_base_of_v<KernelScheduleBlockScaledGemmSm100, BuilderScheduleTag>)
|| (SfVectorSize == 32 && cute::is_base_of_v<KernelTmaWarpSpecializedPingpong, BuilderScheduleTag>)
|| (SfVectorSize == 32 && cute::is_base_of_v<KernelTmaWarpSpecializedCooperative, BuilderScheduleTag>)
|| (SfVectorSize == 32 && cute::is_base_of_v<KernelSchedulePtrArrayBlockScaledGemmSm100, BuilderScheduleTag>)
|| (SfVectorSize == 64 && cute::is_base_of_v<KernelScheduleBlockScaledSparseGemmSm100, BuilderScheduleTag>
|| (SfVectorSize == 32 && cute::is_base_of_v<KernelScheduleBlockScaledGemmSm120, BuilderScheduleTag>)
|| (SfVectorSize == 64 && cute::is_base_of_v<KernelScheduleBlockScaledSparseGemmSm120, BuilderScheduleTag>)
), "Incorrect SfVectorSize for MX_F4F6F8 is deduced.");
return detail::blockscaled::BlockScaledInstr::MXF4F6F8;
}
else if constexpr (( sizeof_bits_v<ElementA> == 4 && (sizeof_bits_v<ElementB> == 6 || sizeof_bits_v<ElementB> == 8)) ||
((sizeof_bits_v<ElementA> == 6 || sizeof_bits_v<ElementA> == 8) && sizeof_bits_v<ElementB> == 4)) {
// Fp4 can be mixed with FP6, Fp8 with MMA.MXF8F6F4 only
return detail::blockscaled::BlockScaledInstr::MXF4F6F8;
}
else if constexpr (sizeof_bits_v<ElementA> == 4 && sizeof_bits_v<ElementB> == 4) {
// Both A and B are 4bits
if constexpr (UmmaMajorA == UMMA::Major::K && UmmaMajorB == UMMA::Major::K) {
// MXF4_NVF4 possible
return detail::blockscaled::BlockScaledInstr::MXF4_NVF4;
}
else {
static_assert(
((SfVectorSize == 32 && cute::is_same_v<KernelScheduleAuto, BuilderScheduleTag>)
|| (SfVectorSize == 32 && cute::is_base_of_v<KernelTmaWarpSpecializedPingpong, BuilderScheduleTag>)
|| (SfVectorSize == 32 && cute::is_base_of_v<KernelTmaWarpSpecializedCooperative, BuilderScheduleTag>)
|| (SfVectorSize == 32 && cute::is_base_of_v<KernelScheduleBlockScaledGemmSm100, BuilderScheduleTag>)
|| (SfVectorSize == 32 && cute::is_base_of_v<KernelSchedulePtrArrayBlockScaledGemmSm100, BuilderScheduleTag>)
|| (SfVectorSize == 64 && cute::is_base_of_v<KernelScheduleBlockScaledSparseGemmSm100, BuilderScheduleTag>)
|| (SfVectorSize == 32 && cute::is_base_of_v<KernelScheduleBlockScaledGemmSm120, BuilderScheduleTag>)
|| (SfVectorSize == 64 && cute::is_base_of_v<KernelScheduleBlockScaledSparseGemmSm120, BuilderScheduleTag>)
), "Incorrect SfVectorSize for MX_F4F6F8 is deduced.");
static_assert(cute::is_same_v<ElementSF, cutlass::float_ue8m0_t> &&
(cute::is_same_v<ElementA, cutlass::float_e2m1_t> &&
cute::is_same_v<ElementB, cutlass::float_e2m1_t> ||
cute::is_same_v<ElementA, cutlass::type_erased_dynamic_float4_t> &&
cute::is_same_v<ElementB, cutlass::type_erased_dynamic_float4_t>),
"Only MXF4 support with non-TN and MMA.MXF8F6F4.");
return detail::blockscaled::BlockScaledInstr::MXF4F6F8;
}
}
}
}
} // namespace blockscaled
} // namespace detail
/////////////////////////////////////////////////////////////////////////////////////////////////
} // namespace cutlass::gemm::collective