文件最后提交记录最后更新时间
添加经典和双平面两种实现路径的Dispatch和Combine算子example Co-authored-by: xionglan2<xionglan2@huawei.com> # message auto-generated for no-merge-commit merge: !350 merge feature/dispatch-combine-examples into master 添加经典和双平面两种实现路径的Dispatch和Combine算子example Created-by: xionglan2 Commit-by: xionglan2 Merged-by: cann-robot Description: ## 描述 本次 PR 将 dispatchcombinedispatch_doubleplanecombine_doubleplane 四个 MoE 通信算子上库,并对 classic / DoublePlane 两类路径做统一整理和性能优化,目标是在保持现有输入输出语义不变的前提下,补齐基础能力、统一脚本与文档,并提升大包传输场景下的吞吐表现。 具体改动包括: - 补齐 classic dispatch / combine 与 DoublePlane dispatch_doubleplane / combine_doubleplane 四个算子的构建、运行脚本和说明文档,统一功能验证和性能测试入口。 - dispatch 路径将输入token按路由规则分发到目标expert,生成后续combine所需的中间结果;combine 路径将个expert输出按源token和topK权重回传聚合,生成最终输出结果。 - dispatch_doubleplane / combine_doubleplane 引入基于 segment size 的自适应传输策略,在 direct MTE 与 SDMA 之间按段大小选择传输 plane;对大段优先走 SDMA,小段保留 direct 路径,以降低小包 SDMA 开销并提升大包场景吞吐。 - 保持四个算子的外部接口、输出格式和校验方式一致,便于后续统一冒烟、泛化和性能对比。 ## 关联的Issue https://gitcode.com/cann/shmem/issues/249 ## 测试 已按以下维度进行验证,具体参数和结果可按实际执行情况补充: - 功能正确性:使用各目录 scripts/run.sh 完成 dispatchcombinedispatch_doubleplanecombine_doubleplane 基础冒烟,校验 expand_xassist_info_for_combineep_recv_countexpert_token_numsx_out 与 golden 一致。 - 二级冒烟:覆盖 [2/4/8] 卡、[int32_t/float16_t][bs/topk/h/expertPerPe] 典型组合,确认 classic 与 DoublePlane 路径均可稳定运行。 - 算子泛化:覆盖不同 pesbshtopkexpertPerPe 组合,验证不同 shape 下输出语义与 classic 基线保持一致。 - 性能验证:通过 --perf 模式对 dispatch vs dispatch_doubleplanecombine vs combine_doubleplane 进行 full_opcomm_only 对比,重点观察多卡场景下的带宽和耗时表现。 - 协议一致性:验证 DoublePlane 在 SDMA/direct 混合路径下,payload、assist、ready、count、status 的写入/可见性时序正确,无功能回归。 验证结果如下: ![91CDE5B2-5437-41ED-A859-9F0C5013E64C.png](https://raw.gitcode.com/user-images/assets/8546182/a1858f90-6331-47a6-9347-46d1131a7550/91CDE5B2-5437-41ED-A859-9F0C5013E64C.png '91CDE5B2-5437-41ED-A859-9F0C5013E64C.png') ![D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png](https://raw.gitcode.com/user-images/assets/8546182/683ebd6c-df45-4d48-9c08-1360b7bbb0cc/D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png 'D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png') ![E19255BB-42E0-4CDE-E609-7E35E761F343.png](https://raw.gitcode.com/user-images/assets/8546182/7557886f-947a-4b17-b62f-107f1e1823b3/E19255BB-42E0-4CDE-E609-7E35E761F343.png 'E19255BB-42E0-4CDE-E609-7E35E761F343.png') ## 文档更新 - 更新/补充 dispatchcombinedispatch_doubleplanecombine_doubleplane 的 README,说明构建、功能运行和性能测试方法。 - 更新/补充 DoublePlane 设计说明文档,记录分段判定、传输策略和控制面协议。 ## 类型标签 - [ ] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [x] 其他,请描述:Add example/perftest See merge request: cann/shmem!3504 天前
添加经典和双平面两种实现路径的Dispatch和Combine算子example Co-authored-by: xionglan2<xionglan2@huawei.com> # message auto-generated for no-merge-commit merge: !350 merge feature/dispatch-combine-examples into master 添加经典和双平面两种实现路径的Dispatch和Combine算子example Created-by: xionglan2 Commit-by: xionglan2 Merged-by: cann-robot Description: ## 描述 本次 PR 将 dispatchcombinedispatch_doubleplanecombine_doubleplane 四个 MoE 通信算子上库,并对 classic / DoublePlane 两类路径做统一整理和性能优化,目标是在保持现有输入输出语义不变的前提下,补齐基础能力、统一脚本与文档,并提升大包传输场景下的吞吐表现。 具体改动包括: - 补齐 classic dispatch / combine 与 DoublePlane dispatch_doubleplane / combine_doubleplane 四个算子的构建、运行脚本和说明文档,统一功能验证和性能测试入口。 - dispatch 路径将输入token按路由规则分发到目标expert,生成后续combine所需的中间结果;combine 路径将个expert输出按源token和topK权重回传聚合,生成最终输出结果。 - dispatch_doubleplane / combine_doubleplane 引入基于 segment size 的自适应传输策略,在 direct MTE 与 SDMA 之间按段大小选择传输 plane;对大段优先走 SDMA,小段保留 direct 路径,以降低小包 SDMA 开销并提升大包场景吞吐。 - 保持四个算子的外部接口、输出格式和校验方式一致,便于后续统一冒烟、泛化和性能对比。 ## 关联的Issue https://gitcode.com/cann/shmem/issues/249 ## 测试 已按以下维度进行验证,具体参数和结果可按实际执行情况补充: - 功能正确性:使用各目录 scripts/run.sh 完成 dispatchcombinedispatch_doubleplanecombine_doubleplane 基础冒烟,校验 expand_xassist_info_for_combineep_recv_countexpert_token_numsx_out 与 golden 一致。 - 二级冒烟:覆盖 [2/4/8] 卡、[int32_t/float16_t][bs/topk/h/expertPerPe] 典型组合,确认 classic 与 DoublePlane 路径均可稳定运行。 - 算子泛化:覆盖不同 pesbshtopkexpertPerPe 组合,验证不同 shape 下输出语义与 classic 基线保持一致。 - 性能验证:通过 --perf 模式对 dispatch vs dispatch_doubleplanecombine vs combine_doubleplane 进行 full_opcomm_only 对比,重点观察多卡场景下的带宽和耗时表现。 - 协议一致性:验证 DoublePlane 在 SDMA/direct 混合路径下,payload、assist、ready、count、status 的写入/可见性时序正确,无功能回归。 验证结果如下: ![91CDE5B2-5437-41ED-A859-9F0C5013E64C.png](https://raw.gitcode.com/user-images/assets/8546182/a1858f90-6331-47a6-9347-46d1131a7550/91CDE5B2-5437-41ED-A859-9F0C5013E64C.png '91CDE5B2-5437-41ED-A859-9F0C5013E64C.png') ![D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png](https://raw.gitcode.com/user-images/assets/8546182/683ebd6c-df45-4d48-9c08-1360b7bbb0cc/D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png 'D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png') ![E19255BB-42E0-4CDE-E609-7E35E761F343.png](https://raw.gitcode.com/user-images/assets/8546182/7557886f-947a-4b17-b62f-107f1e1823b3/E19255BB-42E0-4CDE-E609-7E35E761F343.png 'E19255BB-42E0-4CDE-E609-7E35E761F343.png') ## 文档更新 - 更新/补充 dispatchcombinedispatch_doubleplanecombine_doubleplane 的 README,说明构建、功能运行和性能测试方法。 - 更新/补充 DoublePlane 设计说明文档,记录分段判定、传输策略和控制面协议。 ## 类型标签 - [ ] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [x] 其他,请描述:Add example/perftest See merge request: cann/shmem!3504 天前
添加经典和双平面两种实现路径的Dispatch和Combine算子example Co-authored-by: xionglan2<xionglan2@huawei.com> # message auto-generated for no-merge-commit merge: !350 merge feature/dispatch-combine-examples into master 添加经典和双平面两种实现路径的Dispatch和Combine算子example Created-by: xionglan2 Commit-by: xionglan2 Merged-by: cann-robot Description: ## 描述 本次 PR 将 dispatchcombinedispatch_doubleplanecombine_doubleplane 四个 MoE 通信算子上库,并对 classic / DoublePlane 两类路径做统一整理和性能优化,目标是在保持现有输入输出语义不变的前提下,补齐基础能力、统一脚本与文档,并提升大包传输场景下的吞吐表现。 具体改动包括: - 补齐 classic dispatch / combine 与 DoublePlane dispatch_doubleplane / combine_doubleplane 四个算子的构建、运行脚本和说明文档,统一功能验证和性能测试入口。 - dispatch 路径将输入token按路由规则分发到目标expert,生成后续combine所需的中间结果;combine 路径将个expert输出按源token和topK权重回传聚合,生成最终输出结果。 - dispatch_doubleplane / combine_doubleplane 引入基于 segment size 的自适应传输策略,在 direct MTE 与 SDMA 之间按段大小选择传输 plane;对大段优先走 SDMA,小段保留 direct 路径,以降低小包 SDMA 开销并提升大包场景吞吐。 - 保持四个算子的外部接口、输出格式和校验方式一致,便于后续统一冒烟、泛化和性能对比。 ## 关联的Issue https://gitcode.com/cann/shmem/issues/249 ## 测试 已按以下维度进行验证,具体参数和结果可按实际执行情况补充: - 功能正确性:使用各目录 scripts/run.sh 完成 dispatchcombinedispatch_doubleplanecombine_doubleplane 基础冒烟,校验 expand_xassist_info_for_combineep_recv_countexpert_token_numsx_out 与 golden 一致。 - 二级冒烟:覆盖 [2/4/8] 卡、[int32_t/float16_t][bs/topk/h/expertPerPe] 典型组合,确认 classic 与 DoublePlane 路径均可稳定运行。 - 算子泛化:覆盖不同 pesbshtopkexpertPerPe 组合,验证不同 shape 下输出语义与 classic 基线保持一致。 - 性能验证:通过 --perf 模式对 dispatch vs dispatch_doubleplanecombine vs combine_doubleplane 进行 full_opcomm_only 对比,重点观察多卡场景下的带宽和耗时表现。 - 协议一致性:验证 DoublePlane 在 SDMA/direct 混合路径下,payload、assist、ready、count、status 的写入/可见性时序正确,无功能回归。 验证结果如下: ![91CDE5B2-5437-41ED-A859-9F0C5013E64C.png](https://raw.gitcode.com/user-images/assets/8546182/a1858f90-6331-47a6-9347-46d1131a7550/91CDE5B2-5437-41ED-A859-9F0C5013E64C.png '91CDE5B2-5437-41ED-A859-9F0C5013E64C.png') ![D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png](https://raw.gitcode.com/user-images/assets/8546182/683ebd6c-df45-4d48-9c08-1360b7bbb0cc/D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png 'D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png') ![E19255BB-42E0-4CDE-E609-7E35E761F343.png](https://raw.gitcode.com/user-images/assets/8546182/7557886f-947a-4b17-b62f-107f1e1823b3/E19255BB-42E0-4CDE-E609-7E35E761F343.png 'E19255BB-42E0-4CDE-E609-7E35E761F343.png') ## 文档更新 - 更新/补充 dispatchcombinedispatch_doubleplanecombine_doubleplane 的 README,说明构建、功能运行和性能测试方法。 - 更新/补充 DoublePlane 设计说明文档,记录分段判定、传输策略和控制面协议。 ## 类型标签 - [ ] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [x] 其他,请描述:Add example/perftest See merge request: cann/shmem!3504 天前
添加经典和双平面两种实现路径的Dispatch和Combine算子example Co-authored-by: xionglan2<xionglan2@huawei.com> # message auto-generated for no-merge-commit merge: !350 merge feature/dispatch-combine-examples into master 添加经典和双平面两种实现路径的Dispatch和Combine算子example Created-by: xionglan2 Commit-by: xionglan2 Merged-by: cann-robot Description: ## 描述 本次 PR 将 dispatchcombinedispatch_doubleplanecombine_doubleplane 四个 MoE 通信算子上库,并对 classic / DoublePlane 两类路径做统一整理和性能优化,目标是在保持现有输入输出语义不变的前提下,补齐基础能力、统一脚本与文档,并提升大包传输场景下的吞吐表现。 具体改动包括: - 补齐 classic dispatch / combine 与 DoublePlane dispatch_doubleplane / combine_doubleplane 四个算子的构建、运行脚本和说明文档,统一功能验证和性能测试入口。 - dispatch 路径将输入token按路由规则分发到目标expert,生成后续combine所需的中间结果;combine 路径将个expert输出按源token和topK权重回传聚合,生成最终输出结果。 - dispatch_doubleplane / combine_doubleplane 引入基于 segment size 的自适应传输策略,在 direct MTE 与 SDMA 之间按段大小选择传输 plane;对大段优先走 SDMA,小段保留 direct 路径,以降低小包 SDMA 开销并提升大包场景吞吐。 - 保持四个算子的外部接口、输出格式和校验方式一致,便于后续统一冒烟、泛化和性能对比。 ## 关联的Issue https://gitcode.com/cann/shmem/issues/249 ## 测试 已按以下维度进行验证,具体参数和结果可按实际执行情况补充: - 功能正确性:使用各目录 scripts/run.sh 完成 dispatchcombinedispatch_doubleplanecombine_doubleplane 基础冒烟,校验 expand_xassist_info_for_combineep_recv_countexpert_token_numsx_out 与 golden 一致。 - 二级冒烟:覆盖 [2/4/8] 卡、[int32_t/float16_t][bs/topk/h/expertPerPe] 典型组合,确认 classic 与 DoublePlane 路径均可稳定运行。 - 算子泛化:覆盖不同 pesbshtopkexpertPerPe 组合,验证不同 shape 下输出语义与 classic 基线保持一致。 - 性能验证:通过 --perf 模式对 dispatch vs dispatch_doubleplanecombine vs combine_doubleplane 进行 full_opcomm_only 对比,重点观察多卡场景下的带宽和耗时表现。 - 协议一致性:验证 DoublePlane 在 SDMA/direct 混合路径下,payload、assist、ready、count、status 的写入/可见性时序正确,无功能回归。 验证结果如下: ![91CDE5B2-5437-41ED-A859-9F0C5013E64C.png](https://raw.gitcode.com/user-images/assets/8546182/a1858f90-6331-47a6-9347-46d1131a7550/91CDE5B2-5437-41ED-A859-9F0C5013E64C.png '91CDE5B2-5437-41ED-A859-9F0C5013E64C.png') ![D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png](https://raw.gitcode.com/user-images/assets/8546182/683ebd6c-df45-4d48-9c08-1360b7bbb0cc/D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png 'D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png') ![E19255BB-42E0-4CDE-E609-7E35E761F343.png](https://raw.gitcode.com/user-images/assets/8546182/7557886f-947a-4b17-b62f-107f1e1823b3/E19255BB-42E0-4CDE-E609-7E35E761F343.png 'E19255BB-42E0-4CDE-E609-7E35E761F343.png') ## 文档更新 - 更新/补充 dispatchcombinedispatch_doubleplanecombine_doubleplane 的 README,说明构建、功能运行和性能测试方法。 - 更新/补充 DoublePlane 设计说明文档,记录分段判定、传输策略和控制面协议。 ## 类型标签 - [ ] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [x] 其他,请描述:Add example/perftest See merge request: cann/shmem!3504 天前
添加经典和双平面两种实现路径的Dispatch和Combine算子example Co-authored-by: xionglan2<xionglan2@huawei.com> # message auto-generated for no-merge-commit merge: !350 merge feature/dispatch-combine-examples into master 添加经典和双平面两种实现路径的Dispatch和Combine算子example Created-by: xionglan2 Commit-by: xionglan2 Merged-by: cann-robot Description: ## 描述 本次 PR 将 dispatchcombinedispatch_doubleplanecombine_doubleplane 四个 MoE 通信算子上库,并对 classic / DoublePlane 两类路径做统一整理和性能优化,目标是在保持现有输入输出语义不变的前提下,补齐基础能力、统一脚本与文档,并提升大包传输场景下的吞吐表现。 具体改动包括: - 补齐 classic dispatch / combine 与 DoublePlane dispatch_doubleplane / combine_doubleplane 四个算子的构建、运行脚本和说明文档,统一功能验证和性能测试入口。 - dispatch 路径将输入token按路由规则分发到目标expert,生成后续combine所需的中间结果;combine 路径将个expert输出按源token和topK权重回传聚合,生成最终输出结果。 - dispatch_doubleplane / combine_doubleplane 引入基于 segment size 的自适应传输策略,在 direct MTE 与 SDMA 之间按段大小选择传输 plane;对大段优先走 SDMA,小段保留 direct 路径,以降低小包 SDMA 开销并提升大包场景吞吐。 - 保持四个算子的外部接口、输出格式和校验方式一致,便于后续统一冒烟、泛化和性能对比。 ## 关联的Issue https://gitcode.com/cann/shmem/issues/249 ## 测试 已按以下维度进行验证,具体参数和结果可按实际执行情况补充: - 功能正确性:使用各目录 scripts/run.sh 完成 dispatchcombinedispatch_doubleplanecombine_doubleplane 基础冒烟,校验 expand_xassist_info_for_combineep_recv_countexpert_token_numsx_out 与 golden 一致。 - 二级冒烟:覆盖 [2/4/8] 卡、[int32_t/float16_t][bs/topk/h/expertPerPe] 典型组合,确认 classic 与 DoublePlane 路径均可稳定运行。 - 算子泛化:覆盖不同 pesbshtopkexpertPerPe 组合,验证不同 shape 下输出语义与 classic 基线保持一致。 - 性能验证:通过 --perf 模式对 dispatch vs dispatch_doubleplanecombine vs combine_doubleplane 进行 full_opcomm_only 对比,重点观察多卡场景下的带宽和耗时表现。 - 协议一致性:验证 DoublePlane 在 SDMA/direct 混合路径下,payload、assist、ready、count、status 的写入/可见性时序正确,无功能回归。 验证结果如下: ![91CDE5B2-5437-41ED-A859-9F0C5013E64C.png](https://raw.gitcode.com/user-images/assets/8546182/a1858f90-6331-47a6-9347-46d1131a7550/91CDE5B2-5437-41ED-A859-9F0C5013E64C.png '91CDE5B2-5437-41ED-A859-9F0C5013E64C.png') ![D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png](https://raw.gitcode.com/user-images/assets/8546182/683ebd6c-df45-4d48-9c08-1360b7bbb0cc/D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png 'D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png') ![E19255BB-42E0-4CDE-E609-7E35E761F343.png](https://raw.gitcode.com/user-images/assets/8546182/7557886f-947a-4b17-b62f-107f1e1823b3/E19255BB-42E0-4CDE-E609-7E35E761F343.png 'E19255BB-42E0-4CDE-E609-7E35E761F343.png') ## 文档更新 - 更新/补充 dispatchcombinedispatch_doubleplanecombine_doubleplane 的 README,说明构建、功能运行和性能测试方法。 - 更新/补充 DoublePlane 设计说明文档,记录分段判定、传输策略和控制面协议。 ## 类型标签 - [ ] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [x] 其他,请描述:Add example/perftest See merge request: cann/shmem!3504 天前
添加经典和双平面两种实现路径的Dispatch和Combine算子example Co-authored-by: xionglan2<xionglan2@huawei.com> # message auto-generated for no-merge-commit merge: !350 merge feature/dispatch-combine-examples into master 添加经典和双平面两种实现路径的Dispatch和Combine算子example Created-by: xionglan2 Commit-by: xionglan2 Merged-by: cann-robot Description: ## 描述 本次 PR 将 dispatchcombinedispatch_doubleplanecombine_doubleplane 四个 MoE 通信算子上库,并对 classic / DoublePlane 两类路径做统一整理和性能优化,目标是在保持现有输入输出语义不变的前提下,补齐基础能力、统一脚本与文档,并提升大包传输场景下的吞吐表现。 具体改动包括: - 补齐 classic dispatch / combine 与 DoublePlane dispatch_doubleplane / combine_doubleplane 四个算子的构建、运行脚本和说明文档,统一功能验证和性能测试入口。 - dispatch 路径将输入token按路由规则分发到目标expert,生成后续combine所需的中间结果;combine 路径将个expert输出按源token和topK权重回传聚合,生成最终输出结果。 - dispatch_doubleplane / combine_doubleplane 引入基于 segment size 的自适应传输策略,在 direct MTE 与 SDMA 之间按段大小选择传输 plane;对大段优先走 SDMA,小段保留 direct 路径,以降低小包 SDMA 开销并提升大包场景吞吐。 - 保持四个算子的外部接口、输出格式和校验方式一致,便于后续统一冒烟、泛化和性能对比。 ## 关联的Issue https://gitcode.com/cann/shmem/issues/249 ## 测试 已按以下维度进行验证,具体参数和结果可按实际执行情况补充: - 功能正确性:使用各目录 scripts/run.sh 完成 dispatchcombinedispatch_doubleplanecombine_doubleplane 基础冒烟,校验 expand_xassist_info_for_combineep_recv_countexpert_token_numsx_out 与 golden 一致。 - 二级冒烟:覆盖 [2/4/8] 卡、[int32_t/float16_t][bs/topk/h/expertPerPe] 典型组合,确认 classic 与 DoublePlane 路径均可稳定运行。 - 算子泛化:覆盖不同 pesbshtopkexpertPerPe 组合,验证不同 shape 下输出语义与 classic 基线保持一致。 - 性能验证:通过 --perf 模式对 dispatch vs dispatch_doubleplanecombine vs combine_doubleplane 进行 full_opcomm_only 对比,重点观察多卡场景下的带宽和耗时表现。 - 协议一致性:验证 DoublePlane 在 SDMA/direct 混合路径下,payload、assist、ready、count、status 的写入/可见性时序正确,无功能回归。 验证结果如下: ![91CDE5B2-5437-41ED-A859-9F0C5013E64C.png](https://raw.gitcode.com/user-images/assets/8546182/a1858f90-6331-47a6-9347-46d1131a7550/91CDE5B2-5437-41ED-A859-9F0C5013E64C.png '91CDE5B2-5437-41ED-A859-9F0C5013E64C.png') ![D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png](https://raw.gitcode.com/user-images/assets/8546182/683ebd6c-df45-4d48-9c08-1360b7bbb0cc/D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png 'D9BE8A9E-29EE-49FB-8FCD-6C11504295D5.png') ![E19255BB-42E0-4CDE-E609-7E35E761F343.png](https://raw.gitcode.com/user-images/assets/8546182/7557886f-947a-4b17-b62f-107f1e1823b3/E19255BB-42E0-4CDE-E609-7E35E761F343.png 'E19255BB-42E0-4CDE-E609-7E35E761F343.png') ## 文档更新 - 更新/补充 dispatchcombinedispatch_doubleplanecombine_doubleplane 的 README,说明构建、功能运行和性能测试方法。 - 更新/补充 DoublePlane 设计说明文档,记录分段判定、传输策略和控制面协议。 ## 类型标签 - [ ] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [x] 其他,请描述:Add example/perftest See merge request: cann/shmem!3504 天前
README.md

