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-07-28 12:11:00 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));
      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          325 :     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              :     IpAddress    locIpv4Addr{};
     115              :     IpAddress    rmtIpv4Addr{};
     116              :     u32          tokenValue{GetUbToken()};
     117              :     Eid          rmtEid{};
     118              :     Eid          locEid{};
     119              :     u8           qos_{static_cast<u8>(UB_QOS_DEFAULT)}; // 业务 QoS,GetTpInfo / ReleaseTpInfo 缓存键
     120              : 
     121              :     bool         devUsed_{false};
     122              : 
     123              :     int32_t   devLogicId{0};
     124              :     u32       dieId{0};
     125              :     u32       funcId{0};
     126              :     JfcHandle jfcHandle{0};
     127              :     u32       sqDepth{0};
     128              :     uint64_t  sqBuffVa{0};
     129              : 
     130              :     RequestHandle  reqHandle{0};
     131              :     vector<char_t> reqDataBuffer;
     132              : 
     133              :     u8             remoteQpKey[HRT_UB_QP_KEY_MAX_LEN] = {0};
     134              :     u32            keySize{0};
     135              :     u32            remoteTokenValue{0};
     136              :     JettyImportCfg jettyImportCfg{};
     137              :     void          *remoteJettyHandlePtr{nullptr};
     138              : 
     139              :     JettyHandle jettyHandle{0};
     140              :     void       *jettyHandlePtr{nullptr};
     141              :     JettyHandle remoteJettyHandle{0};
     142              :     u8          localQpKey[HRT_UB_QP_KEY_MAX_LEN]{0};
     143              : 
     144              :     u32 jettyId{0};
     145              :     u64 dbAddr{0};
     146              :     u32 tpn{0};
     147              : 
     148              :     u32                 localTpnStart{0};
     149              :     u32                 localTpNum{0};
     150              :     TpInfo              tpInfo{};
     151              : 
     152              :     u32 piVal{0};
     153              :     u32 ciVal{0};
     154              : 
     155              :     CqCreateInfo cqInfo_{0};
     156              : 
     157              :     bool isdevUsed{false};
     158              : 
     159              :     // 最大传输size,切片使用
     160              :     u32 maxReadSize{0};
     161              :     u32 maxWriteSize{0};
     162              : 
     163              :     bool CheckRequestResult();
     164              :     void ThrowAbnormalStatus(std::string funcName);
     165              :     void AdvanceUbConnFromInit();
     166              :     void AdvanceUbConnFromTpInfoGetting();
     167              :     void AdvanceUbConnAfterTpInfoReady();
     168              :     void AdvanceUbConnFromJettyCreating();
     169              :     void AdvanceUbConnFromJettyCreated();
     170              :     void AdvanceUbConnFromJettyImporting();
     171              : 
     172              :     void         GenerateLocalPsn();
     173              :     void         CreateJetty(const bool devUsed);
     174              :     void         SetJettyInfo();
     175              :     bool         GetTpInfo();
     176              :     void         UpdateLocTpInfo();
     177              :     TpInfo       SelectTpInfo();
     178              :     void         ImportJetty();
     179              :     void         SetImportInfo();
     180              :     void         UnImportJetty();
     181              :     void         DestroyJetty();
     182              :     void         ReleaseResource();
     183              : 
     184              :     void ProcessSlices(const MemoryBuffer &loc, const MemoryBuffer &rmt,
     185              :                        std::function<void(const MemoryBuffer &, const MemoryBuffer &, u32)> processOneSlice,
     186            4 :                        DataType dataType = DataType::INVALID) const;
     187              : 
     188              :     void ProcessSlicesWithNotify(const MemoryBuffer &loc, const MemoryBuffer &rmt,
     189              :                                  std::function<void(const MemoryBuffer &, const MemoryBuffer &, u32)> processOneSlice,
     190              :                                  std::function<void(const MemoryBuffer &, const MemoryBuffer &)> processOneSliceWithNotify,
     191            2 :                                  DataType dataType = DataType::INVALID) const;
     192              :     
     193              :     std::unique_ptr<BaseTask> ConstructTaskUbSend(const HrtRaUbSendWrRespParam &sendWrResp, const SqeConfig &config);
     194              :     void                      UpdateCiVal(u32 ci);
     195              :     HcclResult                CalcTotalTimeout(uint32_t &outTotalTimeoutMs);
     196              : };
     197              : 
     198              : class DevUbTpConnection : public DevUbConnection {
     199              : public:
     200              :     DevUbTpConnection(const RdmaHandle rdmaHandle, const IpAddress &locAddr, const IpAddress &rmtAddr,
     201            2 :                       const OpMode opMode, const bool devUsed = false, const HrtUbJfcMode jfcMode = HrtUbJfcMode::STARS_POLL,
     202              :                       const IpAddress &locIpv4Addr = IpAddress(), const IpAddress &rmtIpv4Addr = IpAddress(),
     203              :                       u8 qos = static_cast<u8>(UB_QOS_DEFAULT));
     204              : };
     205              : 
     206              : class DevUbCtpConnection : public DevUbConnection {
     207              : public:
     208              :     DevUbCtpConnection(const RdmaHandle rdmaHandle, const IpAddress &locAddr, const IpAddress &rmtAddr,
     209           36 :                        const OpMode opMode, const bool devUsed = false, const HrtUbJfcMode jfcMode = HrtUbJfcMode::STARS_POLL,
     210              :                        const IpAddress &locIpv4Addr = IpAddress(), const IpAddress &rmtIpv4Addr = IpAddress(),
     211              :                        u8 qos = static_cast<u8>(UB_QOS_DEFAULT));
     212              : };
     213              : 
     214              : class DevUbUboeConnection : public DevUbConnection {
     215              : public:
     216              :     DevUbUboeConnection(const RdmaHandle rdmaHandle, const IpAddress &locAddr, const IpAddress &rmtAddr,
     217              :                         const OpMode opMode, const bool devUsed = false, const HrtUbJfcMode jfcMode = HrtUbJfcMode::STARS_POLL,
     218              :                         const IpAddress &locIpv4Addr = IpAddress(), const IpAddress &rmtIpv4Addr = IpAddress(),
     219              :                         u8 qos = static_cast<u8>(UB_QOS_DEFAULT));
     220              : };
     221              : 
     222              : class DevUbUbgConnection : public DevUbConnection {
     223              : public:
     224              :     DevUbUbgConnection(const RdmaHandle rdmaHandle, const IpAddress &locAddr, const IpAddress &rmtAddr,
     225              :                        const OpMode opMode, const bool devUsed = false, const HrtUbJfcMode jfcMode = HrtUbJfcMode::STARS_POLL,
     226              :                        const IpAddress &locAddrEid = IpAddress(), const IpAddress &rmtAddrEid = IpAddress());
     227              : };
     228              : 
     229              : std::vector<DevUbConnection *> GetStarsPollUbConns(const std::vector<RmaConnection *> &rmaConns);
     230              : 
     231              : bool IfNeedUpdatingUbCi(const std::vector<DevUbConnection *> &ubConns);
     232              : 
     233              : } // namespace Hccl
     234              : 
     235              : #endif // HCCLV2_DEV_UB_CONNECTION_H
        

Generated by: LCOV version 2.0-1