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 HCCLV2_UB_CONN_LITE_H_
12 : #define HCCLV2_UB_CONN_LITE_H_
13 :
14 : #include <queue>
15 : #include "data_type.h"
16 : #include "reduce_op.h"
17 : #include "rma_buf_slice_lite.h"
18 : #include "rmt_rma_buf_slice_lite.h"
19 : #include "rma_conn_lite.h"
20 : #include "udma_data_struct.h"
21 : #include "kernel_param_lite.h"
22 : #include "stream_lite.h"
23 :
24 : namespace Hccl {
25 :
26 : enum class SlicePosition { ONLY = 0, FIRST = 1, MIDDLE = 2, LAST = 3 };
27 : struct UbConnLiteParam {
28 : u32 dieId;
29 : u32 funcId;
30 : u32 jettyId;
31 :
32 : u64 dbAddr;
33 : u64 sqVa;
34 : u32 sqDepth;
35 : u32 tpn;
36 : bool dwqeCacheLocked;
37 : u32 jfcPollMode; // 0代表STARS POLL, 1代表软件Poll
38 : u64 sqCiAddr; // 预留给 软件poll CQ 的Jetty使用
39 :
40 : Eid rmtEid;
41 : Eid locEid;
42 : uint64_t jettyHandle{0};
43 :
44 : u32 maxReadSize;
45 : u32 maxWriteSize;
46 :
47 : UbConnLiteParam(std::vector<char>& uniqueId);
48 :
49 : std::string Describe() const;
50 : };
51 :
52 : class UbConnLite : public RmaConnLite {
53 : public:
54 : UbConnLite(const UbJettyLiteId& id, const UbJettyLiteAttr& attr, const Eid& rmtInfo);
55 :
56 : explicit UbConnLite(const UbConnLiteParam& liteParam);
57 :
58 : std::string Describe() final;
59 :
60 : void FillCommSqe(
61 : UdmaSqeCommon* sqe, const RmtRmaBufSliceLite& rmt, const SqeConfigLite& cfg, u32 opCode,
62 : SlicePosition slicePos = SlicePosition::ONLY);
63 :
64 : void Read(
65 : const RmaBufSliceLite& loc, const RmtRmaBufSliceLite& rmt, const SqeConfigLite& cfg, const StreamLite& stream,
66 : ConnLiteOperationOut& out) override;
67 :
68 : void ReadReduce(
69 : ReduceIn reduceIn, const RmaBufSliceLite& loc, const RmtRmaBufSliceLite& rmt, const StreamLite& stream,
70 : const SqeConfigLite& cfg, ConnLiteOperationOut& out) override;
71 :
72 : void Write(
73 : const RmaBufSliceLite& loc, const RmtRmaBufSliceLite& rmt, const SqeConfigLite& cfg, const StreamLite& stream,
74 : ConnLiteOperationOut& out) override;
75 :
76 : void InlineWrite(
77 : const u8* data, u16 size, const RmtRmaBufSliceLite& rmt, const SqeConfigLite& cfg, const StreamLite& stream,
78 : ConnLiteOperationOut& out) override;
79 :
80 : void WriteReduce(
81 : DataType dataType, ReduceOp reduceOp, const RmaBufSliceLite& loc, const StreamLite& stream,
82 : const RmtRmaBufSliceLite& rmt, const SqeConfigLite& cfg, ConnLiteOperationOut& out) override;
83 :
84 : void FillNotifySqe(struct UdmaSqeNotify* sqe, const RmtRmaBufSliceLite& notify, u64 notifyData) const;
85 : void FillLocalSgeSqe(UdmaNormalSge* sqe, const RmaBufSliceLite& loc) const;
86 :
87 : void WriteWithNotify(
88 : const RmaBufSliceLite& loc, const RmtRmaBufSliceLite& rmt, const SqeConfigLite& cfg, ConnLiteOperationOut& out,
89 : const RmtRmaBufSliceLite& notify, const StreamLite& stream, u64 notifyData) override;
90 :
91 : void WriteReduceWithNotify(
92 : DataType dataType, ReduceOp reduceOp, const RmaBufSliceLite& loc, const RmtRmaBufSliceLite& rmt,
93 : const SqeConfigLite& cfg, const StreamLite& stream, ConnLiteOperationOut& out, const RmtRmaBufSliceLite& notify,
94 : u64 notifyData) override;
95 :
96 : void CustomizeSqeByOneSidedComm(UdmaSqeCommon* sqe, bool isLastWqe) const;
97 :
98 : void FillBatchOneWqe(
99 : const RmaBufSliceLite& loc, const RmtRmaBufSliceLite& rmt, const SqeConfigLite& cfg, bool isLastWqe, u32 opCode,
100 : const StreamLite& stream);
101 :
102 : void BatchProcessOneSlice(
103 : const RmaBufSliceLite& loc, const RmtRmaBufSliceLite& rmt, const SqeConfigLite& cfg, u32 maxSliceSize,
104 : bool isLastSlice, u32 opCode, const StreamLite& stream);
105 :
106 : void BatchCommDataProcess(
107 : const vector<RmaBufSliceLite>& loc, const vector<RmtRmaBufSliceLite>& rmt, const SqeConfigLite& cfg,
108 : u32 maxSliceSize, u32 opCode, const StreamLite& stream);
109 :
110 : void BatchOneSidedRead(
111 : const vector<RmaBufSliceLite>& loc, const vector<RmtRmaBufSliceLite>& rmt, const SqeConfigLite& cfg,
112 : const StreamLite& stream, ConnLiteOperationOut& out) override;
113 : void BatchOneSidedWrite(
114 : const vector<RmaBufSliceLite>& loc, const vector<RmtRmaBufSliceLite>& rmt, const SqeConfigLite& cfg,
115 : const StreamLite& stream, ConnLiteOperationOut& out) override;
116 :
117 : // 用于aicpu task cache或者WQE打印
118 0 : inline HcclResult EnableWqeTasks()
119 : {
120 0 : isTrackWqeTasks_ = true;
121 0 : wqeTasks_.clear();
122 0 : return HCCL_SUCCESS;
123 : }
124 0 : inline HcclResult DisableWqeTasks()
125 : {
126 0 : isTrackWqeTasks_ = false;
127 0 : wqeTasks_.clear();
128 0 : return HCCL_SUCCESS;
129 : }
130 0 : inline const std::vector<WqeTask>& GetWqeTasks() const { return wqeTasks_; }
131 :
132 : // 用于aicpu task cache下发刷新后的WQE
133 : void LaunchOneWqe(UdmaSqeWrite* sqe, UdmaSqOpcode opCode);
134 : void LaunchOneWqeWithNotify(UdmaSqeWriteWithNotify* sqe, u32 opCode);
135 :
136 : // 用于aicpu task cache更新DbSqe
137 0 : uint16_t GetPi() const { return pi; }
138 :
139 : private:
140 : u16 pi{0};
141 : u16 ci{0};
142 : u32 piDetourCount{0};
143 : u32 ciDetourCount{0};
144 : u32 maxReadSize{0};
145 : u32 maxWriteSize{0};
146 : void ProcessSlices(
147 : const RmaBufSliceLite& loc, const RmtRmaBufSliceLite& rmt, u32 maxSliceSize,
148 : std::function<void(const RmaBufSliceLite&, const RmtRmaBufSliceLite&, SlicePosition)> processOneSlice,
149 6 : DataType dataType = DataType::INVALID) const;
150 : void ProcessSlicesWithNotify(
151 : const RmaBufSliceLite& loc, const RmtRmaBufSliceLite& rmt, u32 maxSliceSize,
152 : std::function<void(const RmaBufSliceLite&, const RmtRmaBufSliceLite&, SlicePosition)> processOneSlice,
153 : std::function<void(const RmaBufSliceLite&, const RmtRmaBufSliceLite&, SlicePosition)> processOneSliceWithNotify,
154 6 : DataType dataType = DataType::INVALID) const;
155 21 : inline void ProcessOneWqe(UdmaSqeWrite* sqe, UdmaSqOpcode opCode, const StreamLite& stream)
156 : {
157 : (void)stream;
158 21 : LaunchOneWqe(sqe, opCode);
159 21 : }
160 : void FillOneWqeWithNotify(
161 : const RmaBufSliceLite& loc, const RmtRmaBufSliceLite& rmt, const SqeConfigLite& cfg,
162 : UdmaSqeWriteWithNotify* sqe, const RmtRmaBufSliceLite& notify, u64 notifyData, u32 opCode,
163 : SlicePosition slicePos);
164 18 : inline void ProcessOneWqeWithNotify(UdmaSqeWriteWithNotify* sqe, u32 opCode, const StreamLite& stream)
165 : {
166 : (void)stream;
167 18 : LaunchOneWqeWithNotify(sqe, opCode);
168 16 : }
169 : void FillCommSqeReduceInfo(UdmaSqeCommon& sqeComm, ReduceOp reduceOp, DataType dataType, u32 udfType = 0) const;
170 : void FillOneSqeWrite(
171 : const RmaBufSliceLite& loc, const RmtRmaBufSliceLite& rmt, const SqeConfigLite& cfg, UdmaSqeWrite* sqe,
172 : UdmaSqOpcode opCode, SlicePosition slicePos);
173 : void MemorySetAndCopy(u8* va, u32 sqeSize, void* sqe);
174 :
175 : // 用于aicpu task cache或者WQE打印
176 : bool isTrackWqeTasks_{false};
177 : std::vector<WqeTask> wqeTasks_;
178 25 : inline void UpdateWqeTasks(UdmaSqeWrite& sqe)
179 : {
180 25 : if (isTrackWqeTasks_) {
181 0 : wqeTasks_.emplace_back(sqe);
182 : }
183 25 : }
184 16 : inline void UpdateWqeTasks(UdmaSqeWriteWithNotify& sqe)
185 : {
186 16 : if (isTrackWqeTasks_) {
187 0 : wqeTasks_.emplace_back(sqe);
188 : }
189 16 : }
190 : };
191 : } // namespace Hccl
192 :
193 : #endif // HCCLV2_UB_CONN_LITE_H_
|