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