LCOV - code coverage report
Current view: top level - legacy/ascend950/common - stream_utils.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 71.4 % 35 25
Test Date: 2026-08-18 17:47:01 Functions: 66.7 % 6 4

            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_utils.h"
      12              : #include <unordered_map>
      13              : #include <functional>
      14              : #include "log.h"
      15              : #include "acl/acl_rt.h"
      16              : #include "rt_external.h"
      17              : 
      18              : namespace Hccl {
      19              : #ifdef CCL_FWK_LLT
      20              : #define ACL_ERROR_RT_FEATURE_NOT_SUPPORT 207000 // feature not support
      21              : #endif
      22              : 
      23              : static const std::unordered_map<int, std::function<void(bool&)>> captureStatusHandlers = {
      24              :     // ACL Graph 获取capture状态处理
      25              :     {aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_ACTIVE,
      26            0 :      [](bool& isCapture) {
      27            0 :          isCapture = true;
      28            0 :      }},
      29              :     {aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE,
      30           76 :      [](bool& isCapture) {
      31          228 :          HCCL_DEBUG("[GetStreamCaptureInfo]Stream capture status NONE, isCapture is %d", isCapture);
      32           76 :      }},
      33            0 :     {aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_INVALIDATED, [](bool& isCapture) {
      34            0 :          HCCL_ERROR("[GetStreamCaptureInfo]Stream capture status invalidated, isCapture is %d", isCapture);
      35            0 :      }}};
      36              : 
      37           78 : HcclResult GetStreamCaptureInfo(rtStream_t stream, rtModel_t& rtModel, bool& isCapture)
      38              : {
      39           78 :     isCapture = false;
      40           78 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
      41           78 :     rtError_t ret = aclmdlRICaptureGetInfo(stream, &captureStatus, &rtModel);
      42           78 :     if (ret == ACL_ERROR_RT_FEATURE_NOT_SUPPORT) {
      43            3 :         HCCL_WARNING("[%s]Stream capture not support.", __func__);
      44            1 :         return HCCL_SUCCESS;
      45              :     } else {
      46           80 :         CHK_PRT_RET(
      47              :             ret != RT_ERROR_NONE, HCCL_ERROR("[%s]rtStreamGetCaptureInfo fail. return[%d].", __func__, ret),
      48              :             HCCL_E_RUNTIME);
      49              :     }
      50           76 :     auto it = captureStatusHandlers.find(captureStatus);
      51           76 :     if (it != captureStatusHandlers.end()) {
      52           76 :         it->second(isCapture);
      53              :     } else {
      54            0 :         HCCL_ERROR("[%s]Unsupported stream capture status.", __func__);
      55            0 :         return HCCL_E_NOT_SUPPORT;
      56              :     }
      57           76 :     return HCCL_SUCCESS;
      58              : }
      59              : 
      60            1 : HcclResult AddStreamToModel(rtStream_t stream, rtModel_t& rtModel)
      61              : {
      62            1 :     rtError_t ret = rtStreamAddToModel(stream, rtModel);
      63            1 :     if (ret != RT_ERROR_NONE) {
      64            3 :         HCCL_ERROR("[%s]rtStreamAddToModel failed. ret[%d].", __func__, ret);
      65            1 :         return HCCL_E_RUNTIME;
      66              :     }
      67            0 :     return HCCL_SUCCESS;
      68              : }
      69              : 
      70            1 : HcclResult GetModelId(rtModel_t& rtModel, u32& modelId)
      71              : {
      72            1 :     rtError_t ret = rtModelGetId(rtModel, &modelId);
      73            1 :     if (ret != RT_ERROR_NONE) {
      74            3 :         HCCL_ERROR("[%s]rtModelGetId failed. ret[%d].", __func__, ret);
      75            1 :         return HCCL_E_RUNTIME;
      76              :     }
      77            0 :     return HCCL_SUCCESS;
      78              : }
      79              : 
      80              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1