LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/resource_manager - stream_active_manager.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 76.3 % 38 29
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 6 6

            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 "stream_active_manager.h"
      12              : #include "adapter_rts_common.h"
      13              : 
      14              : using namespace hccl;
      15              : std::atomic<bool> StreamActiveManager::initFlag_ = {false};
      16          650 : StreamActiveManager::StreamActiveManager() {}
      17              : 
      18          650 : StreamActiveManager::~StreamActiveManager()
      19              : {
      20          650 :     std::unique_lock<std::mutex> lock(streamActiveManagerMutex_);
      21          650 :     initFlag_ = false;
      22          650 :     streamActiveManager_.clear();
      23          650 :     lock.unlock();
      24          650 : }
      25              : 
      26          537 : StreamActiveManager& StreamActiveManager::GetInstance(s32 deviceLogicID)
      27              : {
      28         1187 :     static StreamActiveManager streamActiveManager[MAX_MODULE_DEVICE_NUM];
      29          539 :     if (static_cast<u32>(deviceLogicID) >= MAX_MODULE_DEVICE_NUM) {
      30            8 :         HCCL_WARNING("[HcomGetCtxHomInfo][GetInstance] deviceLogicID[%d] is invalid", deviceLogicID);
      31            8 :         return streamActiveManager[0];
      32              :     }
      33          531 :     return streamActiveManager[deviceLogicID];
      34              : }
      35              : 
      36          524 : HcclResult StreamActiveManager::Init()
      37              : {
      38          524 :     initFlag_ = true;
      39          524 :     return HCCL_SUCCESS;
      40              : }
      41              : 
      42            2 : HcclResult StreamActiveManager::StreamActive(HcclRtStream activeStream, HcclRtStream stream)
      43              : {
      44            2 :     std::unique_lock<std::mutex> lock(streamActiveManagerMutex_);
      45            2 :     if (initFlag_ && streamActiveManager_.count(activeStream) == 0) {
      46            0 :         CHK_RET(hrtStreamActive(activeStream, stream));
      47            0 :         streamActiveManager_.insert(activeStream);
      48            0 :         lock.unlock();
      49            0 :         s32 activeStreamId = 0;
      50            0 :         CHK_RET(hrtGetStreamId(activeStream, activeStreamId));
      51            0 :         s32 streamId = 0;
      52            0 :         CHK_RET(hrtGetStreamId(stream, streamId));
      53            0 :         HCCL_INFO("StreamActive: activeStream[%d] stream[%d]", activeStreamId, streamId);
      54              :     }
      55            2 :     return HCCL_SUCCESS;
      56            2 : }
      57              : 
      58              : // ge在model析构时,先销毁流、在unload task,此时hccl获取不到流id
      59           13 : HcclResult StreamActiveManager::StreamsUnactive(const std::vector<Stream>& streams)
      60              : {
      61           13 :     if (initFlag_) {
      62           18 :         for (auto& curStream : streams) {
      63            7 :             std::unique_lock<std::mutex> lock(streamActiveManagerMutex_);
      64            8 :             if (streamActiveManager_.count(curStream.ptr()) == 1) {
      65            0 :                 streamActiveManager_.erase(curStream.ptr());
      66              :             }
      67            7 :             lock.unlock();
      68            6 :         }
      69              :     }
      70           12 :     return HCCL_SUCCESS;
      71              : }
        

Generated by: LCOV version 2.0-1