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