36 template <
typename GridwiseGemm,
37 bool HasMainKBlockLoop,
42 #if CK_USE_LAUNCH_BOUNDS
48 #if defined(__gfx9__) || defined(__gfx11__) || defined(__gfx12__)
49 if constexpr(GridwiseGemm::template IsValidCompilationParameter<CGlobalMemoryDataOperation>())
51 __shared__
char p_shared[GridwiseGemm::GetSharedMemoryNumberOfByte()];
53 auto splitk_batch_offset =
typename GridwiseGemm::SplitKBatchOffset(karg, blockIdx.z);
55 GridwiseGemm::template Run<HasMainKBlockLoop, CGlobalMemoryDataOperation, TailNum>(
56 karg.p_sorted_token_ids,
57 karg.p_sorted_expert_ids,
59 karg.p_a_grid + splitk_batch_offset.a_k_split_offset,
60 karg.p_b_grid + splitk_batch_offset.b_k_split_offset,
63 karg.p_a_scale_grid + splitk_batch_offset.ascale_k_split_offset,
64 karg.p_b_scale_grid + splitk_batch_offset.bscale_k_split_offset,
76 template <
typename GridwiseGemm,
77 bool HasMainKBlockLoop,
82 #if CK_USE_LAUNCH_BOUNDS
88 #if defined(__gfx9__) || defined(__gfx11__) || defined(__gfx12__)
89 if constexpr(GridwiseGemm::template IsValidCompilationParameter<CGlobalMemoryDataOperation>())
91 __shared__
char p_shared[GridwiseGemm::GetSharedMemoryNumberOfByte()];
92 __shared__
char p_shared1[GridwiseGemm::GetSharedMemoryNumberOfByte()];
94 auto splitk_batch_offset =
typename GridwiseGemm::SplitKBatchOffset(karg, blockIdx.z);
96 GridwiseGemm::template Run_2Lds<HasMainKBlockLoop, CGlobalMemoryDataOperation, TailNum>(
97 karg.p_sorted_token_ids,
98 karg.p_sorted_expert_ids,
100 karg.p_a_grid + splitk_batch_offset.a_k_split_offset,
101 karg.p_b_grid + splitk_batch_offset.b_k_split_offset,
104 karg.p_a_scale_grid + splitk_batch_offset.ascale_k_split_offset,
105 karg.p_b_scale_grid + splitk_batch_offset.bscale_k_split_offset,
118 template <
typename ALayout,
124 typename AccDataType,
125 typename CShuffleDataType,
128 typename AElementwiseOperation,
129 typename BElementwiseOperation,
130 typename CElementwiseOperation,
145 typename ABlockTransferThreadClusterLengths_AK0_M_AK1,
146 typename ABlockTransferThreadClusterArrangeOrder,
147 typename ABlockTransferSrcAccessOrder,
148 index_t ABlockTransferSrcVectorDim,
149 index_t ABlockTransferSrcScalarPerVector,
150 index_t ABlockTransferDstScalarPerVector_AK1,
151 bool AThreadTransferSrcResetCoordinateAfterRun,
153 typename BBlockTransferThreadClusterLengths_BK0_N_BK1,
154 typename BBlockTransferThreadClusterArrangeOrder,
155 typename BBlockTransferSrcAccessOrder,
156 index_t BBlockTransferSrcVectorDim,
157 index_t BBlockTransferSrcScalarPerVector,
158 index_t BBlockTransferDstScalarPerVector_BK1,
159 bool BThreadTransferSrcResetCoordinateAfterRun,
161 index_t CShuffleMXdlPerWavePerShuffle,
162 index_t CShuffleNXdlPerWavePerShuffle,
163 typename CShuffleBlockTransferClusterLengths_MBlock_MPerBlock_NBlock_NPerBlock,
164 typename CDEShuffleBlockTransferScalarPerVectors,
167 index_t ActivationOperation = 0,
168 bool NSwizzle =
false,
169 bool IsInputGemm =
true,
170 bool IsSplitK =
false,
171 bool MulRoutedWeight =
true,
173 typename ComputeTypeA = CDataType,
174 typename ComputeTypeB = ComputeTypeA,
175 typename LDSTypeA = ADataType,
176 typename LDSTypeB = BDataType>
192 CDEShuffleBlockTransferScalarPerVectors{}[
I0];
230 return static_cast<const DDataType*
>(
nullptr);
257 const index_t gridx = NSwizzle ? nblock * mblock : nblock;
258 const index_t gridy = NSwizzle ? 1 : mblock;
292 return K_Batch == 1 ? K / AK1Value : K_Batch * KPerBlock / AK1Value;
299 return K_Batch == 1 ? K / BK1Value : K_Batch * KPerBlock / BK1Value;
306 return K_Batch == 1 ? K : K_Batch * KPerBlock;
315 : K_Batch * KPerBlock;
328 template <index_t MNXdlPerWave, index_t MNWaves, index_t MNPerXdl,
typename TileDesc_K0_MN_K1>
344 IndexType M, IndexType MPad, IndexType K, IndexType KPad, IndexType StrideA, IndexType AK0)
346 const auto a_grid_desc_mraw_kraw = [&]() {
347 if constexpr(is_same_v<tensor_layout::gemm::RowMajor, ALayout>)
351 else if constexpr(is_same_v<tensor_layout::gemm::ColumnMajor, ALayout>)
359 if constexpr(GemmSpec == GemmSpecialization::MKPadding ||
360 GemmSpec == GemmSpecialization::MNKPadding)
363 const auto a_grid_desc_m_k =
377 return a_grid_desc_ak0_m_ak1;
379 else if constexpr(GemmSpec == GemmSpecialization::MPadding ||
380 GemmSpec == GemmSpecialization::MNPadding)
384 a_grid_desc_mraw_kraw,
390 return a_grid_desc_ak0_m_ak1;
392 else if constexpr(GemmSpec == GemmSpecialization::KPadding ||
393 GemmSpec == GemmSpecialization::NKPadding)
397 a_grid_desc_mraw_kraw,
409 return a_grid_desc_ak0_m_ak1;
415 a_grid_desc_mraw_kraw,
420 return a_grid_desc_ak0_m_ak1;
426 constexpr
index_t MWave = MPerBlock / (MXdlPerWave * MPerXdl);
427 constexpr
index_t WaveSize = BlockSize / (MWave *
NWave);
431 make_tuple(
NWave * K0 * NkSwizzleNumber, K0 * NkSwizzleNumber, NkSwizzleNumber,
I1));
437 const auto b_grid_desc_nraw_kraw = [&]() {
451 GemmSpec != GemmSpecialization::Default),
452 "pk_i4_t does not support padding");
454 if constexpr(GemmSpec == GemmSpecialization::NKPadding ||
455 GemmSpec == GemmSpecialization::MNKPadding)
458 const auto b_grid_desc_n_k =
472 return b_grid_desc_bk0_n_bk1;
474 else if constexpr(GemmSpec == GemmSpecialization::NPadding ||
475 GemmSpec == GemmSpecialization::MNPadding)
479 b_grid_desc_nraw_kraw,
485 return b_grid_desc_bk0_n_bk1;
487 else if constexpr(GemmSpec == GemmSpecialization::KPadding ||
488 GemmSpec == GemmSpecialization::MKPadding)
492 b_grid_desc_nraw_kraw,
504 return b_grid_desc_bk0_n_bk1;
510 b_grid_desc_nraw_kraw,
516 return b_grid_desc_bk0_n_bk1;
520 template <
typename ABlockDesc_AK0_M_AK1>
521 __host__ __device__
static constexpr
auto
524 constexpr
index_t MWaves = MPerBlock / (MXdlPerWave * MPerXdl);
526 return MakeGemmMmaTileDescriptor<MXdlPerWave, MWaves, MPerXdl>(ABlockDesc_AK0_M_AK1{});
529 template <
typename BBlockDesc_BK0_N_BK1>
530 __host__ __device__
static constexpr
auto
533 return MakeGemmMmaTileDescriptor<NXdlPerWave, NWave, NPerXdl>(BBlockDesc_BK0_N_BK1{});
536 template <
typename ELayout>
538 IndexType M, IndexType MPad, IndexType N, IndexType NPad, IndexType StrideC)
540 const auto c_grid_desc_mraw_nraw = [&]() {
559 template <
typename DLayout>
560 __host__ __device__
static auto
563 const auto c_grid_desc_mraw_nraw = [&]() {
588 return MakeDGridDescriptor_M_N<DLayout>(M, MPad, N, NPad, StrideDs[i]);
593 template <
typename DsGr
idDesc>
595 const DsGridDesc& ds_grid_desc_m_n,
index_t MBlock,
index_t NBlock)
600 ds_grid_desc_m_n[i], MBlock, NBlock);
616 std::array<index_t, NumDTensor> StrideDs_,
642 std::cout <<
"problem {" <<
"NumTokens:" <<
NumTokens <<
", " <<
"TopK:" <<
TopK <<
", "
643 <<
"M:" <<
M <<
", " <<
"N:" <<
N <<
", " <<
"K:" <<
K <<
", "
646 <<
"KRead:" <<
KRead <<
", " <<
"KP:" <<
KPadded <<
", " <<
"AK0:" <<
AK0
647 <<
", " <<
"BK0:" <<
BK0 <<
", " <<
"MBlock: " <<
MBlock <<
", "
648 <<
"NBlock: " <<
NBlock <<
"}" << std::endl;
675 const index_t* p_sorted_expert_ids_,
676 const index_t* p_max_token_id_,
677 const ADataType* p_a_grid_,
678 const BDataType* p_b_grid_,
679 std::array<const void*, NumDTensor> p_ds_grid_,
680 CDataType* p_c_grid_,
688 std::array<index_t, NumDTensor> StrideDs_,
693 AElementwiseOperation a_element_op_,
694 BElementwiseOperation b_element_op_,
695 CElementwiseOperation c_element_op_)
725 p_ds_grid(i) =
static_cast<const DDataType_*
>(p_ds_grid_[i]);
749 if constexpr(is_same_v<tensor_layout::gemm::RowMajor, ALayout>)
754 else if constexpr(is_same_v<tensor_layout::gemm::ColumnMajor, ALayout>)
760 if constexpr(is_same_v<tensor_layout::gemm::RowMajor, BLayout>)
765 else if constexpr(is_same_v<tensor_layout::gemm::ColumnMajor, BLayout>)
790 constexpr
index_t MWave = MPerBlock / (MXdlPerWave * MPerXdl);
791 constexpr
index_t WaveSize = BlockSize / (MWave *
NWave);
793 if constexpr(ABlockLdsExtraM)
803 constexpr
auto a_lds_block_desc =
815 return a_lds_block_desc_permuted;
822 constexpr
auto M0 = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I1);
823 constexpr
auto M1 = MPerBlock / M0;
825 constexpr
auto KThreadWrite = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I0);
826 constexpr
auto K0PerThreadWrite =
AK0Number / KThreadWrite;
827 constexpr
auto KThreadRead = WaveSize / MPerXdl;
828 constexpr
auto K0PerThreadRead =
AK0Number / KThreadRead;
830 constexpr
auto kfold = (
AK1Number * M0 *
sizeof(LDSTypeA) > 128)
832 : 128 / (
AK1Number * M0 *
sizeof(LDSTypeA));
833 constexpr
auto KThreadReadPerm =
834 (kfold * K0PerThreadWrite / K0PerThreadRead) > 1
835 ? KThreadRead / (kfold * K0PerThreadWrite / K0PerThreadRead)
839 constexpr
auto mpair = (
AK1Number * MPerXdl *
sizeof(LDSTypeA) > 128)
841 : ((128 / (
AK1Number * MPerXdl *
sizeof(LDSTypeA))) > M0
843 : 128 / (
AK1Number * MPerXdl *
sizeof(LDSTypeA)));
849 Number<kfold * M0 / mpair>{},
868 a_lds_block_desc_permuted,
890 a_lds_block_desc_unmerged,
893 Number<KThreadWrite / kfold / KThreadReadPerm>{},
902 return a_lds_block_desc_ak0_m_ak1;
915 constexpr
index_t MWave = MPerBlock / (MXdlPerWave * MPerXdl);
917 constexpr
auto c_shuffle_block_desc_mblock_mperblock_nblock_nperblock =
924 return c_shuffle_block_desc_mblock_mperblock_nblock_nperblock;
942 ABlockTransferSrcScalarPerVector,
943 BBlockTransferSrcScalarPerVector,
955 IsInputGemm && !IsSplitK > ())>;
965 a_block_desc_ak0_m_ak1.GetElementSpaceSize(), max_lds_align);
968 constexpr
auto c_shuffle_block_desc_mblock_mperblock_nblock_nperblock =
971 constexpr
auto c_block_size =
972 c_shuffle_block_desc_mblock_mperblock_nblock_nperblock.GetElementSpaceSize();
975 c_block_size *
sizeof(CShuffleDataType));
983 static_assert((MPerBlock % (MPerXdl * MXdlPerWave) == 0) &&
984 (NPerBlock % (NXdlPerWave * NPerXdl)) == 0,
985 "Invalid tuning param!");
993 if(!(karg.M % MPerBlock == 0))
996 std::cout <<
"Arg M value is not a multiple of MPerBlock! M: " << karg.M <<
" "
997 << __FILE__ <<
":" << __LINE__ <<
", in function: " << __func__
1011 if(!(karg.N % NPerBlock == 0))
1014 std::cout <<
"Arg N value is not a multiple of NPerBlock! N: " << karg.N <<
" "
1015 << __FILE__ <<
":" << __LINE__ <<
", in function: " << __func__
1029 auto K_t = karg.KBatch * KPerBlock;
1030 if(!(karg.K % K_t == 0))
1033 std::cout <<
"Arg K value is not a multiple of K_Batch * K0PerBlock * K1! K: "
1034 << karg.K <<
" " << __FILE__ <<
":" << __LINE__
1035 <<
", in function: " << __func__ << std::endl;
1044 auto K_t = karg.KBatch * KReadVec;
1046 if((KReadPadSplited * (karg.KBatch - 1)) >= karg.K)
1054 if(karg.K % ABlockTransferSrcScalarPerVector != 0)
1057 std::cout <<
"Arg K (" << karg.K
1058 <<
") value is not a multiple of ABlockTransferSrcScalarPerVector ("
1059 << ABlockTransferSrcScalarPerVector <<
" )! " << __FILE__ <<
":"
1060 << __LINE__ <<
", in function: " << __func__ << std::endl;
1068 if(karg.M % ABlockTransferSrcScalarPerVector != 0)
1071 std::cout <<
"Arg M (" << karg.M
1072 <<
") value is not a multiple of ABlockTransferSrcScalarPerVector ("
1073 << ABlockTransferSrcScalarPerVector <<
" )! " << __FILE__ <<
":"
1074 << __LINE__ <<
", in function: " << __func__ << std::endl;
1083 if(karg.N % BBlockTransferSrcScalarPerVector != 0)
1086 std::cout <<
"Arg N (" << karg.N
1087 <<
") value is not a multiple of BBlockTransferSrcScalarPerVector ("
1088 << BBlockTransferSrcScalarPerVector <<
" )! " << __FILE__ <<
":"
1089 << __LINE__ <<
", in function: " << __func__ << std::endl;
1097 if(karg.K % BBlockTransferSrcScalarPerVector != 0)
1100 std::cout <<
"Arg K (" << karg.K
1101 <<
") value is not a multiple of BBlockTransferSrcScalarPerVector ("
1102 << BBlockTransferSrcScalarPerVector <<
" )! " << __FILE__ <<
":"
1103 << __LINE__ <<
", in function: " << __func__ << std::endl;
1115 std::cout <<
"Arg N (" << karg.N
1116 <<
") value is not a multiple of "
1117 "CShuffleBlockTransferScalarPerVector_NPerBlock ("
1119 <<
":" << __LINE__ <<
", in function: " << __func__ << std::endl;
1130 std::cout <<
"Arg M (" << karg.M
1131 <<
") value is not a multiple of "
1132 "CShuffleBlockTransferScalarPerVector_NPerBlock ("
1134 <<
":" << __LINE__ <<
", in function: " << __func__ << std::endl;
1143 const auto num_k_loop = karg.AK0 / (KPerBlock / AK1Value);
1145 if(num_k_loop <= BlockwiseGemmPipe::PrefetchStages)
1156 const index_t num_loop = K / KPerBlock;
1158 return BlockwiseGemmPipe::BlockHasHotloop(num_loop);
1163 const index_t num_loop = K / KPerBlock;
1165 return BlockwiseGemmPipe::BlockLoopTailNum(num_loop);
1168 template <
typename CGr
idDesc>
1170 const CGridDesc& c_grid_desc_m_n,
index_t MBlock,
index_t NBlock)
1179 return c_grid_desc_mblock_mperblock_nblock_nperblock;
1187 template <
bool HasMainKBlockLoop,
1191 const index_t* p_sorted_expert_ids,
1192 const index_t* p_max_token_id,
1193 const ADataType* p_a_grid,
1194 const BDataType* p_b_grid,
1196 CDataType* p_c_grid,
1201 AElementwiseOperation a_element_op,
1202 BElementwiseOperation b_element_op,
1203 CElementwiseOperation c_element_op)
1215 const auto b_grid_desc_bpreshuffled =
1217 const auto c_grid_desc_m_n = MakeCGridDescriptor_M_N<CLayout>(
1220 problem.
N * (IsInputGemm && IsSplitK ? 2 : 1),
1221 problem.
NPadded * (IsInputGemm && IsSplitK ? 2 : 1),
1236 const auto c_grid_desc_mblock_mperblock_nblock_nperblock =
1239 const index_t max_token_id = __builtin_amdgcn_readfirstlane(p_max_token_id[0]);
1241 const index_t expert_block_id = NSwizzle ? blockIdx.x / problem.
NBlock : blockIdx.y;
1242 if(expert_block_id * MPerBlock >= max_token_id)
1245 __builtin_amdgcn_readfirstlane(p_sorted_expert_ids[expert_block_id]);
1246 const auto block_mn = [&]() -> std::pair<int, int> {
1247 if constexpr(NSwizzle)
1249 const index_t ecnt_prefix = p_max_token_id[1 + expert_id];
1251 const index_t ecnt = p_max_token_id[2 + expert_id] - ecnt_prefix;
1252 const index_t expert_swizzle =
1253 ecnt > 0 ? ecnt : 1;
1254 const index_t bid_new = blockIdx.x - prefix_block;
1255 const index_t nid = __builtin_amdgcn_readfirstlane(
1256 bid_new % 8 + bid_new / (8 * expert_swizzle) * 8);
1258 __builtin_amdgcn_readfirstlane(ecnt_prefix + bid_new / 8 % expert_swizzle);
1263 return {blockIdx.x, blockIdx.y};
1266 const index_t block_n_id = block_mn.first;
1267 const index_t block_m_id = block_mn.second;
1269 __builtin_amdgcn_readfirstlane(p_sorted_token_ids[block_m_id * MPerBlock] & 0xffffff);
1272 constexpr
auto AMThreads = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I1);
1273 constexpr
auto AK0Threads = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I0);
1274 constexpr
auto AK1Threads = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I2);
1275 constexpr
auto AKThreads = AK0Threads * AK1Threads;
1276 constexpr
auto AMRepeats = MPerBlock / AMThreads;
1277 const index_t token_pos = block_m_id * MPerBlock + threadIdx.x / AKThreads * AMRepeats;
1279 if(token_pos >= max_token_id || token0 >= problem.
NumTokens)
1283 const index_t fused_token = p_sorted_token_ids[token_pos + m0];
1284 index_t token_offset = fused_token & 0xffffff;
1285 if constexpr(!IsInputGemm)
1287 token_offset = token_offset * problem.
TopK + (fused_token >> 24);
1289 gather_offsets(m0) =
static_cast<IndexType
>(token_offset) * problem.
K;
1292 __builtin_amdgcn_readfirstlane(problem.
N * problem.
K * (IsInputGemm ? 2 : 1));
1293 const index_t expert_scale_stride = __builtin_amdgcn_readfirstlane(
1298 const index_t n_block_data_idx_on_grid =
1299 __builtin_amdgcn_readfirstlane(block_n_id * NXdlPerWave);
1301 const auto a_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
1302 p_a_grid, a_grid_desc_ak0_m_ak1.GetElementSpaceSize());
1303 const auto b_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
1305 b_grid_desc_bpreshuffled.GetElementSpaceSize());
1307 const auto a_scale_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
1308 p_a_scale_grid, a_scale_grid_desc_am_ak.GetElementSpaceSize());
1309 const auto b_scale_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
1310 p_b_scale_grid + expert_id * expert_scale_stride,
1311 b_scale_grid_desc_bn_ak.GetElementSpaceSize());
1322 AElementwiseOperation,
1326 ABlockTransferThreadClusterLengths_AK0_M_AK1,
1327 ABlockTransferThreadClusterArrangeOrder,
1330 decltype(a_grid_desc_ak0_m_ak1),
1331 decltype(a_block_desc_ak0_m_ak1),
1332 ABlockTransferSrcAccessOrder,
1334 ABlockTransferSrcVectorDim,
1336 ABlockTransferSrcScalarPerVector,
1337 ABlockTransferDstScalarPerVector_AK1,
1340 AThreadTransferSrcResetCoordinateAfterRun,
1344 BlockwiseGemmPipe::GlobalBufferNum>(a_grid_desc_ak0_m_ak1,
1347 a_block_desc_ak0_m_ak1,
1354 auto b_block_buf = make_static_buffer<AddressSpaceEnum::Vgpr, BDataType>(
1355 b_block_desc_bk0_n_bk1.GetElementSpaceSize());
1360 decltype(b_grid_desc_bpreshuffled),
1361 decltype(b_block_desc_bk0_n_bk1),
1365 BBlockTransferSrcScalarPerVector,
1366 BThreadTransferSrcResetCoordinateAfterRun,
1367 true>(b_grid_desc_bpreshuffled,
1375 auto a_block_buf = make_dynamic_buffer<AddressSpaceEnum::Lds>(
1376 static_cast<LDSTypeA*
>(p_shared), a_block_desc_ak0_m_ak1.GetElementSpaceSize());
1382 static_assert(std::is_default_constructible_v<BlockwiseGemmPipe>);
1384 auto c_thread_buf = blockwise_gemm_pipeline.GetCThreadBuffer();
1385 decltype(c_thread_buf) c_thread_buf_up;
1387 const index_t num_k_block_main_loop = __builtin_amdgcn_readfirstlane(
1389 ? (a_grid_desc_ak0_m_ak1.GetLength(
I0) * a_grid_desc_ak0_m_ak1.GetLength(
I2)) /
1392 constexpr
index_t ScaleSliceSizeM = MXdlPerWave;
1401 constexpr
index_t MWaves = MPerBlock / (MXdlPerWave * MPerXdl);
1402 constexpr
index_t NWaves = NPerBlock / (NXdlPerWave * NPerXdl);
1403 constexpr
index_t WaveSize = BlockSize / (MWaves * NWaves);
1415 const index_t token_scale_pos = block_m_id * MPerBlock / ScaleBlockM;
1417 if(token_scale_pos >= max_token_id || token0 >= problem.
NumTokens)
1422 p_sorted_token_ids[token_scale_pos + m0 * MPerXdl * MWaves + a_thread_offset];
1423 index_t token_offset = fused_token & 0xffffff;
1424 if constexpr(!IsInputGemm)
1426 token_offset = token_offset * problem.
TopK + (fused_token >> 24);
1428 scale_gather_offsets(m0) =
1432 auto a_scale_thread_copy =
1435 decltype(a_scale_grid_desc_am_ak),
1436 decltype(a_scale_thread_desc),
1446 auto b_scale_thread_copy =
1449 decltype(b_scale_grid_desc_bn_ak),
1450 decltype(b_scale_thread_desc),
1457 b_scale_grid_desc_bn_ak,
make_multi_index(block_n_id * NPerBlock / ScaleBlockN, 0));
1460 constexpr
auto a_scale_thread_slice_copy_step =
1462 constexpr
auto b_scale_thread_slice_copy_step =
make_multi_index(0, ScaleSliceSizeK);
1465 if constexpr(IsInputGemm && !IsSplitK)
1467 const BDataType* p_b_grid_up = p_b_grid + expert_stride / 2 /
BPackedSize;
1468 const auto b_grid_buf_up = make_dynamic_buffer<AddressSpaceEnum::Global>(
1470 b_grid_desc_bpreshuffled.GetElementSpaceSize());
1474 decltype(b_grid_desc_bpreshuffled),
1475 decltype(b_block_desc_bk0_n_bk1),
1479 BBlockTransferSrcScalarPerVector,
1480 BThreadTransferSrcResetCoordinateAfterRun,
1481 true>(b_grid_desc_bpreshuffled,
1487 p_b_scale_grid + expert_scale_stride / 2 /
BPackedSize;
1488 const auto b_scale_grid_buf_up = make_dynamic_buffer<AddressSpaceEnum::Global>(
1489 p_b_scale_grid_up + expert_id * expert_scale_stride,
1490 b_scale_grid_desc_bn_ak.GetElementSpaceSize());
1491 auto b_scale_thread_copy_up =
1494 decltype(b_scale_grid_desc_bn_ak),
1495 decltype(b_scale_thread_desc),
1502 b_scale_grid_desc_bn_ak,
1505 blockwise_gemm_pipeline.template Run<HasMainKBlockLoop, NumKBlockPerScale, TailNum>(
1506 a_grid_desc_ak0_m_ak1,
1507 a_block_desc_ak0_m_ak1,
1511 a_block_slice_copy_step,
1513 b_grid_desc_bpreshuffled,
1514 b_block_desc_bk0_n_bk1,
1516 b_blockwise_copy_up,
1520 b_block_slice_copy_step,
1522 c_scale_thread_desc,
1526 a_scale_grid_desc_am_ak,
1527 a_scale_thread_desc,
1528 a_scale_thread_copy,
1530 a_scale_thread_slice_copy_step,
1532 b_scale_grid_desc_bn_ak,
1533 b_scale_thread_desc,
1534 b_scale_thread_copy,
1535 b_scale_thread_copy_up,
1537 b_scale_grid_buf_up,
1538 b_scale_thread_slice_copy_step,
1540 num_k_block_main_loop);
1544 blockwise_gemm_pipeline.template Run<HasMainKBlockLoop, NumKBlockPerScale, TailNum>(
1545 a_grid_desc_ak0_m_ak1,
1546 a_block_desc_ak0_m_ak1,
1550 a_block_slice_copy_step,
1552 b_grid_desc_bpreshuffled,
1553 b_block_desc_bk0_n_bk1,
1557 b_block_slice_copy_step,
1559 c_scale_thread_desc,
1562 a_scale_grid_desc_am_ak,
1563 a_scale_thread_desc,
1564 a_scale_thread_copy,
1566 a_scale_thread_slice_copy_step,
1568 b_scale_grid_desc_bn_ak,
1569 b_scale_thread_desc,
1570 b_scale_thread_copy,
1572 b_scale_thread_slice_copy_step,
1574 num_k_block_main_loop);
1579 static_assert(MXdlPerWave % CShuffleMXdlPerWavePerShuffle == 0 &&
1580 NXdlPerWave % CShuffleNXdlPerWavePerShuffle == 0,
1583 constexpr
index_t MWave = MPerBlock / (MXdlPerWave * MPerXdl);
1587 constexpr
auto c_thread_desc_m0_n0_m1_n1_m2_n2_n3_n4 =
1588 blockwise_gemm_pipeline.GetCThreadDescriptor_M0_N0_M1_N1_M2_N2_N3_N4();
1592 constexpr
auto c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp =
1593 blockwise_gemm_pipeline.GetCBlockDescriptor_M0_N0_M1_N1_M2_N2_N3_N4();
1595 constexpr
auto M0 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I0);
1596 constexpr
auto N0 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I1);
1597 constexpr
auto M1 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I2);
1598 constexpr
auto N1 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I3);
1599 constexpr
auto M2 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I4);
1600 constexpr
auto N2 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I5);
1601 constexpr
auto N3 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I6);
1602 constexpr
auto N4 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I7);
1604 static_assert(N0 * N1 * N2 * N3 * N4 == NPerBlock);
1605 static_assert(M0 * M1 * M2 == MPerBlock);
1606 static_assert(N4 == 4 || N4 == 8);
1613 if constexpr(MulRoutedWeight)
1615 const index_t m_pos = block_m_id * MPerBlock + m0 * M1 * M2 + m1 * M2 + m2;
1616 topk_weight = p_ds_grid[
I0][m_pos];
1621 blockwise_gemm_pipeline.GetCThreadDesc().CalculateOffset(
1624 if constexpr(IsInputGemm && !IsSplitK)
1628 float gate = c_thread_buf[cidx];
1629 float up = c_thread_buf_up[cidx];
1630 if constexpr(MulRoutedWeight)
1632 gate = gate * topk_weight;
1633 up = up * topk_weight;
1641 c_thread_buf(cidx) = gate * up;
1645 float gate = c_thread_buf[cidx];
1646 float up = c_thread_buf_up[cidx];
1647 if constexpr(MulRoutedWeight)
1649 gate = gate * topk_weight;
1650 up = up * topk_weight;
1658 c_thread_buf(cidx) = gate * up;
1663 if constexpr(MulRoutedWeight)
1665 c_thread_buf(cidx) = c_thread_buf[cidx] * topk_weight;
1673 constexpr
auto c_shuffle_block_desc_mblock_mperblock_nblock_nperblock =
1676 auto c_shuffle_block_buf = make_dynamic_buffer<AddressSpaceEnum::Lds>(
1677 static_cast<CShuffleDataType*
>(p_shared),
1678 c_shuffle_block_desc_mblock_mperblock_nblock_nperblock.GetElementSpaceSize());
1681 c_shuffle_block_desc_mblock_mperblock_nblock_nperblock,
1701 const auto c_thread_mtx_on_block =
1702 blockwise_gemm_pipeline.CalculateCThreadOriginDataIndex(
I0,
I0,
I0,
I0);
1704 const index_t m_thread_data_on_block = c_thread_mtx_on_block[
I0];
1705 const index_t n_thread_data_on_block = c_thread_mtx_on_block[
I1];
1707 const auto m_thread_data_on_block_to_m0_m1_m2_adaptor =
1713 const auto m_thread_data_on_block_idx =
1714 m_thread_data_on_block_to_m0_m1_m2_adaptor.CalculateBottomIndex(
1717 const auto n_thread_data_on_block_to_n0_n1_n2_n3_n4_adaptor =
1723 const auto n_thread_data_on_block_idx =
1724 n_thread_data_on_block_to_n0_n1_n2_n3_n4_adaptor.CalculateBottomIndex(
1728 auto c_thread_copy_vgpr_to_lds =
1731 decltype(c_thread_desc_m0_n0_m1_n1_m2_n2_n3_n4),
1732 decltype(c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4),
1734 Sequence<CShuffleMXdlPerWavePerShuffle,
1735 CShuffleNXdlPerWavePerShuffle,
1748 c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4,
1751 m_thread_data_on_block_idx[
I1],
1752 n_thread_data_on_block_idx[
I1],
1753 m_thread_data_on_block_idx[
I2],
1754 n_thread_data_on_block_idx[
I2],
1755 n_thread_data_on_block_idx[
I3],
1756 n_thread_data_on_block_idx[
I4]),
1759 using EDataType = CDataType;
1761 const auto ds_grid_desc_m_n =
1764 problem.
N * (IsInputGemm && IsSplitK ? 2 : 1),
1765 problem.
NPadded * (IsInputGemm && IsSplitK ? 2 : 1),
1768 const auto ds_grid_desc_mblock_mperblock_nblock_nperblock =
1775 const DDataType* ptr_ = p_ds_grid[i];
1778 return make_dynamic_buffer<AddressSpaceEnum::Global>(
1779 ptr_, ds_grid_desc_m_n[i].GetElementSpaceSize());
1785 tie(c_shuffle_block_desc_mblock_mperblock_nblock_nperblock),
1787 {
return ds_grid_desc_mblock_mperblock_nblock_nperblock[i]; },
1792 tie(c_shuffle_block_buf),
1794 {
return ds_grid_buf[i]; },
1798 const auto idx_c_ds_block_begin =
1808 const auto e_grid_desc_mblock_mperblock_nblock_nperblock =
1809 c_grid_desc_mblock_mperblock_nblock_nperblock;
1811 using CDEBlockTransferCluster =
1812 CShuffleBlockTransferClusterLengths_MBlock_MPerBlock_NBlock_NPerBlock;
1813 const auto EGlobalMemoryDataOperation = CGlobalMemoryDataOperation;
1814 constexpr
index_t scatter_weight_idx = IsInputGemm ? 1 : 1;
1819 decltype(c_ds_desc_refs),
1820 decltype(
tie(e_grid_desc_mblock_mperblock_nblock_nperblock)),
1821 CElementwiseOperation,
1825 CShuffleMXdlPerWavePerShuffle * MWave * MPerXdl,
1827 CShuffleNXdlPerWavePerShuffle *
NWave * NPerXdl>,
1828 CDEBlockTransferCluster,
1834 CDEShuffleBlockTransferScalarPerVectors,
1846 idx_c_ds_block_begin,
1847 tie(e_grid_desc_mblock_mperblock_nblock_nperblock),
1851 auto c_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
1852 p_c_grid, c_grid_desc_mblock_mperblock_nblock_nperblock.GetElementSpaceSize());
1854 constexpr
auto sfc_c_vgpr =
1857 Sequence<CShuffleMXdlPerWavePerShuffle,
1858 CShuffleNXdlPerWavePerShuffle,
1866 constexpr
index_t num_access = sfc_c_vgpr.GetNumOfAccess();
1869 constexpr
auto sfc_cde_block =
1873 CShuffleMXdlPerWavePerShuffle * MWave * MPerXdl,
1875 CShuffleNXdlPerWavePerShuffle *
NWave * NPerXdl>>{};
1877 static_assert(num_access == sfc_cde_block.GetNumOfAccess(),
"wrong!");
1878 constexpr
auto EMThreads =
1879 CDEBlockTransferCluster{}.At(
I0) * CDEBlockTransferCluster{}.At(
I1);
1880 constexpr
auto EMRepeats = CShuffleMXdlPerWavePerShuffle * MWave * MPerXdl / EMThreads;
1881 constexpr
auto ENThreads =
1882 CDEBlockTransferCluster{}.At(
I2) * CDEBlockTransferCluster{}.At(
I3);
1887 auto dstidx = sfc_cde_block.GetIndex(access_id);
1889 block_m_id * MPerBlock + threadIdx.x / ENThreads * EMRepeats + dstidx(
I1);
1891 const index_t fused_token = p_sorted_token_ids[c_token_pos + m0];
1892 index_t token_offset = fused_token & 0xffffff;
1893 if constexpr(IsInputGemm)
1895 token_offset = token_offset * problem.
TopK + (fused_token >> 24);
1897 scatter_offsets(m0) =
1898 token_offset * problem.
N * (IsInputGemm && IsSplitK ? 2 : 1);
1904 c_thread_copy_vgpr_to_lds.Run(c_thread_desc_m0_n0_m1_n1_m2_n2_n3_n4,
1905 sfc_c_vgpr.GetIndexTupleOfNumber(access_id),
1907 c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4,
1908 c_shuffle_block_buf);
1914 cde_block_copy_lds_and_global.Run(
1917 tie(e_grid_desc_mblock_mperblock_nblock_nperblock),
1921 if constexpr(access_id < num_access - 1)
1923 constexpr
auto cde_lds_and_global_step =
1924 sfc_cde_block.GetForwardStep(access_id);
1928 cde_block_copy_lds_and_global.MoveSrcSliceWindow(
1929 c_ds_desc_refs, i +
I1, cde_lds_and_global_step);
1933 cde_block_copy_lds_and_global.MoveDstSliceWindow(
1934 tie(e_grid_desc_mblock_mperblock_nblock_nperblock),
1936 cde_lds_and_global_step);
1942 template <
bool HasMainKBlockLoop,
1946 const index_t* p_sorted_expert_ids,
1947 const index_t* p_max_token_id,
1948 const ADataType* p_a_grid,
1949 const BDataType* p_b_grid,
1951 CDataType* p_c_grid,
1957 AElementwiseOperation a_element_op,
1958 BElementwiseOperation b_element_op,
1959 CElementwiseOperation c_element_op)
1971 const auto b_grid_desc_bpreshuffled =
1973 const auto c_grid_desc_m_n = MakeCGridDescriptor_M_N<CLayout>(
1976 problem.
N * (IsInputGemm && IsSplitK ? 2 : 1),
1977 problem.
NPadded * (IsInputGemm && IsSplitK ? 2 : 1),
1990 const auto c_grid_desc_mblock_mperblock_nblock_nperblock =
1993 const index_t max_token_id = __builtin_amdgcn_readfirstlane(p_max_token_id[0]);
1994 const index_t expert_block_id = NSwizzle ? blockIdx.x / problem.
NBlock : blockIdx.y;
1995 if(expert_block_id * MPerBlock >= max_token_id)
1998 __builtin_amdgcn_readfirstlane(p_sorted_expert_ids[expert_block_id]);
1999 const auto block_mn = [&]() -> std::pair<int, int> {
2000 if constexpr(NSwizzle)
2002 const index_t ecnt_prefix = p_max_token_id[1 + expert_id];
2004 const index_t ecnt = p_max_token_id[2 + expert_id] - ecnt_prefix;
2005 const index_t expert_swizzle = ecnt > 0 ? ecnt : 1;
2006 const index_t bid_new = blockIdx.x - prefix_block;
2007 const index_t nid = __builtin_amdgcn_readfirstlane(
2008 bid_new % 8 + bid_new / (8 * expert_swizzle) * 8);
2010 __builtin_amdgcn_readfirstlane(ecnt_prefix + bid_new / 8 % expert_swizzle);
2015 return {blockIdx.x, blockIdx.y};
2018 const index_t block_n_id = block_mn.first;
2019 const index_t block_m_id = block_mn.second;
2022 __builtin_amdgcn_readfirstlane(p_sorted_token_ids[block_m_id * MPerBlock] & 0xffffff);
2025 constexpr
auto AMThreads = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I1);
2026 constexpr
auto AK0Threads = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I0);
2027 constexpr
auto AK1Threads = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I2);
2028 constexpr
auto AKThreads = AK0Threads * AK1Threads;
2029 constexpr
auto AMRepeats = MPerBlock / AMThreads;
2030 const index_t token_pos = block_m_id * MPerBlock + threadIdx.x / AKThreads * AMRepeats;
2032 if(token_pos >= max_token_id || expert_block_id * MPerBlock >= max_token_id ||
2038 const index_t fused_token = p_sorted_token_ids[token_pos + m0];
2039 index_t token_offset = fused_token & 0xffffff;
2040 if constexpr(!IsInputGemm)
2042 token_offset = token_offset * problem.
TopK + (fused_token >> 24);
2044 gather_offsets(m0) =
static_cast<IndexType
>(token_offset) * problem.
K;
2047 __builtin_amdgcn_readfirstlane(problem.
N * problem.
K * (IsInputGemm ? 2 : 1));
2048 const index_t expert_scale_stride = __builtin_amdgcn_readfirstlane(
2052 const index_t n_block_data_idx_on_grid =
2053 __builtin_amdgcn_readfirstlane(block_n_id * NXdlPerWave);
2055 const auto a_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
2056 p_a_grid, a_grid_desc_ak0_m_ak1.GetElementSpaceSize());
2057 const auto b_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
2059 b_grid_desc_bpreshuffled.GetElementSpaceSize());
2061 const auto a_scale_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
2062 p_a_scale_grid, a_scale_grid_desc_am_ak.GetElementSpaceSize());
2063 const auto b_scale_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
2064 p_b_scale_grid + expert_id * expert_scale_stride,
2065 b_scale_grid_desc_bn_ak.GetElementSpaceSize());
2076 AElementwiseOperation,
2080 ABlockTransferThreadClusterLengths_AK0_M_AK1,
2081 ABlockTransferThreadClusterArrangeOrder,
2084 decltype(a_grid_desc_ak0_m_ak1),
2085 decltype(a_block_desc_ak0_m_ak1),
2086 ABlockTransferSrcAccessOrder,
2088 ABlockTransferSrcVectorDim,
2090 ABlockTransferSrcScalarPerVector,
2091 ABlockTransferDstScalarPerVector_AK1,
2094 AThreadTransferSrcResetCoordinateAfterRun,
2098 BlockwiseGemmPipe::GlobalBufferNum>(a_grid_desc_ak0_m_ak1,
2101 a_block_desc_ak0_m_ak1,
2108 auto b_block_buf_ping = make_static_buffer<AddressSpaceEnum::Vgpr, BDataType>(
2109 b_block_desc_bk0_n_bk1.GetElementSpaceSize());
2110 auto b_block_buf_pong = make_static_buffer<AddressSpaceEnum::Vgpr, BDataType>(
2111 b_block_desc_bk0_n_bk1.GetElementSpaceSize());
2112 auto b_block_bufs =
make_tuple(b_block_buf_ping, b_block_buf_pong);
2117 decltype(b_grid_desc_bpreshuffled),
2118 decltype(b_block_desc_bk0_n_bk1),
2122 BBlockTransferSrcScalarPerVector,
2123 BThreadTransferSrcResetCoordinateAfterRun,
2124 true>(b_grid_desc_bpreshuffled,
2132 auto a_block_buf_ping = make_dynamic_buffer<AddressSpaceEnum::Lds>(
2133 static_cast<ADataType*
>(p_shared), a_block_desc_ak0_m_ak1.GetElementSpaceSize());
2134 auto a_block_buf_pong = make_dynamic_buffer<AddressSpaceEnum::Lds>(
2135 static_cast<ADataType*
>(p_shared1), a_block_desc_ak0_m_ak1.GetElementSpaceSize());
2136 auto a_block_bufs =
make_tuple(a_block_buf_ping, a_block_buf_pong);
2142 static_assert(std::is_default_constructible_v<BlockwiseGemmPipe>);
2144 auto c_thread_buf = blockwise_gemm_pipeline.GetCThreadBuffer();
2145 decltype(c_thread_buf) c_thread_buf_up;
2147 const index_t num_k_block_main_loop = __builtin_amdgcn_readfirstlane(
2149 ? (a_grid_desc_ak0_m_ak1.GetLength(
I0) * a_grid_desc_ak0_m_ak1.GetLength(
I2)) /
2154 constexpr
index_t ScaleSliceSizeM = MXdlPerWave;
2163 constexpr
index_t MWaves = MPerBlock / (MXdlPerWave * MPerXdl);
2164 constexpr
index_t NWaves = NPerBlock / (NXdlPerWave * NPerXdl);
2165 constexpr
index_t WaveSize = BlockSize / (MWaves * NWaves);
2177 const index_t token_scale_pos = block_m_id * MPerBlock / ScaleBlockM;
2179 if(token_scale_pos >= max_token_id || token0 >= problem.
NumTokens)
2184 p_sorted_token_ids[token_scale_pos + m0 * MPerXdl * MWaves + a_thread_offset];
2185 index_t token_offset = fused_token & 0xffffff;
2186 if constexpr(!IsInputGemm)
2188 token_offset = token_offset * problem.
TopK + (fused_token >> 24);
2190 scale_gather_offsets(m0) =
static_cast<IndexType
>(token_offset) *
2194 auto a_scale_thread_copy =
2197 decltype(a_scale_grid_desc_am_ak),
2198 decltype(a_scale_thread_desc),
2208 auto b_scale_thread_copy =
2211 decltype(b_scale_grid_desc_bn_ak),
2212 decltype(b_scale_thread_desc),
2219 b_scale_grid_desc_bn_ak,
make_multi_index(block_n_id * NPerBlock / ScaleBlockN, 0));
2222 constexpr
auto a_scale_thread_slice_copy_step =
2224 constexpr
auto b_scale_thread_slice_copy_step =
make_multi_index(0, ScaleSliceSizeK);
2227 if constexpr(IsInputGemm && !IsSplitK)
2229 const BDataType* p_b_grid_up = p_b_grid + expert_stride / 2 /
BPackedSize;
2230 const auto b_grid_buf_up = make_dynamic_buffer<AddressSpaceEnum::Global>(
2232 b_grid_desc_bpreshuffled.GetElementSpaceSize());
2236 decltype(b_grid_desc_bpreshuffled),
2237 decltype(b_block_desc_bk0_n_bk1),
2241 BBlockTransferSrcScalarPerVector,
2242 BThreadTransferSrcResetCoordinateAfterRun,
2243 true>(b_grid_desc_bpreshuffled,
2249 p_b_scale_grid + expert_scale_stride / 2 /
BPackedSize;
2250 const auto b_scale_grid_buf_up = make_dynamic_buffer<AddressSpaceEnum::Global>(
2251 p_b_scale_grid_up + expert_id * expert_scale_stride /
BPackedSize,
2252 b_scale_grid_desc_bn_ak.GetElementSpaceSize());
2253 auto b_scale_thread_copy_up =
2256 decltype(b_scale_grid_desc_bn_ak),
2257 decltype(b_scale_thread_desc),
2264 b_scale_grid_desc_bn_ak,
2267 blockwise_gemm_pipeline.template Run<HasMainKBlockLoop, NumKBlockPerScale, TailNum>(
2268 a_grid_desc_ak0_m_ak1,
2269 a_block_desc_ak0_m_ak1,
2273 a_block_slice_copy_step,
2274 b_grid_desc_bpreshuffled,
2275 b_block_desc_bk0_n_bk1,
2277 b_blockwise_copy_up,
2281 b_block_slice_copy_step,
2282 c_scale_thread_desc,
2285 a_scale_grid_desc_am_ak,
2286 a_scale_thread_desc,
2287 a_scale_thread_copy,
2289 a_scale_thread_slice_copy_step,
2290 b_scale_grid_desc_bn_ak,
2291 b_scale_thread_desc,
2292 b_scale_thread_copy,
2293 b_scale_thread_copy_up,
2295 b_scale_grid_buf_up,
2296 b_scale_thread_slice_copy_step,
2297 num_k_block_main_loop);
2301 blockwise_gemm_pipeline.template Run<HasMainKBlockLoop, NumKBlockPerScale, TailNum>(
2302 a_grid_desc_ak0_m_ak1,
2303 a_block_desc_ak0_m_ak1,
2307 a_block_slice_copy_step,
2308 b_grid_desc_bpreshuffled,
2309 b_block_desc_bk0_n_bk1,
2313 b_block_slice_copy_step,
2314 c_scale_thread_desc,
2316 a_scale_grid_desc_am_ak,
2317 a_scale_thread_desc,
2318 a_scale_thread_copy,
2320 a_scale_thread_slice_copy_step,
2321 b_scale_grid_desc_bn_ak,
2322 b_scale_thread_desc,
2323 b_scale_thread_copy,
2325 b_scale_thread_slice_copy_step,
2326 num_k_block_main_loop);
2332 static_assert(MXdlPerWave % CShuffleMXdlPerWavePerShuffle == 0 &&
2333 NXdlPerWave % CShuffleNXdlPerWavePerShuffle == 0,
2336 constexpr
index_t MWave = MPerBlock / (MXdlPerWave * MPerXdl);
2340 constexpr
auto c_thread_desc_m0_n0_m1_n1_m2_n2_n3_n4 =
2341 blockwise_gemm_pipeline.GetCThreadDescriptor_M0_N0_M1_N1_M2_N2_N3_N4();
2345 constexpr
auto c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp =
2346 blockwise_gemm_pipeline.GetCBlockDescriptor_M0_N0_M1_N1_M2_N2_N3_N4();
2348 constexpr
auto M0 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I0);
2349 constexpr
auto N0 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I1);
2350 constexpr
auto M1 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I2);
2351 constexpr
auto N1 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I3);
2352 constexpr
auto M2 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I4);
2353 constexpr
auto N2 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I5);
2354 constexpr
auto N3 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I6);
2355 constexpr
auto N4 = c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4_tmp.GetLength(
I7);
2357 static_assert(N0 * N1 * N2 * N3 * N4 == NPerBlock);
2358 static_assert(M0 * M1 * M2 == MPerBlock);
2359 static_assert(N4 == 4 || N4 == 8);
2366 if constexpr(MulRoutedWeight)
2368 const index_t m_pos = block_m_id * MPerBlock + m0 * M1 * M2 + m1 * M2 + m2;
2369 topk_weight = p_ds_grid[
I0][m_pos];
2374 blockwise_gemm_pipeline.GetCThreadDesc().CalculateOffset(
2377 if constexpr(IsInputGemm && !IsSplitK)
2381 float gate = c_thread_buf[cidx];
2382 float up = c_thread_buf_up[cidx];
2383 if constexpr(MulRoutedWeight)
2385 gate = gate * topk_weight;
2386 up = up * topk_weight;
2394 c_thread_buf(cidx) = gate * up;
2398 float gate = c_thread_buf[cidx];
2399 float up = c_thread_buf_up[cidx];
2400 if constexpr(MulRoutedWeight)
2402 gate = gate * topk_weight;
2403 up = up * topk_weight;
2411 c_thread_buf(cidx) = gate * up;
2416 if constexpr(MulRoutedWeight)
2418 c_thread_buf(cidx) = c_thread_buf[cidx] * topk_weight;
2427 constexpr
auto c_shuffle_block_desc_mblock_mperblock_nblock_nperblock =
2430 auto c_shuffle_block_buf = make_dynamic_buffer<AddressSpaceEnum::Lds>(
2431 static_cast<CShuffleDataType*
>(p_shared),
2432 c_shuffle_block_desc_mblock_mperblock_nblock_nperblock.GetElementSpaceSize());
2435 c_shuffle_block_desc_mblock_mperblock_nblock_nperblock,
2455 const auto c_thread_mtx_on_block =
2456 blockwise_gemm_pipeline.CalculateCThreadOriginDataIndex(
I0,
I0,
I0,
I0);
2458 const index_t m_thread_data_on_block = c_thread_mtx_on_block[
I0];
2459 const index_t n_thread_data_on_block = c_thread_mtx_on_block[
I1];
2461 const auto m_thread_data_on_block_to_m0_m1_m2_adaptor =
2467 const auto m_thread_data_on_block_idx =
2468 m_thread_data_on_block_to_m0_m1_m2_adaptor.CalculateBottomIndex(
2471 const auto n_thread_data_on_block_to_n0_n1_n2_n3_n4_adaptor =
2477 const auto n_thread_data_on_block_idx =
2478 n_thread_data_on_block_to_n0_n1_n2_n3_n4_adaptor.CalculateBottomIndex(
2482 auto c_thread_copy_vgpr_to_lds =
2485 decltype(c_thread_desc_m0_n0_m1_n1_m2_n2_n3_n4),
2486 decltype(c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4),
2488 Sequence<CShuffleMXdlPerWavePerShuffle,
2489 CShuffleNXdlPerWavePerShuffle,
2502 c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4,
2505 m_thread_data_on_block_idx[
I1],
2506 n_thread_data_on_block_idx[
I1],
2507 m_thread_data_on_block_idx[
I2],
2508 n_thread_data_on_block_idx[
I2],
2509 n_thread_data_on_block_idx[
I3],
2510 n_thread_data_on_block_idx[
I4]),
2513 using EDataType = CDataType;
2518 const auto ds_grid_desc_mblock_mperblock_nblock_nperblock =
2524 return make_dynamic_buffer<AddressSpaceEnum::Global>(
2525 p_ds_grid[i], ds_grid_desc_m_n[i].GetElementSpaceSize());
2531 tie(c_shuffle_block_desc_mblock_mperblock_nblock_nperblock),
2533 {
return ds_grid_desc_mblock_mperblock_nblock_nperblock[i]; },
2538 tie(c_shuffle_block_buf),
2540 {
return ds_grid_buf[i]; },
2544 const auto idx_c_ds_block_begin =
2554 const auto e_grid_desc_mblock_mperblock_nblock_nperblock =
2555 c_grid_desc_mblock_mperblock_nblock_nperblock;
2557 using CDEBlockTransferCluster =
2558 CShuffleBlockTransferClusterLengths_MBlock_MPerBlock_NBlock_NPerBlock;
2559 const auto EGlobalMemoryDataOperation = CGlobalMemoryDataOperation;
2560 constexpr
index_t scatter_weight_idx = IsInputGemm ? 1 : 1;
2565 decltype(c_ds_desc_refs),
2566 decltype(
tie(e_grid_desc_mblock_mperblock_nblock_nperblock)),
2567 CElementwiseOperation,
2571 CShuffleMXdlPerWavePerShuffle * MWave * MPerXdl,
2573 CShuffleNXdlPerWavePerShuffle *
NWave * NPerXdl>,
2574 CDEBlockTransferCluster,
2580 CDEShuffleBlockTransferScalarPerVectors,
2592 idx_c_ds_block_begin,
2593 tie(e_grid_desc_mblock_mperblock_nblock_nperblock),
2597 auto c_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
2598 p_c_grid, c_grid_desc_mblock_mperblock_nblock_nperblock.GetElementSpaceSize());
2600 constexpr
auto sfc_c_vgpr =
2603 Sequence<CShuffleMXdlPerWavePerShuffle,
2604 CShuffleNXdlPerWavePerShuffle,
2612 constexpr
index_t num_access = sfc_c_vgpr.GetNumOfAccess();
2615 constexpr
auto sfc_cde_block =
2619 CShuffleMXdlPerWavePerShuffle * MWave * MPerXdl,
2621 CShuffleNXdlPerWavePerShuffle *
NWave * NPerXdl>>{};
2623 static_assert(num_access == sfc_cde_block.GetNumOfAccess(),
"wrong!");
2624 constexpr
auto EMThreads =
2625 CDEBlockTransferCluster{}.At(
I0) * CDEBlockTransferCluster{}.At(
I1);
2626 constexpr
auto EMRepeats = CShuffleMXdlPerWavePerShuffle * MWave * MPerXdl / EMThreads;
2627 constexpr
auto ENThreads =
2628 CDEBlockTransferCluster{}.At(
I2) * CDEBlockTransferCluster{}.At(
I3);
2634 auto dstidx = sfc_cde_block.GetIndex(access_id);
2636 block_m_id * MPerBlock + threadIdx.x / ENThreads * EMRepeats + dstidx(
I1);
2638 const index_t fused_token = p_sorted_token_ids[c_token_pos + m0];
2639 index_t token_offset = fused_token & 0xffffff;
2640 if constexpr(IsInputGemm)
2642 token_offset = token_offset * problem.
TopK + (fused_token >> 24);
2644 scatter_offsets(m0) =
2645 token_offset * problem.
N * (IsInputGemm && IsSplitK ? 2 : 1);
2651 c_thread_copy_vgpr_to_lds.Run(c_thread_desc_m0_n0_m1_n1_m2_n2_n3_n4,
2652 sfc_c_vgpr.GetIndexTupleOfNumber(access_id),
2654 c_block_desc_m0_n0_m1_n1_m2_n2_n3_n4,
2655 c_shuffle_block_buf);
2661 cde_block_copy_lds_and_global.Run(
2664 tie(e_grid_desc_mblock_mperblock_nblock_nperblock),
2668 if constexpr(access_id < num_access - 1)
2670 constexpr
auto cde_lds_and_global_step =
2671 sfc_cde_block.GetForwardStep(access_id);
2675 cde_block_copy_lds_and_global.MoveSrcSliceWindow(
2676 c_ds_desc_refs, i +
I1, cde_lds_and_global_step);
2680 cde_block_copy_lds_and_global.MoveDstSliceWindow(
2681 tie(e_grid_desc_mblock_mperblock_nblock_nperblock),
2683 cde_lds_and_global_step);
#define CK_MAX_THREAD_PER_BLOCK
Definition: ck.hpp:30
#define IS_VALID_COMPILATION_PARAMETER_IMPL(CDataType_)
Definition: device_base.hpp:251
Y __host__ constexpr __device__ auto lcm(X x, Y y)
Definition: math.hpp:198
__host__ constexpr __device__ auto integer_least_multiple(X x, Y y)
Definition: math.hpp:78
__host__ constexpr __device__ auto integer_divide_ceil(X x, Y y)
Definition: math.hpp:72
__host__ constexpr __device__ auto integer_divide_floor(X x, Y y)
Definition: math.hpp:66
__host__ constexpr __device__ T max(T x)
Definition: math.hpp:84
GemmSpecialization
Definition: gemm_specialization.hpp:11
ck_tile::element_wise::PassThrough PassThrough
Definition: grouped_convolution_utils.hpp:54
typename detail::StaticallyIndexedArrayImpl< T, N >::type StaticallyIndexedArray
Definition: statically_indexed_array.hpp:45
__host__ constexpr __device__ auto make_multi_index(Xs &&... xs)
Definition: array_multi_index.hpp:15
__device__ index_t get_warp_local_1d_id()
Definition: get_id.hpp:45
__host__ constexpr __device__ auto generate_tie(F &&f, Number< N >)
Definition: tuple_helper.hpp:34
__host__ constexpr __device__ auto make_naive_tensor_descriptor(const Tuple< Lengths... > &lengths, const Tuple< Strides... > &strides)
Definition: tensor_descriptor_helper.hpp:49
typename uniform_sequence_gen< NSize, I >::type uniform_sequence_gen_t
Definition: sequence.hpp:835
typename tuple_element< I, TTuple >::type tuple_element_t
Definition: tuple.hpp:208
__host__ constexpr __device__ auto generate_tuple(F &&f, Number< N >)
Definition: tuple_helper.hpp:21
InMemoryDataOperationEnum
Definition: ck.hpp:279
__host__ constexpr __device__ auto make_naive_tensor_descriptor_packed(const Tuple< Lengths... > &lengths)
Definition: tensor_descriptor_helper.hpp:101
__host__ constexpr __device__ auto make_merge_transform(const LowLengths &low_lengths)
Definition: multi_index_transform_helper.hpp:55
BlockGemmPipelineVersion
Block GEMM pipeline version enumeration.
Definition: scheduler_enum.hpp:17
__host__ constexpr __device__ auto make_merge_transform_v3_division_mod(const LowLengths &low_lengths)
Definition: multi_index_transform_helper.hpp:84
__global__ void kernel_moe_gemm(typename GridwiseGemm::Argument karg)
Definition: gridwise_moe_gemm.hpp:46
int64_t long_index_t
Definition: ck.hpp:302
TailNumber
Tail number enumeration for pipeline buffering.
Definition: scheduler_enum.hpp:49
@ Even
Even number of iterations.
@ Odd
Odd number of iterations.
__host__ constexpr __device__ auto make_single_stage_tensor_adaptor(const Transforms &transforms, LowerDimensionOldTopIdss, UpperDimensionNewTopIdss)
Definition: tensor_adaptor.hpp:425
__host__ constexpr __device__ auto make_freeze_transform(const LowerIndex &low_idx)
Definition: multi_index_transform_helper.hpp:151
constexpr detail::ignore_t ignore
Definition: ignore.hpp:20
constexpr Tuple< Args &... > tie(Args &... args) noexcept
Definition: tuple.hpp:218
__host__ constexpr __device__ auto make_xor_with_modulo_transform(const LowLengths &low_lengths)
Definition: multi_index_transform_helper.hpp:185
Activation
Definition: gridwise_moe_gemm.hpp:31
@ silu_and_mul
Definition: gridwise_moe_gemm.hpp:33
@ gelu_and_mul
Definition: gridwise_moe_gemm.hpp:32
constexpr __device__ index_t get_warp_size()
Definition: get_id.hpp:10
__host__ constexpr __device__ auto container_concat(const X &x, const Ys &... ys)
Definition: container_helper.hpp:320
__host__ constexpr __device__ auto make_pass_through_transform(const LowLength &low_length)
Definition: multi_index_transform_helper.hpp:12
__host__ constexpr __device__ auto concat_tuple_of_reference(const Tuple< X &... > &tx, const Tuple< Y &... > &ty)
Definition: tuple_helper.hpp:42
constexpr bool is_same_v
Definition: type.hpp:283
typename sequence_merge< Sx, Sy >::type sequence_merge_t
Definition: sequence.hpp:832
BlockGemmPipelineScheduler
Block GEMM pipeline scheduler enumeration.
Definition: scheduler_enum.hpp:33
@ Intrawave
Schedule within a single wavefront.
__host__ constexpr __device__ auto make_tuple(Xs &&... xs)
Definition: tuple.hpp:211
remove_cv_t< remove_reference_t< T > > remove_cvref_t
Definition: type.hpp:297
__host__ constexpr __device__ auto make_unmerge_transform(const UpLengths &up_lengths, integral_constant< bool, Use24BitIntegerCalculation >=integral_constant< bool, false >{})
Definition: multi_index_transform_helper.hpp:90
int32_t index_t
Definition: ck.hpp:301
__device__ index_t get_thread_local_1d_id()
Definition: get_id.hpp:41
__host__ constexpr __device__ auto transform_tensor_descriptor(const OldTensorDescriptor &old_tensor_desc, const NewTransforms &new_transforms, NewLowerDimensionOldVisibleIdss, NewUpperDimensionNewVisibleIdss)
Definition: tensor_descriptor.hpp:319
__host__ constexpr __device__ auto make_right_pad_transform(const LowLength &low_length, const RightPadLength &right_pad, integral_constant< bool, SkipIsValidCheck >=integral_constant< bool, false >{})
Definition: multi_index_transform_helper.hpp:37
constexpr auto BlockGemmBlockMoeScaleBPreshufflePipeline_Selector()
Definition: blockwise_gemm_pipeline_xdlops_moe_blockscale_b_preshuffle_selector.hpp:37
__device__ void block_sync_lds()
Definition: synchronization.hpp:16
__global__ void kernel_moe_gemm_2lds(typename GridwiseGemm::Argument karg)
Definition: gridwise_moe_gemm.hpp:84
Definition: gridwise_moe_gemm_blockscale.hpp:673
DsGridPointer p_ds_grid
Definition: gridwise_moe_gemm_blockscale.hpp:734
const ADataType * p_a_grid
Definition: gridwise_moe_gemm_blockscale.hpp:732
CDataType * p_c_grid
Definition: gridwise_moe_gemm_blockscale.hpp:735
const index_t * p_sorted_token_ids
Definition: gridwise_moe_gemm_blockscale.hpp:729
const BElementwiseOperation b_element_op
Definition: gridwise_moe_gemm_blockscale.hpp:741
const index_t * p_max_token_id
Definition: gridwise_moe_gemm_blockscale.hpp:731
const index_t * p_sorted_expert_ids
Definition: gridwise_moe_gemm_blockscale.hpp:730
const AScaleType * p_a_scale_grid
Definition: gridwise_moe_gemm_blockscale.hpp:737
const AElementwiseOperation a_element_op
Definition: gridwise_moe_gemm_blockscale.hpp:740
__host__ Argument(const index_t *p_sorted_token_ids_, const index_t *p_sorted_expert_ids_, const index_t *p_max_token_id_, const ADataType *p_a_grid_, const BDataType *p_b_grid_, std::array< const void *, NumDTensor > p_ds_grid_, CDataType *p_c_grid_, index_t NumTokens_, index_t TopK_, index_t M_, index_t N_, index_t K_, index_t StrideA_, index_t StrideB_, std::array< index_t, NumDTensor > StrideDs_, index_t StrideC_, const AScaleType *p_a_scale_grid_, const BScaleType *p_b_scale_grid_, index_t k_batch_, AElementwiseOperation a_element_op_, BElementwiseOperation b_element_op_, CElementwiseOperation c_element_op_)
Definition: gridwise_moe_gemm_blockscale.hpp:674
const CElementwiseOperation c_element_op
Definition: gridwise_moe_gemm_blockscale.hpp:742
const BDataType * p_b_grid
Definition: gridwise_moe_gemm_blockscale.hpp:733
const BScaleType * p_b_scale_grid
Definition: gridwise_moe_gemm_blockscale.hpp:738
Definition: gridwise_moe_gemm_blockscale.hpp:608
index_t K
Definition: gridwise_moe_gemm_blockscale.hpp:655
index_t AK0
Definition: gridwise_moe_gemm_blockscale.hpp:665
index_t MBlock
Definition: gridwise_moe_gemm_blockscale.hpp:667
__host__ __device__ Problem(index_t NumTokens_, index_t TopK_, index_t M_, index_t N_, index_t K_, index_t StrideA_, index_t StrideB_, std::array< index_t, NumDTensor > StrideDs_, index_t StrideC_, index_t KBatch_)
Definition: gridwise_moe_gemm_blockscale.hpp:609
index_t StrideB
Definition: gridwise_moe_gemm_blockscale.hpp:657
index_t KRead
Definition: gridwise_moe_gemm_blockscale.hpp:663
index_t StrideC
Definition: gridwise_moe_gemm_blockscale.hpp:659
index_t TopK
Definition: gridwise_moe_gemm_blockscale.hpp:652
index_t KPadded
Definition: gridwise_moe_gemm_blockscale.hpp:664
index_t NumTokens
Definition: gridwise_moe_gemm_blockscale.hpp:651
std::array< index_t, NumDTensor > StrideDs
Definition: gridwise_moe_gemm_blockscale.hpp:658
index_t N
Definition: gridwise_moe_gemm_blockscale.hpp:654
index_t StrideA
Definition: gridwise_moe_gemm_blockscale.hpp:656
index_t NBlock
Definition: gridwise_moe_gemm_blockscale.hpp:668
index_t BK0
Definition: gridwise_moe_gemm_blockscale.hpp:666
__host__ void Print() const
Definition: gridwise_moe_gemm_blockscale.hpp:640
index_t M
Definition: gridwise_moe_gemm_blockscale.hpp:653
index_t NPadded
Definition: gridwise_moe_gemm_blockscale.hpp:662
index_t KBatch
Definition: gridwise_moe_gemm_blockscale.hpp:660
index_t MPadded
Definition: gridwise_moe_gemm_blockscale.hpp:661
Definition: gridwise_moe_gemm_blockscale.hpp:746
index_t a_k_split_offset
Definition: gridwise_moe_gemm_blockscale.hpp:782
index_t ascale_k_split_offset
Definition: gridwise_moe_gemm_blockscale.hpp:784
index_t bscale_k_split_offset
Definition: gridwise_moe_gemm_blockscale.hpp:785
index_t b_k_split_offset
Definition: gridwise_moe_gemm_blockscale.hpp:783
__device__ SplitKBatchOffset(Argument &karg, index_t k_id)
Definition: gridwise_moe_gemm_blockscale.hpp:747
Definition: gridwise_moe_gemm_blockscale.hpp:178
static constexpr auto I2
Definition: gridwise_moe_gemm_blockscale.hpp:184
static constexpr index_t KRepeat
Definition: gridwise_moe_gemm_blockscale.hpp:218
static constexpr auto I7
Definition: gridwise_moe_gemm_blockscale.hpp:189
static constexpr auto I3
Definition: gridwise_moe_gemm_blockscale.hpp:185
static constexpr auto BK1Number
Definition: gridwise_moe_gemm_blockscale.hpp:197
__host__ static __device__ auto CalculateKPadded(index_t K, index_t K_Batch=1)
Definition: gridwise_moe_gemm_blockscale.hpp:302
__host__ static __device__ auto MakeBGridDescriptor_Preshuffled(index_t N0, index_t K0)
Definition: gridwise_moe_gemm_blockscale.hpp:424
__host__ static __device__ auto CalculateKRead(index_t K, index_t K_Batch=1)
Definition: gridwise_moe_gemm_blockscale.hpp:309
static constexpr index_t KLane
Definition: gridwise_moe_gemm_blockscale.hpp:216
static __host__ auto CalculateGridSize(index_t M, index_t N, index_t K, index_t KBatch)
Definition: gridwise_moe_gemm_blockscale.hpp:253
__host__ static __device__ auto CalculateMBlock(index_t M)
Definition: gridwise_moe_gemm_blockscale.hpp:318
static constexpr index_t BPackedSize
Definition: gridwise_moe_gemm_blockscale.hpp:246
static __device__ void Run_2Lds(const index_t *p_sorted_token_ids, const index_t *p_sorted_expert_ids, const index_t *p_max_token_id, const ADataType *p_a_grid, const BDataType *p_b_grid, DsGridPointer &p_ds_grid, CDataType *p_c_grid, const AScaleType *p_a_scale_grid, const BScaleType *p_b_scale_grid, void *p_shared, void *p_shared1, const Problem &problem, AElementwiseOperation a_element_op, BElementwiseOperation b_element_op, CElementwiseOperation c_element_op)
Definition: gridwise_moe_gemm_blockscale.hpp:1945
static constexpr index_t NLane
Definition: gridwise_moe_gemm_blockscale.hpp:219
__host__ static __device__ auto CalculateBN0Shuffled(index_t N)
Definition: gridwise_moe_gemm_blockscale.hpp:274
remove_cvref_t< decltype(BlockGemmBlockMoeScaleBPreshufflePipeline_Selector< BlkGemmPipelineVer, BlkGemmPipeSched, BlockSize, ADataType, BDataType, ComputeTypeA, AccDataType, decltype(GetABlockDescriptor_AK0PerBlock_MPerBlock_AK1()), decltype(GetBBlockDescriptor_BK0PerBlock_NPerBlock_BK1()), decltype(MakeAMmaTileDescriptor_M0_M1_M2_K(GetABlockDescriptor_AK0PerBlock_MPerBlock_AK1())), decltype(MakeBMmaTileDescriptor_N0_N1_N2_K(GetBBlockDescriptor_BK0PerBlock_NPerBlock_BK1())), ABlockTransferSrcScalarPerVector, BBlockTransferSrcScalarPerVector, MPerBlock, NPerBlock, KPerBlock, ScaleBlockM, ScaleBlockN, ScaleBlockK, MPerXdl, NPerXdl, MXdlPerWave, NXdlPerWave, KPack, IsInputGemm &&!IsSplitK >())> BlockwiseGemmPipe
Definition: gridwise_moe_gemm_blockscale.hpp:955
static constexpr __device__ index_t GetSharedMemoryNumberOfByte()
Definition: gridwise_moe_gemm_blockscale.hpp:957
static constexpr auto I1
Definition: gridwise_moe_gemm_blockscale.hpp:183
__host__ static __device__ auto CalculateBK0Shuffled(index_t K)
Definition: gridwise_moe_gemm_blockscale.hpp:278
__host__ static constexpr __device__ bool CalculateHasMainKBlockLoop(index_t K)
Definition: gridwise_moe_gemm_blockscale.hpp:1154
float BScaleType
Definition: gridwise_moe_gemm_blockscale.hpp:180
__host__ static __device__ auto MakeAGridDescriptor_AK0_M_AK1(IndexType M, IndexType MPad, IndexType K, IndexType KPad, IndexType StrideA, IndexType AK0)
Definition: gridwise_moe_gemm_blockscale.hpp:343
__host__ static constexpr __device__ auto MakeBMmaTileDescriptor_N0_N1_N2_K(const BBlockDesc_BK0_N_BK1 &)
Definition: gridwise_moe_gemm_blockscale.hpp:531
static constexpr auto BlockSizeNumber
Definition: gridwise_moe_gemm_blockscale.hpp:198
remove_cvref_t< decltype(MakeDsGridDescriptor_M_N(0, 0, 0, 0, {}))> DsGridDesc_M_N
Definition: gridwise_moe_gemm_blockscale.hpp:605
__host__ static __device__ auto CalculateMPadded(index_t M)
Definition: gridwise_moe_gemm_blockscale.hpp:264
static constexpr auto AK1Number
Definition: gridwise_moe_gemm_blockscale.hpp:196
ThisThreadBlock< BlockSize > ThisThreadBlock
Definition: gridwise_moe_gemm_blockscale.hpp:237
static constexpr auto I5
Definition: gridwise_moe_gemm_blockscale.hpp:187
__host__ static __device__ auto MakeDsGridDescriptor_M_N(index_t M, index_t MPad, index_t N, index_t NPad, std::array< index_t, NumDTensor > StrideDs)
Definition: gridwise_moe_gemm_blockscale.hpp:582
decltype(MakeDsGridPointer()) DsGridPointer
Definition: gridwise_moe_gemm_blockscale.hpp:235
static constexpr index_t APackedSize
Definition: gridwise_moe_gemm_blockscale.hpp:239
static constexpr auto MakeDsGridPointer()
Definition: gridwise_moe_gemm_blockscale.hpp:224
static constexpr __device__ auto GetCShuffleBlockDescriptor_MBlock_MPerBlock_NBlock_NPerBlock()
Definition: gridwise_moe_gemm_blockscale.hpp:913
__host__ static __device__ auto CalculateKPadded(index_t K)
Definition: gridwise_moe_gemm_blockscale.hpp:283
static constexpr auto I4
Definition: gridwise_moe_gemm_blockscale.hpp:186
float AScaleType
Definition: gridwise_moe_gemm_blockscale.hpp:179
static constexpr index_t KPack
Definition: gridwise_moe_gemm_blockscale.hpp:203
__host__ static __device__ auto CalculateAK0Padded(index_t K, index_t K_Batch=1)
Definition: gridwise_moe_gemm_blockscale.hpp:288
static constexpr __device__ auto GetBBlockDescriptor_BK0PerBlock_NPerBlock_BK1()
Definition: gridwise_moe_gemm_blockscale.hpp:906
static constexpr __device__ auto MakeDsGridDescriptor_MBlock_MPerBlock_NBlock_NPerBlock(const DsGridDesc &ds_grid_desc_m_n, index_t MBlock, index_t NBlock)
Definition: gridwise_moe_gemm_blockscale.hpp:594
__host__ static constexpr __device__ auto MakeAMmaTileDescriptor_M0_M1_M2_K(const ABlockDesc_AK0_M_AK1 &)
Definition: gridwise_moe_gemm_blockscale.hpp:522
static constexpr __host__ bool CheckValidity(const Argument &karg)
Definition: gridwise_moe_gemm_blockscale.hpp:981
static constexpr index_t NumDTensor
Definition: gridwise_moe_gemm_blockscale.hpp:200
__host__ static __device__ auto MakeCGridDescriptor_M_N(IndexType M, IndexType MPad, IndexType N, IndexType NPad, IndexType StrideC)
Definition: gridwise_moe_gemm_blockscale.hpp:537
static constexpr __device__ auto GetABlockDescriptor_AK0PerBlock_MPerBlock_AK1()
Definition: gridwise_moe_gemm_blockscale.hpp:788
static constexpr auto AK0Number
Definition: gridwise_moe_gemm_blockscale.hpp:194
__host__ static __device__ auto MakeBGridDescriptor_BK0_N_BK1(index_t K, index_t KPad, index_t N, index_t NPad, index_t StrideB, index_t BK0)
Definition: gridwise_moe_gemm_blockscale.hpp:434
__host__ static constexpr __device__ TailNumber CalculateKBlockLoopTailNum(index_t K)
Definition: gridwise_moe_gemm_blockscale.hpp:1161
static constexpr auto CShuffleBlockTransferScalarPerVector_NPerBlock
Definition: gridwise_moe_gemm_blockscale.hpp:191
static constexpr index_t KGroup
Definition: gridwise_moe_gemm_blockscale.hpp:205
static __device__ void Run(const index_t *p_sorted_token_ids, const index_t *p_sorted_expert_ids, const index_t *p_max_token_id, const ADataType *p_a_grid, const BDataType *p_b_grid, DsGridPointer &p_ds_grid, CDataType *p_c_grid, const AScaleType *p_a_scale_grid, const BScaleType *p_b_scale_grid, void *p_shared, const Problem &problem, AElementwiseOperation a_element_op, BElementwiseOperation b_element_op, CElementwiseOperation c_element_op)
Definition: gridwise_moe_gemm_blockscale.hpp:1190
__host__ static constexpr __device__ auto MakeGemmMmaTileDescriptor(const TileDesc_K0_MN_K1 &)
Definition: gridwise_moe_gemm_blockscale.hpp:329
static constexpr index_t SortedTileSize
Definition: gridwise_moe_gemm_blockscale.hpp:222
static constexpr auto BK0Number
Definition: gridwise_moe_gemm_blockscale.hpp:195
static constexpr auto I0
Definition: gridwise_moe_gemm_blockscale.hpp:182
static constexpr index_t NWave
Definition: gridwise_moe_gemm_blockscale.hpp:220
__host__ static __device__ auto MakeDGridDescriptor_M_N(index_t M, index_t MPad, index_t N, index_t NPad, index_t StrideC)
Definition: gridwise_moe_gemm_blockscale.hpp:561
static constexpr __device__ auto MakeCGridDescriptor_MBlock_MPerBlock_NBlock_NPerBlock(const CGridDesc &c_grid_desc_m_n, index_t MBlock, index_t NBlock)
Definition: gridwise_moe_gemm_blockscale.hpp:1169
static constexpr auto I6
Definition: gridwise_moe_gemm_blockscale.hpp:188
__host__ static __device__ auto CalculateNPadded(index_t N)
Definition: gridwise_moe_gemm_blockscale.hpp:269
__host__ static __device__ auto CalculateNBlock(index_t N)
Definition: gridwise_moe_gemm_blockscale.hpp:323
__host__ static __device__ auto CalculateBK0Padded(index_t K, index_t K_Batch=1)
Definition: gridwise_moe_gemm_blockscale.hpp:295
Selects the appropriate MFMA instruction type and configuration for given data types and tile sizes o...
Definition: xdlops_gemm.hpp:1255
static constexpr index_t GetK1PerXdlops()
Definition: xdlops_gemm.hpp:1861
static constexpr auto selected_mfma
Definition: xdlops_gemm.hpp:1808
static constexpr index_t GetKPerXdlops()
Definition: xdlops_gemm.hpp:1855
Definition: sequence.hpp:43
Definition: tensor_space_filling_curve.hpp:20
Blockwise data transfer.
Definition: thread_group_tensor_slice_transfer_v4r1_gather.hpp:48
Definition: thread_group_tensor_slice_transfer_v7r3_scatter.hpp:51
Definition: threadwise_tensor_slice_transfer.hpp:39
Definition: threadwise_tensor_slice_transfer.hpp:440
Helper structure that facilitates transfer of source (grid) data to destination threads.
Definition: threadwise_tensor_slice_transfer.hpp:234
Definition: tuple.hpp:117
Definition: amd_ck_fp8.hpp:36
Definition: integral_constant.hpp:20
Definition: data_type.hpp:187
Definition: functional2.hpp:33
Definition: device_base.hpp:270
Definition: unary_element_wise_operation.hpp:1041
Definition: unary_element_wise_operation.hpp:340
Definition: unary_element_wise_operation.hpp:1087