LCOV - code coverage report
Current view: top level - legacy/ascend910/framework/device/framework - aicpu_symmetric_memory.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 90.0 % 30 27
Test Date: 2026-08-29 17:38:31 Functions: 100.0 % 2 2

            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 "aicpu_symmetric_memory.h"
      12              : #include "symmetric_memory/symmetric_memory.h"
      13              : 
      14              : #ifdef CCL_KERNEL_AICPU
      15              : namespace hccl {
      16              : 
      17              : class SymmetricMemory::SimpleVaAllocator {
      18              : public:
      19              :     // 不需要任何成员,只要让编译器觉得它是个完整的类就行
      20              :     SimpleVaAllocator() {}
      21              :     ~SimpleVaAllocator() {}
      22              : };
      23              : 
      24              : SymmetricMemory::~SymmetricMemory() {}
      25              : } // namespace hccl
      26              : #endif // CCL_KERNEL_AICPU
      27              : 
      28              : using namespace hccl;
      29              : 
      30              : #ifdef __cplusplus
      31              : extern "C" {
      32              : #endif // __cplusplus
      33              : 
      34            2 : HcclResult HcclSymWinGetPeerPointer(HcclCommSymWindow winHandle, size_t offset, uint32_t peerRank, void** ptr)
      35              : {
      36            2 :     CHK_PTR_NULL(winHandle);
      37            2 :     CHK_PTR_NULL(ptr);
      38            2 :     SymmetricWindow* symWin = static_cast<SymmetricWindow*>(winHandle);
      39            2 :     if (symWin->mode == SymmetricMemoryMode::URMA) {
      40            0 :         HCCL_ERROR("[HcclSymWinGetPeerPointer] not support URMA mode, winHandle[%p] is URMA mode.", winHandle);
      41            0 :         *ptr = nullptr;
      42            0 :         return HCCL_E_NOT_SUPPORT;
      43              :     }
      44            2 :     CHK_PRT_RET(
      45              :         peerRank >= symWin->rankSize,
      46              :         HCCL_ERROR("[HcclSymWinGetPeerPointer] Invalid peerRank: %d. rankSize[%u]", peerRank, symWin->rankSize),
      47              :         HCCL_E_PARA);
      48            2 :     CHK_PRT_RET(
      49              :         offset >= symWin->userSize,
      50              :         HCCL_ERROR("[%s] Invalid offset: %llu. userSize[%llu]", __func__, offset, symWin->userSize), HCCL_E_PARA);
      51              : 
      52            2 :     size_t peerOffset = peerRank * symWin->stride + offset;
      53            2 :     *ptr = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(symWin->baseVa) + peerOffset);
      54            2 :     HCCL_INFO(
      55              :         "[HcclSymWinGetPeerPointer] Get Ptr[%p] from winHandle[%p], peerRank[%d], peerOffset[%llu]", *ptr, winHandle,
      56              :         peerRank, peerOffset);
      57              : 
      58            2 :     return HCCL_SUCCESS;
      59              : }
      60              : 
      61            9 : HcclResult HcclSymWinGetRemoteAddr(HcclCommSymWindow winHandle, size_t offset, uint32_t peerRank, void** ptr)
      62              : {
      63            9 :     CHK_PTR_NULL(winHandle);
      64            8 :     CHK_PTR_NULL(ptr);
      65            7 :     SymmetricWindow* symWin = static_cast<SymmetricWindow*>(winHandle);
      66            7 :     if (symWin->mode != SymmetricMemoryMode::URMA) {
      67            1 :         HCCL_ERROR("[HcclSymWinGetRemoteAddr] only support URMA mode, winHandle[%p] is not URMA mode.", winHandle);
      68            1 :         *ptr = nullptr;
      69            1 :         return HCCL_E_NOT_SUPPORT;
      70              :     }
      71            6 :     CHK_PTR_NULL(symWin->remoteMems);
      72            5 :     CHK_PRT_RET(
      73              :         peerRank >= symWin->remoteMemNum,
      74              :         HCCL_ERROR("[HcclSymWinGetRemoteAddr] Invalid peerRank: %d. remoteMemNum[%u]", peerRank, symWin->remoteMemNum),
      75              :         HCCL_E_PARA);
      76            4 :     CommMem& remoteMem = symWin->remoteMems[peerRank];
      77            4 :     CHK_PRT_RET(
      78              :         remoteMem.addr == nullptr || remoteMem.type == COMM_MEM_TYPE_INVALID,
      79              :         HCCL_ERROR(
      80              :             "[HcclSymWinGetRemoteAddr] remote mem is invalid, peerRank[%u], addr[%p], type[%d].", peerRank,
      81              :             remoteMem.addr, remoteMem.type),
      82              :         HCCL_E_PARA);
      83            2 :     CHK_PRT_RET(
      84              :         offset >= remoteMem.size,
      85              :         HCCL_ERROR("[%s] Invalid offset: %llu. remoteMemSize[%llu]", __func__, offset, remoteMem.size), HCCL_E_PARA);
      86            1 :     *ptr = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(remoteMem.addr) + offset);
      87            1 :     HCCL_INFO(
      88              :         "[HcclSymWinGetRemoteAddr] Get URMA Ptr[%p] from winHandle[%p], peerRank[%d], offset[%llu]", *ptr, winHandle,
      89              :         peerRank, offset);
      90              : 
      91            1 :     return HCCL_SUCCESS;
      92              : }
      93              : 
      94              : #ifdef __cplusplus
      95              : }
      96              : #endif // __cplusplus
        

Generated by: LCOV version 2.0-1