Skip to content

Commit e8ecfad

Browse files
b8zhongBrayden Zhong
andauthored
add tileN = 8,16 for SM120 blockscale GEMM. (#3292)
* add tileN = 8,16 * add a guard --------- Co-authored-by: Brayden Zhong <brayden.zhong@radixark.ai>
1 parent 12ff513 commit e8ecfad

3 files changed

Lines changed: 55 additions & 19 deletions

File tree

include/cutlass/epilogue/collective/builders/sm120_builder.inl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ sm120_compute_tile_shape_or_override() {
191191
}
192192
}
193193
else {
194-
return Shape<_64, _32>{};
194+
constexpr int EpiN = CTA_N < 32 ? CTA_N : 32;
195+
constexpr int EpiM = CTA_N < 16 ? 128 : 64;
196+
return Shape<Int<EpiM>, Int<EpiN>>{};
195197
}
196198
}
197199
} // EpilogueTileAuto

include/cutlass/gemm/collective/builders/sm120_blockscaled_mma_builder.inl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ struct CollectiveBuilder<
7373
cute::is_base_of_v<KernelPtrArrayTmaWarpSpecializedCooperative, BuilderScheduleTag> ||
7474
cute::is_same_v<KernelScheduleAuto, BuilderScheduleTag>)
7575
&&
76+
!((cute::is_base_of_v<KernelTmaWarpSpecializedPingpong, BuilderScheduleTag> ||
77+
cute::is_base_of_v<KernelPtrArrayTmaWarpSpecializedPingpong, BuilderScheduleTag>) &&
78+
cute::tuple_element_t<1, TileShape_MNK>::value < 16)
79+
&&
7680
// Alignment check
7781
detail::sm1xx_blockscaled_gemm_is_aligned<typename detail::blockscaled::blockscaled_type<BuilderScheduleTag, ElementPairA>::data_type,
7882
AlignmentA,
@@ -98,7 +102,7 @@ struct CollectiveBuilder<
98102
static_assert(cute::is_static_v<ClusterShape_MNK>, "Cluster has to be static");
99103
static_assert(detail::blockscaled::check_input_datatypes<BuilderScheduleTag, ElementPairA, ElementPairB, UmmaMajorA, UmmaMajorB>(), "Incorrect input types");
100104
static_assert(cute::size(ClusterShape_MNK{}) == Int<1>{}, "no programmatic multicast on this arch");
101-
static_assert(size<1>(TileShape_MNK{}) >= 32, "Invalid tile shape N.");
105+
static_assert(size<1>(TileShape_MNK{}) >= 8, "Invalid tile shape N.");
102106

103107
static constexpr auto Instr = detail::blockscaled::select_instr<ElementPairA,
104108
ElementPairB,
@@ -108,7 +112,7 @@ struct CollectiveBuilder<
108112
BuilderScheduleTag>();
109113
static constexpr bool UseMxf8f6f4 = Instr == detail::blockscaled::BlockScaledInstr::MXF4F6F8;
110114
using PermTileM = decltype(cute::min(size<0>(TileShape_MNK{}), _128{}));
111-
using PermTileN = decltype(detail::sm120_tile_n_permute_selector<SFVectorSize>());
115+
using PermTileN = decltype(detail::sm120_tile_n_permute_selector<SFVectorSize, size<1>(TileShape_MNK{})>());
112116
using PermTileK = cute::conditional_t<(UseMxf8f6f4
113117
), _32, _64>;
114118

@@ -125,7 +129,9 @@ struct CollectiveBuilder<
125129
"TileSize and MNK Major does not met with MMA Mix 8-bit TMA load requirement" );
126130

127131
using AtomLayoutMNK = cute::conditional_t<IsCooperative,
128-
Layout<Shape<_4,_2,_1>>, Layout<Shape<_2,_2,_1>>>;
132+
cute::conditional_t<(size<1>(TileShape_MNK{}) >= 16), Layout<Shape<_4,_2,_1>>,
133+
Layout<Shape<_8,_1,_1>>>,
134+
Layout<Shape<_2,_2,_1>>>;
129135

