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.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(std::string commId, RankId myRank, u32 rankSize, RankId rankInParentComm, const DevType &devType, bool devUsed = false, bool isWorldGroup = false)
40 21 : : commId(std::move(commId)), myRank(myRank), rankSize(rankSize), rankInParentComm(rankInParentComm), devType(devType), devUsed(devUsed), isWorldGroup(isWorldGroup)
41 : {
42 21 : }
43 :
44 402 : CommParams()
45 1206 : {
46 402 : }
47 : };
48 :
49 : class CollOpParams {
50 : public:
51 : OpType opType;
52 : DataType dataType;
53 : ReduceOp reduceOp;
54 : u32 dstRank;
55 : void *sendBuf;
56 : void *recvBuf;
57 : u64 count{0};
58 : u32 root{0};
59 : bool staticAddr{false};
60 : bool staticShape{false};
61 : DataType outputDataType{DataType::INVALID};
62 : std::string opTag;
63 : bool isMc2{false};
64 : std::string algConfig;
65 : HcclAccelerator commEngine;
66 : union {
67 : struct {
68 : u64 dataCount;
69 : DataType dataType;
70 : u64 strideCount;
71 : } dataDes;
72 : struct {
73 : void* counts;
74 : void* displs;
75 : DataType dataType;
76 : } vDataDes;
77 : struct {
78 : DataType sendType;
79 : DataType recvType;
80 : u64 sendCount;
81 : u64 recvCount;
82 : } all2AllDataDes;
83 : struct {
84 : DataType sendType;
85 : DataType recvType;
86 : void* sendCounts;
87 : void* recvCounts;
88 : void* sdispls;
89 : void* rdispls;
90 : } all2AllVDataDes;
91 : struct {
92 : DataType sendType;
93 : DataType recvType;
94 : void* sendCountMatrix;
95 : } all2AllVCDataDes;
96 : struct {
97 : void* sendRecvItemsPtr;
98 : u32 itemNum;
99 : } batchSendRecvDataDes;
100 : };
101 : // 使用初始化列表
102 1033 : CollOpParams() : opType(), dataType(), reduceOp(), dstRank(), sendBuf(), recvBuf(),
103 17561 : count(), root(), staticAddr(), staticShape(), outputDataType() {
104 : // 显式初始化 union 的默认成员
105 1033 : dataDes = {0, DataType::INVALID, 0}; // 假设 dataDes 是默认使用的成员
106 1033 : }
107 :
108 : std::string Describe() const;
109 :
110 : private:
111 : std::string DescReduceScatter(const CollOpParams &opParams);
112 :
113 : std::string DescAllreduce(const CollOpParams &opParams);
114 :
115 : std::string DescAllgather(const CollOpParams &opParams);
116 :
117 : std::string DescScatter(const CollOpParams &opParams);
118 :
119 : std::string DescAlltoall(const CollOpParams &opParams);
120 :
121 : std::string DescAlltoallV(const CollOpParams &opParams);
122 :
123 : std::string DescAlltoallVC(const CollOpParams &opParams);
124 :
125 : std::string DescSend(const CollOpParams &opParams);
126 :
127 : std::string DescRecv(const CollOpParams &opParams);
128 :
129 : std::string DescReduce(const CollOpParams &opParams);
130 :
131 : std::string DescBroadcast(const CollOpParams &opParams);
132 :
133 : std::string DescBatchSendRecv(const CollOpParams &opParams);
134 :
135 : std::string DescAllGatherV(const CollOpParams &opParams);
136 :
137 : std::string DescReduceScatterV(const CollOpParams &opParams);
138 :
139 : std::unordered_map<OpType, std::function<std::string(const CollOpParams &)>, std::EnumClassHash> descOpMap{
140 : {OpType::REDUCESCATTER, std::bind(&CollOpParams::DescReduceScatter, this, std::placeholders::_1)},
141 : {OpType::ALLREDUCE, std::bind(&CollOpParams::DescAllreduce, this, std::placeholders::_1)},
142 : {OpType::ALLGATHER, std::bind(&CollOpParams::DescAllgather, this, std::placeholders::_1)},
143 : {OpType::SCATTER, std::bind(&CollOpParams::DescScatter, this, std::placeholders::_1)},
144 : {OpType::ALLTOALL, std::bind(&CollOpParams::DescAlltoall, this, std::placeholders::_1)},
145 : {OpType::ALLTOALLV, std::bind(&CollOpParams::DescAlltoallV, this, std::placeholders::_1)},
146 : {OpType::ALLTOALLVC, std::bind(&CollOpParams::DescAlltoallVC, this, std::placeholders::_1)},
147 : {OpType::SEND, std::bind(&CollOpParams::DescSend, this, std::placeholders::_1)},
148 : {OpType::RECV, std::bind(&CollOpParams::DescRecv, this, std::placeholders::_1)},
149 : {OpType::REDUCE, std::bind(&CollOpParams::DescReduce, this, std::placeholders::_1)},
150 : {OpType::BROADCAST, std::bind(&CollOpParams::DescBroadcast, this, std::placeholders::_1)},
151 : {OpType::BATCHSENDRECV, std::bind(&CollOpParams::DescBatchSendRecv, this, std::placeholders::_1)},
152 : {OpType::ALLGATHERV, std::bind(&CollOpParams::DescAllGatherV, this, std::placeholders::_1)},
153 : {OpType::REDUCESCATTERV, std::bind(&CollOpParams::DescReduceScatterV, this, std::placeholders::_1)}
154 : // 后续待补充其他算子信息
155 : };
156 : };
157 :
158 : struct CollOffloadOpResReq {
159 : u64 requiredSubQueNum{0};
160 : u64 requiredScratchMemSize{0};
161 : };
162 : } // namespace Hccl
163 :
164 : #endif // HCCL_HCCL_PARAMS_PUB_H
|