LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/buffer - remote_rma_buffer.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 92.9 % 14 13
Test Date: 2026-08-18 17:47:01 Functions: 86.7 % 15 13

            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_REMOTE_RMA_BUFFER_H
      12              : #define HCCLV2_REMOTE_RMA_BUFFER_H
      13              : 
      14              : #include "orion_adapter_hccp.h"
      15              : #include "orion_adapter_rts.h"
      16              : #include "rma_type.h"
      17              : #include "serializable.h"
      18              : #include <hcomm_res_defs.h>
      19              : #include "hccl_mem_defs.h"
      20              : namespace Hccl {
      21              : 
      22              : class RemoteRmaBuffer {
      23              : public:
      24           98 :     explicit RemoteRmaBuffer(const RmaType rmaType) : rmaType(rmaType) {}
      25              : 
      26           98 :     virtual ~RemoteRmaBuffer() = default;
      27              : 
      28            5 :     RmaType GetRmaType() const { return rmaType; }
      29              : 
      30           75 :     inline uintptr_t GetAddr() const { return addr; }
      31              : 
      32           52 :     inline u64 GetSize() const { return size; }
      33              : 
      34           21 :     inline HcclMemType GetMemType() const { return memType; }
      35              : 
      36           22 :     inline const std::string GetMemInfo() const { return memInfo; }
      37              : 
      38           17 :     u64 GetMemHandle() const { return memHandle; }
      39              : 
      40              :     virtual std::string Describe() const = 0;
      41              : 
      42              : protected:
      43              :     uintptr_t addr{0};
      44              :     u64 size{0};
      45              :     RmaType rmaType;
      46              :     HcclMemType memType;
      47              :     std::string memInfo;
      48              :     u64 memHandle{0};
      49              : };
      50              : 
      51              : class RemoteIpcRmaBuffer : public RemoteRmaBuffer {
      52              : public:
      53              :     RemoteIpcRmaBuffer();
      54              : 
      55              :     explicit RemoteIpcRmaBuffer(const Serializable& rmtDto);
      56              : 
      57              :     RemoteIpcRmaBuffer(const Serializable& rmtDto, const std::string tag);
      58              : 
      59              :     ~RemoteIpcRmaBuffer() override;
      60              : 
      61              :     RemoteIpcRmaBuffer(const RemoteIpcRmaBuffer& that) = delete;
      62              : 
      63              :     RemoteIpcRmaBuffer& operator=(const RemoteIpcRmaBuffer& that) = delete;
      64              : 
      65              :     std::string Describe() const override;
      66              : 
      67            1 :     void SetPathMode(uint8_t pathMode) { pathMode_ = pathMode; }
      68              : 
      69              : private:
      70              :     void Close() const;
      71              : 
      72              :     uint8_t pathMode_{0};
      73              : 
      74              :     char ipcName[RTS_IPC_MEM_NAME_LEN]{0};
      75              :     u64 ipcAddr{0};
      76              :     u64 ipcOffset{0};
      77              :     void* ipcPtr{};
      78              :     u32 remotePid{0};
      79              :     u32 myPid{0};
      80              :     bool isOpened;
      81              : };
      82              : 
      83              : class RemoteRdmaRmaBuffer : public RemoteRmaBuffer {
      84              : public:
      85              :     explicit RemoteRdmaRmaBuffer(RdmaHandle rdmaHandle);
      86              : 
      87              :     RemoteRdmaRmaBuffer(RdmaHandle rdmaHandle, const Serializable& rmtDto);
      88              : 
      89              :     ~RemoteRdmaRmaBuffer() override;
      90              : 
      91              :     RemoteRdmaRmaBuffer(const RemoteRdmaRmaBuffer& that) = delete;
      92              : 
      93              :     RemoteRdmaRmaBuffer& operator=(const RemoteRdmaRmaBuffer& that) = delete;
      94              : 
      95              :     std::string Describe() const override;
      96              : 
      97              :     const u8* GetKey() const { return key; }
      98              : 
      99           17 :     u32 GetRkey() const { return rkey; }
     100              : 
     101              : private:
     102              :     RdmaHandle rdmaHandle{nullptr};
     103              :     u8 exchangedKey[RDMA_MEM_KEY_MAX_LEN]{0};
     104              :     u8 key[RDMA_MEM_KEY_MAX_LEN]{0};
     105              :     u32 keyValidLen{0};
     106              :     u32 rkey{0};
     107              : };
     108              : 
     109              : class RemoteUbRmaBuffer : public RemoteRmaBuffer {
     110              : public:
     111              :     explicit RemoteUbRmaBuffer(RdmaHandle rdmaHandle);
     112              : 
     113              :     RemoteUbRmaBuffer(
     114              :         uintptr_t addr, u64 size, u32 tokenId, u32 tokenValue, HcclMemType memType, const std::string& memInfo);
     115              : 
     116              :     RemoteUbRmaBuffer(RdmaHandle rdmaHandle1, const Serializable& rmtDto);
     117              : 
     118              :     ~RemoteUbRmaBuffer() override;
     119              : 
     120              :     RemoteUbRmaBuffer(const RemoteUbRmaBuffer& that) = delete;
     121              : 
     122              :     RemoteUbRmaBuffer& operator=(const RemoteUbRmaBuffer& that) = delete;
     123              : 
     124              :     std::string Describe() const final;
     125              : 
     126            7 :     uint32_t GetTokenId() const { return tokenId; }
     127              : 
     128            7 :     uint32_t GetTokenValue() const { return tokenValue; }
     129              : 
     130            0 :     uint64_t GetSegVa() const { return segVa; }
     131              : 
     132            5 :     uint32_t GetNotifyId() const { return notifyId; }
     133              : 
     134              : private:
     135              :     RdmaHandle rdmaHandle{nullptr};
     136              :     u8 key[HRT_UB_MEM_KEY_MAX_LEN]{0};
     137              :     u32 tokenId{0};
     138              :     u32 tokenValue{0};
     139              :     u32 keySize{0};
     140              :     u64 segVa{0};
     141              :     u32 notifyId{UINT32_MAX};
     142              : };
     143              : 
     144              : } // namespace Hccl
     145              : #endif
        

Generated by: LCOV version 2.0-1