Closed
【cleancode】dispatch v2 算子整改 #8042
Simple_Bright&ManAdd on 10 days agoClosed at 6 days ago
10 days ago Associated pull request
周云飞
10 days ago Comments:
10 days ago Comments:
/assign @SimpleBright_Man


10 days ago Assign SimpleBright_Man as responsible person
周云飞
10 days ago Comments:
10 days ago Comments:
这项整改主要是按职责拆分 Dispatch V2 的算子定义、shape 推导、Tiling 和 Kernel 逻辑,以降低维护复杂度;具体拆分方式及其影响还需评估。
可以考虑先抽取 scales 的数据类型表,再分别拆分输入输出解析、校验和各平台分发流程。重构时需要保留 A2/A3/A5/A6 的平台差异,以及数据类型顺序、窗口和 UB 计算、通信同步和输出行为。
关于 expandScalesOut 参数、辅助函数声明顺序和 BUFFER_NUM,Issue 中提出的问题及调整方式仍需结合对应调用和编译结果确认。我们会继续评估这些建议及其兼容性影响。


6 days ago Close issue
6 days ago changed custom state from 待办的 to 已完成
5 days ago Added label: resolved
mc2/moe_distribute_dispatch_v2/op_host/moe_distribute_dispatch_v2_def.cpp:MoeDistributeDispatchV2、scalesDType
抽取静态 DataType 配置表,简化算子定义初始化逻辑。
mc2/moe_distribute_dispatch_v2/op_host/moe_distribute_dispatch_v2_infershape.cpp:GetDispatchV2InferInputs、GetDispatchV2InferAttrs、GetDispatchV2InferOutputs、SetDispatchV2InferOutputs、InferShapeMoeDistributeDispatchV2
将输入、属性、输出解析和输出 shape 推导拆分,保留 A2/A3/A5/A6 的平台差异处理。
mc2/moe_distribute_dispatch_v2/op_host/op_tiling/arch22/moe_distribute_dispatch_v2_tiling_arch22.cpp:CheckA2LayeredWinSize、CheckA2FullMeshWinSize、MoeDistributeDispatchA2CheckWinSize、GetA2AttrPointers、CheckA2AttrValues、MoeDistributeDispatchA2CheckAttrAndSetTiling、GetA2ShapeInputs、MoeDistributeDispatchA2CheckShapeAndSetTiling、SetA2RuntimeConfig、SetA2CommunicationConfig、MoeDistributeDispatchV2TilingFuncA2A3::CalTilingKey、MoeDistributeDispatchV2TilingFuncA2A3::CheckTensorDataType
拆分 A2 的通信算法、窗口大小、属性、shape、数据类型和 runtime 配置校验,降低单函数复杂度。
mc2/moe_distribute_dispatch_v2/op_host/op_tiling/moe_distribute_check_win_size.h:CheckActualWinSize、CheckActualWinSizeImpl
将窗口大小实际校验逻辑抽取为独立实现函数,并补充前置声明。
mc2/moe_distribute_dispatch_v2/op_host/op_tiling/moe_distribute_dispatch_tiling_helper.cpp:CheckTensorFormat
拆分输入、输出和可选 tensor 的 format 校验逻辑。
mc2/moe_distribute_dispatch_v2/op_host/op_tiling/moe_distribute_dispatch_v2_tiling.cpp:CheckSharedExpertAttrs、CheckMoeExpertAttrLimits、CheckExpertAttrParams、CheckDynamicScalesShape、CheckExpandXAndDynamicScalesTensorShape、CalculateMoeCumSumUbBuffer、CalculateMoeSerialUbBuffer、AllToAllBasicUsedBuffer、AllToAllBasicUsedBufferImpl、CalculateBasicUbBuffers、CalculateQuantUbBuffers、CalculateFinalUbBuffers、CheckUBSize、MoeDistributeDispatchV2TilingFuncBase::MoeDistributeDispatchA3TilingFuncImplPublicImpl
将 expert 属性、动态量化 shape、UB buffer 预算、A3 tiling 入口拆分为职责明确的辅助函数。
mc2/moe_distribute_dispatch_v2/op_host/op_tiling/moe_distribute_dispatch_tiling_v2.h:MoeDistributeDispatchA3TilingFuncImplPublicImpl
增加 A3 tiling 公共实现入口,复用统一 tiling 流程。
mc2/moe_distribute_dispatch_v2/op_kernel/arch22/moe_distribute_dispatch_v2_a2.cpp:RunA2Mte、RunA2Layered、RunA2PackedInt32、RunA2Dispatch、moe_distribute_dispatch_v2
拆分 A2 的 MTE、layered、INT32 packed 和统一分发入口,补齐 layered AICPU expandScalesOut 参数传递。
mc2/moe_distribute_dispatch_v2/op_kernel/arch22/moe_distribute_dispatch_a2.h:ProcessReorderToken、CopySingleServerRank、ProcessWaitRank、PrepareStatusCumSum、BuildStatusCumSumOutput、WriteStatusCumSumOutput、GetStatusCumSum
拆分 token 重排、单机拷贝、等待 rank 和状态前缀和计算流程。
mc2/moe_distribute_dispatch_v2/op_kernel/arch22/moe_distribute_dispatch_a2_layered.h:WaitRdmaQueue、CreateInnerReduceInfoImpl、CreateOuterReduceInfoImpl、ReorderTokensImpl、Win2IpcImpl、Ipc2OutImpl
拆分 layered AIV 的 RDMA 等待、内外层 reduce、token 重排和 IPC 数据搬运流程。
mc2/moe_distribute_dispatch_v2/op_kernel/arch22/moe_distribute_dispatch_a2_layered_aicpu.h:ReorderTokensImpl、CreateInnerReduceInfoImpl、CreateOuterReduceInfoImpl、Win2IpcImpl、WriteIpcOutputCounts、Ipc2OutImpl
拆分 layered AICPU 的 token 重排、reduce、IPC 输出和计数写回流程。
mc2/moe_distribute_dispatch_v2/op_kernel/arch22/moe_distribute_dispatch_v2_full_mesh.h:SetTilingDataAndCalImpl、GetCumSumImpl、CopyInAndOutImpl、WaitAndFormatOutputImpl、ExpIdsCopyAndMaskCalImpl
拆分 fullmesh 的 tiling 初始化、前缀和、数据搬运、输出格式化和 expert id mask 计算流程。
mc2/moe_distribute_dispatch_v2/op_kernel/arch22/moe_distribute_dispatch_v2_a3.cpp:RunA3Dispatch、moe_distribute_dispatch_v2
拆分 A3 kernel 入口和模板分发逻辑。
mc2/moe_distribute_dispatch_v2/op_kernel/moe_distribute_dispatch_v2.h:InitBasicParamImpl、InitDataBufferImpl、ProcessTokenImpl、LocalWindowCopyImpl
拆分通用 V2 kernel 的基础参数初始化、数据 buffer 初始化、token 处理和 local window copy 流程。
mc2/moe_distribute_dispatch_v2/op_kernel/moe_distribute_dispatch_v2_quant.h:QuantDynamicPerTokenImpl
拆分动态 per-token 量化处理逻辑。
mc2/moe_distribute_dispatch_v2/op_kernel/moe_distribute_v2_base.h:AIVRDMAPostSendImpl
拆分 AIV RDMA 发送流程,保留原有同步和 doorbell 逻辑。
mc2/moe_distribute_dispatch_v2/op_kernel/arch22/moe_distribute_dispatch_v2_a2.cpp:RunA2Layered
修复 layered AICPU 调用 Init 时遗漏 expandScalesOut 参数导致的编译错误。
mc2/moe_distribute_dispatch_v2/op_host/op_tiling/moe_distribute_check_win_size.h:CheckActualWinSizeImpl
修复实现函数声明顺序问题。
mc2/moe_distribute_dispatch_v2/op_host/op_tiling/moe_distribute_dispatch_v2_tiling.cpp:AllToAllBasicUsedBufferImpl
修复 UB buffer 计算实现函数声明顺序问题。
mc2/moe_distribute_dispatch_v2/op_host/op_tiling/arch22/moe_distribute_dispatch_v2_tiling_arch22.cpp:BUFFER_NUM
恢复 A2 layered window size 计算所需的 buffer 数量常量。