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_INS_TEMP_ALL_TO_ALL_MESH
12 : #define HCCLV2_INS_TEMP_ALL_TO_ALL_MESH
13 :
14 : #include "string_util.h"
15 :
16 : #include "ins_alg_template_base.h"
17 : #include "alg_data_trans_wrapper.h"
18 :
19 : namespace Hccl {
20 :
21 : const uint32_t ALLTOALLV_DIRECT_FULLMESH_CONCURRENT_SIZE = 16; // fullmesh最大的并发数量
22 :
23 : class InsTempAlltoAllMesh : public InsAlgTemplateBase {
24 : public:
25 : explicit InsTempAlltoAllMesh(
26 : const RankId virtualRank, const u32 tempRankSize, const std::vector<std::vector<RankId>>& tempVTopo,
27 : const std::map<RankId, u32>& tempVirtRankMap);
28 : ~InsTempAlltoAllMesh() override;
29 :
30 0 : std::string Describe() const override
31 : {
32 0 : return StringFormat("Instruction based Template of alltoall mesh with tempRankSize [%u].", tempRankSize_);
33 : }
34 :
35 : HcclResult CalcRes(AlgTempResReq& tempResReq) override;
36 : HcclResult
37 : Run(const TempFuncs& tempFuncs, const RankSliceInfo& sliceInfoVec, const BuffInfo& buffInfo,
38 : const ResLinks& tempLinks, std::vector<InsQuePtr>& tempInsQues) override;
39 : void SetA2ASendRecvInfo(const A2ASendRecvInfo& sendRecvInfo);
40 : HcclResult GetScratchBufferInfo(const u64& scratchBufferSize, DataType dataType);
41 :
42 : private:
43 : u32 CalcStepNum(); // 计算step数
44 : HcclResult CalcSendRecvAllSliceInfo(
45 : std::unordered_map<u32, UsrData>& sendSliceInfoMap,
46 : std::unordered_map<u32, UsrData>& recvSliceInfoMap); // 计算每个rank当前step的send/recv slice
47 :
48 : HcclResult CalcSendSliceInfo(u32 remoteRank, UsrData& sendSliceInfo);
49 :
50 : HcclResult CalcRecvSliceInfo(u32 remoteRank, UsrData& readSliceInfo);
51 :
52 : HcclResult RunSendRecvForAllRanks(
53 : u32 step, std::unordered_map<u32, UsrData>& sendSliceInfoMap,
54 : std::unordered_map<u32, UsrData>& recvSliceInfoMap, const ResLinks& tempLinks,
55 : std::vector<InsQuePtr>& queues); // 所有对端send/Recv循环一次
56 :
57 : HcclResult RunSendRecvBufferLoop(
58 : u32 step, const std::vector<u32>& commRanks, std::unordered_map<u32, UsrData>& sendSliceInfoMap,
59 : std::unordered_map<u32, UsrData>& recvSliceInfoMap, const ResLinks& tempLinks,
60 : std::vector<InsQuePtr>& queues) const; // 循环一次buffer
61 :
62 : HcclResult CalcCommRankSetforOneLoop(
63 : u32 roundIdx, const u32 groupRankSize,
64 : std::vector<u32>& commRanks) const; // 计算当前循环的send/recv rank set
65 :
66 : HcclResult CopySendDataToScratch(
67 : u32 step, const std::vector<u32>& commRanks, std::unordered_map<u32, UsrData>& sendSliceInfo,
68 : const ResLinks& tempLinks, std::vector<InsQuePtr>& queues) const;
69 :
70 : HcclResult SendRecvData(
71 : u32 step, const std::vector<u32>& commRanks, std::unordered_map<u32, UsrData>& sendSliceInfo,
72 : std::unordered_map<u32, UsrData>& readSliceInfo, const ResLinks& tempLinks,
73 : std::vector<InsQuePtr>& queues) const;
74 :
75 : HcclResult CopyRecvDataFromScratch(
76 : u32 step, const std::vector<u32>& commRanks, std::unordered_map<u32, UsrData>& readSliceInfo,
77 : const ResLinks& tempLinks, std::vector<InsQuePtr>& queues) const;
78 :
79 : HcclResult LocalDataCopy(InsQuePtr tempInsQue);
80 :
81 : HcclResult SetBuffBlockSize(const u64 buffBlockSize);
82 :
83 : HcclResult SetConcurrentSendRecvNum(const u32 concurrentSendRecvNum);
84 :
85 : u32 concurrentSendRecvNum_ = 8;
86 : u64 buffBlockSize_ = 0;
87 : A2ASendRecvInfo localSendRecvInfo_;
88 : BuffInfo buffInfo_;
89 : u32 maxPathNum = 0;
90 : };
91 :
92 : } // namespace Hccl
93 :
94 : #endif // !HCCLV2_INS_TEMP_ALL_TO_ALL_MESH
|