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 0 : {aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_ACTIVE, [](bool& isCapture) { isCapture = true; }},
26 81 : {aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE, [](bool& isCapture)
27 324 : { HCCL_DEBUG("[GetStreamCaptureInfo]Stream capture status NONE, isCapture is %d", isCapture);}},
28 0 : {aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_INVALIDATED, [](bool& isCapture)
29 0 : { HCCL_ERROR("[GetStreamCaptureInfo]Stream capture status invalidated, isCapture is %d", isCapture);}}
30 : };
31 :
32 82 : HcclResult GetStreamCaptureInfo(rtStream_t stream, rtModel_t &rtModel, bool &isCapture)
33 : {
34 82 : isCapture = false;
35 82 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
36 82 : rtError_t ret = aclmdlRICaptureGetInfo(stream, &captureStatus, &rtModel);
37 82 : if (ret == ACL_ERROR_RT_FEATURE_NOT_SUPPORT) {
38 3 : HCCL_WARNING("[%s]Stream capture not support.", __func__);
39 1 : return HCCL_SUCCESS;
40 : } else {
41 81 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[%s]rtStreamGetCaptureInfo fail. return[%d].", __func__, ret),
42 : HCCL_E_RUNTIME);
43 : }
44 81 : auto it = captureStatusHandlers.find(captureStatus);
45 81 : if (it != captureStatusHandlers.end()) {
46 81 : it->second(isCapture);
47 : } else {
48 0 : HCCL_ERROR("[%s]Unsupported stream capture status.", __func__);
49 0 : return HCCL_E_NOT_SUPPORT;
50 : }
51 81 : return HCCL_SUCCESS;
52 : }
53 :
54 1 : HcclResult AddStreamToModel(rtStream_t stream, rtModel_t &rtModel)
55 : {
56 1 : rtError_t ret = rtStreamAddToModel(stream, rtModel);
57 1 : if (ret != RT_ERROR_NONE) {
58 3 : HCCL_ERROR("[%s]rtStreamAddToModel failed. ret[%d].", __func__, ret);
59 1 : return HCCL_E_RUNTIME;
60 : }
61 0 : return HCCL_SUCCESS;
62 : }
63 :
64 1 : HcclResult GetModelId(rtModel_t &rtModel, u32 &modelId)
65 : {
66 1 : rtError_t ret = rtModelGetId(rtModel, &modelId);
67 1 : if (ret != RT_ERROR_NONE) {
68 3 : HCCL_ERROR("[%s]rtModelGetId failed. ret[%d].", __func__, ret);
69 1 : return HCCL_E_RUNTIME;
70 : }
71 0 : return HCCL_SUCCESS;
72 : }
73 :
74 : } // namespace Hccl
|