130136
using TiledMma = decltype(cute::make_tiled_mma(
131137
cute::rr_blockscaled_op_selector_sm120<ElementA,
@@ -166,7 +172,8 @@ struct CollectiveBuilder<
166172
>()), SmemAllocTypeA>;
167173
using SmemCopyAtomB = Copy_Atom<decltype(detail::sm120_rr_smem_copy_selector_B<ElementA,
168174
ElementB,
169-
UseMxf8f6f4
175+
UseMxf8f6f4,
176+
size<1>(TileShape_MNK{})
170177
>()), SmemAllocTypeB>;
171178

172179
using SmemCopyAtomSF = Copy_Atom<UniversalCopy<SmemAllocTypeSF>, SmemAllocTypeSF>; // auto-vectorized LDS

include/cutlass/gemm/collective/builders/sm120_common.inl

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ sm120_rr_smem_copy_selector_A() {
7373
template <
7474
class ElementA,
7575
class ElementB,
76-
bool UseF8f6f4
76+
bool UseF8f6f4,
77+
int TileShapeN = 32
7778
>
7879
CUTLASS_HOST_DEVICE constexpr
7980
auto
@@ -83,14 +84,38 @@ sm120_rr_smem_copy_selector_B() {
8384
return SM100_SU6_DU8x16_x4_LDSM_N{};
8485
}
8586
else if constexpr (sizeof_bits_v<ElementB> == 4) {
86-
return SM100_SU4_DU8x16_x4_LDSM_N{};
87+
if constexpr (TileShapeN < 16) {
88+
return SM100_SU4_DU8x16_x1_LDSM_N{};
89+
}
90+
else if constexpr (TileShapeN < 32) {
91+
return SM100_SU4_DU8x16_x2_LDSM_N{};
92+
}
93+
else {
94+
return SM100_SU4_DU8x16_x4_LDSM_N{};
95+
}
8796
}
8897
else {
89-
return SM75_U32x4_LDSM_N{};
98+
if constexpr (TileShapeN < 16) {
99+
return SM75_U32x1_LDSM_N{};
100+
}
101+
else if constexpr (TileShapeN < 32) {
102+
return SM75_U32x2_LDSM_N{};
103+
}
104+
else {
105+
return SM75_U32x4_LDSM_N{};
106+
}
90107
}
91-
}
108+
}
92109
else {
93-
return SM75_U32x4_LDSM_N{};
110+
if constexpr (TileShapeN < 16) {
111+
return SM75_U32x1_LDSM_N{};
112+
}
113+
else if constexpr (TileShapeN < 32) {
114+
return SM75_U32x2_LDSM_N{};
115+
}
116+
else {
117+
return SM75_U32x4_LDSM_N{};
118+
}
94119
}
95120
}
96121

@@ -140,22 +165,24 @@ sm120_rr_smem_selector_sparse() {
140165
}
141166
}
142167

143-
template <int SFVectorSize>
168+
template <int SFVectorSize, int TileShapeN = 32>
144169
CUTLASS_HOST_DEVICE constexpr
145170
auto
146171
sm120_tile_n_permute_selector() {
147-
// VS = 16
148-
if constexpr (SFVectorSize == 16) {
149-
// Permute in the N mode to allow a warp to own all the elements needed for SF reduction
172+
static_assert(SFVectorSize == 16 || SFVectorSize == 32,
173+
"Unsupported SFVectorSize for SM120 collective builder.");
174+
if constexpr (TileShapeN >= 32) {
150175
return cute::Layout<cute::Shape<_8,_2,_2>, cute::Stride<_1, _16,_8>>{};
151176
}
152-
// VS = 32
153-
else if constexpr (SFVectorSize == 32) {
154-
return cute::Layout<cute::Shape<_8,_2,_2>, cute::Stride<_1, _16,_8>>{};
177+
else if constexpr (TileShapeN == 16) {
178+
return cute::Layout<cute::Shape<_8,_2>, cute::Stride<_1,_8>>{};
179+
}
180+
else if constexpr (TileShapeN == 8) {
181+
return cute::Layout<cute::Shape<_8>, cute::Stride<_1>>{};
155182
}
156183
else {
157-
static_assert(cutlass::detail::dependent_false<cute::C<SFVectorSize>>,
158-
"Unsupported SFVectorSize for SM120 collective builder.");
184+
static_assert(cutlass::detail::dependent_false<cute::C<TileShapeN>>,
185+
"TileShape_N must be at least 8 for SM120 blockscaled.");
159186
}
160187
}
161188

0 commit comments

Comments
 (0)