LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/buffer - local_ipc_rma_buffer.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 69.0 % 29 20
Test Date: 2026-08-04 10:52:23 Functions: 85.7 % 7 6

            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              : 
      13              : #include "rma_buffer.h"
      14              : #include "exchange_ipc_buffer_dto.h"
      15              : 
      16              : namespace Hccl {
      17              : 
      18           11 : LocalIpcRmaBuffer::LocalIpcRmaBuffer(std::shared_ptr<Buffer> buf) : LocalRmaBuffer(buf, RmaType::IPC)
      19              : {
      20           11 :     HrtDevMemAlignWithPage(reinterpret_cast<void *>(buf->GetAddr()), buf->GetSize(), ipcPtr, ipcSize, ipcOffset);
      21           11 :     HrtIpcSetMemoryName(ipcPtr, name, ipcSize, RTS_IPC_MEM_NAME_LEN);
      22           11 : }
      23              : 
      24            0 : LocalIpcRmaBuffer::LocalIpcRmaBuffer(std::shared_ptr<Buffer> buf, const LocalIpcRmaBuffer& parent)
      25            0 :     : LocalRmaBuffer(buf, RmaType::IPC, true)
      26              : {
      27            0 :     (void)memcpy_s(name, RTS_IPC_MEM_NAME_LEN, parent.name, RTS_IPC_MEM_NAME_LEN);
      28            0 :     ipcPtr   = parent.ipcPtr;
      29            0 :     ipcOffset = parent.ipcOffset;
      30            0 :     ipcSize   = parent.ipcSize;
      31            0 :     HCCL_INFO("[LocalIpcRmaBuffer] alias constructor, parent name[%s] ipcPtr[%p] ipcOffset[%llu] ipcSize[%llu] buf=%s",
      32              :         name, ipcPtr, static_cast<unsigned long long>(ipcOffset), static_cast<unsigned long long>(ipcSize),
      33              :         buf->Describe().c_str());
      34            0 : }
      35              : 
      36           15 : LocalIpcRmaBuffer::~LocalIpcRmaBuffer()
      37              : {
      38           11 :     if (!isAlias_) {
      39           11 :         DECTOR_TRY_CATCH("LocalIpcRmaBuffer", HrtIpcDestroyMemoryName(name));
      40              :     }
      41           15 : }
      42              : 
      43            1 : string LocalIpcRmaBuffer::Describe() const
      44              : {
      45              :     return StringFormat("LocalIpcRmaBuffer[buf=%s, ipcPtr=0x%llx, ipcOffset=0x%llx, ipcSize=0x%llx, name=%s]",
      46            2 :                         buf->Describe().c_str(), reinterpret_cast<uintptr_t>(ipcPtr), ipcOffset, ipcSize, name);
      47              : }
      48              : 
      49            1 : std::unique_ptr<Serializable> LocalIpcRmaBuffer::GetExchangeDto()
      50              : {
      51              :     std::unique_ptr<ExchangeIpcBufferDto> dto
      52            1 :         = make_unique<ExchangeIpcBufferDto>(buf->GetAddr(), buf->GetSize(), ipcOffset, HrtDeviceGetBareTgid(), buf->GetMemInfo().c_str());
      53            1 :     (void)memcpy_s(dto->name, RTS_IPC_MEM_NAME_LEN, name, RTS_IPC_MEM_NAME_LEN);
      54            2 :     return std::unique_ptr<Serializable>(dto.release());
      55            1 : }
      56              : 
      57            1 : void LocalIpcRmaBuffer::Grant(u32 pid)
      58              : {
      59            1 :     u32 myPid = HrtDeviceGetBareTgid();
      60            1 :     if (pid == myPid) {
      61            3 :         HCCL_INFO("pid is equal to myPid, do need to use HrtIpcSetMemoryPid grant, pid==myPid=%u", pid);
      62            1 :         return;
      63              :     }
      64            0 :     HrtIpcSetMemoryPid(name, static_cast<s32>(pid));
      65              : }
      66              : 
      67              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1