LCOV - code coverage report
Current view: top level - legacy/ascend910/common/stream - stream_utils.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 88.9 % 27 24
Test Date: 2026-07-28 12:11:00 Functions: 83.3 % 6 5

            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 "rt_external.h"
      16              : #include "error_codes/rt_error_codes.h"
      17              : #include "workflow_pub.h"
      18              : 
      19              : static const std::unordered_map<int, std::function<void(bool&)>> captureStatusHandlers = {
      20              :     // ACL Graph 获取capture状态处理
      21           12 :     {aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_ACTIVE, [](bool& isCapture) { isCapture = true; }},
      22              :     {aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE,
      23           92 :         [](bool& isCapture) { HCCL_DEBUG("[GetStreamCaptureInfo]Stream capture status NONE."); }},
      24              :     {aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_INVALIDATED,
      25            0 :         [](bool& isCapture) { HCCL_ERROR("[GetStreamCaptureInfo]Stream capture status invalidated."); }}
      26              : };
      27              : 
      28          127 : HcclResult GetStreamCaptureInfo(aclrtStream stream, aclmdlRI &rtModel, bool &isCapture)
      29              : {
      30          127 :     isCapture = false;
      31          127 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
      32          127 :     aclError ret = aclmdlRICaptureGetInfo(stream, &captureStatus, &rtModel);
      33          123 :     if (ret == ACL_ERROR_RT_FEATURE_NOT_SUPPORT) {
      34            1 :         HCCL_WARNING("[%s]Stream capture not support.", __func__);
      35            1 :         return HCCL_SUCCESS;
      36              :     } else {
      37          122 :         CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[%s]aclmdlRICaptureGetInfo fail.  return[%d].", __func__, ret),
      38              :             HCCL_E_RUNTIME);
      39              :     }
      40          122 :     auto it = captureStatusHandlers.find(captureStatus);
      41          107 :     if (it != captureStatusHandlers.end()) {
      42          106 :         it->second(isCapture);
      43              :     } else {
      44            0 :         HCCL_ERROR("[%s]Unsupported stream capture status.", __func__);
      45              :     }
      46          133 :     return HCCL_SUCCESS;
      47              : }
      48              : 
      49            1 : HcclResult AddStreamToModel(rtStream_t stream, rtModel_t &rtModel)
      50              : {
      51            1 :     rtError_t ret = rtStreamAddToModel(stream, rtModel);
      52            1 :     if (ret != RT_ERROR_NONE) {
      53            1 :         HCCL_ERROR("[%s]rtStreamAddToModel failed. ret[%d].", __func__, ret);
      54            1 :         return HCCL_E_RUNTIME;
      55              :     }
      56            0 :     return HCCL_SUCCESS;
      57              : }
      58              : 
      59            6 : HcclResult GetModelId(aclmdlRI &rtModel, u64 &modelId)
      60              : {
      61              :     uint32_t mdlId;
      62            6 :     rtError_t rtRet = rtModelGetId(rtModel, &mdlId);
      63            6 :     CHK_PRT_RET(rtRet != RT_ERROR_NONE,
      64              :                 HCCL_ERROR("[%s]rtGet stream get model id fail. return[%d]", __func__, rtRet), HCCL_E_RUNTIME);
      65            6 :     modelId = static_cast<uint64_t>(mdlId);
      66            6 :     return HCCL_SUCCESS;
      67              : }
        

Generated by: LCOV version 2.0-1