LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/ccu_transport - ccu_connection.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 66.7 % 3 2
Test Date: 2026-08-18 17:47:01 Functions: 84.6 % 13 11

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

Generated by: LCOV version 2.0-1