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: 60.5 % 43 26
Test Date: 2026-08-18 17:47:01 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            6 : LocalRdmaRmaBuffer::LocalRdmaRmaBuffer(const HcclNetDevCtx netDevCtx, void* addr, u64 size, const RmaMemType memType)
      16            6 :     : RmaBuffer(netDevCtx, addr, size, memType, RmaType::RDMA_RMA)
      17              : {
      18            6 :     pimpl_ = std::make_unique<LocalRdmaRmaBufferImpl>(netDevCtx, addr, size, memType);
      19            6 : }
      20              : 
      21            4 : LocalRdmaRmaBuffer::LocalRdmaRmaBuffer(
      22            4 :     const HcclNetDevCtx netDevCtx, void* addr, u64 size, const RmaMemType memType, const LocalRdmaRmaBuffer& parent)
      23            4 :     : RmaBuffer(netDevCtx, addr, size, memType, RmaType::RDMA_RMA, true)
      24              : {
      25            4 :     pimpl_ = std::make_unique<LocalRdmaRmaBufferImpl>(netDevCtx, addr, size, memType, parent.GetImpl());
      26            4 :     this->devAddr = pimpl_->GetDevAddr();
      27            4 :     HCCL_INFO("[LocalRdmaRmaBuffer] alias constructor, lkey[%u]", GetKey());
      28            4 : }
      29              : 
      30           10 : LocalRdmaRmaBuffer::~LocalRdmaRmaBuffer()
      31              : {
      32           10 :     if (!isAlias_) {
      33            6 :         HcclResult res = Destroy();
      34            6 :         if (res != HCCL_SUCCESS) {
      35            0 :             HCCL_ERROR("[LocalRdmaRmaBuffer][~LocalRdmaRmaBuffer]failed, ret[%d]", res);
      36              :         }
      37              :     }
      38           10 : }
      39              : 
      40            0 : HcclResult LocalRdmaRmaBuffer::Init()
      41              : {
      42            0 :     CHK_PTR_NULL(addr);
      43            0 :     CHK_PRT_RET(
      44              :         (memType >= RmaMemType::TYPE_NUM),
      45              :         HCCL_ERROR("[LocalRdmaRmaBuffer][Init]RmaMemType[%d] is invalid.", static_cast<int>(memType)), HCCL_E_PARA);
      46            0 :     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              :             "[LocalRdmaRmaBuffer][Init]memory size[%llu] should be greater than 0 and less than [%llu].", size,
      51              :             (memType == RmaMemType::DEVICE ? DEVICE_MEM_MAX_COUNT : HOST_MEM_MAX_COUNT)),
      52              :         HCCL_E_PARA);
      53              : 
      54            0 :     CHK_SMART_PTR_NULL(pimpl_);
      55            0 :     HcclResult ret = pimpl_->Init();
      56            0 :     if (ret != HCCL_SUCCESS) {
      57            0 :         pimpl_ = nullptr;
      58            0 :         HCCL_ERROR("[LocalRdmaRmaBuffer][Init]Init failed, ret[%d]", ret);
      59            0 :         return ret;
      60              :     }
      61              : 
      62            0 :     this->devAddr = pimpl_->GetDevAddr();
      63              : 
      64            0 :     return HCCL_SUCCESS;
      65              : }
      66              : 
      67            6 : HcclResult LocalRdmaRmaBuffer::Destroy()
      68              : {
      69            6 :     if (pimpl_ != nullptr) {
      70            6 :         HcclResult ret = pimpl_->Destroy();
      71            6 :         if (ret != HCCL_SUCCESS) {
      72            0 :             HCCL_ERROR("[LocalRdmaRmaBuffer][Destroy]Destroy failed, ret[%d]", ret);
      73              :         }
      74            6 :         pimpl_ = nullptr;
      75            6 :         addr = nullptr;
      76            6 :         size = 0;
      77            6 :         devAddr = nullptr;
      78            6 :         return ret;
      79              :     }
      80            0 :     return HCCL_SUCCESS;
      81              : }
      82              : 
      83            0 : std::string& LocalRdmaRmaBuffer::Serialize() { return pimpl_->Serialize(); }
      84              : 
      85           12 : u32 LocalRdmaRmaBuffer::GetKey() const { return pimpl_->GetKey(); }
      86              : 
      87            0 : HcclResult LocalRdmaRmaBuffer::Remap(void* addr, u64 length) { return pimpl_->Remap(addr, length); }
      88              : 
      89              : } // namespace hccl
        

Generated by: LCOV version 2.0-1