LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/connection - dev_ub_connection.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 6 6
Test Date: 2026-08-04 10:52:23 Functions: 85.7 % 7 6

            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_DEV_UB_CONNECTION_H
      12              : #define HCCLV2_DEV_UB_CONNECTION_H
      13              : 
      14              : #include "rma_connection.h"
      15              : #include "op_mode.h"
      16              : #include "orion_adapter_hccp.h"
      17              : #include "../../../framework/env_config/env_config.h"
      18              : #include "tp_manager.h"
      19              : #include "local_ub_rma_buffer.h"
      20              : #include "stream.h"
      21              : #include "task.h"
      22              : #include "mc2_type.h"
      23              : #include "hcomm/hcomm_res_entity_defs.h"
      24              : 
      25              : namespace Hccl {
      26              : 
      27              : class DevUbConnection : public RmaConnection {
      28              : public:
      29              :     DevUbConnection(const RdmaHandle rdmaHandle, const IpAddress &locAddr, const IpAddress &rmtAddr,
      30           99 :                     const OpMode opMode, const bool devUsed = false, const HrtUbJfcMode jfcMode = HrtUbJfcMode::STARS_POLL,
      31              :                     const IpAddress &locIpv4Addr = IpAddress(), const IpAddress &rmtIpv4Addr = IpAddress(),
      32              :                     u8 qos = static_cast<u8>(UB_QOS_DEFAULT), CommEngine engine = COMM_ENGINE_RESERVED);
      33              :     void          Connect() override;
      34              :     RmaConnStatus GetStatus() override;
      35              :     bool          Suspend() override;
      36              : 
      37              :     std::unique_ptr<Serializable> GetExchangeDto() override;
      38              :     void                          ParseRmtExchangeDto(const Serializable &rmtDto) override;
      39              :     void                          ImportRmtDto() override;
      40              : 
      41              :     std::vector<char> GetUniqueId() const override;
      42              : 
      43              :     void SetCqInfo(HcclAiRMACQ &cq) const;
      44              :          
      45              :         void SetWqInfo(HcclAiRMAWQ &wq) const;
      46              :     
      47              :     void SetCqContextInfo(CqContext &cq) const;
      48              :     void SetSqContextInfo(SqContext &sq) const;
      49              : 
      50              :     unique_ptr<BaseTask> PrepareRead(const MemoryBuffer &remoteMemBuf, const MemoryBuffer &localMemBuf,
      51              :                                      const SqeConfig &config) override;
      52              : 
      53              :     unique_ptr<BaseTask> PrepareReadReduce(const MemoryBuffer &remoteMemBuf, const MemoryBuffer &localMemBuf,
      54              :                                            DataType dataType, ReduceOp reduceOp, const SqeConfig &config) override;
      55              : 
      56              :     unique_ptr<BaseTask> PrepareWrite(const MemoryBuffer &remoteMemBuf, const MemoryBuffer &localMemBuf,
      57              :                                       const SqeConfig &config) override;
      58              : 
      59              :     unique_ptr<BaseTask> PrepareWriteReduce(const MemoryBuffer &remoteMemBuf, const MemoryBuffer &localMemBuf,
      60              :                                             DataType dataType, ReduceOp reduceOp, const SqeConfig &config) override;
      61              : 
      62              :     unique_ptr<BaseTask> PrepareInlineWrite(const MemoryBuffer &remoteMemBuf, u64 data,
      63              :                                             const SqeConfig &config) override;
      64              : 
      65              :     unique_ptr<BaseTask> PrepareWriteWithNotify(const MemoryBuffer &remoteMemBuf, const MemoryBuffer &localMemBuf,
      66              :                                                 u64 data, const MemoryBuffer &remoteNotifyMemBuf,
      67              :                                                 const SqeConfig &config) override;
      68              : 
      69              :     unique_ptr<BaseTask> PrepareWriteReduceWithNotify(const MemoryBuffer &remoteMemBuf, const MemoryBuffer &localMemBuf,
      70              :                                                       DataType dataType, ReduceOp reduceOp, u64 data,
      71              :                                                       const MemoryBuffer &remoteNotifyMemBuf,
      72              :                                                       const SqeConfig    &config) override;
      73              : 
      74              :     class UbCiUpdater;
      75              : 
      76              :     void AddNop(const Stream &stream) override;
      77              : 
      78              :     void         ReleaseTp();
      79              :     ~DevUbConnection() override;
      80              : 
      81              :     string Describe() const override;
      82              :     HcclResult Describe(std::string &dfxMsg) override;
      83              : 
      84              :     HrtUbJfcMode GetUbJfcMode() const;
      85              :     JettyHandle& GetJettyHandle();
      86              :     JettyHandle& GetRemoteJettyHandle();
      87              :     RdmaHandle&  GetRdmaHandle();
      88              :     u32          GetPiVal() const;
      89              :     u32          GetCiVal() const;
      90              :     u32          GetSqDepth() const;
      91              : 
      92              :     void SetMaxReadSize(u32 value);
      93              :     void SetMaxWriteSize(u32 value);
      94              : 
      95              : protected:
      96              :     TpProtocol     tpProtocol{TpProtocol::INVALID};
      97              :     void           GetTimeOut();
      98              :     u8             jettyTimeOut{8};
      99              : 
     100              : private:
     101          327 :     MAKE_ENUM(UbConnStatus,
     102              :         INIT, TP_INFO_GETTING, JETTY_CREATING, JETTY_CREATED,
     103              :         JETTY_IMPORTING,
     104              :         READY,
     105              :         CONN_INVALID);
     106              : 
     107              :     UbConnStatus ubConnStatus{UbConnStatus::INIT};
     108              : 
     109              :     RdmaHandle   rdmaHandle{nullptr};
     110              :     IpAddress    locAddr{};
     111              :     IpAddress    rmtAddr{};
     112              :     OpMode       opMode{OpMode::OPBASE};
     113              :     HrtUbJfcMode jfcMode{HrtUbJfcMode::STARS_POLL};
     114              :     CommEngine   engine_{COMM_ENGINE_RESERVED};
     115              :     IpAddress    locIpv4Addr{};
     116              :     IpAddress    rmtIpv4Addr{};
     117              :     u32          tokenValue{GetUbToken()};
     118              :     Eid          rmtEid{};
     119              :     Eid          locEid{};
     120              :     u8           qos_{static_cast<u8>(UB_QOS_DEFAULT)}; // 业务 QoS,GetTpInfo / ReleaseTpInfo 缓存键
     121              : 
     122              :     bool         devUsed_{false};
     123              : 
     124              :     int32_t   devLogicId{0};
     125              :     u32       dieId{0};
     126              :     u32       funcId{0};
     127              :     JfcHandle jfcHandle{0};
     128              :     u32       sqDepth{0};
     129              :     uint64_t  sqBuffVa{0};
     130              : 
     131              :     RequestHandle  reqHandle{0};
     132              :     vector<char_t> reqDataBuffer;
     133              : 
     134              :     u8             remoteQpKey[HRT_UB_QP_KEY_MAX_LEN] = {0};
     135              :     u32            keySize{0};
     136              :     u32            remoteTokenValue{0};
     137              :     JettyImportCfg jettyImportCfg{};
     138              :     void          *remoteJettyHandlePtr{nullptr};
     139              : 
     140              :     JettyHandle jettyHandle{0};
     141              :     void       *jettyHandlePtr{nullptr};
     142              :     JettyHandle remoteJettyHandle{0};
     143              :     u8          localQpKey[HRT_UB_QP_KEY_MAX_LEN]{0};
     144              : 
     145              :     u32 jettyId{0};
     146              :     u64 dbAddr{0};
     147              :     u32 tpn{0};
     148              : 
     149              :     u32                 localTpnStart{0};
     150              :     u32                 localTpNum{0};
     151              :     TpInfo              tpInfo{};
     152              : 
     153              :     u32 piVal{0};
     154              :     u32 ciVal{0};
     155              : 
     156              :     CqCreateInfo cqInfo_{0};
     157              : 
     158              :     bool isdevUsed{false};
     159              : 
     160              :     // 最大传输size,切片使用
     161              :     u32 maxReadSize{0};
     162              :     u32 maxWriteSize{0};
     163              : 
     164              :     bool CheckRequestResult();
     165              :     void ThrowAbnormalStatus(std::string funcName);
     166              :     void AdvanceUbConnFromInit();
     167              :     void AdvanceUbConnFromTpInfoGetting();
     168              :     void AdvanceUbConnAfterTpInfoReady();
     169              :     void AdvanceUbConnFromJettyCreating();
     170              :     void AdvanceUbConnFromJettyCreated();
     171              :     void AdvanceUbConnFromJettyImporting();
     172              : 
     173              :     void         GenerateLocalPsn();
     174              :     void         CreateJetty(const bool devUsed);
     175              :     void         CreateAivUrmaJfc();
     176              :     void         SetJettyInfo();
     177              :     bool         GetTpInfo();
     178              :     void         UpdateLocTpInfo();
     179              :     TpInfo       SelectTpInfo();
     180              :     void         ImportJetty();
     181              :     void         SetImportInfo();
     182              :     void         UnImportJetty();
     183              :     void         DestroyJetty();
     184              :     void         ReleaseResource();
     185              : 
     186              :     void ProcessSlices(const MemoryBuffer &loc, const MemoryBuffer &rmt,
     187              :                        std::function<void(const MemoryBuffer &, const MemoryBuffer &, u32)> processOneSlice,
     188            4 :                        DataType dataType = DataType::INVALID) const;
     189              : 
     190              :     void ProcessSlicesWithNotify(const MemoryBuffer &loc, const MemoryBuffer &rmt,
     191              :                                  std::function<void(const MemoryBuffer &, const MemoryBuffer &, u32)> processOneSlice,
     192              :                                  std::function<void(const MemoryBuffer &, const MemoryBuffer &)> processOneSliceWithNotify,
     193            2 :                                  DataType dataType = DataType::INVALID) const;
     194              :     
     195              :     std::unique_ptr<BaseTask> ConstructTaskUbSend(const HrtRaUbSendWrRespParam &sendWrResp, const SqeConfig &config);
     196              :     void                      UpdateCiVal(u32 ci);
     197              :     HcclResult                CalcTotalTimeout(uint32_t &outTotalTimeoutMs);
     198              : };
     199              : 
     200              : class DevUbTpConnection : public DevUbConnection {
     201              : public:
     202              :     DevUbTpConnection(const RdmaHandle rdmaHandle, const IpAddress &locAddr, const IpAddress &rmtAddr,
     203            2 :                       const OpMode opMode, const bool devUsed = false, const HrtUbJfcMode jfcMode = HrtUbJfcMode::STARS_POLL,
     204              :                       const IpAddress &locIpv4Addr = IpAddress(), const IpAddress &rmtIpv4Addr = IpAddress(),
     205              :                       u8 qos = static_cast<u8>(UB_QOS_DEFAULT), CommEngine engine = COMM_ENGINE_RESERVED);
     206              : };
     207              : 
     208              : class DevUbCtpConnection : public DevUbConnection {
     209              : public:
     210              :     DevUbCtpConnection(const RdmaHandle rdmaHandle, const IpAddress &locAddr, const IpAddress &rmtAddr,
     211           36 :                        const OpMode opMode, const bool devUsed = false, const HrtUbJfcMode jfcMode = HrtUbJfcMode::STARS_POLL,
     212              :                        const IpAddress &locIpv4Addr = IpAddress(), const IpAddress &rmtIpv4Addr = IpAddress(),
     213              :                        u8 qos = static_cast<u8>(UB_QOS_DEFAULT), CommEngine engine = COMM_ENGINE_RESERVED);
     214              : };
     215              : 
     216              : class DevUbUboeConnection : public DevUbConnection {
     217              : public:
     218              :     DevUbUboeConnection(const RdmaHandle rdmaHandle, const IpAddress &locAddr, const IpAddress &rmtAddr,
     219              :                         const OpMode opMode, const bool devUsed = false, const HrtUbJfcMode jfcMode = HrtUbJfcMode::STARS_POLL,
     220              :                         const IpAddress &locIpv4Addr = IpAddress(), const IpAddress &rmtIpv4Addr = IpAddress(),
     221              :                         u8 qos = static_cast<u8>(UB_QOS_DEFAULT), CommEngine engine = COMM_ENGINE_RESERVED);
     222              : };
     223              : 
     224              : class DevUbUbgConnection : public DevUbConnection {
     225              : public:
     226              :     DevUbUbgConnection(const RdmaHandle rdmaHandle, const IpAddress &locAddr, const IpAddress &rmtAddr,
     227              :                        const OpMode opMode, const bool devUsed = false, const HrtUbJfcMode jfcMode = HrtUbJfcMode::STARS_POLL,
     228              :                        const IpAddress &locAddrEid = IpAddress(), const IpAddress &rmtAddrEid = IpAddress(),
     229              :                        CommEngine engine = COMM_ENGINE_RESERVED);
     230              : };
     231              : 
     232              : std::vector<DevUbConnection *> GetStarsPollUbConns(const std::vector<RmaConnection *> &rmaConns);
     233              : 
     234              : bool IfNeedUpdatingUbCi(const std::vector<DevUbConnection *> &ubConns);
     235              : 
     236              : } // namespace Hccl
     237              : 
     238              : #endif // HCCLV2_DEV_UB_CONNECTION_H
        

Generated by: LCOV version 2.0-1