Line data Source code
1 : /**
2 : * Copyright (c) 2026 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 ROCE_TRANSPORT_LITE_IMPL_H
12 : #define ROCE_TRANSPORT_LITE_IMPL_H
13 :
14 : #include <vector>
15 : #include <memory>
16 : #include "base_transport_lite_impl.h"
17 : #include "notify_lite.h"
18 : #include "rma_buffer_lite.h"
19 : #include "rmt_rma_buffer_lite.h"
20 : #include "rdma_conn_lite_v2.h"
21 :
22 : namespace Hccl {
23 :
24 : class RoceTransportLiteImpl : public BaseTransportLiteImpl {
25 : public:
26 : explicit RoceTransportLiteImpl(std::vector<char>& uniqueId);
27 0 : RoceTransportLiteImpl() = default;
28 : ~RoceTransportLiteImpl() override;
29 :
30 : void Init(std::vector<char>& uniqueId);
31 :
32 : std::string Describe() const override;
33 :
34 : // ========== Buffer 构造接口 ==========
35 : HcclResult BuildLocRmaBufferLite(const uintptr_t addr, const size_t size, RmaBufferLite& rmaBufferLite) override;
36 :
37 : // ========== RMA 数据传输接口 ==========
38 : void Read(const RmaBufferLite& loc, const Buffer& rmt, const StreamLite& stream) override;
39 : void Write(const RmaBufferLite& loc, const Buffer& rmt, const StreamLite& stream) override;
40 : void WriteReduce(
41 : const RmaBufferLite& loc, const Buffer& rmt, const ReduceIn& reduceIn, const StreamLite& stream) override;
42 : void WriteWithNotify(
43 : const RmaBufferLite& loc, const Buffer& rmt, const WithNotifyIn& withNotify, const StreamLite& stream) override;
44 : void WriteReduceWithNotify(
45 : const RmaBufferLite& loc, const Buffer& rmt, const ReduceIn& reduceIn, const WithNotifyIn& withNotify,
46 : const StreamLite& stream) override;
47 :
48 : // ========== 同步 / Notify 接口 ==========
49 : HcclResult Fence() override;
50 : void Post(u32 index, const StreamLite& stream) override;
51 : void WaitWithTimeout(u32 index, const StreamLite& stream, u32 timeout) override;
52 :
53 : // ========== 错误上报 接口 ==========
54 : HcclResult PollCq(int32_t numEntries, int32_t timeOut, std::vector<int32_t>& errList);
55 :
56 : // 设置TaskException开关
57 : void SetTaskExceptionEnable(bool flag) { taskExceptionEnable_ = flag; }
58 :
59 : private:
60 : u32 notifyNum_{0};
61 : u32 bufferNum_{0};
62 : u32 connNum_{0};
63 :
64 : bool fence_{false};
65 : bool taskExceptionEnable_{true};
66 :
67 : std::vector<std::unique_ptr<NotifyLite>> localNotifies_{};
68 : std::vector<RmtRmaBufferLite> remoteNotifies_{};
69 : std::vector<RmaBufferLite> locBufferVec_{};
70 : std::vector<RmtRmaBufferLite> rmtBufferVec_{};
71 : std::vector<std::vector<char>> connUniqueIdVec_{};
72 : std::vector<std::unique_ptr<RdmaConnLiteV2>> connVec_{};
73 : std::unique_ptr<RmaBufferLite> notifyValueBuffer_{};
74 :
75 : RmaBufSliceLite GetRmaBufSlicelite(const RmaBufferLite& lite) const;
76 : RmaBufSliceLite GetNotifySlicelite(u32 index) const;
77 : RmtRmaBufSliceLite GetRmtRmaBufSliceLite(const Buffer& rmtBuf) const;
78 : RmtRmaBufSliceLite GetRmtNotifySliceLite(u32 index) const;
79 : void SetFenceConfig(SqeConfigLite& cfg);
80 :
81 : void ParseLocNotifyVec(std::vector<char>& data);
82 : void ParseRmtNotifyVec(std::vector<char>& data);
83 : void ParseNotifyValueBuffer(std::vector<char>& data);
84 : void ParseLocBufferVec(std::vector<char>& data);
85 : void ParseRmtBufferVec(std::vector<char>& data);
86 : void ParseConnVec(std::vector<char>& data);
87 :
88 : // ========== 底层 Task 构造接口(rtsq) ==========
89 : void BuildRdmaDbSendTask(const StreamLite& stream, u64 remoteAddr, u64 dbValue) const;
90 : void BuildNotifyWaitTask(u32 notifyId, const StreamLite& stream, u32 timeout) const;
91 :
92 : // ========== Profiling接口 ==========
93 : void ReportDmaTask(
94 : const void* src, const void* dst, u64 size, const StreamLite& stream, u32 taskId, TaskParamType taskType,
95 : DmaOp dmaOp, u64 notifyId, u32 notifyValue, const char* funcName);
96 : void ReportReduceTask(
97 : const void* src, const void* dst, u64 size, const ReduceIn& reduceIn, const StreamLite& stream, u32 taskId,
98 : TaskParamType taskType, u64 notifyId, u32 notifyValue, const char* funcName);
99 : void ReportNotifyWaitTask(u64 notifyId, const StreamLite& stream, u32 taskId);
100 : bool IsReportTask();
101 : };
102 :
103 : } // namespace Hccl
104 : #endif
|