LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/aiv - ub_memory_transport.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 7 7
Test Date: 2026-07-28 12:11:00 Functions: 62.5 % 8 5

            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              : #ifndef UB_MEMORY_TRANSPORT_H
      11              : #define UB_MEMORY_TRANSPORT_H
      12              : #include "virtual_topo.h"
      13              : #include "dev_buffer.h"
      14              : #include "socket.h"
      15              : #include "local_ipc_rma_buffer.h"
      16              : #include "remote_rma_buffer.h"
      17              : #include "base_mem_transport.h"
      18              : 
      19              : namespace Hccl {
      20              : class UbMemoryTransport {
      21              : public:
      22           56 :     MAKE_ENUM(UBTransportStatus, INIT, SOCKET_OK, SEND_MEM_INFO, RECV_MEM_INFO, RECV_MEM_INFO_PROCESS, SEND_NAME, RECV_NAME, CONNECT_FAILED,
      23              :               SOCKET_TIMEOUT, READY)
      24              : 
      25              :     UbMemoryTransport(const std::shared_ptr<Buffer> cclBuffer, const std::shared_ptr<Buffer> aivTagBuffer, 
      26              :                 const std::shared_ptr<Buffer> aivOffloadTagBuffer, Socket *socket, int32_t deviceLogicId);
      27              : 
      28              :     UbMemoryTransport(const UbMemoryTransport &that)             = delete;
      29              :     UbMemoryTransport &operator=(const UbMemoryTransport &other) = delete;
      30              :     HcclResult Init();
      31              :     UBTransportStatus   GetStatus();
      32              : 
      33              :     // 给算子开发提供的两个接口
      34              :     LocalIpcRmaBuffer  *GetLocMemBuffer(const u32 bufIndex) const;
      35              :     RemoteIpcRmaBuffer *GetRmtMemBuffer(const u32 bufIndex) const;
      36              :     std::string         Describe() const;
      37              : 
      38              :     vector<char> GetRmtHandshakeMsg() // 返回握手消息
      39              :     {
      40              :         return rmtHandshakeMsg;
      41              :     }
      42              : 
      43              :     vector<char> GetLocalHandshakeMsg() // 返回握手消息
      44              :     {
      45              :         return localHandshakeMsg;
      46              :     }
      47              : 
      48            1 :     void SetHandshakeMsg(const vector<char> &handshakeMsg)
      49              :     {
      50            1 :         localHandshakeMsg = handshakeMsg;
      51            1 :     }
      52              : 
      53              :     AcceleratorState &GetRmtOpAcceState()
      54              :     {
      55              :         return rmtOpAcceState;
      56              :     }
      57              : 
      58              :     AcceleratorState &GetLocalOpAcceState()
      59              :     {
      60              :         return locOpAcceState;
      61              :     }
      62              : 
      63            1 :     void SetLocalOpAcceState(const AcceleratorState &opAcceState)
      64              :     {
      65            1 :         locOpAcceState = opAcceState;
      66            1 :     }
      67              : 
      68              :     struct CclBufferInfo {
      69              :         uint64_t addr{0};
      70              :         uint32_t size{0};
      71              :         uint32_t tokenId{0};
      72              :         uint32_t tokenValue{0};
      73              : 
      74              :         void Pack(BinaryStream &binaryStream) const
      75              :         {
      76              :             binaryStream << addr << size << tokenId << tokenValue;
      77              :             HCCL_INFO("Pack Ccl Buffer Info: addr[%llu] size[%u]", addr, size);
      78              :         }
      79              : 
      80              :         void Unpack(BinaryStream &binaryStream)
      81              :         {
      82              :             binaryStream >> addr >> size >> tokenId >> tokenValue;
      83              :             HCCL_INFO("Unpack Ccl Buffer Info: addr[%llu] size[%u]", addr, size);
      84              :         }
      85              :     };
      86              : 
      87              : private:
      88              :     UBTransportStatus     ubStatus{UBTransportStatus::INIT};
      89              :     vector<char> rmtHandshakeMsg{0}; // 远端握手消息
      90              :     vector<char> localHandshakeMsg{0};
      91              :     vector<char> recvDataMsg{0};
      92              :     AcceleratorState                         rmtOpAcceState{AcceleratorState::AIV};
      93              :     AcceleratorState                         locOpAcceState{AcceleratorState::AIV};
      94              : 
      95              :     CclBufferInfo locCclBufInfo;
      96              :     CclBufferInfo rmtCclBufInfo;
      97              :     uint32_t      exchangeDataSize{0};
      98              : 
      99              :     //  新增
     100              :     std::shared_ptr<Buffer> cclBuffer; 
     101              :     std::shared_ptr<Buffer> aivTagBuffer;
     102              :     std::shared_ptr<Buffer> aivOffloadTagBuffer;
     103              :     Socket                 *socket{};
     104              :     int32_t                 deviceLogicId{0};
     105              : 
     106              :     std::vector<std::unique_ptr<RemoteIpcRmaBuffer>> rmtBufferVec;
     107              :     std::vector<std::unique_ptr<LocalIpcRmaBuffer>>  localBufferVec;
     108              :     std::vector<RemoteRmaBuffer *>                   rmtRmaBufferVec;
     109              : 
     110              :     void     HandshakeMsgPack(BinaryStream &binaryStream);
     111              :     void     HandshakeMsgUnpack(BinaryStream &binaryStream);
     112              :     UBTransportStatus StateMachine();
     113              :     void     ReleaseRes();
     114              :     void     SendMemInfo();
     115              :     void     RecvMemInfo();
     116              :     void     RecvMemProcess();
     117              :     void     BufferPack(BinaryStream &binaryStream);
     118              :     void     RmtBufferUnpackProc(BinaryStream &binaryStream);
     119              :     void     SendName();
     120              :     void     RecvName();
     121              : };
     122              : } // namespace Hccl
     123              : 
     124              : #endif
        

Generated by: LCOV version 2.0-1