LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/resource_manager/stream - aicpu_stream_manager.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 98.1 % 54 53
Test Date: 2026-07-28 12:11:00 Functions: 100.0 % 7 7

            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_stream_manager.h"
      12              : #include <algorithm>
      13              : #include "log.h"
      14              : #include "exception_util.h"
      15              : #include "binary_stream.h"
      16              : #include "internal_exception.h"
      17              : #include "stream_utils.h"
      18              : 
      19              : namespace Hccl {
      20              : 
      21          491 : AicpuStreamManager::~AicpuStreamManager()
      22              : {
      23          491 :     DECTOR_TRY_CATCH("AicpuStreamManager", Clear());
      24          491 : }
      25              : 
      26           11 : void AicpuStreamManager::AllocStreams(u32 num)
      27              : {
      28           11 :     int size = streams.size();
      29           11 :     if (static_cast<int>(num) <= size) {
      30            1 :         return;
      31              :     }
      32           10 :     streams.resize(num);
      33           20 :     for (int i = size; i < static_cast<int>(num); i++) {
      34           10 :         streams[i] = std::make_unique<Stream>(true, false);
      35           10 :         stream_pointers.push_back(streams[i].get());
      36              :     }
      37              : }
      38              : 
      39          497 : void AicpuStreamManager::Clear()
      40              : {
      41          497 :     streams.clear();
      42          497 : }
      43              : 
      44            2 : std::vector<char> AicpuStreamManager::GetPackedData()
      45              : {
      46            2 :     u32 num = streams.size();
      47            2 :     if (num == 0) {
      48            0 :         THROW<InternalException>("opbase stream num is 0.");
      49              :     }
      50              : 
      51            2 :     std::vector<char> data;
      52            4 :     for (auto &it : streams) {
      53            2 :         auto uniqueId = it->GetUniqueId();
      54            6 :         HCCL_INFO("AicpuStreamManager::GetPackedData:%s", it->Describe().c_str());
      55            2 :         data.insert(data.end(), uniqueId.begin(), uniqueId.end());
      56            2 :     }
      57              : 
      58            2 :     BinaryStream binaryStream;
      59            2 :     binaryStream << num;
      60            2 :     binaryStream << data;
      61              : 
      62            2 :     std::vector<char> result;
      63            2 :     binaryStream.Dump(result);
      64            6 :     HCCL_INFO("AicpuStreamManager::GetPackedData:%s", Bytes2hex(result.data(), result.size()).c_str());
      65            2 :     return result;
      66            2 : }
      67              : 
      68           17 : void AicpuStreamManager::AllocFreeStream()
      69              : {
      70           17 :     if (freeStream  == nullptr) {
      71           14 :         freeStream = std::make_unique<Stream>(false, false);
      72           42 :         HCCL_RUN_INFO("AicpuStreamManager %s allocted: %s", __func__, freeStream->Describe().c_str());
      73              :     }
      74           17 : }
      75              : 
      76            9 : HcclResult AicpuStreamManager::CaptureFreeStream(const Stream *mainStream, const Stream *slaveStream) const
      77              : {
      78           27 :     HCCL_DEBUG("[AicpuStreamManager][%s] mainStream[%u] slaveStream[%u]",
      79              :         __func__, mainStream->GetId(), slaveStream->GetId());
      80            9 :     rtModel_t rtModel = nullptr;
      81            9 :     bool isCapture = false;
      82            9 :     u32 modelId = 0;
      83           12 :     CHK_RET(GetStreamCaptureInfo(mainStream->GetPtr(), rtModel, isCapture));
      84            8 :     if (isCapture) {
      85           13 :         CHK_PTR_NULL(rtModel);
      86            1 :         CHK_RET(GetModelId(rtModel, modelId));
      87            1 :         CHK_RET(AddStreamToModel(slaveStream->GetPtr(), rtModel));
      88            3 :         HCCL_INFO("[AicpuStreamManager][%s] Add freeStream[%u] to model[%u] success, mainStream[%u]",
      89              :             __func__, slaveStream->GetId(), modelId, mainStream->GetId());
      90              :     }
      91            5 :     return HCCL_SUCCESS;
      92              : }
      93              : 
      94            8 : void AicpuStreamManager::AclGraphCaptureFreeStream(const Stream *mainStream) const
      95              : {
      96            8 :     auto ret = CaptureFreeStream(mainStream, freeStream.get());
      97            8 :     if (ret != HCCL_SUCCESS) {
      98            4 :         THROW<InternalException>(StringFormat("[AicpuStreamManager::%s] capture freeStream fail, "
      99              :                                               "error code:%d", __func__, ret));
     100              :     }
     101            4 : }
     102              : 
     103              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1