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: 57.9 % 19 11
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 1 1

            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 = reinterpret_cast<SymmetricWindow*>(winHandle);
      39            2 :     CHK_PRT_RET(
      40              :         peerRank >= symWin->rankSize,
      41              :         HCCL_ERROR("[HcclSymWinGetPeerPointer] Invalid peerRank: %d. rankSize[%u]", peerRank, symWin->rankSize),
      42              :         HCCL_E_PARA);
      43            2 :     CHK_PRT_RET(
      44              :         offset >= symWin->userSize,
      45              :         HCCL_ERROR("[%s] Invalid offset: %llu. userSize[%llu]", __func__, offset, symWin->userSize), HCCL_E_PARA);
      46              : 
      47            2 :     if (symWin->mode == SymmetricMemoryMode::URMA) {
      48            0 :         CHK_PTR_NULL(symWin->remoteMems);
      49            0 :         CHK_PRT_RET(
      50              :             peerRank >= symWin->remoteMemNum,
      51              :             HCCL_ERROR(
      52              :                 "[HcclSymWinGetPeerPointer] Invalid peerRank: %d. remoteMemNum[%u]", peerRank, symWin->remoteMemNum),
      53              :             HCCL_E_PARA);
      54            0 :         CommMem& remoteMem = symWin->remoteMems[peerRank];
      55            0 :         CHK_PRT_RET(
      56              :             remoteMem.addr == nullptr || remoteMem.type == COMM_MEM_TYPE_INVALID,
      57              :             HCCL_ERROR(
      58              :                 "[HcclSymWinGetPeerPointer] remote mem is invalid, peerRank[%u], addr[%p], type[%d].", peerRank,
      59              :                 remoteMem.addr, remoteMem.type),
      60              :             HCCL_E_PARA);
      61            0 :         CHK_PRT_RET(
      62              :             offset >= remoteMem.size,
      63              :             HCCL_ERROR("[%s] Invalid offset: %llu. remoteMemSize[%llu]", __func__, offset, remoteMem.size),
      64              :             HCCL_E_PARA);
      65            0 :         *ptr = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(remoteMem.addr) + offset);
      66            0 :         HCCL_INFO(
      67              :             "[HcclSymWinGetPeerPointer] Get URMA Ptr[%p] from winHandle[%p], peerRank[%d], offset[%llu]", *ptr,
      68              :             winHandle, peerRank, offset);
      69            0 :         return HCCL_SUCCESS;
      70              :     }
      71              : 
      72            2 :     size_t peerOffset = peerRank * symWin->stride + offset;
      73            2 :     *ptr = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(symWin->baseVa) + peerOffset);
      74            2 :     HCCL_INFO(
      75              :         "[HcclSymWinGetPeerPointer] Get Ptr[%p] from winHandle[%p], peerRank[%d], peerOffset[%llu]", *ptr, winHandle,
      76              :         peerRank, peerOffset);
      77              : 
      78            2 :     return HCCL_SUCCESS;
      79              : }
      80              : 
      81              : #ifdef __cplusplus
      82              : }
      83              : #endif // __cplusplus
        

Generated by: LCOV version 2.0-1