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 : {aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_ACTIVE,
22 12 : [](bool& isCapture) {
23 12 : isCapture = true;
24 12 : }},
25 : {aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE,
26 91 : []([[maybe_unused]] bool& isCapture) {
27 91 : HCCL_DEBUG("[GetStreamCaptureInfo]Stream capture status NONE.");
28 124 : }},
29 0 : {aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_INVALIDATED, []([[maybe_unused]] bool& isCapture) {
30 0 : HCCL_ERROR("[GetStreamCaptureInfo]Stream capture status invalidated.");
31 0 : }}};
32 :
33 124 : HcclResult GetStreamCaptureInfo(aclrtStream stream, aclmdlRI& rtModel, bool& isCapture)
34 : {
35 124 : isCapture = false;
36 124 : aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
37 124 : aclError ret = aclmdlRICaptureGetInfo(stream, &captureStatus, &rtModel);
38 122 : if (ret == ACL_ERROR_RT_FEATURE_NOT_SUPPORT) {
39 1 : HCCL_WARNING("[%s]Stream capture not support.", __func__);
40 1 : return HCCL_SUCCESS;
41 : } else {
42 121 : CHK_PRT_RET(
43 : ret != ACL_SUCCESS, HCCL_ERROR("[%s]aclmdlRICaptureGetInfo fail. return[%d].", __func__, ret),
44 : HCCL_E_RUNTIME);
45 : }
46 121 : auto it = captureStatusHandlers.find(captureStatus);
47 105 : if (it != captureStatusHandlers.end()) {
48 107 : it->second(isCapture);
49 : } else {
50 0 : HCCL_ERROR("[%s]Unsupported stream capture status.", __func__);
51 : }
52 133 : return HCCL_SUCCESS;
53 : }
54 :
55 1 : HcclResult AddStreamToModel(rtStream_t stream, rtModel_t& rtModel)
56 : {
57 1 : rtError_t ret = rtStreamAddToModel(stream, rtModel);
58 1 : if (ret != RT_ERROR_NONE) {
59 1 : HCCL_ERROR("[%s]rtStreamAddToModel failed. ret[%d].", __func__, ret);
60 1 : return HCCL_E_RUNTIME;
61 : }
62 0 : return HCCL_SUCCESS;
63 : }
64 :
65 6 : HcclResult GetModelId(aclmdlRI& rtModel, u64& modelId)
66 : {
67 : uint32_t mdlId;
68 6 : rtError_t rtRet = rtModelGetId(rtModel, &mdlId);
69 6 : CHK_PRT_RET(
70 : rtRet != RT_ERROR_NONE, HCCL_ERROR("[%s]rtGet stream get model id fail. return[%d]", __func__, rtRet),
71 : HCCL_E_RUNTIME);
72 6 : modelId = static_cast<uint64_t>(mdlId);
73 6 : return HCCL_SUCCESS;
74 : }
|