LCOV - code coverage report
Current view: top level - legacy/ascend910/platform/resource/rma_buffer - local_rdma_rma_buffer.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 58.7 % 46 27
Test Date: 2026-07-28 12:11:00 Functions: 55.6 % 9 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              : 
      11              : #include "local_rdma_rma_buffer.h"
      12              : #include "local_rdma_rma_buffer_impl.h"
      13              : 
      14              : namespace hccl {
      15            4 : LocalRdmaRmaBuffer::LocalRdmaRmaBuffer(const HcclNetDevCtx netDevCtx, void* addr, u64 size, const RmaMemType memType)
      16            4 :     : RmaBuffer(netDevCtx, addr, size, memType, RmaType::RDMA_RMA)
      17              : {
      18            4 :     pimpl_ = std::make_unique<LocalRdmaRmaBufferImpl>(netDevCtx, addr, size, memType);
      19            4 : }
      20              : 
      21            2 : LocalRdmaRmaBuffer::LocalRdmaRmaBuffer(const HcclNetDevCtx netDevCtx, void* addr, u64 size,
      22            2 :     const RmaMemType memType, const LocalRdmaRmaBuffer& parent)
      23            2 :     : RmaBuffer(netDevCtx, addr, size, memType, RmaType::RDMA_RMA, true)
      24              : {
      25            2 :     pimpl_ = std::make_unique<LocalRdmaRmaBufferImpl>(netDevCtx, addr, size, memType, parent.GetImpl());
      26            2 :     this->devAddr = pimpl_->GetDevAddr();
      27            2 :     HCCL_INFO("[LocalRdmaRmaBuffer] alias constructor, lkey[%u]", GetKey());
      28            2 : }
      29              : 
      30            6 : LocalRdmaRmaBuffer::~LocalRdmaRmaBuffer()
      31              : {
      32            6 :     if (!isAlias_) {
      33            4 :         HcclResult res = Destroy();
      34            4 :         if (res != HCCL_SUCCESS) {
      35            0 :             HCCL_ERROR("[LocalRdmaRmaBuffer][~LocalRdmaRmaBuffer]failed, ret[%d]", res);
      36              :         }
      37              :     }
      38            6 : }
      39              : 
      40            0 : HcclResult LocalRdmaRmaBuffer::Init()
      41              : {
      42            0 :     CHK_PTR_NULL(addr);
      43            0 :     CHK_PRT_RET((memType >= RmaMemType::TYPE_NUM),
      44              :         HCCL_ERROR("[LocalRdmaRmaBuffer][Init]RmaMemType[%d] is invalid.", static_cast<int>(memType)), HCCL_E_PARA);
      45            0 :     CHK_PRT_RET((size == 0 || (memType == RmaMemType::HOST && size >= HOST_MEM_MAX_COUNT) ||
      46              :         (memType == RmaMemType::DEVICE && size >= DEVICE_MEM_MAX_COUNT)),
      47              :         HCCL_ERROR("[LocalRdmaRmaBuffer][Init]memory size[%llu] should be greater than 0 and less than [%llu].",
      48              :         size, (memType == RmaMemType::DEVICE ? DEVICE_MEM_MAX_COUNT : HOST_MEM_MAX_COUNT)), HCCL_E_PARA);
      49              : 
      50            0 :     CHK_SMART_PTR_NULL(pimpl_);
      51            0 :     HcclResult ret = pimpl_->Init();
      52            0 :     if (ret != HCCL_SUCCESS) {
      53            0 :         pimpl_ = nullptr;
      54            0 :         HCCL_ERROR("[LocalRdmaRmaBuffer][Init]Init failed, ret[%d]", ret);
      55            0 :         return ret;
      56              :     }
      57              : 
      58            0 :     this->devAddr   = pimpl_->GetDevAddr();
      59              : 
      60            0 :     return HCCL_SUCCESS;
      61              : }
      62              : 
      63            4 : HcclResult LocalRdmaRmaBuffer::Destroy()
      64              : {
      65            4 :     if (pimpl_ != nullptr) {
      66            4 :         HcclResult ret = pimpl_->Destroy();
      67            4 :         if (ret != HCCL_SUCCESS) {
      68            0 :             HCCL_ERROR("[LocalRdmaRmaBuffer][Destroy]Destroy failed, ret[%d]", ret);
      69              :         }
      70            4 :         pimpl_  = nullptr;
      71            4 :         addr    = nullptr;
      72            4 :         size    = 0;
      73            4 :         devAddr = nullptr;
      74            4 :         return ret;
      75              :     }
      76            0 :     return HCCL_SUCCESS;
      77              : }
      78              : 
      79            0 : std::string &LocalRdmaRmaBuffer::Serialize()
      80              : {
      81            0 :     return pimpl_->Serialize();
      82              : }
      83              : 
      84            6 : u32 LocalRdmaRmaBuffer::GetKey() const
      85              : {
      86            6 :     return pimpl_->GetKey();
      87              : }
      88              : 
      89            0 : HcclResult LocalRdmaRmaBuffer::Remap(void* addr, u64 length)
      90              : {
      91            0 :     return pimpl_->Remap(addr, length);
      92              : }
      93              : 
      94              : }
        

Generated by: LCOV version 2.0-1