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 31063894 : HcclResult AicpuHdcUtils::GetOpExecCtrlCmd(std::shared_ptr<HDCommunicate> h2dTransfer, KfcCommand& cmd)
55 : {
56 31063894 : if (!h2dTransfer) {
57 1606 : return HCCL_SUCCESS;
58 : }
59 : static KfcCommand lastCmd = KfcCommand::kNone;
60 31062288 : KfcCommand newCmd = KfcCommand::kNone;
61 31062288 : CHK_RET(h2dTransfer->Get(0, sizeof(newCmd), reinterpret_cast<uint8_t*>(&newCmd)));
62 :
63 31062288 : if ((newCmd == KfcCommand::kExit) || (newCmd == KfcCommand::kStopLaunch) || (newCmd == KfcCommand::NsStopLaunch)) {
64 439228 : cmd = newCmd;
65 : } else {
66 30623060 : cmd = (lastCmd != newCmd) ? newCmd : KfcCommand::kNone;
67 : }
68 31062288 : lastCmd = newCmd;
69 31062288 : if (cmd != KfcCommand::kNone) {
70 439245 : HCCL_INFO("hccl aicpu get cmd:%u", cmd);
71 : }
72 31062288 : return HCCL_SUCCESS;
73 : }
74 :
75 64 : HcclResult AicpuHdcUtils::GetSuspendingStatus(std::shared_ptr<HDCommunicate> h2dTransfer, HcclComSuspendingFlag& flag)
76 : {
77 64 : if (!h2dTransfer) {
78 2 : return HCCL_SUCCESS;
79 : }
80 62 : u32 startOffset = sizeof(KfcCommand) + sizeof(BackgroundCommand);
81 62 : CHK_RET(h2dTransfer->Get(startOffset, sizeof(HcclComSuspendingFlag), reinterpret_cast<uint8_t*>(&flag)));
82 62 : return HCCL_SUCCESS;
83 : }
84 :
85 8101 : HcclResult AicpuHdcUtils::GetBackGroundCommand(std::shared_ptr<HDCommunicate> h2dTransfer, BackgroundCommand& bgCmd)
86 : {
87 8101 : if (!h2dTransfer) {
88 800 : return HCCL_SUCCESS;
89 : }
90 7301 : u32 startOffset = sizeof(KfcCommand);
91 7301 : CHK_RET(h2dTransfer->Get(startOffset, sizeof(BackgroundCommand), reinterpret_cast<uint8_t*>(&bgCmd)));
92 7301 : return HCCL_SUCCESS;
93 : }
94 :
95 1 : HcclResult AicpuHdcUtils::ResponseBackGroundStatus(std::shared_ptr<HDCommunicate> d2hTransfer, KfcExecStatus& kfcStatus)
96 : {
97 1 : if (!d2hTransfer) {
98 0 : return HCCL_SUCCESS;
99 : }
100 1 : CHK_RET(d2hTransfer->Put(0, sizeof(KfcExecStatus), reinterpret_cast<uint8_t*>(&kfcStatus)));
101 1 : return HCCL_SUCCESS;
102 : }
103 :
104 0 : HcclResult AicpuHdcUtils::GetKfcCommand(const std::shared_ptr<HDCommunicate>& h2dTransfer, KfcCommand& cmd)
105 : {
106 0 : if (!h2dTransfer) {
107 0 : return HCCL_SUCCESS;
108 : }
109 0 : CHK_RET(h2dTransfer->Get(0, sizeof(KfcCommand), reinterpret_cast<uint8_t*>(&cmd)));
110 0 : return HCCL_SUCCESS;
111 : }
|