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_model_wait_end_graph.h"
12 :
13 : #include "aicpusd_info.h"
14 : #include "aicpusd_status.h"
15 : #include "aicpusd_resource_manager.h"
16 : #include "aicpusd_model_statistic.h"
17 : #include "operator_kernel_common.h"
18 :
19 :
20 : namespace AicpuSchedule {
21 : namespace {
22 : const std::string KERNEL_MODEL_WAIT_END_GRAPH = "modelWaitEndGraph";
23 : } // namespace
24 :
25 2 : int32_t OperatorKernelModelWaitEndGraph::Compute(const AicpuTaskInfo &kernelTaskInfo, const RunContext &taskContext)
26 : {
27 2 : const auto modelIdPtr = PtrToPtr<void, uint32_t>(ValueToPtr(static_cast<uintptr_t>(kernelTaskInfo.paraBase)));
28 2 : if (modelIdPtr == nullptr) {
29 1 : aicpusd_err("ModelWaitEndGraph kernelTaskInfo paramBase is null, modelId[%u], streamId[%u], taskId[%u]",
30 : taskContext.modelId, taskContext.streamId, kernelTaskInfo.taskID);
31 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
32 : }
33 :
34 1 : const uint32_t modelId = *modelIdPtr;
35 1 : if (*modelIdPtr != taskContext.modelId) {
36 1 : aicpusd_warn("ModelWaitEndGraph kernelTaskInfo modelId[%u] is diff with context, "
37 : "modelId[%u], streamId[%u], taskId[%u]",
38 : modelId, taskContext.modelId, taskContext.streamId, kernelTaskInfo.taskID);
39 : }
40 :
41 1 : aicpusd_info("Begin to execute WaitEndGraph. modelId[%u].", modelId);
42 1 : bool needWait = false;
43 1 : EventWaitManager::EndGraphWaitManager().WaitEvent(static_cast<size_t>(modelId), taskContext.streamId, needWait);
44 1 : if (needWait) {
45 0 : bool * const pending = const_cast<bool *>(&taskContext.pending);
46 0 : *pending = true;
47 : } else {
48 1 : AicpuSdModelStatistic::GetInstance().StatNNModelExecTime(modelId);
49 1 : aicpusd_info("WaitEndGraph Over, modelId[%u], streamId[%u]", taskContext.modelId, taskContext.streamId);
50 : }
51 :
52 1 : return AICPU_SCHEDULE_OK;
53 : }
54 :
55 6 : REGISTER_OPERATOR_KERNEL(KERNEL_MODEL_WAIT_END_GRAPH, OperatorKernelModelWaitEndGraph);
56 : } // namespace AicpuSchedule
|