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(
25 : const OpParam& param, std::set<u32>& ranksLinked, AlgResourceRequest& resourceRequest,
26 : bool& needIncreLink) override;
27 : HcclResult GetSendTargetLink(u32 remoteUserRank, LINK& targetLink);
28 : HcclResult GetRecvTargetLink(u32 remoteUserRank, LINK& targetLink);
29 :
30 : protected:
31 : /* *************** 资源计算 *************** */
32 : void ParseParam(const OpParam& param) override;
33 : HcclResult CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport) override;
34 :
35 : /* *************** 算法编排 *************** */
36 :
37 : u64 CalcSendLoopMaxCount(DeviceMem& inCCLBuffer, const u32 unitSize);
38 : u64 CalcRecvLoopMaxCount(DeviceMem& outCCLBuffer, const u32 unitSize);
39 : HcclResult ProcessSendDataSlice(Stream& stream, bool needStreamSync, bool retryEnable);
40 : HcclResult ProcessRecvDataSlice(Stream& stream, bool retryEnable);
41 : HcclResult CalcSendSlices(AlgResourceResponse& algRes);
42 : HcclResult CalcRecvSlices(AlgResourceResponse& algRes);
43 : HcclResult GetPairWiseList(HcclSendRecvItem* sendRecvInfo, u32 itemNum);
44 : HcclResult ProcessSelfSendRecvTasks(Stream& stream);
45 : HcclResult SendKernelRun(Stream& stream, ExecMem& execMem, u32 remoteUserRank, bool retryEnable);
46 : HcclResult RecvKernelRun(Stream& stream, ExecMem& execMem, u32 remoteUserRank, bool retryEnable);
47 : HcclResult GetTransport(u32 commIndex, u32 remoteUserRank, LINK& targetLink);
48 : struct SendRecvSlice {
49 : u8* addr;
50 : u64 size;
51 : u32 remoteRank;
52 0 : SendRecvSlice(u8* addr, u64 size, u32 remoteRank) : addr(addr), size(size), remoteRank(remoteRank) {}
53 : };
54 :
55 : u32 remoteUserRank_ = 0;
56 : const u32 MAX_LOOP_IN_ONCE_LAUNCH = 200;
57 : std::deque<SendRecvSlice> sendDataSilces_;
58 : std::deque<SendRecvSlice> recvDataSilces_;
59 :
60 : private:
61 : HcclResult RunLoopInHostUnfoldMode(OpParam& param);
62 : HcclResult RunLoopInAicpuUnfoldMode(OpParam& param);
63 : HcclResult CalcStreamNum(u32& streamNum) override;
64 :
65 : HcclResult MainPostSubWait(Stream& mainStream, Stream& subStream);
66 : HcclResult SubPostMainWait(Stream& mainStream, Stream& subStream);
67 :
68 : protected:
69 : std::set<u32> commTargetUserRankSet_;
70 : std::deque<HcclSendRecvItem*> sendToSelfDeque_;
71 : std::deque<HcclSendRecvItem*> recvFromSelfDeque_;
72 : std::deque<HcclSendRecvItem*> sendDeque_;
73 : std::deque<HcclSendRecvItem*> recvDeque_;
74 : };
75 : } // namespace hccl
76 :
77 : #endif
|