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_handler.h"
12 : #include "log.h"
13 : #include "internal_exception.h"
14 : #include "exception_util.h"
15 :
16 : namespace Hccl {
17 :
18 2 : AicpuHdcHandler::AicpuHdcHandler(const HDCommunicateLite& h2dTransfer, const HDCommunicateLite& d2hTransfer)
19 2 : : h2dTransfer_(const_cast<HDCommunicateLite*>(&h2dTransfer)),
20 2 : d2hTransfer_(const_cast<HDCommunicateLite*>(&d2hTransfer))
21 2 : {}
22 :
23 2 : KfcCommand AicpuHdcHandler::GetKfcCommand()
24 : {
25 2 : KfcCommand cmd;
26 2 : auto ret = h2dTransfer_->Get(0, sizeof(KfcCommand), reinterpret_cast<uint8_t*>(&cmd));
27 2 : if (ret != HcclResult::HCCL_SUCCESS) {
28 0 : THROW<InternalException>(StringFormat("[AicpuHdcHandler] h2dTransfer Get fail, ret[%d]", ret));
29 : }
30 :
31 2 : if (lastCmd_ != cmd) {
32 6 : HCCL_INFO("[AicpuHdcHandler] Get new KfcCommand[%u], last KfcCommand[%u]", cmd, lastCmd_);
33 2 : lastCmd_ = cmd;
34 : }
35 2 : return cmd;
36 : }
37 :
38 2 : void AicpuHdcHandler::SetKfcExecStatus(KfcStatus state, KfcErrType errorCode) const
39 : {
40 2 : KfcExecStatus status;
41 2 : status.kfcStatus = state;
42 2 : status.kfcError = errorCode;
43 6 : HCCL_INFO("[AicpuHdcHandler] SetKfcExecStatus: state[%u], code[%u]", state, errorCode);
44 2 : auto ret = d2hTransfer_->Put(0, sizeof(KfcExecStatus), reinterpret_cast<uint8_t*>(&status));
45 2 : if (ret != HcclResult::HCCL_SUCCESS) {
46 0 : THROW<InternalException>(StringFormat("[AicpuHdcHandler] d2hTransfer Put fail, ret[%d]", ret));
47 : }
48 2 : }
49 :
50 : } // namespace Hccl
|