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_HCCL_PARAMS_PUB_H
12 : #define HCCL_HCCL_PARAMS_PUB_H
13 :
14 : #include <string>
15 : #include <functional>
16 : #include <unordered_map>
17 : #include "types.h"
18 : #include "enum_factory_legacy.h"
19 : #include "data_type.h"
20 : #include "op_type.h"
21 : #include "reduce_op.h"
22 : #include "dev_type.h"
23 :
24 : namespace Hccl {
25 :
26 : class CommParams {
27 : public:
28 : std::string commId{""};
29 : RankId myRank{0};
30 : u32 rankSize{0};
31 : /* rankInParentGroup: 子通信域(group)内的rank在父通信域(hccl_world_group)中的rankId.
32 : 创建hccl_world_group通信域时,myRank与rankInParentGroup相等;
33 : CreateGroup创建子通信域时,myRank为子通信域内的rankId,此时myRank与rankInParentGroup不一定相等 */
34 : RankId rankInParentComm{0};
35 : DevType devType{DevType::DEV_TYPE_950};
36 : bool devUsed{false};
37 : bool isWorldGroup{false};
38 :
39 21 : CommParams(
40 : std::string commId, RankId myRank, u32 rankSize, RankId rankInParentComm, const DevType& devType,
41 : bool devUsed = false, bool isWorldGroup = false)
42 21 : : commId(std::move(commId)),
43 21 : myRank(myRank),
44 21 : rankSize(rankSize),
45 21 : rankInParentComm(rankInParentComm),
46 21 : devType(devType),
47 21 : devUsed(devUsed),
48 21 : isWorldGroup(isWorldGroup)
49 21 : {}
50 :
51 1215 : CommParams() {}
52 : };
53 :
54 : class CollOpParams {
55 : public:
56 : OpType opType;
57 : DataType dataType;
58 : ReduceOp reduceOp;
59 : u32 dstRank;
60 : void* sendBuf;
61 : void* recvBuf;
62 : u64 count{0};
63 : u32 root{0};
64 : bool staticAddr{false};
65 : bool staticShape{false};
66 : DataType outputDataType{DataType::INVALID};
67 : std::string opTag;
68 : bool isMc2{false};
69 : std::string algConfig;
70 : HcclAccelerator commEngine;
71 : union {
72 : struct {
73 : u64 dataCount;
74 : DataType dataType;
75 : u64 strideCount;
76 : } dataDes;
77 : struct {
78 : void* counts;
79 : void* displs;
80 : DataType dataType;
81 : } vDataDes;
82 : struct {
83 : DataType sendType;
84 : DataType recvType;
85 : u64 sendCount;
86 : u64 recvCount;
87 : } all2AllDataDes;
88 : struct {
89 : DataType sendType;
90 : DataType recvType;
91 : void* sendCounts;
92 : void* recvCounts;
93 : void* sdispls;
94 : void* rdispls;
95 : } all2AllVDataDes;
96 : struct {
97 : DataType sendType;
98 : DataType recvType;
99 : void* sendCountMatrix;
100 : } all2AllVCDataDes;
101 : struct {
102 : void* sendRecvItemsPtr;
103 : u32 itemNum;
104 : } batchSendRecvDataDes;
105 : };
106 : // 使用初始化列表
107 1040 : CollOpParams()
108 1040 : : opType(),
109 1040 : dataType(),
110 1040 : reduceOp(),
111 1040 : dstRank(),
112 1040 : sendBuf(),
113 1040 : recvBuf(),
114 1040 : count(),
115 1040 : root(),
116 1040 : staticAddr(),
117 1040 : staticShape(),
118 17680 : outputDataType()
119 : {
120 : // 显式初始化 union 的默认成员
121 1040 : dataDes = {0, DataType::INVALID, 0}; // 假设 dataDes 是默认使用的成员
122 1040 : }
123 :
124 : std::string Describe() const;
125 :
126 : private:
127 : std::string DescReduceScatter(const CollOpParams& opParams);
128 :
129 : std::string DescAllreduce(const CollOpParams& opParams);
130 :
131 : std::string DescAllgather(const CollOpParams& opParams);
132 :
133 : std::string DescScatter(const CollOpParams& opParams);
134 :
135 : std::string DescAlltoall(const CollOpParams& opParams);
136 :
137 : std::string DescAlltoallV(const CollOpParams& opParams);
138 :
139 : std::string DescAlltoallVC(const CollOpParams& opParams);
140 :
141 : std::string DescSend(const CollOpParams& opParams);
142 :
143 : std::string DescRecv(const CollOpParams& opParams);
144 :
145 : std::string DescReduce(const CollOpParams& opParams);
146 :
147 : std::string DescBroadcast(const CollOpParams& opParams);
148 :
149 : std::string DescBatchSendRecv(const CollOpParams& opParams);
150 :
151 : std::string DescAllGatherV(const CollOpParams& opParams);
152 :
153 : std::string DescReduceScatterV(const CollOpParams& opParams);
154 :
155 : std::unordered_map<OpType, std::function<std::string(const CollOpParams&)>, std::EnumClassHash> descOpMap{
156 : {OpType::REDUCESCATTER, std::bind(&CollOpParams::DescReduceScatter, this, std::placeholders::_1)},
157 : {OpType::ALLREDUCE, std::bind(&CollOpParams::DescAllreduce, this, std::placeholders::_1)},
158 : {OpType::ALLGATHER, std::bind(&CollOpParams::DescAllgather, this, std::placeholders::_1)},
159 : {OpType::SCATTER, std::bind(&CollOpParams::DescScatter, this, std::placeholders::_1)},
160 : {OpType::ALLTOALL, std::bind(&CollOpParams::DescAlltoall, this, std::placeholders::_1)},
161 : {OpType::ALLTOALLV, std::bind(&CollOpParams::DescAlltoallV, this, std::placeholders::_1)},
162 : {OpType::ALLTOALLVC, std::bind(&CollOpParams::DescAlltoallVC, this, std::placeholders::_1)},
163 : {OpType::SEND, std::bind(&CollOpParams::DescSend, this, std::placeholders::_1)},
164 : {OpType::RECV, std::bind(&CollOpParams::DescRecv, this, std::placeholders::_1)},
165 : {OpType::REDUCE, std::bind(&CollOpParams::DescReduce, this, std::placeholders::_1)},
166 : {OpType::BROADCAST, std::bind(&CollOpParams::DescBroadcast, this, std::placeholders::_1)},
167 : {OpType::BATCHSENDRECV, std::bind(&CollOpParams::DescBatchSendRecv, this, std::placeholders::_1)},
168 : {OpType::ALLGATHERV, std::bind(&CollOpParams::DescAllGatherV, this, std::placeholders::_1)},
169 : {OpType::REDUCESCATTERV, std::bind(&CollOpParams::DescReduceScatterV, this, std::placeholders::_1)}
170 : // 后续待补充其他算子信息
171 : };
172 : };
173 :
174 : struct CollOffloadOpResReq {
175 : u64 requiredSubQueNum{0};
176 : u64 requiredScratchMemSize{0};
177 : };
178 : } // namespace Hccl
179 :
180 : #endif // HCCL_HCCL_PARAMS_PUB_H
|