LCOV - code coverage report
Current view: top level - legacy/ascend910/platform/resource/rma_buffer - local_ipc_rma_buffer.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 85.7 % 42 36
Test Date: 2026-08-18 17:47:01 Functions: 87.5 % 8 7

            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_ipc_rma_buffer.h"
      12              : #include "local_ipc_rma_buffer_impl.h"
      13              : 
      14              : namespace hccl {
      15           16 : LocalIpcRmaBuffer::LocalIpcRmaBuffer(const HcclNetDevCtx netDevCtx, void* addr, u64 size, const RmaMemType memType)
      16           16 :     : RmaBuffer(netDevCtx, addr, size, memType, RmaType::IPC_RMA)
      17              : {
      18           16 :     pimpl_ = std::make_unique<LocalIpcRmaBufferImpl>(netDevCtx, addr, size, memType);
      19           16 : }
      20              : 
      21            7 : LocalIpcRmaBuffer::LocalIpcRmaBuffer(
      22            7 :     const HcclNetDevCtx netDevCtx, void* addr, u64 size, const RmaMemType memType, const LocalIpcRmaBuffer& parent)
      23            7 :     : RmaBuffer(netDevCtx, addr, size, memType, RmaType::IPC_RMA, true)
      24              : {
      25            7 :     pimpl_ = std::make_unique<LocalIpcRmaBufferImpl>(netDevCtx, addr, size, memType, *parent.pimpl_);
      26            7 :     this->devAddr = pimpl_->GetDevAddr();
      27            7 :     HCCL_INFO("[LocalIpcRmaBuffer] alias constructor");
      28            7 : }
      29              : 
      30           23 : LocalIpcRmaBuffer::~LocalIpcRmaBuffer()
      31              : {
      32           23 :     if (!isAlias_) {
      33           16 :         HcclResult res = Destroy();
      34           16 :         if (res != HCCL_SUCCESS) {
      35            0 :             HCCL_ERROR("[LocalIpcRmaBuffer][~LocalIpcRmaBuffer]failed, ret[%d]", res);
      36              :         }
      37              :     }
      38           23 : }
      39              : 
      40            9 : HcclResult LocalIpcRmaBuffer::Init()
      41              : {
      42            9 :     CHK_PTR_NULL(addr);
      43            9 :     CHK_PRT_RET(
      44              :         (memType >= RmaMemType::TYPE_NUM),
      45              :         HCCL_ERROR("[LocalIpcRmaBuffer][Init]RmaMemType[%d] is invalid.", static_cast<int>(memType)), HCCL_E_PARA);
      46            9 :     CHK_PRT_RET(
      47              :         (size == 0 || (memType == RmaMemType::HOST && size >= HOST_MEM_MAX_COUNT)
      48              :          || (memType == RmaMemType::DEVICE && size >= DEVICE_MEM_MAX_COUNT)),
      49              :         HCCL_ERROR(
      50              :             "[LocalIpcRmaBuffer][Init]memory size[%llu] should be greater than 0 and less than [%llu].", size,
      51              :             (memType == RmaMemType::DEVICE ? HOST_MEM_MAX_COUNT : DEVICE_MEM_MAX_COUNT)),
      52              :         HCCL_E_PARA);
      53              : 
      54            9 :     CHK_SMART_PTR_NULL(pimpl_);
      55            9 :     HcclResult ret = pimpl_->Init();
      56            9 :     if (ret != HCCL_SUCCESS) {
      57            0 :         pimpl_ = nullptr;
      58            0 :         HCCL_ERROR("[LocalIpcRmaBuffer][Init]Init failed, ret[%d]", ret);
      59            0 :         return ret;
      60              :     }
      61              : 
      62            9 :     this->devAddr = pimpl_->GetDevAddr();
      63              : 
      64            9 :     return HCCL_SUCCESS;
      65              : }
      66              : 
      67           16 : HcclResult LocalIpcRmaBuffer::Destroy()
      68              : {
      69           16 :     if (pimpl_ != nullptr) {
      70           16 :         HcclResult ret = pimpl_->Destroy();
      71           16 :         if (ret != HCCL_SUCCESS) {
      72            0 :             HCCL_ERROR("[LocalIpcRmaBuffer][Destroy]Destroy failed, ret[%d]", ret);
      73              :         }
      74           16 :         pimpl_ = nullptr;
      75           16 :         addr = nullptr;
      76           16 :         size = 0;
      77           16 :         devAddr = nullptr;
      78           16 :         return ret;
      79              :     }
      80            0 :     return HCCL_SUCCESS;
      81              : }
      82              : 
      83            2 : std::string& LocalIpcRmaBuffer::Serialize() { return pimpl_->Serialize(); }
      84              : 
      85            2 : HcclResult LocalIpcRmaBuffer::Grant(u32 remotePid, u32 remoteSdid) { return pimpl_->Grant(remotePid, remoteSdid); }
      86              : } // namespace hccl
        

Generated by: LCOV version 2.0-1