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 "aicpu_hdc_utils.h"
12 :
13 : using namespace hccl;
14 :
15 59 : HcclResult AicpuHdcUtils::InitOpExecStatus(std::shared_ptr<hccl::HDCommunicate> d2hTransfer, HcclOpIdentifier& opId)
16 : {
17 59 : if (!d2hTransfer) {
18 2 : return HCCL_SUCCESS;
19 : }
20 57 : KfcExecStatus status;
21 57 : status.opId = opId;
22 57 : status.execStatus.kfcStatus = KfcStatus::kRuning;
23 57 : status.execStatus.kfcError = KfcError::kNone;
24 57 : status.execStatus.retryInfo.retryCount = 0;
25 57 : HCCL_INFO("InitOpExecStatus: id:%u", status.opId.index);
26 57 : return d2hTransfer->Put(0, sizeof(status), reinterpret_cast<uint8_t*>(&status));
27 : }
28 :
29 0 : HcclResult AicpuHdcUtils::SetErrorMessage(std::shared_ptr<hccl::HDCommunicate> d2hTransfer, ErrorMessageReport& emrInfo)
30 : {
31 0 : if (!d2hTransfer) {
32 0 : return HCCL_SUCCESS;
33 : }
34 :
35 0 : return d2hTransfer->Put(
36 0 : sizeof(HcclOpIdentifier) + sizeof(ExecStatusDef), sizeof(emrInfo), reinterpret_cast<uint8_t*>(&emrInfo));
37 : }
38 :
39 95 : HcclResult AicpuHdcUtils::SetOpExecStatus(
40 : std::shared_ptr<HDCommunicate> d2hTransfer, KfcStatus state, KfcError errorCode, u32 retryCount)
41 : {
42 95 : if (!d2hTransfer) {
43 11 : return HCCL_SUCCESS;
44 : }
45 84 : KfcExecStatus status;
46 84 : status.execStatus.kfcStatus = state;
47 84 : status.execStatus.kfcError = errorCode;
48 84 : status.execStatus.retryInfo.retryCount = retryCount;
49 84 : HCCL_INFO("SetOpExecStatus: state:%u", state);
50 84 : return d2hTransfer->Put(
51 84 : sizeof(status.opId), sizeof(status.execStatus), reinterpret_cast<uint8_t*>(&status.execStatus));
52 : }
53 :
54 30564576 : HcclResult AicpuHdcUtils::GetOpExecCtrlCmd(std::shared_ptr<HDCommunicate> h2dTransfer, KfcCommand& cmd)
55 : {
56 30564576 : if (!h2dTransfer) {
57 1606 : return HCCL_SUCCESS;
58 : }
59 : static KfcCommand lastCmd = KfcCommand::kNone;
60 30562970 : KfcCommand newCmd = KfcCommand::kNone;
61 30562970 : CHK_RET(h2dTransfer->Get(0, sizeof(newCmd), reinterpret_cast<uint8_t*>(&newCmd)));
62 :
63 30562970 : if ((newCmd == KfcCommand::kExit) || (newCmd == KfcCommand::kStopLaunch) || (newCmd == KfcCommand::NsStopLaunch)) {
64 448370 : cmd = newCmd;
65 : } else {
66 30114600 : cmd = (lastCmd != newCmd) ? newCmd : KfcCommand::kNone;
67 : }
68 30562970 : lastCmd = newCmd;
69 30562970 : if (cmd != KfcCommand::kNone) {
70 448387 : HCCL_INFO("hccl aicpu get cmd:%u", cmd);
71 : }
72 30562970 : return HCCL_SUCCESS;
73 : }
74 :
75 : HcclResult
76 64 : AicpuHdcUtils::GetSuspendingStatus(std::shared_ptr<HDCommunicate> h2dTransfer, HcclComSuspendingFlag& kfcFlag)
77 : {
78 64 : if (!h2dTransfer) {
79 2 : return HCCL_SUCCESS;
80 : }
81 62 : u32 startOffset = sizeof(KfcCommand) + sizeof(BackgroundCommand);
82 62 : CHK_RET(h2dTransfer->Get(startOffset, sizeof(HcclComSuspendingFlag), reinterpret_cast<uint8_t*>(&kfcFlag)));
83 62 : return HCCL_SUCCESS;
84 : }
85 :
86 8101 : HcclResult AicpuHdcUtils::GetBackGroundCommand(std::shared_ptr<HDCommunicate> h2dTransfer, BackgroundCommand& bgCmd)
87 : {
88 8101 : if (!h2dTransfer) {
89 800 : return HCCL_SUCCESS;
90 : }
91 7301 : u32 startOffset = sizeof(KfcCommand);
92 7301 : CHK_RET(h2dTransfer->Get(startOffset, sizeof(BackgroundCommand), reinterpret_cast<uint8_t*>(&bgCmd)));
93 7301 : return HCCL_SUCCESS;
94 : }
95 :
96 1 : HcclResult AicpuHdcUtils::ResponseBackGroundStatus(std::shared_ptr<HDCommunicate> d2hTransfer, KfcExecStatus& kfcStatus)
97 : {
98 1 : if (!d2hTransfer) {
99 0 : return HCCL_SUCCESS;
100 : }
101 1 : CHK_RET(d2hTransfer->Put(0, sizeof(KfcExecStatus), reinterpret_cast<uint8_t*>(&kfcStatus)));
102 1 : return HCCL_SUCCESS;
103 : }
104 :
105 0 : HcclResult AicpuHdcUtils::GetKfcCommand(const std::shared_ptr<HDCommunicate>& h2dTransfer, KfcCommand& cmd)
106 : {
107 0 : if (!h2dTransfer) {
108 0 : return HCCL_SUCCESS;
109 : }
110 0 : CHK_RET(h2dTransfer->Get(0, sizeof(KfcCommand), reinterpret_cast<uint8_t*>(&cmd)));
111 0 : return HCCL_SUCCESS;
112 : }
|