LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/connection - host_ub_connection.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 4 4
Test Date: 2026-07-28 12:11:00 Functions: 85.7 % 7 6

            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 HCCLV2_HOST_UB_CONNECTION_H
      12              : #define HCCLV2_HOST_UB_CONNECTION_H
      13              : 
      14              : #include "rma_connection.h"
      15              : #include "op_mode.h"
      16              : #include "orion_adapter_hccp.h"
      17              : #include "tp_manager.h"
      18              : #include "local_ub_rma_buffer.h"
      19              : #include "stream.h"
      20              : #include "task.h"
      21              : #include "mc2_type.h"
      22              : #include "env_config/env_config.h"
      23              : 
      24              : namespace Hccl {
      25              : 
      26              : class HostUbConnection : public RmaConnection {
      27              : public:
      28              :     HostUbConnection(const RdmaHandle rdmaHandle, const IpAddress &locAddr, const IpAddress &rmtAddr,
      29           32 :                     const OpMode opMode, const HrtUbJfcMode jfcMode = HrtUbJfcMode::NORMAL,
      30              :                     u8 qos = static_cast<u8>(UB_QOS_DEFAULT));
      31              :     void          Connect() override;
      32              :     RmaConnStatus GetStatus() override;
      33              :     bool          Suspend() override;
      34              : 
      35              :     std::unique_ptr<Serializable> GetExchangeDto() override;
      36              :     void                          ParseRmtExchangeDto(const Serializable &rmtDto) override;
      37              :     void                          ImportRmtDto() override;
      38              : 
      39              :     std::vector<char> GetUniqueId() const override;
      40              : 
      41              :     void SetCqInfo(HcclAiRMACQ &cq);
      42              : 
      43              :     void SetWqInfo(HcclAiRMAWQ &wq);
      44              : 
      45              :     unique_ptr<BaseTask> PrepareRead(const MemoryBuffer &remoteMemBuf, const MemoryBuffer &localMemBuf,
      46              :                                     const SqeConfig &config) override;
      47              : 
      48              :     unique_ptr<BaseTask> PrepareReadReduce(const MemoryBuffer &remoteMemBuf, const MemoryBuffer &localMemBuf,
      49              :                                         DataType dataType, ReduceOp reduceOp, const SqeConfig &config) override;
      50              : 
      51              :     unique_ptr<BaseTask> PrepareWrite(const MemoryBuffer &remoteMemBuf, const MemoryBuffer &localMemBuf,
      52              :                                     const SqeConfig &config) override;
      53              : 
      54              :     unique_ptr<BaseTask> PrepareWriteReduce(const MemoryBuffer &remoteMemBuf, const MemoryBuffer &localMemBuf,
      55              :                                             DataType dataType, ReduceOp reduceOp, const SqeConfig &config) override;
      56              : 
      57              :     unique_ptr<BaseTask> PrepareInlineWrite(const MemoryBuffer &remoteMemBuf, u64 data,
      58              :                                             const SqeConfig &config) override;
      59              : 
      60              :     class UbCiUpdater;
      61              : 
      62              :     void AddNop(const Stream &stream) override;
      63              : 
      64              :     void ReleaseTp();
      65              :     ~HostUbConnection() override;
      66              : 
      67              :     string Describe() const override;
      68              : 
      69              :     HrtUbJfcMode GetUbJfcMode() const;
      70              :     JettyHandle& GetJettyHandle();
      71              :     JettyHandle& GetRemoteJettyHandle();
      72              :     RdmaHandle&  GetRdmaHandle();
      73              :     u32          GetPiVal() const;
      74              :     u32          GetCiVal() const;
      75              :     u32          GetSqDepth() const;
      76              : 
      77              :     uint64_t GetCqVa() const;
      78              :     u64 GetJettyVa() const;
      79              :     JettyHandle GetTJettyVa() const;
      80              : 
      81              : protected:
      82              :     TpProtocol     tpProtocol{TpProtocol::INVALID};
      83              : 
      84              : private:
      85          160 :     MAKE_ENUM(UbConnStatus,
      86              :         INIT, TP_INFO_GETTING, JETTY_CREATED,
      87              :         JETTY_IMPORTING,
      88              :         READY,
      89              :         CONN_INVALID);
      90              : 
      91              :     UbConnStatus ubConnStatus{UbConnStatus::INIT};
      92              : 
      93              :     RdmaHandle   rdmaHandle{nullptr};
      94              :     IpAddress    locAddr{};
      95              :     IpAddress    rmtAddr{};
      96              :     OpMode       opMode{OpMode::OPBASE};
      97              :     HrtUbJfcMode jfcMode{HrtUbJfcMode::NORMAL}; //Peer模式只支持jfcMode为NORMAL类型
      98              :     u32          tokenValue{GetUbToken()};
      99              :     Eid          rmtEid{};
     100              :     Eid          locEid{};
     101              : 
     102              :     u32       dieId{0};
     103              :     u32       funcId{0};
     104              :     JfcHandle jfcHandle{0};
     105              :     u32       sqDepth{0};
     106              :     uint64_t  sqBuffVa{0};
     107              : 
     108              :     RequestHandle  reqHandle{0};
     109              :     vector<char_t> reqDataBuffer;
     110              :     HrtRaUbJettyCreatedOutParam repJetty_{};
     111              :     HrtRaUbJettyImportedOutParam remOutParam_{};
     112              : 
     113              :     u8             remoteQpKey[HRT_UB_QP_KEY_MAX_LEN] = {0};
     114              :     u32            keySize{0};
     115              :     u32            remoteTokenValue{0};
     116              :     JettyImportCfg jettyImportCfg{};
     117              : 
     118              :     JettyHandle jettyHandle_{0};
     119              :     u64         jettyVa_{0};
     120              :     void       *jettyHandlePtr{nullptr};
     121              :     JettyHandle remoteJettyVa_{0};
     122              :     TargetJettyHandle remoteJettyHandle_{0};
     123              :     u8          localQpKey[HRT_UB_QP_KEY_MAX_LEN]{0};
     124              : 
     125              :     u32 jettyId_{0};
     126              :     u64 dbAddr{0};
     127              :     u32 tpn{0};
     128              : 
     129              :     u32                 localTpnStart{0};
     130              :     u32                 localTpNum{0};
     131              :     TpInfo              tpInfo{};
     132              : 
     133              :     u8 qos_{static_cast<u8>(UB_QOS_DEFAULT)}; // 业务 QoS,GetTpInfo / ReleaseTpInfo 缓存键
     134              : 
     135              :     u32 piVal{0};
     136              :     u32 ciVal{0};
     137              : 
     138              :     CqCreateInfo cqInfo_{};
     139              : 
     140              :     bool CheckRequestResult();
     141              :     void ThrowAbnormalStatus(std::string funcName);
     142              : 
     143              :     void         GenerateLocalPsn();
     144              :     void         CreateJetty();
     145              :     void         SetJettyInfo();
     146              :     bool         GetTpInfo();
     147              :     void         ImportJetty();
     148              :     void         SetImportInfo();
     149              :     void         ReleaseResource();
     150              : 
     151              :     void ProcessSlices(const MemoryBuffer &loc, const MemoryBuffer &rmt,
     152              :                     std::function<void(const MemoryBuffer &, const MemoryBuffer &, u32)> processOneSlice,
     153              :                     DataType dataType = DataType::INVALID) const;
     154              : 
     155              :     std::unique_ptr<BaseTask> ConstructTaskUbSend(const HrtRaUbSendWrRespParam &sendWrResp, const SqeConfig &config) const;
     156              :     void                      UpdateCiVal(u32 ci);
     157              : };
     158              : 
     159              : class HostUbTpConnection : public HostUbConnection {
     160              : public:
     161              :     HostUbTpConnection(const RdmaHandle rdmaHandle, const IpAddress &locAddr, const IpAddress &rmtAddr,
     162            1 :                     const OpMode opMode, const HrtUbJfcMode jfcMode = HrtUbJfcMode::NORMAL,
     163              :                     u8 qos = static_cast<u8>(UB_QOS_DEFAULT));
     164              : };
     165              : 
     166              : class HostUbCtpConnection : public HostUbConnection {
     167              : public:
     168              :     HostUbCtpConnection(const RdmaHandle rdmaHandle, const IpAddress &locAddr, const IpAddress &rmtAddr,
     169            1 :                     const OpMode opMode, const HrtUbJfcMode jfcMode = HrtUbJfcMode::NORMAL,
     170              :                     u8 qos = static_cast<u8>(UB_QOS_DEFAULT));
     171              : };
     172              : 
     173              : bool IfNeedUpdatingUbCi(const std::vector<HostUbConnection *> &ubConns);
     174              : 
     175              : } // namespace Hccl
     176              : 
     177              : #endif // HCCLV2_HOST_UB_CONNECTION_H
        

Generated by: LCOV version 2.0-1