LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/stream - stream.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 76.9 % 52 40
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 13 13

            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.h"
      12              : #include "runtime_api_exception.h"
      13              : #include "log.h"
      14              : #include "binary_stream.h"
      15              : namespace Hccl {
      16              : 
      17          202 : Stream::Stream(aclrtStream ptr, bool isMaster) : ptr(ptr), selfOwned(false), isMaster_(isMaster)
      18              : {
      19          202 :     id = static_cast<u32>(HrtGetStreamId(ptr));
      20          202 :     InitDevPhyId();
      21          202 : }
      22              : 
      23          123 : Stream::Stream(bool deviceUsed, bool isMaster) : selfOwned(true), devUsed(deviceUsed), isMaster_(isMaster)
      24              : {
      25              :     try {
      26          123 :         if (deviceUsed) {
      27           11 :             ptr = HrtStreamCreateWithFlags(HCCL_STREAM_PRIORITY_HIGH, ACL_STREAM_DEVICE_USE_ONLY);
      28           11 :             sqId = HrtStreamGetSqId(ptr);
      29           11 :             cqId = HrtStreamGetCqId(ptr);
      30              :         } else {
      31          112 :             ptr = HrtStreamCreateWithFlags(HCCL_STREAM_PRIORITY_HIGH, ACL_STREAM_FAST_LAUNCH | ACL_STREAM_FAST_SYNC);
      32          112 :             HrtStreamSetMode(ptr, STREAM_MODE_STOP_ON_FAILURE);
      33              :         }
      34          123 :         id = static_cast<u32>(HrtGetStreamId(ptr));
      35          123 :         InitDevPhyId();
      36            0 :     } catch (RuntimeApiException& e) {
      37            0 :         HCCL_ERROR("HrtGetStreamId failed: %s", e.what());
      38            0 :         HrtStreamDestroy(ptr);
      39            0 :         throw;
      40            0 :     }
      41          123 : }
      42              : 
      43          325 : Stream::~Stream()
      44              : {
      45              :     try {
      46          325 :         if (selfOwned) {
      47          123 :             HrtStreamDestroy(ptr);
      48              :         }
      49            0 :     } catch (HcclException& e) {
      50            0 :         HCCL_ERROR("%s", e.what());
      51            0 :     } catch (std::exception& e) {
      52            0 :         HCCL_ERROR("%s", e.what());
      53            0 :     } catch (...) {
      54            0 :         HCCL_ERROR("Unknown Error occurs when destruct stream %d", id);
      55            0 :     }
      56          325 : }
      57              : 
      58           36 : void Stream::SetStmMode(u64 stmMode) { mode = stmMode; }
      59              : 
      60          150 : aclrtStream Stream::GetPtr() const { return ptr; }
      61              : 
      62          137 : u32 Stream::GetId() const { return id; }
      63              : 
      64            7 : u32 Stream::GetSqId() const { return sqId; }
      65              : 
      66           25 : bool Stream::IsMaster() const { return isMaster_; }
      67              : 
      68            3 : bool Stream::IsSelfOwned() const { return selfOwned; }
      69              : 
      70           16 : u64 Stream::GetMode() const { return mode; }
      71              : 
      72            3 : std::vector<char> Stream::GetUniqueId() const
      73              : {
      74            3 :     std::vector<char> result;
      75              : 
      76            3 :     BinaryStream binaryStream;
      77            3 :     binaryStream << id;
      78            3 :     binaryStream << sqId;
      79            3 :     binaryStream << devPhyId;
      80            3 :     binaryStream << cqId;
      81            3 :     binaryStream.Dump(result);
      82            9 :     HCCL_INFO("Stream::GetUniqueId:%s:data=%s", Describe().c_str(), Bytes2hex(result.data(), result.size()).c_str());
      83            3 :     return result;
      84            3 : }
      85              : 
      86           26 : std::string Stream::Describe() const
      87              : {
      88              :     return StringFormat(
      89           26 :         "Stream[ptr=%p, id=%u, sqId=%u, selfOwned=%u, devUsed=%d, devPhyId=%u]", ptr, id, sqId, selfOwned, devUsed,
      90           26 :         devPhyId);
      91              : }
      92              : 
      93          303 : void Stream::InitDevPhyId() { devPhyId = HrtGetDevicePhyIdByIndex(HrtGetDevice()); }
      94              : 
      95              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1