LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/resource_manager - workspace_resource.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 48.0 % 50 24
Test Date: 2026-08-18 17:47:01 Functions: 53.3 % 15 8

            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 "workspace_resource_impl.h"
      12              : #include "workspace_resource.h"
      13              : 
      14              : namespace hccl {
      15          524 : WorkspaceResource::WorkspaceResource(u32 devicePhyId, s32 deviceLogicId, CCLBufferManager* cclBufferManagerPtr)
      16              : {
      17          524 :     pimpl_.reset((new (std::nothrow) WorkspaceResourceImpl(devicePhyId, deviceLogicId, cclBufferManagerPtr)));
      18          524 : }
      19              : 
      20          524 : WorkspaceResource::~WorkspaceResource() {}
      21              : 
      22           91 : HcclResult WorkspaceResource::GetWorkspaceMemSize(
      23              :     const std::string& opType, u64 count, HcclDataType dataType, u32 rankSize, u64& memSize, DevType deviceType) const
      24              : {
      25           91 :     CHK_SMART_PTR_NULL(pimpl_);
      26           91 :     return pimpl_->GetWorkspaceMemSize(opType, count, dataType, rankSize, memSize, deviceType);
      27              : }
      28              : 
      29            0 : HcclResult WorkspaceResource::RegisterMaster(const std::string& tag, Stream stream)
      30              : {
      31            0 :     CHK_SMART_PTR_NULL(pimpl_);
      32            0 :     return pimpl_->RegisterMaster(tag, stream);
      33              : }
      34              : 
      35              : // 基于tag 初始设置资源,包含 Stream 资源 和 内存 资源
      36          155 : HcclResult WorkspaceResource::SetWorkspaceResource(
      37              :     const std::string& tag, void* memPtr, u64& maxSize, std::vector<rtStream_t>& stream)
      38              : {
      39          155 :     CHK_SMART_PTR_NULL(pimpl_);
      40          155 :     return pimpl_->SetWorkspaceResource(tag, memPtr, maxSize, stream);
      41              : }
      42              : 
      43              : // 基于 tag 销毁资源,包含 Stream 资源 和 内存 资源
      44           16 : void WorkspaceResource::DestroyWorkspaceResource(const std::string& tag)
      45              : {
      46           16 :     CHK_SMART_PTR_RET_NULL(pimpl_);
      47           14 :     pimpl_->DestroyWorkspaceResource(tag);
      48           16 :     return;
      49              : }
      50              : 
      51              : // 销毁 Workspace全局资源,包含 Stream 资源 和 内存 资源
      52            0 : void WorkspaceResource::DestroyWorkspaceResource()
      53              : {
      54            0 :     CHK_SMART_PTR_RET_NULL(pimpl_);
      55            0 :     pimpl_->DestroyWorkspaceResource();
      56            0 :     return;
      57              : }
      58              : 
      59              : // 基于tag 分配 Stream 资源
      60           15 : std::vector<Stream> WorkspaceResource::AllocSlaveStreams(const std::string& tag, u32 num)
      61              : {
      62           15 :     HCCL_DEBUG("[WorkspaceResource][AllocSlaveStreams]requesting for [%u] slaves, tag[%s].", num, tag.c_str());
      63              :     // 安全性的保护,无实际业务意义
      64           16 :     if (!pimpl_) {
      65            0 :         HCCL_ERROR("[WorkspaceResource][AllocSlaveStreams] pimpl_ is nullptr.");
      66            0 :         return std::vector<Stream>();
      67              :     }
      68           15 :     return pimpl_->AllocSlaveStreams(tag, num);
      69              : }
      70              : 
      71              : // 基于tag 销毁 Stream 资源
      72            0 : HcclResult WorkspaceResource::DestroyStream(const std::string& tag)
      73              : {
      74            0 :     CHK_SMART_PTR_NULL(pimpl_);
      75            0 :     return pimpl_->DestroyStream(tag);
      76              : }
      77              : 
      78           24 : DeviceMem WorkspaceResource::AllocDeviceMem(const std::string& tag, u64 size)
      79              : {
      80              :     // 安全性的保护,无实际业务意义
      81           24 :     if (!pimpl_) {
      82            0 :         HCCL_ERROR("[WorkspaceResource][AllocDeviceMem] pimpl_ is nullptr.");
      83            0 :         return DeviceMem::create(nullptr, 0);
      84              :     }
      85           24 :     return pimpl_->AllocDeviceMem(tag, size);
      86              : }
      87              : 
      88              : // 基于tag 销毁 DeviceMem 资源
      89            0 : HcclResult WorkspaceResource::DestroyDeviceMem(const std::string& tag)
      90              : {
      91            0 :     CHK_SMART_PTR_NULL(pimpl_);
      92            0 :     return pimpl_->DestroyDeviceMem(tag);
      93              : }
      94              : 
      95           95 : HcclResult WorkspaceResource::CreateOpBasedResources(
      96              :     const HcclCMDType& opType, const std::string& tag, const HcomCollOpInfo& opInfo)
      97              : {
      98           95 :     CHK_SMART_PTR_NULL(pimpl_);
      99           95 :     return pimpl_->CreateOpBasedResources(opType, tag, opInfo);
     100              : }
     101              : 
     102            0 : HcclResult WorkspaceResource::CreateRemoteOpBasedResources(u64 memSize, const std::string& tag)
     103              : {
     104            0 :     CHK_SMART_PTR_NULL(pimpl_);
     105            0 :     return pimpl_->CreateRemoteOpBasedResources(memSize, tag);
     106              : }
     107              : 
     108            0 : HcclResult WorkspaceResource::CreateOrUpdateRemoteOpBasedResources(u64 memSize, const std::string& tag)
     109              : {
     110            0 :     CHK_SMART_PTR_NULL(pimpl_);
     111            0 :     return pimpl_->CreateOrUpdateRemoteOpBasedResources(memSize, tag);
     112              : }
     113              : 
     114            0 : HcclResult WorkspaceResource::DestroyRemoteOpBasedMem(const std::string& tag)
     115              : {
     116            0 :     CHK_SMART_PTR_NULL(pimpl_);
     117            0 :     return pimpl_->DestroyRemoteOpBasedMem(tag);
     118              : }
     119              : } // namespace hccl
        

Generated by: LCOV version 2.0-1