经典 MoE Dispatch 示例

本示例实现非量化 MoE 的经典 dispatch 算子,对应设计文档 DOC/moe_dispatch_combine_non_quant_architecture.md。Dispatch 的职责是根据 expert_ids 将本 PE 的 token/topK 路由到目标 expert 所在 PE,并生成 combine 阶段需要的辅助信息。

功能说明

输入包括:

  • x:本 PE 的 token hidden states。
  • expert_ids:每个 token/topK 对应的全局 expert id。

输出包括:

  • expand_x:按目标 expert 聚合后的 token 数据。
  • assist_info_for_combine:combine 回传使用的辅助信息,格式为 [src_rank_id, src_token_id, src_topk_id]
  • ep_recv_count:按 (local_expert_id, src_rank_id) 排列的累计接收计数。
  • expert_token_nums:每个本地 expert 实际收到的 token 数。

输出顺序固定为 (local_expert_id, src_rank_id),便于后续 combine 和 golden 校验。

实现逻辑

Kernel 启动 pe_size 个 AIV core。发送阶段中,core_id == dst_rank 的 core 负责写入对应目标 PE 的对称窗口。

主要流程:

  1. 每个 active core 扫描本 PE 的 expert_ids,统计发往自己负责目标 PE 的每个 local expert 的 token 数。
  2. 对每个命中的 token/topK,通过 MTE put_nbi 写 payload 到目标 PE 的 SHMEM window。
  3. 写入 assist_info_for_combine、token ready flag 和 segment count 信号。
  4. 所有发送 core 完成后,接收端等待各来源 rank 的 count 信号。
  5. 根据 count 构造 ep_recv_countexpert_token_nums,再按确定顺序 compact 到最终输出。

