LCOV - code coverage report
Current view: top level - base_comm/resources/endpoint_pairs/channels/aicpu - aicpu_ts_uboe_ubg_channel_helper.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 33.3 % 3 1
Test Date: 2026-08-04 10:52:23 Functions: 66.7 % 6 4

            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              : #ifndef AICPU_TS_UBOE_UBG_CHANNEL_HELPER_H
      11              : #define AICPU_TS_UBOE_UBG_CHANNEL_HELPER_H
      12              : 
      13              : #include <cstdint>
      14              : #include <memory>
      15              : #include <mutex>
      16              : #include <string>
      17              : #include <vector>
      18              : 
      19              : #include "channel.h"
      20              : #include "aicpu_ts_channel_helper.h"
      21              : #include "socket_mgr.h"
      22              : 
      23              : // Orion
      24              : #include "../../../../../../src/legacy/ascend950/unified_platform/resource/socket/socket.h"
      25              : #include "rma_connection.h"
      26              : #include "ub_mem_transport.h"
      27              : #include "dev_ub_connection.h"
      28              : #include "ub_local_notify.h"
      29              : #include "hcomm_adapter_hccp.h"
      30              : 
      31              : namespace hcomm {
      32              : 
      33              : constexpr u32    FINISH_MSG_SIZE             = 128;
      34              : constexpr char_t FINISH_MSG[FINISH_MSG_SIZE] = "Uboe Comm Pipe ready!";
      35              : 
      36              : class AicpuTsUboeUbgChannelHelper : public Channel {
      37              : public:
      38              :     AicpuTsUboeUbgChannelHelper(EndpointHandle endpointHandle, const HcommChannelDesc &channelDesc);
      39              :     virtual ~AicpuTsUboeUbgChannelHelper();
      40              : 
      41              :     HcclResult GetNotifyNum(uint32_t *notifyNum) const override;
      42              :     HcclResult GetRemoteMems(uint32_t *memNum, CommMem **remoteMem, char ***memInfos) override;
      43              : 
      44              :     HcclResult H2DResPack(std::vector<char>& buffer);
      45            0 :     const HcommChannelDesc& GetChannelDesc() const override { return channelDesc_; }
      46              :     virtual HcclResult Clean() override;
      47              :     virtual HcclResult Resume() override;
      48              : 
      49              :     // 数据面接口
      50              :     HcclResult NotifyRecord(const uint32_t remoteNotifyIdx) override;
      51              :     HcclResult NotifyWait(const uint32_t localNotifyIdx, const uint32_t timeout) override;
      52              :     HcclResult WriteWithNotify(void *dst, const void *src, const uint64_t len, uint32_t remoteNotifyIdx) override;
      53              :     HcclResult Write(void *dst, const void *src, uint64_t len) override;
      54              :     HcclResult Read(void *dst, const void *src, uint64_t len) override;
      55              :     HcclResult ChannelFence() override;
      56              : 
      57            0 :     AicpuTsChannelHelper *GetAicpuTsHelper() override { return &aicpuTsHelper_; }
      58              : 
      59              : protected:
      60              :     static constexpr u64 NORMAL_NOTIFY_VAL = 1;
      61              : 
      62           43 :     MAKE_ENUM(UboeRmtBufType, NOTIFY, BUFFER)
      63              :     using RemoteBufferVec = std::vector<std::unique_ptr<Hccl::RemoteUbRmaBuffer>>;
      64              :     using LocalBufferVec = std::vector<Hccl::LocalUbRmaBuffer *>;
      65              : 
      66              :     virtual HcclResult BuildConnection() = 0;
      67              :     virtual void SendFinish() = 0;
      68              :     virtual void RecvFinish() = 0;
      69              : 
      70              :     HcclResult ParseInputParam();
      71              :     HcclResult BuildNotify();
      72              :     HcclResult BuildDrainResource();
      73              :     HcclResult BuildSocket();
      74              :     void BuildConn();
      75              : 
      76              :     bool IsSocketReady();
      77              :     bool IsResReady();
      78              :     bool IsConnsReady();
      79              :     bool RecvDataProcess();
      80              :     void SendDataSize();
      81              :     void RecvDataSize();
      82              :     void SendExchangeData();
      83              :     void RecvExchangeData();
      84              : 
      85              :     void NotifyVecPack(Hccl::BinaryStream &binaryStream);
      86              :     void BufferVecPack(Hccl::BinaryStream &binaryStream, std::vector<Hccl::LocalRmaBuffer *> &bufferVec);
      87              :     void DrainBufferPack(Hccl::BinaryStream &binaryStream);
      88              :     void ConnVecPack(Hccl::BinaryStream &binaryStream);
      89              :     void RmtBufferVecUnpackProc(u32 locNum, Hccl::BinaryStream &binaryStream,
      90              :         RemoteBufferVec &bufferVec, UboeRmtBufType type);
      91              :     void RmtDrainBufferUnpackProc(Hccl::BinaryStream &binaryStream);
      92              :     bool ConnVecUnpackProc(Hccl::BinaryStream &binaryStream);
      93              : 
      94              :     std::vector<char> GetUniqueIdV2();
      95              :     std::vector<char> GetNotifyUniqueIds();
      96              :     std::vector<char> GetRmtBufferUniqueIds(RemoteBufferVec &bufferVec, UboeRmtBufType type) const;
      97              :     std::vector<char> GetLocBufferUniqueIds(LocalBufferVec &bufferVec, UboeRmtBufType type) const;
      98              :     std::vector<char> GetSingleRmtBufferUniqueId(u64 addr, u64 size, u32 tokenId, u32 tokenValue, u32 notifyId) const;
      99              :     std::vector<char> GetDrainUniqueIds() const;
     100              :     std::vector<char> GetConnUniqueIds();
     101              : 
     102              :     // --------------------- 入参 ---------------------
     103              :     EndpointHandle                                              endpointHandle_;
     104              :     HcommChannelDesc                                            channelDesc_;
     105              : 
     106              :     // --------------------- 转换参数 ---------------------
     107              :     EndpointDesc                                                localEp_{};
     108              :     EndpointDesc                                                remoteEp_{};
     109              :     uint32_t                                                    notifyNum_{0};
     110              : 
     111              :     // --------------------- 具体成员 ---------------------
     112              :     Hccl::Socket*                                               socket_{nullptr};
     113              :     RdmaHandle                                                  rdmaHandle_{nullptr};
     114              :     std::unique_ptr<Hccl::UbMemTransport>                       memTransport_{nullptr};
     115              :     Hccl::BaseMemTransport::CommonLocRes                        commonRes_{};
     116              :     std::vector<std::unique_ptr<Hccl::DevUbConnection>>         connections_{};
     117              :     std::vector<std::unique_ptr<Hccl::UbLocalNotify>>           localNotifies_{};
     118              :     std::unique_ptr<Hccl::Socket>                               serverSocket_;
     119              : 
     120              :     std::unique_ptr<Hccl::UbLocalNotify>                        drainNotify_;       // 本端drain notify
     121              :     std::unique_ptr<Hccl::LocalUbRmaBuffer>                     drainBuffer_;       // 本端常量1 buffer
     122              :     std::unique_ptr<Hccl::RemoteUbRmaBuffer>                    rmtDrainBuffer_;    // 对端常量1 buffer
     123              : 
     124              :     ChannelStatus                                               channelStatus{ChannelStatus::INIT};
     125              : 
     126              :     u32 bufferNum_{0};
     127              :     u32 connNum_{0};
     128              :     u32 recvDataSize_{0};
     129              : 
     130              :     RemoteBufferVec rmtNotifyVec_;
     131              :     RemoteBufferVec rmtBufferVec_;
     132              :     LocalBufferVec  locBufferVec_;
     133              :     std::vector<char> recvData_{};
     134              :     std::vector<char> recvFinishMsg_{};
     135              :     std::vector<char> sendData_{};
     136              :     std::vector<char> sendFinishMsg_{};
     137              :     bool isRecvFirst_{false};
     138              : 
     139              :     Hccl::IpAddress     locAddr_;
     140              :     Hccl::IpAddress     rmtAddr_;
     141              : 
     142              :     std::mutex remoteMemsMutex_;
     143              :     bool cacheValid_ = false;
     144              :     std::vector<CommMem>         remoteUserMems_;
     145              :     std::vector<std::string>     memInfoCopies_;
     146              :     std::vector<char*>           memInfoPointers_;
     147              :     const Hccl::SocketConfig*    socketConfig_{nullptr};
     148              :     DevBaseAttr devBaseAttr_{};
     149              :     uint32_t    devicePhyId_{};
     150              : private:
     151              :     AicpuTsChannelHelper aicpuTsHelper_;
     152              : };
     153              : 
     154              : } // namespace hcomm
     155              : 
     156              : #endif // AICPU_TS_UBOE_UBG_CHANNEL_HELPER_H
        

Generated by: LCOV version 2.0-1