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_CCU_CONNECTION_H
12 : #define HCCL_CCU_CONNECTION_H
13 :
14 : #include "ccu_jetty.h"
15 : #include "tp_manager.h"
16 : #include "orion_adapter_hccp.h"
17 : #include "ccu_device_manager.h"
18 :
19 : namespace Hccl {
20 :
21 600 : MAKE_ENUM(CcuConnStatus,
22 : INIT, // 初始化
23 : EXCHANGEABLE, // 可与对端交换
24 : CONNECTED, // 建链完成
25 : CONN_INVALID); // 链接错误
26 :
27 : class CcuConnection {
28 : public:
29 : CcuConnection(const IpAddress &locAddr, const IpAddress &rmtAddr,
30 : const CcuChannelInfo &channelInfo, const std::vector<CcuJetty *> &ccuJettys);
31 : CcuConnection(const CcuConnection &that) = delete;
32 : CcuConnection &operator=(const CcuConnection &other) = delete;
33 : ~CcuConnection();
34 :
35 : // 用于建链过程CcuTransport调用
36 : HcclResult Init();
37 : CcuConnStatus GetStatus();
38 : void Serialize(std::vector<char> &dtoData);
39 : void Deserialize(const std::vector<char> &dtoData);
40 : void ImportJetty();
41 :
42 : uint32_t GetChannelId() const;
43 : uint32_t GetDieId() const;
44 : int32_t GetDevLogicId() const;
45 0 : std::vector<CcuJetty *> GetCcuJettys() const
46 : {
47 0 : return ccuJettys_;
48 : }
49 : void Clean();
50 : std::vector<ConnJettyInfo> GetDeleteJettyInfo();
51 : std::vector<ConnJettyInfo> GetUnimportJettyInfo();
52 :
53 : protected:
54 : TpProtocol tpProtocol{TpProtocol::INVALID};
55 :
56 : private:
57 521 : MAKE_ENUM(InnerStatus,
58 : INIT, JETTY_CREATING, TP_INFO_GETTING,
59 : EXCHANGEABLE, JETTY_IMPORTING,
60 : CONNECTED,
61 : CONN_INVALID);
62 :
63 : struct ImportJettyCtx {
64 : // 保存对端的key,传递数据结构时不需要整个copy
65 : u8 remoteQpKey[HRT_UB_QP_KEY_MAX_LEN]{0};
66 : HrtRaUbJettyImportedInParam inParam{};
67 : HrtRaUbJettyImportedOutParam outParam{};
68 : };
69 :
70 : CcuConnStatus status{CcuConnStatus::CONN_INVALID};
71 : InnerStatus innerStatus{InnerStatus::CONN_INVALID};
72 : bool isJettyCreated{false};
73 : bool isJettyImported{false};
74 :
75 : IpAddress locAddr_{};
76 : IpAddress rmtAddr_{};
77 : CcuChannelInfo channelInfo_{};
78 : std::vector<CcuJetty *> ccuJettys_;
79 :
80 : int32_t devLogicId{0};
81 : uint32_t dieId{0};
82 : uint32_t funcId{0};
83 : RdmaHandle rdmaHandle{nullptr};
84 : uint32_t jettyNum{0};
85 :
86 : // 通过ccu comp 获取 ccu buffer信息
87 : uint64_t ccuBufAddr{0};
88 : uint32_t ccuBufTokenId{0};
89 : uint32_t ccuBufTokenValue{0};
90 :
91 : vector<ImportJettyCtx> importJettyCtxs; // 记录import jetty相关信息
92 : JettyImportCfg jettyImportCfg{}; // import配置信息,因复用TpHandle只需一份
93 :
94 : // 交换后获取对端ccu buffer信息
95 : uint64_t rmtCcuBufAddr{0};
96 : uint32_t rmtCcuBufTokenId{0};
97 : uint32_t rmtCcuBufTokenValue{0};
98 :
99 : // 感知tp获取tp handle,import jetty后urma提供tpn
100 : TpInfo tpInfo{};
101 :
102 : // 异步import上下文信息
103 : vector<RequestHandle> reqHandles;
104 : vector<vector<char_t>> reqDataBuffers;
105 : vector<void*> remoteJettyHandlePtrs;
106 :
107 : HcclResult StatusMachine();
108 : void UpdateInitStatus();
109 : void UpdateExchangeStatus();
110 :
111 : HcclResult GetLocalCcuRmaBufferInfo();
112 : bool CreateJetty();
113 : bool GetTpInfo();
114 : void GenerateLocalPsn();
115 : void ResetRequestCtxs();
116 : HcclResult StartImportJettyRequest(uint32_t jettyIndex, RequestHandle &reqHandle);
117 : bool CheckRequestResults();
118 : void ConfigChannel();
119 : HcclResult ReleaseConnRes();
120 : void ThrowAbnormalStatus(const std::string &funcName);
121 : std::string Describe();
122 : };
123 :
124 : class CcuTpConnection : public CcuConnection {
125 : public:
126 : CcuTpConnection(const IpAddress &locAddr, const IpAddress &rmtAddr,
127 : const CcuChannelInfo &channelInfo, const std::vector<CcuJetty *> &ccuJettys);
128 : };
129 :
130 : class CcuCtpConnection : public CcuConnection {
131 : public:
132 : CcuCtpConnection(const IpAddress &locAddr, const IpAddress &rmtAddr,
133 : const CcuChannelInfo &channelInfo, const std::vector<CcuJetty *> &ccuJettys);
134 : };
135 :
136 : } // namespace Hccl
137 : #endif // HCCL_CCU_CONNECTION_H
|