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