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

Generated by: LCOV version 2.0-1