LCOV - code coverage report
Current view: top level - legacy/ascend910/framework/communicator/impl/zero_copy - zero_copy_address_mgr_host.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 30 0
Test Date: 2026-08-04 10:52:23 Functions: 0.0 % 2 0

            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 "zero_copy_address_mgr.h"
      12              : #include "adapter_rts_common.h"
      13              : 
      14              : namespace hccl
      15              : {
      16            0 :     HcclResult ZeroCopyAddressMgr::InitRingBuffer()
      17              :     {
      18            0 :         if (ringBuffer_.ptr() != nullptr)
      19              :         {
      20            0 :             return HCCL_SUCCESS;
      21              :         }
      22              : 
      23            0 :         CHK_RET(DeviceMem::alloc(ringBuffer_, ZERO_COPY_BUFFER_MAX_MAP_COUNT * sizeof(ZeroCopyRingBufferItem)));
      24            0 :         CHK_RET(hrtMemSet(ringBuffer_.ptr(), ringBuffer_.size(), ringBuffer_.size()));
      25              : 
      26            0 :         CHK_RET(DeviceMem::alloc(ringBufferCtl_, sizeof(u32) + sizeof(u32)));
      27            0 :         CHK_RET(hrtMemSet(ringBufferCtl_.ptr(), ringBufferCtl_.size(), ringBufferCtl_.size()));
      28              : 
      29            0 :         devRingBufBase_ = reinterpret_cast<ZeroCopyRingBufferItem *>(ringBuffer_.ptr());
      30            0 :         devRingHead_ = reinterpret_cast<u32 *>(ringBufferCtl_.ptr());
      31            0 :         devRingTail_ = devRingHead_ + 1;
      32              : 
      33            0 :         HCCL_RUN_INFO("[ZeroCopyAddressMgr][InitRingBuffer] ringbuffer[%p] len[%lu] bufferCtl[%p] len[%lu] head[%p] tail[%p]",
      34              :                       ringBuffer_.ptr(), ringBuffer_.size(), ringBufferCtl_.ptr(), ringBufferCtl_.size(), devRingHead_, devRingTail_);
      35              : 
      36            0 :         HCCL_INFO("[ZeroCopyAddressMgr][InitRingBuffer] ringbuffer[%p] head[%p] tail[%p]", devRingBufBase_, devRingHead_, devRingTail_);
      37            0 :         return HCCL_SUCCESS;
      38              :     }
      39              : 
      40            0 :     HcclResult ZeroCopyAddressMgr::PushOne(ZeroCopyRingBufferItem &item)
      41              :     {
      42            0 :         std::lock_guard<std::mutex> guard(processRingBufferLock_);
      43            0 :         if (!needPushOne)
      44              :         {
      45            0 :             HCCL_DEBUG("[ZeroCopyAddressMgr][PushOne] don't need push");
      46            0 :             return HCCL_SUCCESS;
      47              :         }
      48              : 
      49              :         // 检测RingBuffer是否已经初始化,没有的话就初始化一下
      50            0 :         CHK_RET(InitRingBuffer());
      51              : 
      52            0 :         u32 head = 0;
      53            0 :         CHK_RET(hrtMemSyncCopy(&head, sizeof(head), devRingHead_, sizeof(head), HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_HOST));
      54            0 :         u32 tail = 0;
      55            0 :         CHK_RET(hrtMemSyncCopy(&tail, sizeof(tail), devRingTail_, sizeof(tail), HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_HOST));
      56              : 
      57            0 :         u32 updateTail = (tail + 1) % ZERO_COPY_BUFFER_MAX_MAP_COUNT;
      58            0 :         CHK_PRT_RET(updateTail == head,
      59              :                     HCCL_ERROR("[ZeroCopyAddressMgr][PushOne] ring buffer is full head[%u] tail[%u] capacity[%u]",
      60              :                                head, tail, ZERO_COPY_BUFFER_MAX_MAP_COUNT),
      61              :                     HCCL_E_INTERNAL);
      62              : 
      63            0 :         HCCL_INFO("[ZeroCopyAddressMgr][PushOne] type[%d] head[%u] tail[%u] updateTail[%u] tailAddr[%p]", item.type, head, tail, updateTail, devRingBufBase_ + tail);
      64            0 :         CHK_RET(hrtMemSyncCopy(devRingBufBase_ + tail, sizeof(ZeroCopyRingBufferItem), &item, sizeof(ZeroCopyRingBufferItem),
      65              :                                HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_HOST_TO_DEVICE));
      66            0 :         CHK_RET(hrtMemSyncCopy(devRingTail_, sizeof(updateTail), &updateTail, sizeof(updateTail),
      67              :                                HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_HOST_TO_DEVICE));
      68              : 
      69            0 :         return HCCL_SUCCESS;
      70            0 :     }
      71              : 
      72              : }
        

Generated by: LCOV version 2.0-1