Line data Source code
1 : /**
2 : * Copyright (c) 2026 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 GROUP_SCHEDULE_MGR_H
12 : #define GROUP_SCHEDULE_MGR_H
13 :
14 : #include <deque>
15 : #include <vector>
16 : #include <string>
17 : #include <map>
18 : #include <hccl/hccl_types.h>
19 : #include <hccl/hccl_launch.h>
20 : #include "acl/acl_base_rt.h"
21 : #include "hcomm_res_defs.h"
22 :
23 : constexpr int32_t MAX_P2P_TASK_NUM = 2048;
24 :
25 : namespace hccl {
26 :
27 : struct HcclP2pPair {
28 : uint32_t sendRank;
29 : uint32_t recvRank;
30 : };
31 :
32 : struct HcclP2pTask {
33 : HcclOpP2pDesc desc;
34 : aclrtStream stream;
35 : aclrtStream usrStream;
36 : HcclKernelFuncInfo funcInfo;
37 : uint8_t args[P2P_MAX_ARG_SIZE];
38 : uint32_t argSize;
39 : };
40 :
41 : struct HcclP2pSendRecvQueue {
42 : std::deque<HcclP2pTask> sendQue;
43 : std::deque<HcclP2pTask> recvQue;
44 : };
45 :
46 : void ClearHcclGroupCommList();
47 : std::vector<HcclComm>& GetHcclGroupCommList();
48 : int32_t GetHcclP2pTaskNums();
49 : void SetHcclP2pTaskNums(int32_t targetP2pTaskNums);
50 :
51 : class GroupScheduleMgr {
52 : public:
53 216 : GroupScheduleMgr() : userRank_(0), serverNum_(0), nTasksP2p_(-1), usrStream_(nullptr) {};
54 : ~GroupScheduleMgr();
55 :
56 : HcclResult GetUsrStream(aclrtStream& usrStream);
57 : HcclResult SetUsrStream(const aclrtStream& usrStream);
58 :
59 : HcclResult AppendGroupP2pTask(HcclComm comm, const HcclP2pTask& task, const HcclOpP2pDesc& p2pDesc);
60 : HcclResult GetP2pTaskSchedule(std::vector<HcclP2pTask>& sortedSendQue, std::vector<HcclP2pTask>& sortedRecvQue);
61 :
62 : private:
63 : HcclResult GetCurLocalRank(uint32_t& localRank);
64 : HcclResult CalculateGroupSize();
65 : uint32_t GenerateP2pSchedule(
66 : const std::vector<uint32_t>& groupToServer, const std::vector<uint32_t>& groupToLocalRankBase,
67 : uint32_t curGroupIdx, uint32_t curGroupLocalRankIdx);
68 : HcclResult InitGroupPlanner(HcclComm comm);
69 : HcclResult HcclP2pSchedulerGenerate();
70 :
71 : private:
72 : uint32_t userRank_;
73 : uint32_t serverNum_;
74 : std::map<uint32_t, uint32_t> serverToRankSize_;
75 : std::map<uint32_t, std::vector<uint32_t>> serverToRankList_;
76 : uint32_t rankSize_;
77 : uint32_t groupSize_;
78 : uint32_t nGroups_;
79 :
80 : int32_t nTasksP2p_;
81 : aclrtStream usrStream_;
82 : std::vector<HcclP2pPair> p2pSchedule_;
83 : std::vector<HcclP2pSendRecvQueue> peers_;
84 : };
85 :
86 : } // namespace hccl
87 : #endif // GroupScheduleMgr
|