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 COLL_BATCH_SEND_RECV_EXECUTOR_H
12 : #define COLL_BATCH_SEND_RECV_EXECUTOR_H
13 :
14 : #include "coll_comm_executor.h"
15 :
16 : namespace hccl {
17 : class CollBatchSendRecvExecutor : public CollCommExecutor {
18 : public:
19 : CollBatchSendRecvExecutor(const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher> &topoMatcher);
20 64 : ~CollBatchSendRecvExecutor() override = default;
21 : HcclResult Orchestrate(OpParam& param, AlgResourceResponse& algResource) override;
22 : HcclResult GetAdjInfo(AlgResourceResponse& algRes, AdjInfo& adjInfo) override;
23 : // 增量建链资源计算接口
24 : HcclResult CalcIncreLinkRequest(const OpParam& param, std::set<u32>& ranksLinked, AlgResourceRequest& resourceRequest, bool& needIncreLink)
25 : override;
26 : HcclResult GetSendTargetLink(u32 remoteUserRank, LINK& targetLink);
27 : HcclResult GetRecvTargetLink(u32 remoteUserRank, LINK& targetLink);
28 : protected:
29 : /* *************** 资源计算 *************** */
30 : void ParseParam(const OpParam& param) override;
31 : HcclResult CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport) override;
32 :
33 : /* *************** 算法编排 *************** */
34 :
35 : u64 CalcSendLoopMaxCount(DeviceMem& inCCLBuffer, const u32 unitSize);
36 : u64 CalcRecvLoopMaxCount(DeviceMem& outCCLBuffer, const u32 unitSize);
37 : HcclResult ProcessSendDataSlice(Stream& stream, bool needStreamSync, bool retryEnable);
38 : HcclResult ProcessRecvDataSlice(Stream& stream, bool retryEnable);
39 : HcclResult CalcSendSlices(AlgResourceResponse& algRes);
40 : HcclResult CalcRecvSlices(AlgResourceResponse& algRes);
41 : HcclResult GetPairWiseList(HcclSendRecvItem *sendRecvInfo, u32 itemNum);
42 : HcclResult ProcessSelfSendRecvTasks(Stream& stream);
43 : HcclResult SendKernelRun(Stream& stream, ExecMem &execMem, u32 remoteUserRank, bool retryEnable);
44 : HcclResult RecvKernelRun(Stream& stream, ExecMem &execMem, u32 remoteUserRank, bool retryEnable);
45 : HcclResult GetTransport(u32 commIndex, u32 remoteUserRank, LINK &targetLink);
46 : struct SendRecvSlice {
47 : u8* addr;
48 : u64 size;
49 : u32 remoteRank;
50 0 : SendRecvSlice(u8* addr, u64 size, u32 remoteRank) : addr(addr), size(size), remoteRank(remoteRank) {}
51 : };
52 :
53 : u32 remoteUserRank_ = 0;
54 : const u32 MAX_LOOP_IN_ONCE_LAUNCH = 200;
55 : std::deque<SendRecvSlice> sendDataSilces_;
56 : std::deque<SendRecvSlice> recvDataSilces_;
57 : private:
58 : HcclResult RunLoopInHostUnfoldMode(OpParam& param);
59 : HcclResult RunLoopInAicpuUnfoldMode(OpParam& param);
60 : HcclResult CalcStreamNum(u32& streamNum) override;
61 :
62 : HcclResult MainPostSubWait(Stream& mainStream, Stream& subStream);
63 : HcclResult SubPostMainWait(Stream& mainStream, Stream& subStream);
64 :
65 : protected:
66 :
67 : std::set<u32> commTargetUserRankSet_;
68 : std::deque<HcclSendRecvItem*> sendToSelfDeque_;
69 : std::deque<HcclSendRecvItem*> recvFromSelfDeque_;
70 : std::deque<HcclSendRecvItem*> sendDeque_;
71 : std::deque<HcclSendRecvItem*> recvDeque_;
72 : };
73 : } // namespace hccl
74 :
75 : #endif
|