Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #ifndef HCCLV2_CCU_CONTEXT_HALF_ALL_TO_ALL_V_MESH_1D_H_
12 : #define HCCLV2_CCU_CONTEXT_HALF_ALL_TO_ALL_V_MESH_1D_H_
13 :
14 : #include <vector>
15 :
16 : #include <ios>
17 : #include "log.h"
18 : #include "ccu_context_alg_base.h"
19 : #include "ccu_assist.h"
20 : #include "ccu_datatype.h"
21 : #include "ccu_instruction_half_alltoallv_mesh1d.h"
22 :
23 : namespace Hccl {
24 :
25 : /*
26 : 当前只考虑mc2场景,且
27 : 由于:
28 : 1. 预留扩展为64P双die通过unions全互联的算法(需要解决通道保序的RC模式不支持unions的两个端口做bonding的问题);
29 : 2. Fast model当前不支持双die均连接每个对端,只有1D Fullmesh结构支持连接每个对端;
30 : 故:
31 : 拆分为两个context实现,每个context搬运一半数据;
32 : 可实现:
33 : 1. 两个context可以放在一个die或两个die上执行;
34 : 2. 可以通过调整sendSize & sendOffset实现单context搬运全部数据,等同于常规典型1D Fullmesh算法;
35 : 3. 通信域规模最大支持到64P(需要框架提供相应的64P连接);
36 : */
37 : /*
38 : * 此外,考虑到通道保序方案尚不明确,故后同步采用源端保序方式,当前最大支持8P通信域;
39 : */
40 :
41 : class CcuContextHalfAllToAllVMesh1D : public CcuContextAlgBase {
42 : public:
43 : CcuContextHalfAllToAllVMesh1D(
44 : const CcuCtxArg& arg, const std::vector<CcuTransport*>& transports, const CcuTransportGroup& group);
45 0 : ~CcuContextHalfAllToAllVMesh1D() override {}
46 :
47 : void Algorithm() override;
48 : std::vector<uint64_t> GeneArgs(const CcuTaskArg& arg) override;
49 :
50 : private:
51 : void ExchangeCtxResource();
52 : void LoadArgs();
53 : void LoadArgsFromMem();
54 : void MissionSync(uint32_t signalIndex);
55 : void PostSync();
56 : void CreateLocalCopyLoop();
57 : void LocalCopyByLoopGroup(CcuRep::Memory dst, CcuRep::Memory src, GroupOpSize& goPara);
58 :
59 : std::string ctxName_;
60 : uint32_t missionId_{
61 : 0}; // 分别对应两个context,指示搬运前一半或后一半数据,两个mission可以放在同一个或不同的die上执行
62 : uint32_t signalNum_{0}; // 需要使用的signal数量
63 : uint64_t myCclBufferAddr_{0};
64 :
65 : std::vector<CcuRep::Variable> token_;
66 :
67 : // mc2的传入参数
68 : CcuRep::Variable userInAddr_; // mc2传入的输入地址
69 : CcuRep::Variable sendSizeAddr_; // 切分后的分片大小,默认前rankSize个是sizeA,后rankSize个是sizeB
70 : CcuRep::Variable sendOffsetAddr_; // 切分后的分片相对userInAddr的偏移
71 : CcuRep::Variable recvOffset_; // 本端给任意对端写时相对对端cclBuffer首地址的偏移,status*winSize/2+rankId*GRID_SIZE
72 : GroupOpSize goSize_; // mc2传入的给自己的分片大小
73 :
74 : // 本地资源
75 : CcuRep::Memory curSrc_;
76 : std::vector<CcuRep::Memory> curDst_;
77 : std::vector<CcuRep::Variable> sendSizeA_; // 最多64个连续的,对应数据片的前半部分
78 : std::vector<CcuRep::Variable> sendSizeB_; // 最多64个连续的,对应数据片的后半部分
79 : std::vector<CcuRep::Variable> sendOffsetA_; // 最多64个连续的,对应数据片的前半部分
80 : std::vector<CcuRep::Variable> sendOffsetB_; // 最多64个连续的,对应数据片的后半部分
81 : CcuRep::MaskSignal ccuStartSignal_;
82 : CcuRep::MaskSignal ccuEndSignal_;
83 : std::vector<CcuRep::MaskSignal> writeDoneSignal_; // 写完成信号
84 :
85 : // 跨mission同步信号
86 : CcuRep::MaskSignal locMiSignal0_; // 本die的
87 : CcuRep::MaskSignal locMiSignal1_;
88 : CcuRep::MaskSignal anoMiSignal0_; // 映射另一个die的
89 : CcuRep::MaskSignal anoMiSignal1_;
90 : CcuRep::Variable anoUserInAddr_;
91 : CcuRep::Variable anoSendSizeAddr_;
92 : CcuRep::Variable anoSendOffsetAddr_;
93 : CcuRep::Variable anoRecvOffset_;
94 : };
95 : } // namespace Hccl
96 :
97 : #endif // HCCLV2_CCU_CONTEXT_HALF_ALL_TO_ALL_V_MESH_1D_H_
|