36 template <
typename GridwiseGemm,
37 bool HasMainKBlockLoop,
42 #if CK_USE_LAUNCH_BOUNDS
48 #if(!defined(__HIP_DEVICE_COMPILE__) || defined(__gfx9__))
49 __shared__
char p_shared[GridwiseGemm::GetSharedMemoryNumberOfByte()];
51 auto splitk_batch_offset =
typename GridwiseGemm::SplitKBatchOffset(karg, blockIdx.z);
53 GridwiseGemm::template Run<HasMainKBlockLoop, CGlobalMemoryDataOperation, TailNum>(
54 karg.p_sorted_token_ids,
55 karg.p_sorted_expert_ids,
57 karg.p_a_grid + splitk_batch_offset.a_k_split_offset,
58 karg.p_b_grid + splitk_batch_offset.b_k_split_offset,
71 template <
typename GridwiseGemm,
72 bool HasMainKBlockLoop,
77 #if CK_USE_LAUNCH_BOUNDS
83 #if(!defined(__HIP_DEVICE_COMPILE__) || defined(__gfx9__))
84 __shared__
char p_shared[GridwiseGemm::GetSharedMemoryNumberOfByte()];
85 __shared__
char p_shared1[GridwiseGemm::GetSharedMemoryNumberOfByte()];
87 auto splitk_batch_offset =
typename GridwiseGemm::SplitKBatchOffset(karg, blockIdx.z);
89 GridwiseGemm::template Run_2Lds<HasMainKBlockLoop, CGlobalMemoryDataOperation, TailNum>(
90 karg.p_sorted_token_ids,
91 karg.p_sorted_expert_ids,
93 karg.p_a_grid + splitk_batch_offset.a_k_split_offset,
94 karg.p_b_grid + splitk_batch_offset.b_k_split_offset,
108 template <
typename ALayout,
114 typename AccDataType,
115 typename CShuffleDataType,
118 typename AElementwiseOperation,
119 typename BElementwiseOperation,
120 typename CElementwiseOperation,
132 typename ABlockTransferThreadClusterLengths_AK0_M_AK1,
133 typename ABlockTransferThreadClusterArrangeOrder,
134 typename ABlockTransferSrcAccessOrder,
135 index_t ABlockTransferSrcVectorDim,
136 index_t ABlockTransferSrcScalarPerVector,
137 index_t ABlockTransferDstScalarPerVector_AK1,
138 bool AThreadTransferSrcResetCoordinateAfterRun,
140 typename BBlockTransferThreadClusterLengths_BK0_N_BK1,
141 typename BBlockTransferThreadClusterArrangeOrder,
142 typename BBlockTransferSrcAccessOrder,
143 index_t BBlockTransferSrcVectorDim,
144 index_t BBlockTransferSrcScalarPerVector,
145 index_t BBlockTransferDstScalarPerVector_BK1,
146 bool BThreadTransferSrcResetCoordinateAfterRun,
148 index_t CShuffleMXdlPerWavePerShuffle,
149 index_t CShuffleNXdlPerWavePerShuffle,
150 typename CShuffleBlockTransferClusterLengths_MBlock_MPerBlock_NBlock_NPerBlock,
151 typename CDEShuffleBlockTransferScalarPerVectors,
154 index_t ActivationOperation = 0,
155 bool NSwizzle =
false,
156 bool IsInputGemm =
true,
157 bool MulRoutedWeight =
true,
158 bool PerTokenQuant =
false,
160 typename ComputeTypeA = CDataType,
161 typename ComputeTypeB = ComputeTypeA,
162 typename LDSTypeA = ADataType,
163 typename LDSTypeB = BDataType>
176 CDEShuffleBlockTransferScalarPerVectors{}[
I0];
217 return static_cast<const DDataType*
>(
nullptr);
244 const index_t gridx = NSwizzle ? nblock * mblock : nblock;
245 const index_t gridy = NSwizzle ? 1 : mblock;
276 auto K_t = K_Batch * KPerBlock;
277 return (K + K_t - 1) / K_t * (KPerBlock / AK1Value);
282 auto K_t = K_Batch * KPerBlock;
283 return (K + K_t - 1) / K_t * (KPerBlock / BK1Value);
288 auto K_t = K_Batch * KPerBlock;
289 return (K + K_t - 1) / K_t * KPerBlock;
295 auto K_t = K_Batch * KReadVec;
296 return (K + K_t - 1) / K_t * KReadVec;
309 template <index_t MNXdlPerWave, index_t MNWaves, index_t MNPerXdl,
typename TileDesc_K0_MN_K1>
325 IndexType M, IndexType MPad, IndexType K, IndexType KPad, IndexType StrideA, IndexType AK0)
327 const auto a_grid_desc_mraw_kraw = [&]() {
328 if constexpr(is_same_v<tensor_layout::gemm::RowMajor, ALayout>)
332 else if constexpr(is_same_v<tensor_layout::gemm::ColumnMajor, ALayout>)
340 if constexpr(GemmSpec == GemmSpecialization::MKPadding ||
341 GemmSpec == GemmSpecialization::MNKPadding)
344 const auto a_grid_desc_m_k =
358 return a_grid_desc_ak0_m_ak1;
360 else if constexpr(GemmSpec == GemmSpecialization::MPadding ||
361 GemmSpec == GemmSpecialization::MNPadding)
365 a_grid_desc_mraw_kraw,
371 return a_grid_desc_ak0_m_ak1;
373 else if constexpr(GemmSpec == GemmSpecialization::KPadding ||
374 GemmSpec == GemmSpecialization::NKPadding)
378 a_grid_desc_mraw_kraw,
390 return a_grid_desc_ak0_m_ak1;
396 a_grid_desc_mraw_kraw,
402 return a_grid_desc_ak0_m_ak1;
411 make_tuple(
NWave * K0 * NkSwizzleNumber, K0 * NkSwizzleNumber, NkSwizzleNumber,
I1));
417 const auto b_grid_desc_nraw_kraw = [&]() {
431 GemmSpec != GemmSpecialization::Default),
432 "pk_i4_t does not support padding");
434 if constexpr(GemmSpec == GemmSpecialization::NKPadding ||
435 GemmSpec == GemmSpecialization::MNKPadding)
438 const auto b_grid_desc_n_k =
452 return b_grid_desc_bk0_n_bk1;
454 else if constexpr(GemmSpec == GemmSpecialization::NPadding ||
455 GemmSpec == GemmSpecialization::MNPadding)
459 b_grid_desc_nraw_kraw,
465 return b_grid_desc_bk0_n_bk1;
467 else if constexpr(GemmSpec == GemmSpecialization::KPadding ||
468 GemmSpec == GemmSpecialization::MKPadding)
472 b_grid_desc_nraw_kraw,
484 return b_grid_desc_bk0_n_bk1;
490 b_grid_desc_nraw_kraw,
496 return b_grid_desc_bk0_n_bk1;
500 template <
typename ABlockDesc_AK0_M_AK1>
501 __host__ __device__
static constexpr
auto
504 constexpr
index_t MWaves = MPerBlock / (MXdlPerWave * MPerXdl);
506 return MakeGemmMmaTileDescriptor<MXdlPerWave, MWaves, MPerXdl>(ABlockDesc_AK0_M_AK1{});
509 template <
typename BBlockDesc_BK0_N_BK1>
510 __host__ __device__
static constexpr
auto
513 return MakeGemmMmaTileDescriptor<NXdlPerWave, NWave, NPerXdl>(BBlockDesc_BK0_N_BK1{});
516 template <
typename ELayout>
518 IndexType M, IndexType MPad, IndexType N, IndexType NPad, IndexType StrideC)
520 const auto c_grid_desc_mraw_nraw = [&]() {
539 template <
typename DLayout>
540 __host__ __device__
static auto
543 const auto c_grid_desc_mraw_nraw = [&]() {
568 return MakeDGridDescriptor_M_N<DLayout>(M, MPad, N, NPad, StrideDs[i]);
573 template <
typename DsGr
idDesc>
575 const DsGridDesc& ds_grid_desc_m_n,
index_t MBlock,
index_t NBlock)
580 ds_grid_desc_m_n[i], MBlock, NBlock);
594 std::array<index_t, NumDTensor> StrideDs_,
622 std::cout <<
"problem {"
624 <<
"TopK:" <<
TopK <<
", "
633 <<
"KRead:" <<
KRead <<
", "
635 <<
"AK0:" <<
AK0 <<
", "
636 <<
"BK0:" <<
BK0 <<
", "
637 <<
"MBlock: " <<
MBlock <<
", "
638 <<
"NBlock: " <<
NBlock <<
"}" << std::endl;
668 const index_t* p_sorted_expert_ids_,
669 const index_t* p_max_token_id_,
670 const ADataType* p_a_grid_,
671 const BDataType* p_b_grid_,
672 std::array<const void*, NumDTensor> p_ds_grid_,
673 CDataType* p_c_grid_,
681 std::array<index_t, NumDTensor> StrideDs_,
684 AElementwiseOperation a_element_op_,
685 BElementwiseOperation b_element_op_,
686 CElementwiseOperation c_element_op_)
714 p_ds_grid(i) =
static_cast<const DDataType_*
>(p_ds_grid_[i]);
735 if constexpr(is_same_v<tensor_layout::gemm::RowMajor, ALayout>)
739 else if constexpr(is_same_v<tensor_layout::gemm::ColumnMajor, ALayout>)
744 if constexpr(is_same_v<tensor_layout::gemm::RowMajor, BLayout>)
748 else if constexpr(is_same_v<tensor_layout::gemm::ColumnMajor, BLayout>)
754 if(k_id < karg.
KBatch - 1)
771 if constexpr(ABlockLdsExtraM)
781 constexpr
auto a_lds_block_desc =
793 return a_lds_block_desc_permuted;
800 constexpr
auto M0 = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I1);
801 constexpr
auto M1 = MPerBlock / M0;
803 constexpr
auto KThreadWrite = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I0);
804 constexpr
auto K0PerThreadWrite =
AK0Number / KThreadWrite;
805 constexpr
auto KThreadRead = 64 / MPerXdl;
806 constexpr
auto K0PerThreadRead =
AK0Number / KThreadRead;
808 constexpr
auto kfold = (
AK1Number * M0 *
sizeof(LDSTypeA) > 128)
810 : 128 / (
AK1Number * M0 *
sizeof(LDSTypeA));
811 constexpr
auto KThreadReadPerm =
812 (kfold * K0PerThreadWrite / K0PerThreadRead) > 1
813 ? KThreadRead / (kfold * K0PerThreadWrite / K0PerThreadRead)
817 constexpr
auto mpair = (
AK1Number * MPerXdl *
sizeof(LDSTypeA) > 128)
819 : ((128 / (
AK1Number * MPerXdl *
sizeof(LDSTypeA))) > M0
821 : 128 / (
AK1Number * MPerXdl *
sizeof(LDSTypeA)));
827 Number<kfold * M0 / mpair>{},
846 a_lds_block_desc_permuted,
868 a_lds_block_desc_unmerged,
871 Number<KThreadWrite / kfold / KThreadReadPerm>{},
880 return a_lds_block_desc_ak0_m_ak1;
893 constexpr
index_t MWave = MPerBlock / (MXdlPerWave * MPerXdl);
895 constexpr
auto c_shuffle_block_desc_mblock_mperblock_nblock_nperblock =
902 return c_shuffle_block_desc_mblock_mperblock_nblock_nperblock;
920 ABlockTransferSrcScalarPerVector,
921 BBlockTransferSrcScalarPerVector,
940 a_block_desc_ak0_m_ak1.GetElementSpaceSize(), max_lds_align);
943 constexpr
auto c_shuffle_block_desc_mblock_mperblock_nblock_nperblock =
946 constexpr
auto c_block_size =
947 c_shuffle_block_desc_mblock_mperblock_nblock_nperblock.GetElementSpaceSize();
950 c_block_size *
sizeof(CShuffleDataType));
956 static_assert((MPerBlock % (MPerXdl * MXdlPerWave) == 0) &&
957 (NPerBlock % (NXdlPerWave * NPerXdl)) == 0,
958 "Invalid tuning param!");
966 if(!(karg.
M % MPerBlock == 0))
969 std::cout <<
"Arg M value is not a multiple of MPerBlock! M: " << karg.
M <<
" "
970 << __FILE__ <<
":" << __LINE__ <<
", in function: " << __func__
984 if(!(karg.
N % NPerBlock == 0))
987 std::cout <<
"Arg N value is not a multiple of NPerBlock! N: " << karg.
N <<
" "
988 << __FILE__ <<
":" << __LINE__ <<
", in function: " << __func__
1002 auto K_t = karg.
KBatch * KPerBlock;
1003 if(!(karg.
K % K_t == 0))
1006 std::cout <<
"Arg K value is not a multiple of K_Batch * K0PerBlock * K1! K: "
1007 << karg.
K <<
" " << __FILE__ <<
":" << __LINE__
1008 <<
", in function: " << __func__ << std::endl;
1017 auto K_t = karg.
KBatch * KReadVec;
1019 if((KReadPadSplited * (karg.
KBatch - 1)) >= karg.
K)
1027 if(karg.
K % ABlockTransferSrcScalarPerVector != 0)
1030 std::cout <<
"Arg K (" << karg.
K
1031 <<
") value is not a multiple of ABlockTransferSrcScalarPerVector ("
1032 << ABlockTransferSrcScalarPerVector <<
" )! " << __FILE__ <<
":"
1033 << __LINE__ <<
", in function: " << __func__ << std::endl;
1041 if(karg.
M % ABlockTransferSrcScalarPerVector != 0)
1044 std::cout <<
"Arg M (" << karg.
M
1045 <<
") value is not a multiple of ABlockTransferSrcScalarPerVector ("
1046 << ABlockTransferSrcScalarPerVector <<
" )! " << __FILE__ <<
":"
1047 << __LINE__ <<
", in function: " << __func__ << std::endl;
1056 if(karg.
N % BBlockTransferSrcScalarPerVector != 0)
1059 std::cout <<
"Arg N (" << karg.
N
1060 <<
") value is not a multiple of BBlockTransferSrcScalarPerVector ("
1061 << BBlockTransferSrcScalarPerVector <<
" )! " << __FILE__ <<
":"
1062 << __LINE__ <<
", in function: " << __func__ << std::endl;
1070 if(karg.
K % BBlockTransferSrcScalarPerVector != 0)
1073 std::cout <<
"Arg K (" << karg.
K
1074 <<
") value is not a multiple of BBlockTransferSrcScalarPerVector ("
1075 << BBlockTransferSrcScalarPerVector <<
" )! " << __FILE__ <<
":"
1076 << __LINE__ <<
", in function: " << __func__ << std::endl;
1088 std::cout <<
"Arg N (" << karg.
N
1089 <<
") value is not a multiple of "
1090 "CShuffleBlockTransferScalarPerVector_NPerBlock ("
1092 <<
":" << __LINE__ <<
", in function: " << __func__ << std::endl;
1103 std::cout <<
"Arg M (" << karg.
M
1104 <<
") value is not a multiple of "
1105 "CShuffleBlockTransferScalarPerVector_NPerBlock ("
1107 <<
":" << __LINE__ <<
", in function: " << __func__ << std::endl;
1116 const auto num_k_loop = karg.
AK0 / (KPerBlock / AK1Value);
1118 if(num_k_loop <= BlockwiseGemmPipe::PrefetchStages)
1129 const index_t num_loop = K / KPerBlock;
1131 return BlockwiseGemmPipe::BlockHasHotloop(num_loop);
1136 const index_t num_loop = K / KPerBlock;
1138 return BlockwiseGemmPipe::BlockLoopTailNum(num_loop);
1141 template <
typename CGr
idDesc>
1143 const CGridDesc& c_grid_desc_m_n,
index_t MBlock,
index_t NBlock)
1152 return c_grid_desc_mblock_mperblock_nblock_nperblock;
1160 template <
bool HasMainKBlockLoop,
1164 const index_t* p_sorted_expert_ids,
1165 const index_t* p_max_token_id,
1166 const ADataType* p_a_grid,
1167 const BDataType* p_b_grid,
1169 CDataType* p_c_grid,
1172 AElementwiseOperation a_element_op,
1173 BElementwiseOperation b_element_op,
1174 CElementwiseOperation c_element_op)
1184 const auto b_grid_desc_bpreshuffled =
1186 const auto c_grid_desc_m_n = MakeCGridDescriptor_M_N<CLayout>(
1192 const auto c_grid_desc_mblock_mperblock_nblock_nperblock =
1195 const index_t max_token_id = __builtin_amdgcn_readfirstlane(p_max_token_id[0]);
1197 const index_t expert_block_id = NSwizzle ? blockIdx.x / problem.
NBlock : blockIdx.y;
1198 if(expert_block_id * MPerBlock >= max_token_id)
1201 __builtin_amdgcn_readfirstlane(p_sorted_expert_ids[expert_block_id]);
1202 const auto block_mn = [&]() -> std::pair<int, int> {
1203 if constexpr(NSwizzle)
1205 const index_t ecnt_prefix = p_max_token_id[1 + expert_id];
1207 const index_t ecnt = p_max_token_id[2 + expert_id] - ecnt_prefix;
1208 const index_t expert_swizzle =
1209 ecnt > 0 ? ecnt : 1;
1210 const index_t bid_new = blockIdx.x - prefix_block;
1211 const index_t nid = __builtin_amdgcn_readfirstlane(
1212 bid_new % 8 + bid_new / (8 * expert_swizzle) * 8);
1214 __builtin_amdgcn_readfirstlane(ecnt_prefix + bid_new / 8 % expert_swizzle);
1219 return {blockIdx.x, blockIdx.y};
1223 const index_t block_n_id = block_mn.first;
1224 const index_t block_m_id = block_mn.second;
1226 __builtin_amdgcn_readfirstlane(p_sorted_token_ids[block_m_id * MPerBlock] & 0xffffff);
1229 constexpr
auto AMThreads = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I1);
1230 constexpr
auto AK0Threads = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I0);
1231 constexpr
auto AK1Threads = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I2);
1232 constexpr
auto AKThreads = AK0Threads * AK1Threads;
1233 constexpr
auto AMRepeats = MPerBlock / AMThreads;
1234 const index_t token_pos = block_m_id * MPerBlock + threadIdx.x / AKThreads * AMRepeats;
1236 if(token_pos >= max_token_id || token0 >= problem.
NumTokens)
1240 const index_t fused_token = p_sorted_token_ids[token_pos + m0];
1241 index_t token_offset = fused_token & 0xffffff;
1242 if constexpr(!IsInputGemm)
1244 token_offset = token_offset * problem.
TopK + (fused_token >> 24);
1246 gather_offsets(m0) =
static_cast<IndexType
>(token_offset) * problem.
K;
1249 __builtin_amdgcn_readfirstlane(problem.
N * problem.
K * (IsInputGemm ? 2 : 1));
1252 const index_t n_block_data_idx_on_grid =
1253 __builtin_amdgcn_readfirstlane(block_n_id * NXdlPerWave);
1255 const auto a_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
1256 p_a_grid, a_grid_desc_ak0_m_ak1.GetElementSpaceSize());
1257 const auto b_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
1258 p_b_grid + expert_id * expert_stride /
BPackedSize,
1259 b_grid_desc_bpreshuffled.GetElementSpaceSize());
1269 AElementwiseOperation,
1273 ABlockTransferThreadClusterLengths_AK0_M_AK1,
1274 ABlockTransferThreadClusterArrangeOrder,
1277 decltype(a_grid_desc_ak0_m_ak1),
1278 decltype(a_block_desc_ak0_m_ak1),
1279 ABlockTransferSrcAccessOrder,
1281 ABlockTransferSrcVectorDim,
1283 ABlockTransferSrcScalarPerVector,
1284 ABlockTransferDstScalarPerVector_AK1,
1287 AThreadTransferSrcResetCoordinateAfterRun,
1291 BlockwiseGemmPipe::GlobalBufferNum>(a_grid_desc_ak0_m_ak1,
1294 a_block_desc_ak0_m_ak1,
1301 auto b_block_buf = make_static_buffer<AddressSpaceEnum::Vgpr, BDataType>(
1302 b_block_desc_bk0_n_bk1.GetElementSpaceSize());
1307 decltype(b_grid_desc_bpreshuffled),
1308 decltype(b_block_desc_bk0_n_bk1),
1312 BBlockTransferSrcScalarPerVector,
1313 BThreadTransferSrcResetCoordinateAfterRun,
1314 true>(b_grid_desc_bpreshuffled,
1322 auto a_block_buf = make_dynamic_buffer<AddressSpaceEnum::Lds>(
1323 static_cast<LDSTypeA*
>(p_shared), a_block_desc_ak0_m_ak1.GetElementSpaceSize());
1329 static_assert(std::is_default_constructible_v<BlockwiseGemmPipe>);
1331 auto c_thread_buf = blockwise_gemm_pipeline.GetCThreadBuffer();
1332 decltype(c_thread_buf) c_thread_buf_up;
1336 c_thread_buf.num_of_v_,
1337 c_thread_buf.s_per_v,
1341 const index_t num_k_block_main_loop = __builtin_amdgcn_readfirstlane(
1342 (a_grid_desc_ak0_m_ak1.GetLength(
I0) * a_grid_desc_ak0_m_ak1.GetLength(
I2)) /
1344 if constexpr(IsInputGemm)
1346 const BDataType* p_b_grid_up = p_b_grid + expert_stride / 2 /
BPackedSize;
1347 const auto b_grid_buf_up = make_dynamic_buffer<AddressSpaceEnum::Global>(
1348 p_b_grid_up + expert_id * expert_stride /
BPackedSize,
1349 b_grid_desc_bpreshuffled.GetElementSpaceSize());
1353 decltype(b_grid_desc_bpreshuffled),
1354 decltype(b_block_desc_bk0_n_bk1),
1358 BBlockTransferSrcScalarPerVector,
1359 BThreadTransferSrcResetCoordinateAfterRun,
1360 true>(b_grid_desc_bpreshuffled,
1366 blockwise_gemm_pipeline.template Run<HasMainKBlockLoop, TailNum>(
1367 a_grid_desc_ak0_m_ak1,
1368 a_block_desc_ak0_m_ak1,
1372 a_block_slice_copy_step,
1373 b_grid_desc_bpreshuffled,
1375 b_blockwise_copy_up,
1379 b_block_slice_copy_step,
1382 num_k_block_main_loop);
1386 blockwise_gemm_pipeline.template Run<HasMainKBlockLoop, TailNum>(
1387 a_grid_desc_ak0_m_ak1,
1388 a_block_desc_ak0_m_ak1,
1392 a_block_slice_copy_step,
1393 b_grid_desc_bpreshuffled,
1397 b_block_slice_copy_step,
1399 num_k_block_main_loop);
1404 static_assert(MXdlPerWave % CShuffleMXdlPerWavePerShuffle == 0 &&
1405 NXdlPerWave % CShuffleNXdlPerWavePerShuffle == 0,
1408 constexpr
index_t MWave = MPerBlock / (MXdlPerWave * MPerXdl);
1411 constexpr
auto c_thread_desc_m0_n0_m1_n1_m2_m3_m4_n2 =
1412 blockwise_gemm_pipeline.GetCThreadDescriptor_M0_N0_M1_N1_M2_M3_M4_N2();
1416 constexpr
auto c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp =
1417 blockwise_gemm_pipeline.GetCBlockDescriptor_M0_N0_M1_N1_M2_M3_M4_N2();
1419 constexpr
auto M0 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I0);
1420 constexpr
auto N0 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I1);
1421 constexpr
auto M1 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I2);
1422 constexpr
auto N1 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I3);
1423 constexpr
auto M2 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I4);
1424 constexpr
auto M3 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I5);
1425 constexpr
auto M4 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I6);
1426 constexpr
auto N2 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I7);
1429 const float* p_sorted_weights_0 = p_ds_grid[
I0];
1430 const float* p_scale_b = p_ds_grid[
I1];
1432 static_assert(M0 * M1 * M2 * M3 * M4 == MPerBlock);
1433 static_assert(M4 == 4);
1437 if(p_sorted_weights_0 !=
nullptr && p_scale_b !=
nullptr)
1439 if constexpr(PerTokenQuant)
1441 constexpr
index_t scale_stride = (IsInputGemm ? 2 : 1);
1442 p_scale_b += expert_id * problem.
N * scale_stride + block_n_id * NPerBlock +
1447 p_scale_b += expert_id;
1453 const float scale_b = p_scale_b[n0 *
NWave * NPerXdl * PerTokenQuant];
1456 const index_t m_pos = block_m_id * MPerBlock + m0 * M1 * M2 * M3 * M4 +
1457 m1 * M2 * M3 * M4 + m2 * M3 * M4 + m3 * M4;
1458 if constexpr(PerTokenQuant)
1461 *c_style_pointer_cast<const vector_type<int32_t, M4>*>(
1462 p_sorted_token_ids + m_pos);
1464 if constexpr(MulRoutedWeight)
1466 topk_weights = *c_style_pointer_cast<const vector_type<float, M4>*>(
1467 p_ds_grid[
I2] + m_pos);
1470 float scale_a = [&]() {
1471 if constexpr(PerTokenQuant)
1474 const index_t token_offset = fused_token & 0xffffff;
1476 ? p_sorted_weights_0[IsInputGemm
1486 return p_sorted_weights_0[0];
1490 blockwise_gemm_pipeline.GetCThreadDesc().CalculateOffset(
1493 if constexpr(IsInputGemm)
1497 const float scale_up =
1498 p_scale_b[(n0 *
NWave * NPerXdl + problem.
N) *
1500 float gate = scale_a * scale_b * c_thread_buf[cidx];
1501 float up = scale_a * scale_up * c_thread_buf_up[cidx];
1502 if constexpr(MulRoutedWeight)
1504 gate = gate * topk_weights.AsType<
float>()[m4];
1505 up = up * topk_weights.AsType<
float>()[m4];
1513 c_thread_buf_fp32(cidx) = gate * up;
1517 const float scale_up =
1518 p_scale_b[(n0 *
NWave * NPerXdl + problem.
N) *
1520 float gate = scale_a * scale_b * c_thread_buf[cidx];
1521 float up = scale_a * scale_up * c_thread_buf_up[cidx];
1522 if constexpr(MulRoutedWeight)
1524 gate = gate * topk_weights.AsType<
float>()[m4];
1525 up = up * topk_weights.AsType<
float>()[m4];
1533 c_thread_buf_fp32(cidx) = gate * up;
1538 c_thread_buf_fp32(cidx) =
1539 scale_a * scale_b * c_thread_buf[cidx];
1540 if constexpr(MulRoutedWeight)
1542 c_thread_buf_fp32(cidx) = c_thread_buf_fp32(cidx) *
1543 topk_weights.AsType<
float>()[m4];
1557 const index_t m_pos = block_m_id * MPerBlock + m0 * M1 * M2 * M3 * M4 +
1558 m1 * M2 * M3 * M4 + m2 * M3 * M4 + m3 * M4;
1559 if constexpr(MulRoutedWeight)
1561 topk_weights = *c_style_pointer_cast<const vector_type<float, M4>*>(
1562 p_ds_grid[
I2] + m_pos);
1566 blockwise_gemm_pipeline.GetCThreadDesc().CalculateOffset(
1570 if constexpr(IsInputGemm)
1574 float gate = c_thread_buf[cidx];
1575 float up = c_thread_buf_up[cidx];
1576 if constexpr(MulRoutedWeight)
1578 gate = gate * topk_weights.AsType<
float>()[m4];
1579 up = up * topk_weights.AsType<
float>()[m4];
1582 c_thread_buf_fp32(cidx) = gate * up;
1586 float gate = c_thread_buf[cidx];
1587 float up = c_thread_buf_up[cidx];
1588 if constexpr(MulRoutedWeight)
1590 gate = gate * topk_weights.AsType<
float>()[m4];
1591 up = up * topk_weights.AsType<
float>()[m4];
1594 c_thread_buf_fp32(cidx) = gate * up;
1599 c_thread_buf_fp32(cidx) = c_thread_buf[cidx];
1600 if constexpr(MulRoutedWeight)
1602 c_thread_buf_fp32(cidx) = topk_weights.AsType<
float>()[m4] *
1603 c_thread_buf_fp32[cidx];
1612 constexpr
auto c_shuffle_block_desc_mblock_mperblock_nblock_nperblock =
1615 auto c_shuffle_block_buf = make_dynamic_buffer<AddressSpaceEnum::Lds>(
1616 static_cast<CShuffleDataType*
>(p_shared),
1617 c_shuffle_block_desc_mblock_mperblock_nblock_nperblock.GetElementSpaceSize());
1620 c_shuffle_block_desc_mblock_mperblock_nblock_nperblock,
1640 const auto c_thread_mtx_on_block =
1641 blockwise_gemm_pipeline.CalculateCThreadOriginDataIndex(
I0,
I0,
I0,
I0);
1643 const index_t m_thread_data_on_block = c_thread_mtx_on_block[
I0];
1644 const index_t n_thread_data_on_block = c_thread_mtx_on_block[
I1];
1646 const auto m_thread_data_on_block_to_m0_m1_m2_m3_m4_adaptor =
1652 const auto m_thread_data_on_block_idx =
1653 m_thread_data_on_block_to_m0_m1_m2_m3_m4_adaptor.CalculateBottomIndex(
1656 const auto n_thread_data_on_block_to_n0_n1_n2_adaptor =
1662 const auto n_thread_data_on_block_idx =
1663 n_thread_data_on_block_to_n0_n1_n2_adaptor.CalculateBottomIndex(
1667 auto c_thread_copy_vgpr_to_lds =
1670 decltype(c_thread_desc_m0_n0_m1_n1_m2_m3_m4_n2),
1671 decltype(c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2),
1673 Sequence<CShuffleMXdlPerWavePerShuffle,
1674 CShuffleNXdlPerWavePerShuffle,
1687 c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2,
1690 m_thread_data_on_block_idx[
I1],
1691 n_thread_data_on_block_idx[
I1],
1692 m_thread_data_on_block_idx[
I2],
1693 m_thread_data_on_block_idx[
I3],
1694 m_thread_data_on_block_idx[
I4],
1695 n_thread_data_on_block_idx[
I2]),
1698 using EDataType = CDataType;
1703 const auto ds_grid_desc_mblock_mperblock_nblock_nperblock =
1709 return make_dynamic_buffer<AddressSpaceEnum::Global>(
1710 p_ds_grid[i], ds_grid_desc_m_n[i].GetElementSpaceSize());
1716 tie(c_shuffle_block_desc_mblock_mperblock_nblock_nperblock),
1718 [&](
auto i) ->
const auto&
1719 {
return ds_grid_desc_mblock_mperblock_nblock_nperblock[i]; },
1724 tie(c_shuffle_block_buf),
1726 [&](
auto i) ->
const auto&
1727 {
return ds_grid_buf[i]; },
1731 const auto idx_c_ds_block_begin =
1741 const auto e_grid_desc_mblock_mperblock_nblock_nperblock =
1742 c_grid_desc_mblock_mperblock_nblock_nperblock;
1744 using CDEBlockTransferCluster =
1745 CShuffleBlockTransferClusterLengths_MBlock_MPerBlock_NBlock_NPerBlock;
1746 const auto EGlobalMemoryDataOperation = CGlobalMemoryDataOperation;
1747 constexpr
index_t scatter_weight_idx = 3;
1752 decltype(c_ds_desc_refs),
1753 decltype(
tie(e_grid_desc_mblock_mperblock_nblock_nperblock)),
1754 CElementwiseOperation,
1758 CShuffleMXdlPerWavePerShuffle * MWave * MPerXdl,
1760 CShuffleNXdlPerWavePerShuffle *
NWave * NPerXdl>,
1761 CDEBlockTransferCluster,
1767 CDEShuffleBlockTransferScalarPerVectors,
1779 idx_c_ds_block_begin,
1780 tie(e_grid_desc_mblock_mperblock_nblock_nperblock),
1784 auto c_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
1785 p_c_grid, c_grid_desc_mblock_mperblock_nblock_nperblock.GetElementSpaceSize());
1786 constexpr
auto sfc_c_vgpr =
1789 Sequence<CShuffleMXdlPerWavePerShuffle,
1790 CShuffleNXdlPerWavePerShuffle,
1798 constexpr
index_t num_access = sfc_c_vgpr.GetNumOfAccess();
1801 constexpr
auto sfc_cde_block =
1805 CShuffleMXdlPerWavePerShuffle * MWave * MPerXdl,
1807 CShuffleNXdlPerWavePerShuffle *
NWave * NPerXdl>>{};
1809 static_assert(num_access == sfc_cde_block.GetNumOfAccess(),
"wrong!");
1810 constexpr
auto EMThreads =
1811 CDEBlockTransferCluster{}.At(
I0) * CDEBlockTransferCluster{}.At(
I1);
1812 constexpr
auto EMRepeats = CShuffleMXdlPerWavePerShuffle * MWave * MPerXdl / EMThreads;
1813 constexpr
auto ENThreads =
1814 CDEBlockTransferCluster{}.At(
I2) * CDEBlockTransferCluster{}.At(
I3);
1819 auto dstidx = sfc_cde_block.GetIndex(access_id);
1821 block_m_id * MPerBlock + threadIdx.x / ENThreads * EMRepeats + dstidx(
I1);
1823 const index_t fused_token = p_sorted_token_ids[c_token_pos + m0];
1824 IndexType token_offset = fused_token & 0xffffff;
1825 if constexpr(IsInputGemm)
1827 token_offset = token_offset * problem.
TopK + (fused_token >> 24);
1829 scatter_offsets(m0) =
static_cast<IndexType
>(token_offset) * problem.
N;
1835 c_thread_copy_vgpr_to_lds.Run(c_thread_desc_m0_n0_m1_n1_m2_m3_m4_n2,
1836 sfc_c_vgpr.GetIndexTupleOfNumber(access_id),
1838 c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2,
1839 c_shuffle_block_buf);
1845 cde_block_copy_lds_and_global.Run(
1848 tie(e_grid_desc_mblock_mperblock_nblock_nperblock),
1852 if constexpr(access_id < num_access - 1)
1854 constexpr
auto cde_lds_and_global_step =
1855 sfc_cde_block.GetForwardStep(access_id);
1859 cde_block_copy_lds_and_global.MoveSrcSliceWindow(
1860 c_ds_desc_refs, i +
I1, cde_lds_and_global_step);
1864 cde_block_copy_lds_and_global.MoveDstSliceWindow(
1865 tie(e_grid_desc_mblock_mperblock_nblock_nperblock),
1867 cde_lds_and_global_step);
1873 template <
bool HasMainKBlockLoop,
1877 const index_t* p_sorted_expert_ids,
1878 const index_t* p_max_token_id,
1879 const ADataType* p_a_grid,
1880 const BDataType* p_b_grid,
1882 CDataType* p_c_grid,
1886 AElementwiseOperation a_element_op,
1887 BElementwiseOperation b_element_op,
1888 CElementwiseOperation c_element_op)
1898 const auto b_grid_desc_bpreshuffled =
1900 const auto c_grid_desc_m_n = MakeCGridDescriptor_M_N<CLayout>(
1906 const auto c_grid_desc_mblock_mperblock_nblock_nperblock =
1909 const index_t max_token_id = __builtin_amdgcn_readfirstlane(p_max_token_id[0]);
1911 const index_t expert_block_id = NSwizzle ? blockIdx.x / problem.
NBlock : blockIdx.y;
1912 if(expert_block_id * MPerBlock >= max_token_id)
1915 __builtin_amdgcn_readfirstlane(p_sorted_expert_ids[expert_block_id]);
1916 const auto block_mn = [&]() -> std::pair<int, int> {
1917 if constexpr(NSwizzle)
1919 const index_t ecnt_prefix = p_max_token_id[1 + expert_id];
1921 const index_t ecnt = p_max_token_id[2 + expert_id] - ecnt_prefix;
1922 const index_t expert_swizzle =
1923 ecnt > 0 ? ecnt : 1;
1924 const index_t bid_new = blockIdx.x - prefix_block;
1925 const index_t nid = __builtin_amdgcn_readfirstlane(
1926 bid_new % 8 + bid_new / (8 * expert_swizzle) * 8);
1928 __builtin_amdgcn_readfirstlane(ecnt_prefix + bid_new / 8 % expert_swizzle);
1933 return {blockIdx.x, blockIdx.y};
1937 const index_t block_n_id = block_mn.first;
1938 const index_t block_m_id = block_mn.second;
1940 __builtin_amdgcn_readfirstlane(p_sorted_token_ids[block_m_id * MPerBlock] & 0xffffff);
1943 constexpr
auto AMThreads = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I1);
1944 constexpr
auto AK0Threads = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I0);
1945 constexpr
auto AK1Threads = ABlockTransferThreadClusterLengths_AK0_M_AK1{}.At(
I2);
1946 constexpr
auto AKThreads = AK0Threads * AK1Threads;
1947 constexpr
auto AMRepeats = MPerBlock / AMThreads;
1948 const index_t token_pos = block_m_id * MPerBlock + threadIdx.x / AKThreads * AMRepeats;
1950 if(token_pos >= max_token_id || token0 >= problem.
NumTokens)
1954 const index_t fused_token = p_sorted_token_ids[token_pos + m0];
1955 index_t token_offset = fused_token & 0xffffff;
1956 if constexpr(!IsInputGemm)
1958 token_offset = token_offset * problem.
TopK + (fused_token >> 24);
1960 gather_offsets(m0) =
static_cast<IndexType
>(token_offset) * problem.
K;
1963 __builtin_amdgcn_readfirstlane(problem.
N * problem.
K * (IsInputGemm ? 2 : 1));
1966 const index_t n_block_data_idx_on_grid =
1967 __builtin_amdgcn_readfirstlane(block_n_id * NXdlPerWave);
1969 const auto a_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
1970 p_a_grid, a_grid_desc_ak0_m_ak1.GetElementSpaceSize());
1971 const auto b_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
1972 p_b_grid + expert_id * expert_stride /
BPackedSize,
1973 b_grid_desc_bpreshuffled.GetElementSpaceSize());
1984 AElementwiseOperation,
1988 ABlockTransferThreadClusterLengths_AK0_M_AK1,
1989 ABlockTransferThreadClusterArrangeOrder,
1992 decltype(a_grid_desc_ak0_m_ak1),
1993 decltype(a_block_desc_ak0_m_ak1),
1994 ABlockTransferSrcAccessOrder,
1996 ABlockTransferSrcVectorDim,
1998 ABlockTransferSrcScalarPerVector,
1999 ABlockTransferDstScalarPerVector_AK1,
2002 AThreadTransferSrcResetCoordinateAfterRun,
2006 2>(a_grid_desc_ak0_m_ak1,
2009 a_block_desc_ak0_m_ak1,
2016 auto b_block_buf_ping = make_static_buffer<AddressSpaceEnum::Vgpr, BDataType>(
2017 b_block_desc_bk0_n_bk1.GetElementSpaceSize());
2018 auto b_block_buf_pong = make_static_buffer<AddressSpaceEnum::Vgpr, BDataType>(
2019 b_block_desc_bk0_n_bk1.GetElementSpaceSize());
2020 auto b_block_bufs =
make_tuple(b_block_buf_ping, b_block_buf_pong);
2025 decltype(b_grid_desc_bpreshuffled),
2026 decltype(b_block_desc_bk0_n_bk1),
2030 BBlockTransferSrcScalarPerVector,
2031 BThreadTransferSrcResetCoordinateAfterRun,
2032 true>(b_grid_desc_bpreshuffled,
2040 auto a_block_buf_ping = make_dynamic_buffer<AddressSpaceEnum::Lds>(
2041 static_cast<ADataType*
>(p_shared), a_block_desc_ak0_m_ak1.GetElementSpaceSize());
2042 auto a_block_buf_pong = make_dynamic_buffer<AddressSpaceEnum::Lds>(
2043 static_cast<ADataType*
>(p_shared1), a_block_desc_ak0_m_ak1.GetElementSpaceSize());
2044 auto a_block_bufs =
make_tuple(a_block_buf_ping, a_block_buf_pong);
2050 static_assert(std::is_default_constructible_v<BlockwiseGemmPipe>);
2052 auto c_thread_buf = blockwise_gemm_pipeline.GetCThreadBuffer();
2053 decltype(c_thread_buf) c_thread_buf_up;
2057 c_thread_buf.num_of_v_,
2058 c_thread_buf.s_per_v,
2062 const index_t num_k_block_main_loop = __builtin_amdgcn_readfirstlane(
2063 (a_grid_desc_ak0_m_ak1.GetLength(
I0) * a_grid_desc_ak0_m_ak1.GetLength(
I2)) /
2066 if constexpr(IsInputGemm)
2068 const BDataType* p_b_grid_up = p_b_grid + expert_stride / 2 /
BPackedSize;
2069 const auto b_grid_buf_up = make_dynamic_buffer<AddressSpaceEnum::Global>(
2070 p_b_grid_up + expert_id * expert_stride /
BPackedSize,
2071 b_grid_desc_bpreshuffled.GetElementSpaceSize());
2075 decltype(b_grid_desc_bpreshuffled),
2076 decltype(b_block_desc_bk0_n_bk1),
2080 BBlockTransferSrcScalarPerVector,
2081 BThreadTransferSrcResetCoordinateAfterRun,
2082 true>(b_grid_desc_bpreshuffled,
2087 blockwise_gemm_pipeline.template Run<HasMainKBlockLoop, TailNum>(
2088 a_grid_desc_ak0_m_ak1,
2089 a_block_desc_ak0_m_ak1,
2093 a_block_slice_copy_step,
2094 b_grid_desc_bpreshuffled,
2096 b_blockwise_copy_up,
2100 b_block_slice_copy_step,
2103 num_k_block_main_loop);
2108 blockwise_gemm_pipeline.template Run<HasMainKBlockLoop, TailNum>(
2109 a_grid_desc_ak0_m_ak1,
2110 a_block_desc_ak0_m_ak1,
2114 a_block_slice_copy_step,
2115 b_grid_desc_bpreshuffled,
2119 b_block_slice_copy_step,
2121 num_k_block_main_loop);
2126 static_assert(MXdlPerWave % CShuffleMXdlPerWavePerShuffle == 0 &&
2127 NXdlPerWave % CShuffleNXdlPerWavePerShuffle == 0,
2130 constexpr
index_t MWave = MPerBlock / (MXdlPerWave * MPerXdl);
2133 constexpr
auto c_thread_desc_m0_n0_m1_n1_m2_m3_m4_n2 =
2134 blockwise_gemm_pipeline.GetCThreadDescriptor_M0_N0_M1_N1_M2_M3_M4_N2();
2138 constexpr
auto c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp =
2139 blockwise_gemm_pipeline.GetCBlockDescriptor_M0_N0_M1_N1_M2_M3_M4_N2();
2141 constexpr
auto M0 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I0);
2142 constexpr
auto N0 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I1);
2143 constexpr
auto M1 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I2);
2144 constexpr
auto N1 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I3);
2145 constexpr
auto M2 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I4);
2146 constexpr
auto M3 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I5);
2147 constexpr
auto M4 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I6);
2148 constexpr
auto N2 = c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2_tmp.GetLength(
I7);
2151 const float* p_sorted_weights_0 = p_ds_grid[
I0];
2152 const float* p_scale_b = p_ds_grid[
I1];
2154 static_assert(M0 * M1 * M2 * M3 * M4 == MPerBlock);
2155 static_assert(M4 == 4);
2159 if(p_sorted_weights_0 !=
nullptr && p_scale_b !=
nullptr)
2161 if constexpr(PerTokenQuant)
2163 constexpr
index_t scale_stride = (IsInputGemm ? 2 : 1);
2164 p_scale_b += expert_id * problem.
N * scale_stride + block_n_id * NPerBlock +
2169 p_scale_b += expert_id;
2175 const float scale_b = p_scale_b[n0 *
NWave * NPerXdl * PerTokenQuant];
2178 const index_t m_pos = block_m_id * MPerBlock + m0 * M1 * M2 * M3 * M4 +
2179 m1 * M2 * M3 * M4 + m2 * M3 * M4 + m3 * M4;
2180 if constexpr(PerTokenQuant)
2183 *c_style_pointer_cast<const vector_type<int32_t, M4>*>(
2184 p_sorted_token_ids + m_pos);
2186 if constexpr(MulRoutedWeight)
2188 topk_weights = *c_style_pointer_cast<const vector_type<float, M4>*>(
2189 p_ds_grid[
I2] + m_pos);
2192 float scale_a = [&]() {
2193 if constexpr(PerTokenQuant)
2196 const index_t token_offset = fused_token & 0xffffff;
2198 ? p_sorted_weights_0[IsInputGemm
2208 return p_sorted_weights_0[0];
2212 blockwise_gemm_pipeline.GetCThreadDesc().CalculateOffset(
2215 if constexpr(IsInputGemm)
2219 const float scale_up =
2220 p_scale_b[(n0 *
NWave * NPerXdl + problem.
N) *
2222 float gate = scale_a * scale_b * c_thread_buf[cidx];
2223 float up = scale_a * scale_up * c_thread_buf_up[cidx];
2224 if constexpr(MulRoutedWeight)
2226 gate = gate * topk_weights.AsType<
float>()[m4];
2227 up = up * topk_weights.AsType<
float>()[m4];
2235 c_thread_buf_fp32(cidx) = gate * up;
2239 const float scale_up =
2240 p_scale_b[(n0 *
NWave * NPerXdl + problem.
N) *
2242 float gate = scale_a * scale_b * c_thread_buf[cidx];
2243 float up = scale_a * scale_up * c_thread_buf_up[cidx];
2244 if constexpr(MulRoutedWeight)
2246 gate = gate * topk_weights.AsType<
float>()[m4];
2247 up = up * topk_weights.AsType<
float>()[m4];
2255 c_thread_buf_fp32(cidx) = gate * up;
2260 c_thread_buf_fp32(cidx) =
2261 scale_a * scale_b * c_thread_buf[cidx];
2262 if constexpr(MulRoutedWeight)
2264 c_thread_buf_fp32(cidx) = c_thread_buf_fp32(cidx) *
2265 topk_weights.AsType<
float>()[m4];
2279 const index_t m_pos = block_m_id * MPerBlock + m0 * M1 * M2 * M3 * M4 +
2280 m1 * M2 * M3 * M4 + m2 * M3 * M4 + m3 * M4;
2281 if constexpr(MulRoutedWeight)
2283 topk_weights = *c_style_pointer_cast<const vector_type<float, M4>*>(
2284 p_ds_grid[
I2] + m_pos);
2288 blockwise_gemm_pipeline.GetCThreadDesc().CalculateOffset(
2292 if constexpr(IsInputGemm)
2296 float gate = c_thread_buf[cidx];
2297 float up = c_thread_buf_up[cidx];
2298 if constexpr(MulRoutedWeight)
2300 gate = gate * topk_weights.AsType<
float>()[m4];
2301 up = up * topk_weights.AsType<
float>()[m4];
2304 c_thread_buf_fp32(cidx) = gate * up;
2308 float gate = c_thread_buf[cidx];
2309 float up = c_thread_buf_up[cidx];
2310 if constexpr(MulRoutedWeight)
2312 gate = gate * topk_weights.AsType<
float>()[m4];
2313 up = up * topk_weights.AsType<
float>()[m4];
2316 c_thread_buf_fp32(cidx) = gate * up;
2321 c_thread_buf_fp32(cidx) = c_thread_buf[cidx];
2322 if constexpr(MulRoutedWeight)
2324 c_thread_buf_fp32(cidx) = topk_weights.AsType<
float>()[m4] *
2325 c_thread_buf_fp32[cidx];
2334 constexpr
auto c_shuffle_block_desc_mblock_mperblock_nblock_nperblock =
2337 auto c_shuffle_block_buf = make_dynamic_buffer<AddressSpaceEnum::Lds>(
2338 static_cast<CShuffleDataType*
>(p_shared),
2339 c_shuffle_block_desc_mblock_mperblock_nblock_nperblock.GetElementSpaceSize());
2342 c_shuffle_block_desc_mblock_mperblock_nblock_nperblock,
2362 const auto c_thread_mtx_on_block =
2363 blockwise_gemm_pipeline.CalculateCThreadOriginDataIndex(
I0,
I0,
I0,
I0);
2365 const index_t m_thread_data_on_block = c_thread_mtx_on_block[
I0];
2366 const index_t n_thread_data_on_block = c_thread_mtx_on_block[
I1];
2368 const auto m_thread_data_on_block_to_m0_m1_m2_m3_m4_adaptor =
2374 const auto m_thread_data_on_block_idx =
2375 m_thread_data_on_block_to_m0_m1_m2_m3_m4_adaptor.CalculateBottomIndex(
2378 const auto n_thread_data_on_block_to_n0_n1_n2_adaptor =
2384 const auto n_thread_data_on_block_idx =
2385 n_thread_data_on_block_to_n0_n1_n2_adaptor.CalculateBottomIndex(
2389 auto c_thread_copy_vgpr_to_lds =
2392 decltype(c_thread_desc_m0_n0_m1_n1_m2_m3_m4_n2),
2393 decltype(c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2),
2395 Sequence<CShuffleMXdlPerWavePerShuffle,
2396 CShuffleNXdlPerWavePerShuffle,
2409 c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2,
2412 m_thread_data_on_block_idx[
I1],
2413 n_thread_data_on_block_idx[
I1],
2414 m_thread_data_on_block_idx[
I2],
2415 m_thread_data_on_block_idx[
I3],
2416 m_thread_data_on_block_idx[
I4],
2417 n_thread_data_on_block_idx[
I2]),
2420 using EDataType = CDataType;
2425 const auto ds_grid_desc_mblock_mperblock_nblock_nperblock =
2431 return make_dynamic_buffer<AddressSpaceEnum::Global>(
2432 p_ds_grid[i], ds_grid_desc_m_n[i].GetElementSpaceSize());
2438 tie(c_shuffle_block_desc_mblock_mperblock_nblock_nperblock),
2440 [&](
auto i) ->
const auto&
2441 {
return ds_grid_desc_mblock_mperblock_nblock_nperblock[i]; },
2446 tie(c_shuffle_block_buf),
2448 [&](
auto i) ->
const auto&
2449 {
return ds_grid_buf[i]; },
2453 const auto idx_c_ds_block_begin =
2463 const auto e_grid_desc_mblock_mperblock_nblock_nperblock =
2464 c_grid_desc_mblock_mperblock_nblock_nperblock;
2466 using CDEBlockTransferCluster =
2467 CShuffleBlockTransferClusterLengths_MBlock_MPerBlock_NBlock_NPerBlock;
2468 const auto EGlobalMemoryDataOperation = CGlobalMemoryDataOperation;
2469 constexpr
index_t scatter_weight_idx = 3;
2474 decltype(c_ds_desc_refs),
2475 decltype(
tie(e_grid_desc_mblock_mperblock_nblock_nperblock)),
2476 CElementwiseOperation,
2480 CShuffleMXdlPerWavePerShuffle * MWave * MPerXdl,
2482 CShuffleNXdlPerWavePerShuffle *
NWave * NPerXdl>,
2483 CDEBlockTransferCluster,
2489 CDEShuffleBlockTransferScalarPerVectors,
2501 idx_c_ds_block_begin,
2502 tie(e_grid_desc_mblock_mperblock_nblock_nperblock),
2506 auto c_grid_buf = make_dynamic_buffer<AddressSpaceEnum::Global>(
2507 p_c_grid, c_grid_desc_mblock_mperblock_nblock_nperblock.GetElementSpaceSize());
2508 constexpr
auto sfc_c_vgpr =
2511 Sequence<CShuffleMXdlPerWavePerShuffle,
2512 CShuffleNXdlPerWavePerShuffle,
2520 constexpr
index_t num_access = sfc_c_vgpr.GetNumOfAccess();
2523 constexpr
auto sfc_cde_block =
2527 CShuffleMXdlPerWavePerShuffle * MWave * MPerXdl,
2529 CShuffleNXdlPerWavePerShuffle *
NWave * NPerXdl>>{};
2531 static_assert(num_access == sfc_cde_block.GetNumOfAccess(),
"wrong!");
2532 constexpr
auto EMThreads =
2533 CDEBlockTransferCluster{}.At(
I0) * CDEBlockTransferCluster{}.At(
I1);
2534 constexpr
auto EMRepeats = CShuffleMXdlPerWavePerShuffle * MWave * MPerXdl / EMThreads;
2535 constexpr
auto ENThreads =
2536 CDEBlockTransferCluster{}.At(
I2) * CDEBlockTransferCluster{}.At(
I3);
2541 auto dstidx = sfc_cde_block.GetIndex(access_id);
2543 block_m_id * MPerBlock + threadIdx.x / ENThreads * EMRepeats + dstidx(
I1);
2545 const index_t fused_token = p_sorted_token_ids[c_token_pos + m0];
2546 IndexType token_offset = fused_token & 0xffffff;
2547 if constexpr(IsInputGemm)
2549 token_offset = token_offset * problem.
TopK + (fused_token >> 24);
2551 scatter_offsets(m0) =
static_cast<IndexType
>(token_offset) * problem.
N;
2557 c_thread_copy_vgpr_to_lds.Run(c_thread_desc_m0_n0_m1_n1_m2_m3_m4_n2,
2558 sfc_c_vgpr.GetIndexTupleOfNumber(access_id),
2560 c_block_desc_m0_n0_m1_n1_m2_m3_m4_n2,
2561 c_shuffle_block_buf);
2567 cde_block_copy_lds_and_global.Run(
2570 tie(e_grid_desc_mblock_mperblock_nblock_nperblock),
2574 if constexpr(access_id < num_access - 1)
2576 constexpr
auto cde_lds_and_global_step =
2577 sfc_cde_block.GetForwardStep(access_id);
2581 cde_block_copy_lds_and_global.MoveSrcSliceWindow(
2582 c_ds_desc_refs, i +
I1, cde_lds_and_global_step);
2586 cde_block_copy_lds_and_global.MoveDstSliceWindow(
2587 tie(e_grid_desc_mblock_mperblock_nblock_nperblock),
2589 cde_lds_and_global_step);
#define CK_MAX_THREAD_PER_BLOCK
Definition: ck.hpp:29
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__ T max(T x)
Definition: math.hpp:84
GemmSpecialization
Definition: gemm_specialization.hpp:11
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:23
__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:928
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:278
__host__ constexpr __device__ index_t get_warp_size()
Definition: get_id.hpp:10
__host__ constexpr __device__ auto make_naive_tensor_descriptor_packed(const Tuple< Lengths... > &lengths)
Definition: tensor_descriptor_helper.hpp:101
f8_fnuz_t f8_t
Definition: amd_ck_fp8.hpp:1737
__host__ constexpr __device__ auto make_merge_transform(const LowLengths &low_lengths)
Definition: multi_index_transform_helper.hpp:55
BlockGemmPipelineVersion
Definition: blkgemmpipe_scheduler.hpp:12
__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
TailNumber
Definition: blkgemmpipe_scheduler.hpp:31
__host__ constexpr __device__ auto make_single_stage_tensor_adaptor(const Transforms &transforms, LowerDimensionOldTopIdss, UpperDimensionNewTopIdss)
Definition: tensor_adaptor.hpp:429
__host__ constexpr __device__ auto make_freeze_transform(const LowerIndex &low_idx)
Definition: multi_index_transform_helper.hpp:98
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:132
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 auto BlockGemmBPreshufflePipeline_Selector()
Definition: blockwise_gemm_pipeline_xdlops_b_preshuffle_selector.hpp:41
__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:925
BlockGemmPipelineScheduler
Definition: blkgemmpipe_scheduler.hpp:25
__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:300
__device__ index_t get_thread_local_1d_id()
Definition: get_id.hpp:19
__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
__device__ void block_sync_lds()
Definition: synchronization.hpp:10
__global__ void kernel_moe_gemm_2lds(typename GridwiseGemm::Argument karg)
Definition: gridwise_moe_gemm.hpp:81
Definition: gridwise_moe_gemm.hpp:666
const BDataType * p_b_grid
Definition: gridwise_moe_gemm.hpp:722
const index_t * p_sorted_token_ids
Definition: gridwise_moe_gemm.hpp:718
const index_t * p_sorted_expert_ids
Definition: gridwise_moe_gemm.hpp:719
const AElementwiseOperation a_element_op
Definition: gridwise_moe_gemm.hpp:726
const ADataType * p_a_grid
Definition: gridwise_moe_gemm.hpp:721
__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_, index_t k_batch_, AElementwiseOperation a_element_op_, BElementwiseOperation b_element_op_, CElementwiseOperation c_element_op_)
Definition: gridwise_moe_gemm.hpp:667
const index_t * p_max_token_id
Definition: gridwise_moe_gemm.hpp:720
const BElementwiseOperation b_element_op
Definition: gridwise_moe_gemm.hpp:727
CDataType * p_c_grid
Definition: gridwise_moe_gemm.hpp:724
DsGridPointer p_ds_grid
Definition: gridwise_moe_gemm.hpp:723
const CElementwiseOperation c_element_op
Definition: gridwise_moe_gemm.hpp:728
Definition: gridwise_moe_gemm.hpp:586
std::array< index_t, NumDTensor > StrideDs
Definition: gridwise_moe_gemm.hpp:648
index_t NumTokens
Definition: gridwise_moe_gemm.hpp:641
index_t MBlock
Definition: gridwise_moe_gemm.hpp:657
index_t BK0Shuffled
Definition: gridwise_moe_gemm.hpp:661
index_t TopK
Definition: gridwise_moe_gemm.hpp:642
index_t K
Definition: gridwise_moe_gemm.hpp:645
__host__ void Print() const
Definition: gridwise_moe_gemm.hpp:620
index_t NPadded
Definition: gridwise_moe_gemm.hpp:652
index_t BK0
Definition: gridwise_moe_gemm.hpp:656
index_t KRead
Definition: gridwise_moe_gemm.hpp:653
index_t MPadded
Definition: gridwise_moe_gemm.hpp:651
index_t AK0
Definition: gridwise_moe_gemm.hpp:655
index_t StrideA
Definition: gridwise_moe_gemm.hpp:646
index_t StrideC
Definition: gridwise_moe_gemm.hpp:649
index_t M
Definition: gridwise_moe_gemm.hpp:643
index_t KBatch
Definition: gridwise_moe_gemm.hpp:650
index_t BN0Shuffled
Definition: gridwise_moe_gemm.hpp:660
__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.hpp:587
index_t KPadded
Definition: gridwise_moe_gemm.hpp:654
index_t StrideB
Definition: gridwise_moe_gemm.hpp:647
index_t N
Definition: gridwise_moe_gemm.hpp:644
index_t NBlock
Definition: gridwise_moe_gemm.hpp:658
Definition: gridwise_moe_gemm.hpp:732
index_t a_k_split_offset
Definition: gridwise_moe_gemm.hpp:764
index_t b_k_split_offset
Definition: gridwise_moe_gemm.hpp:765
__device__ SplitKBatchOffset(Argument &karg, index_t k_id)
Definition: gridwise_moe_gemm.hpp:733
Definition: gridwise_moe_gemm.hpp:165
static __host__ auto CalculateGridSize(index_t M, index_t N)
Definition: gridwise_moe_gemm.hpp:240
__host__ static __device__ auto CalculateKRead(index_t K, index_t K_Batch=1)
Definition: gridwise_moe_gemm.hpp:292
static constexpr auto MakeDsGridPointer()
Definition: gridwise_moe_gemm.hpp:211
__host__ static __device__ auto CalculateKPadded(index_t K, index_t K_Batch=1)
Definition: gridwise_moe_gemm.hpp:286
static constexpr index_t KRepeat
Definition: gridwise_moe_gemm.hpp:204
remove_cvref_t< decltype(BlockGemmBPreshufflePipeline_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, MPerXdl, NPerXdl, MXdlPerWave, NXdlPerWave, KPack, IsInputGemm >())> BlockwiseGemmPipe
Definition: gridwise_moe_gemm.hpp:930
__host__ static __device__ auto CalculateNPadded(index_t N)
Definition: gridwise_moe_gemm.hpp:255
static constexpr index_t NLane
Definition: gridwise_moe_gemm.hpp:206
static constexpr auto I5
Definition: gridwise_moe_gemm.hpp:171
__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.hpp:541
static constexpr auto BK0Number
Definition: gridwise_moe_gemm.hpp:179
__host__ static __device__ auto MakeAGridDescriptor_AK0_M_AK1(IndexType M, IndexType MPad, IndexType K, IndexType KPad, IndexType StrideA, IndexType AK0)
Definition: gridwise_moe_gemm.hpp:324
static constexpr index_t NumDTensor
Definition: gridwise_moe_gemm.hpp:184
__host__ static constexpr __device__ TailNumber CalculateKBlockLoopTailNum(index_t K)
Definition: gridwise_moe_gemm.hpp:1134
static constexpr auto I2
Definition: gridwise_moe_gemm.hpp:168
static constexpr index_t APackedSize
Definition: gridwise_moe_gemm.hpp:226
__host__ static __device__ auto CalculateMBlock(index_t M)
Definition: gridwise_moe_gemm.hpp:299
ThisThreadBlock< BlockSize > ThisThreadBlock
Definition: gridwise_moe_gemm.hpp:224
__host__ static __device__ auto MakeBGridDescriptor_Preshuffled(index_t N0, index_t K0)
Definition: gridwise_moe_gemm.hpp:406
__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.hpp:414
__host__ static constexpr __device__ auto MakeBMmaTileDescriptor_N0_N1_N2_K(const BBlockDesc_BK0_N_BK1 &)
Definition: gridwise_moe_gemm.hpp:511
static constexpr auto I6
Definition: gridwise_moe_gemm.hpp:172
static constexpr auto I0
Definition: gridwise_moe_gemm.hpp:166
static constexpr index_t SortedTileSize
Definition: gridwise_moe_gemm.hpp:209
__host__ static constexpr __device__ bool CalculateHasMainKBlockLoop(index_t K)
Definition: gridwise_moe_gemm.hpp:1127
static constexpr auto I1
Definition: gridwise_moe_gemm.hpp:167
static constexpr auto I4
Definition: gridwise_moe_gemm.hpp:170
static constexpr auto AK1Number
Definition: gridwise_moe_gemm.hpp:180
__host__ static __device__ auto CalculateAK0Padded(index_t K, index_t K_Batch=1)
Definition: gridwise_moe_gemm.hpp:274
__host__ static __device__ auto CalculateNBlock(index_t N)
Definition: gridwise_moe_gemm.hpp:304
static constexpr auto BK1Number
Definition: gridwise_moe_gemm.hpp:181
static constexpr auto BlockSizeNumber
Definition: gridwise_moe_gemm.hpp:182
static constexpr index_t BPackedSize
Definition: gridwise_moe_gemm.hpp:233
__host__ static __device__ auto MakeCGridDescriptor_M_N(IndexType M, IndexType MPad, IndexType N, IndexType NPad, IndexType StrideC)
Definition: gridwise_moe_gemm.hpp:517
__host__ static __device__ auto CalculateBK0Shuffled(index_t K)
Definition: gridwise_moe_gemm.hpp:264
decltype(MakeDsGridPointer()) DsGridPointer
Definition: gridwise_moe_gemm.hpp:222
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, 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.hpp:1876
__host__ static __device__ auto CalculateBK0Padded(index_t K, index_t K_Batch=1)
Definition: gridwise_moe_gemm.hpp:280
__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.hpp:562
static constexpr __host__ bool CheckValidity(const Argument &karg)
Definition: gridwise_moe_gemm.hpp:954
static constexpr __device__ auto GetCShuffleBlockDescriptor_MBlock_MPerBlock_NBlock_NPerBlock()
Definition: gridwise_moe_gemm.hpp:891
__host__ static constexpr __device__ auto MakeAMmaTileDescriptor_M0_M1_M2_K(const ABlockDesc_AK0_M_AK1 &)
Definition: gridwise_moe_gemm.hpp:502
static constexpr auto CShuffleBlockTransferScalarPerVector_NPerBlock
Definition: gridwise_moe_gemm.hpp:175
__host__ static __device__ auto CalculateMPadded(index_t M)
Definition: gridwise_moe_gemm.hpp:250
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.hpp:1142
static constexpr __device__ index_t GetSharedMemoryNumberOfByte()
Definition: gridwise_moe_gemm.hpp:932
static constexpr __device__ auto GetBBlockDescriptor_BK0PerBlock_NPerBlock_BK1()
Definition: gridwise_moe_gemm.hpp:884
__host__ static __device__ auto CalculateBN0Shuffled(index_t N)
Definition: gridwise_moe_gemm.hpp:260
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, void *p_shared, const Problem &problem, AElementwiseOperation a_element_op, BElementwiseOperation b_element_op, CElementwiseOperation c_element_op)
Definition: gridwise_moe_gemm.hpp:1163
static constexpr index_t KPack
Definition: gridwise_moe_gemm.hpp:187
static constexpr index_t NWave
Definition: gridwise_moe_gemm.hpp:207
static constexpr auto I3
Definition: gridwise_moe_gemm.hpp:169
__host__ static __device__ auto CalculateKPadded(index_t K)
Definition: gridwise_moe_gemm.hpp:269
static constexpr auto AK0Number
Definition: gridwise_moe_gemm.hpp:178
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.hpp:574
static constexpr index_t KGroup
Definition: gridwise_moe_gemm.hpp:192
__host__ static constexpr __device__ auto MakeGemmMmaTileDescriptor(const TileDesc_K0_MN_K1 &)
Definition: gridwise_moe_gemm.hpp:310
static constexpr __device__ auto GetABlockDescriptor_AK0PerBlock_MPerBlock_AK1()
Definition: gridwise_moe_gemm.hpp:768
static constexpr index_t KLane
Definition: gridwise_moe_gemm.hpp:189
static constexpr auto I7
Definition: gridwise_moe_gemm.hpp:173
Definition: xdlops_gemm.hpp:942
static constexpr index_t GetK1PerXdlops()
Definition: xdlops_gemm.hpp:1388
static constexpr auto selected_mfma
Definition: xdlops_gemm.hpp:1343
static constexpr index_t GetKPerXdlops()
Definition: xdlops_gemm.hpp:1382
Definition: sequence.hpp:43
Definition: tensor_space_filling_curve.hpp:20
Definition: static_buffer.hpp:75
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
Helper structure that facilitates transfer of source (grid) data to destination threads.
Definition: threadwise_tensor_slice_transfer.hpp:234
Definition: tuple.hpp:117
Definition: integral_constant.hpp:20
Definition: data_type.hpp:186
Definition: functional2.hpp:33
Definition: device_base.hpp:51
Definition: unary_element_wise_operation.hpp:981
Definition: unary_element_wise_operation.hpp:308
Definition: unary_element_wise_operation.hpp:1023