当前经典版本优先保证逻辑清晰、可验证和输出顺序稳定,数据面使用 MTE 传输。

构建

在仓库根目录执行:

bash scripts/build.sh -examples

运行

基础 2 卡测试:

cd examples/dispatch/dispatch_classic
bash scripts/run.sh -pes 2 -bs 8 -h 16 -topk 2 -expertPerPe 2 -type int32_t

8 卡、64 expert 测试:

cd examples/dispatch/dispatch_classic
bash scripts/run.sh -pes 8 -bs 8 -h 16 -topk 2 -expertPerPe 8 -type int32_t

脚本会自动生成输入、路由矩阵和 golden 数据,启动每个 PE 对应的进程,输出写入 output/,并校验 expand_xassist_infoep_recv_countexpert_token_nums

常用参数

-pes <n>            PE/NPU 数量,单机示例要求 -gnpus 与 -pes 相同。
-bs <n>             每个 PE 的 token 数。
-h <n>              token hidden size。
-topk <n>           每个 token 路由的 expert 数。
-expertPerPe <n>    每个 PE 上的 local expert 数,范围为 [1, 1024]。
-type <dtype>       数据类型,支持 int32_t、float16_t、bfloat16_t。
-fnpu <id>          起始 NPU id,默认 0。
-ipport <url>       SHMEM bootstrap 地址,默认 tcp://127.0.0.1:8766。

expertPerPe 上限为 1024。Kernel 在 AI core 栈上为每个目标 local expert 分配固定工作区,超过该上限会被 host 侧拒绝。

性能测试

scripts/run.sh --perf 会在每个 shape 上保留正确性校验,并在 output/perf/ 下写入 CSV。

单 shape profiling:

cd examples/dispatch/dispatch_classic
bash scripts/run.sh --perf -pes 2 -bs 8 -h 256 -topk 2 -expertPerPe 2 -type int32_t \
    --warmup 5 --loops 50

多 shape、多卡数 sweep:

cd examples/dispatch/dispatch_classic
bash scripts/run.sh --perf --pes-list 2,4,8 --bs-list 8,16,32 --h-list 64,256,1024 \
    --topk-list 2 --expert-per-pe-list 2,8 -type int32_t --prof-pe all \
    --warmup 5 --loops 50

CSV 指标包括:

  • full_op:完整 dispatch,包括通信、元数据构造、compact 和同步。
  • comm_only:Stage 1 payload 通信及必要的元数据/status 协议。

单 rank 文件名为 dispatch_perf_rank<rank>.csv。使用 --prof-pe all 时,脚本会轮流 profile 每个 PE,并生成 dispatch_perf_summary.csv