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

Generated by: LCOV version 2.0-1