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 "operator_kernel_end_graph.h"
12 :
13 : #include "aicpusd_info.h"
14 : #include "aicpusd_status.h"
15 : #include "aicpusd_resource_manager.h"
16 : #include "operator_kernel_common.h"
17 :
18 :
19 : namespace AicpuSchedule {
20 : namespace {
21 : const std::string KERNEL_END_GRAPH = "endGraph";
22 : } // namespace
23 :
24 3 : int32_t OperatorKernelEndGraph::Compute(const AicpuTaskInfo &kernelTaskInfo, const RunContext &taskContext)
25 : {
26 3 : const auto modelIdPtr = PtrToPtr<void, uint32_t>(ValueToPtr(static_cast<uintptr_t>(kernelTaskInfo.paraBase)));
27 3 : if (modelIdPtr == nullptr) {
28 1 : aicpusd_err("ModelEndGraph kernelTaskInfo paramBase is null, modelId[%u], streamId[%u], taskId[%u]",
29 : taskContext.modelId, taskContext.streamId, kernelTaskInfo.taskID);
30 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
31 : }
32 :
33 2 : const uint32_t modelId = *modelIdPtr;
34 2 : if (modelId != taskContext.modelId) {
35 1 : aicpusd_warn("ModelEndGraph kernelTaskInfo modelId[%u] is diff with context, "
36 : "modelId[%u], streamId[%u], taskId[%u]", modelId, taskContext.modelId, taskContext.streamId,
37 : kernelTaskInfo.taskID);
38 : }
39 :
40 2 : aicpusd_info("Begin to execute EndGraph. modelId[%u].", modelId);
41 2 : bool hasWait = false;
42 2 : uint32_t waitStreamId = 0U;
43 2 : EventWaitManager::EndGraphWaitManager().Event(static_cast<size_t>(modelId), hasWait, waitStreamId);
44 2 : if (hasWait) {
45 1 : AICPUSubEventInfo subEventInfo = {};
46 1 : subEventInfo.modelId = modelId;
47 1 : subEventInfo.para.streamInfo.streamId = waitStreamId;
48 1 : const int32_t ret = OperatorKernelCommon::SendAICPUSubEvent(PtrToPtr<AICPUSubEventInfo, char_t>(&subEventInfo),
49 : static_cast<uint32_t>(sizeof(AICPUSubEventInfo)), AICPU_SUB_EVENT_RECOVERY_STREAM);
50 1 : return ret;
51 : }
52 :
53 1 : return AICPU_SCHEDULE_OK;
54 : }
55 :
56 6 : REGISTER_OPERATOR_KERNEL(KERNEL_END_GRAPH, OperatorKernelEndGraph);
57 : } // namespace AicpuSchedule
|