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 :
43 : u32 maxReadSize;
44 : u32 maxWriteSize;
45 :
46 : UbConnLiteParam(std::vector<char> &uniqueId);
47 :
48 : std::string Describe() const;
49 : };
50 :
51 : class UbConnLite : public RmaConnLite {
52 : public:
53 : UbConnLite(const UbJettyLiteId &id, const UbJettyLiteAttr &attr, const Eid &rmtInfo);
54 :
55 : explicit UbConnLite(const UbConnLiteParam &liteParam);
56 :
57 : std::string Describe() final;
58 :
59 : void FillCommSqe(UdmaSqeCommon *sqe, const RmtRmaBufSliceLite &rmt, const SqeConfigLite &cfg, u32 opCode,
60 : SlicePosition slicePos = SlicePosition::ONLY);
61 :
62 : void Read(const RmaBufSliceLite &loc, const RmtRmaBufSliceLite &rmt, const SqeConfigLite &cfg,
63 : const StreamLite &stream, ConnLiteOperationOut &out) override;
64 :
65 : void ReadReduce(ReduceIn reduceIn, const RmaBufSliceLite &loc, const RmtRmaBufSliceLite &rmt,
66 : const StreamLite &stream, const SqeConfigLite &cfg, ConnLiteOperationOut &out) override;
67 :
68 : void Write(const RmaBufSliceLite &loc, const RmtRmaBufSliceLite &rmt, const SqeConfigLite &cfg,
69 : const StreamLite &stream, ConnLiteOperationOut &out) override;
70 :
71 : void InlineWrite(const u8 *data, u16 size, const RmtRmaBufSliceLite &rmt, const SqeConfigLite &cfg,
72 : const StreamLite &stream, ConnLiteOperationOut &out) override;
73 :
74 : void WriteReduce(DataType dataType, ReduceOp reduceOp, const RmaBufSliceLite &loc, const StreamLite &stream,
75 : const RmtRmaBufSliceLite &rmt, const SqeConfigLite &cfg, ConnLiteOperationOut &out) override;
76 :
77 : void FillNotifySqe(struct UdmaSqeNotify *sqe, const RmtRmaBufSliceLite ¬ify, u64 notifyData) const;
78 : void FillLocalSgeSqe(UdmaNormalSge *sqe, const RmaBufSliceLite &loc) const;
79 :
80 : void WriteWithNotify(const RmaBufSliceLite &loc, const RmtRmaBufSliceLite &rmt, const SqeConfigLite &cfg,
81 : ConnLiteOperationOut &out, const RmtRmaBufSliceLite ¬ify, const StreamLite &stream,
82 : u64 notifyData) override;
83 :
84 : void WriteReduceWithNotify(DataType dataType, ReduceOp reduceOp, const RmaBufSliceLite &loc,
85 : const RmtRmaBufSliceLite &rmt, const SqeConfigLite &cfg, const StreamLite &stream,
86 : ConnLiteOperationOut &out, const RmtRmaBufSliceLite ¬ify, u64 notifyData) override;
87 :
88 : void CustomizeSqeByOneSidedComm(UdmaSqeCommon *sqe, bool isLastWqe) const;
89 :
90 : void FillBatchOneWqe(const RmaBufSliceLite &loc, const RmtRmaBufSliceLite &rmt, const SqeConfigLite &cfg,
91 : bool isLastWqe, u32 opCode, const StreamLite &stream);
92 :
93 : void BatchProcessOneSlice(const RmaBufSliceLite &loc, const RmtRmaBufSliceLite &rmt, const SqeConfigLite &cfg,
94 : u32 maxSliceSize, bool isLastSlice, u32 opCode, const StreamLite &stream);
95 :
96 : void BatchCommDataProcess(const vector<RmaBufSliceLite> &loc, const vector<RmtRmaBufSliceLite> &rmt,
97 : const SqeConfigLite &cfg, u32 maxSliceSize, u32 opCode, const StreamLite &stream);
98 :
99 : void BatchOneSidedRead(const vector<RmaBufSliceLite> &loc, const vector<RmtRmaBufSliceLite> &rmt,
100 : const SqeConfigLite &cfg, const StreamLite &stream, ConnLiteOperationOut &out) override;
101 : void BatchOneSidedWrite(const vector<RmaBufSliceLite> &loc, const vector<RmtRmaBufSliceLite> &rmt,
102 : const SqeConfigLite &cfg, const StreamLite &stream, ConnLiteOperationOut &out) override;
103 : private:
104 : u16 pi{0};
105 : u16 ci{0};
106 : u32 piDetourCount{0};
107 : u32 ciDetourCount{0};
108 : u32 maxReadSize{0};
109 : u32 maxWriteSize{0};
110 : void ProcessSlices(const RmaBufSliceLite &loc, const RmtRmaBufSliceLite &rmt, u32 maxSliceSize,
111 : std::function<void(const RmaBufSliceLite &, const RmtRmaBufSliceLite &, SlicePosition)> processOneSlice,
112 6 : DataType dataType = DataType::INVALID) const;
113 : void ProcessSlicesWithNotify(
114 : const RmaBufSliceLite &loc, const RmtRmaBufSliceLite &rmt, u32 maxSliceSize,
115 : std::function<void(const RmaBufSliceLite &, const RmtRmaBufSliceLite &, SlicePosition)> processOneSlice,
116 : std::function<void(const RmaBufSliceLite &, const RmtRmaBufSliceLite &, SlicePosition)> processOneSliceWithNotify,
117 6 : DataType dataType = DataType::INVALID) const;
118 : void ProcessOneWqe(UdmaSqeWrite *sqe, UdmaSqOpcode opCode, const StreamLite &stream);
119 : void ProcessOneWqeWithNotify(const RmaBufSliceLite &loc, const RmtRmaBufSliceLite &rmt, const SqeConfigLite &cfg,
120 : UdmaSqeWriteWithNotify *sqe, const RmtRmaBufSliceLite ¬ify, u64 notifyData,
121 : u32 opCode, SlicePosition slicePos, const StreamLite &stream);
122 : void FillCommSqeReduceInfo(UdmaSqeCommon &sqeComm, ReduceOp reduceOp, DataType dataType, u32 udfType = 0) const;
123 : void FillOneSqeWrite(const RmaBufSliceLite &loc, const RmtRmaBufSliceLite &rmt, const SqeConfigLite &cfg,
124 : UdmaSqeWrite *sqe, UdmaSqOpcode opCode, SlicePosition slicePos);
125 : void MemorySetAndCopy(u8 *va, u32 sqeSize, void *sqe);
126 : };
127 : } // namespace Hccl
128 :
129 : #endif // HCCLV2_UB_CONN_LITE_H_
|