LCOV - code coverage report
Current view: top level - legacy/ascend910/pub_inc/inner - rma_buffer.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 60.7 % 28 17
Test Date: 2026-07-28 12:11:00 Functions: 66.7 % 12 8

            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 RMA_BUFFER_H
      12              : #define RMA_BUFFER_H
      13              : 
      14              : #include <memory>
      15              : 
      16              : #include "hccl_common.h"
      17              : #include "hccl_inner_common.h"
      18              : #include "transport_mem.h"
      19              : 
      20              : namespace hccl {
      21              : class RmaBuffer {
      22              : public:
      23           44 :     RmaBuffer(const HcclNetDevCtx netDevCtx, void *addr, u64 size, const RmaMemType memType, const RmaType rmaType)
      24           44 :         : netDevCtx(netDevCtx), addr(addr), size(size), memType(memType), rmaType(rmaType)
      25              :     {
      26           44 :     }
      27              : 
      28           14 :     RmaBuffer(const HcclNetDevCtx netDevCtx, void *addr, u64 size, const RmaMemType memType, const RmaType rmaType, bool isAlias)
      29           14 :         : netDevCtx(netDevCtx), addr(addr), size(size), memType(memType), rmaType(rmaType), isAlias_(isAlias)
      30              :     {
      31           14 :     }
      32              : 
      33           58 :     virtual ~RmaBuffer() = default;
      34              : 
      35              :     RmaBuffer(const RmaBuffer &that) = delete;
      36              : 
      37              :     RmaBuffer &operator=(const RmaBuffer &that) = delete;
      38              : 
      39           27 :     inline bool IsAlias() const
      40              :     {
      41           27 :         return isAlias_;
      42              :     }
      43              : 
      44           95 :     inline void* GetAddr() const
      45              :     {
      46           95 :         return addr;
      47              :     }
      48              : 
      49           88 :     inline u64 GetSize() const
      50              :     {
      51           88 :         return size;
      52              :     }
      53              : 
      54            0 :     inline RmaType GetRmaType() const // used for grant check
      55              :     {
      56            0 :         return rmaType;
      57              :     }
      58              : 
      59            2 :     inline RmaMemType GetMemType() const
      60              :     {
      61            2 :         return memType;
      62              :     }
      63              : 
      64           22 :     inline void *GetDevAddr() const
      65              :     {
      66           22 :         return devAddr;
      67              :     }
      68              : 
      69            0 :     inline HcclNetDevCtx GetNetDevCtx() const
      70              :     {
      71            0 :         return netDevCtx;
      72              :     }
      73              : 
      74              : protected:
      75              :     const       HcclNetDevCtx netDevCtx{nullptr};
      76              :     void*       addr{nullptr};
      77              :         u64         size{0};
      78              :     void*       devAddr{nullptr};
      79              :     RmaMemType  memType{RmaMemType::TYPE_NUM};
      80              :     RmaType     rmaType{RmaType::RMA_TYPE_RESERVED};
      81              :     bool        isAlias_{false};
      82              : };
      83              : 
      84              : struct RmaBufferSlice {
      85              :     std::shared_ptr<RmaBuffer> rmaBuffer{nullptr};
      86              :     void* addr{nullptr};
      87              :     u64 len{0};
      88              :     RmaMemType memType{RmaMemType::DEVICE};
      89              : };
      90              : 
      91            0 : inline HcclResult CheckHcclBuffer(const void* addr, const RmaBuffer *rmaBuffer)
      92              : {
      93            0 :     CHK_PTR_NULL(addr);
      94            0 :     CHK_PTR_NULL(rmaBuffer);
      95            0 :     if (UNLIKELY(reinterpret_cast<u64>(addr) < reinterpret_cast<u64>(rmaBuffer->GetAddr()) ||
      96              :         reinterpret_cast<u64>(addr) > (reinterpret_cast<u64>(rmaBuffer->GetAddr()) + rmaBuffer->GetSize()))) {
      97            0 :         HCCL_ERROR("[CheckHcclBuffer]check buffer failed, hccl buffer addr[%p], "
      98              :             "ramBuffer addr[%p], rmaBuffer size[%u]", addr, rmaBuffer->GetAddr(), rmaBuffer->GetSize());
      99            0 :         return HCCL_E_PARA;
     100              :     }
     101            0 :     return HCCL_SUCCESS;
     102              : }
     103              : }
     104              : #endif //  RDMA_RMA_BUFFER_H
        

Generated by: LCOV version 2.0-1