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 HCCL_GROUP_UTILS_H
12 : #define HCCL_GROUP_UTILS_H
13 :
14 : #include <mutex>
15 : #include <string>
16 : #include <hccl/hccl_types.h>
17 : #include <hccl_inner.h>
18 : #include "op_base.h"
19 : #include "hccl_comm_pub.h"
20 :
21 : namespace hccl {
22 :
23 : using hcclGroupJobState_t = enum hcclGroupJobState {
24 : hcclGroupJobRunning = 0,
25 : hcclGroupJobDone = 1,
26 : hcclGroupJobJoined = 2,
27 : };
28 :
29 1 : struct hcclAsyncJob {
30 : struct hcclAsyncJob* next;
31 : std::unique_ptr<std::thread> thread; /*记录该job异步执行pthread_create 创建的thread句柄*/
32 : HcclResult result; /* 用于记录job->func的执行结果,job->result = job->func(job) */
33 : HcclResult (*func)(struct hcclAsyncJob*);
34 : hcclGroupJobState state;
35 : std::mutex mtx;
36 : HcclComm* comm;
37 : };
38 :
39 : struct hcclCommInitAsyncJob : public hcclAsyncJob {
40 : u32 nRanks;
41 : const HcclRootInfo* rootInfo;
42 : u32 rank;
43 : s32 devId;
44 : HcclComm* initComm;
45 : std::string identifier;
46 : };
47 :
48 : struct hcclCommInitConfigAsyncJob : public hcclAsyncJob {
49 : u32 nRanks;
50 : const HcclRootInfo* rootInfo;
51 : u32 rank;
52 : s32 devId;
53 : HcclComm* initComm;
54 : std::string identifier;
55 : const HcclCommConfig* config;
56 : };
57 :
58 : struct hcclCommInitRankTableAsyncJob : public hcclAsyncJob {
59 : const char* clusterInfo;
60 : u32 rank;
61 : HcclComm* initComm;
62 : s32 devId;
63 : };
64 :
65 : struct hcclCommInitRankTableConfigAsyncJob : public hcclAsyncJob {
66 : const char* clusterInfo;
67 : u32 rank;
68 : HcclComm* initComm;
69 : HcclCommConfig* config;
70 : s32 devId;
71 : };
72 :
73 : struct hcclCommDestroyAsyncJob : public hcclAsyncJob {
74 : HcclComm initComm;
75 : s32 devId;
76 : };
77 :
78 : struct hcclOpInfo { /*用于保存算子的入参。所有算子用同个结构体保存info */
79 : HcclCMDType coll;
80 : void* sendbuff;
81 : void* recvbuff;
82 : u64 sendCount; // for non-V operators
83 : u64 recvCount; // for non-V operators
84 : const void* sendCounts;
85 : const void* recvCounts;
86 : const void* sdispls;
87 : const void* rdispls;
88 : HcclDataType sendType;
89 : HcclDataType recvType;
90 : HcclReduceOp op;
91 : u32 root; // dstRank或root rank
92 : HcclComm comm;
93 : HcclRtStream stream;
94 : };
95 :
96 : struct hcclTaskP2p {
97 : struct hcclTaskP2p* next;
98 : HcclCMDType func;
99 : void* buff;
100 : u64 count;
101 : HcclDataType datatype;
102 : s32 root; /*即peer或dstRank*/
103 : u64 bytes; /*即count*dataTypeSize*/
104 : HcclComm comm;
105 : HcclRtStream stream;
106 : };
107 :
108 : struct hcclKernelPlanner {
109 : s32 nTasksColl = -1;
110 : s32 nTasksP2p = -1; // 该plan中Coll和P2p task的个数
111 : u32 rankSize = 0;
112 :
113 : std::set<HcclRtStream> collStreams;
114 : HcclRtStream sendRecvMainStream; // sendRecv的主流,用于跟从流同步
115 :
116 : std::vector<HcclSendRecvItem> sendRecvInfo;
117 :
118 : std::deque<struct hcclOpInfo> collTaskQueue;
119 : };
120 :
121 : } // namespace hccl
122 : #endif
|