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_postpare.h"
12 :
13 : #include "aicpusd_status.h"
14 : #include "aicpusd_profiler.h"
15 : #include "aicpusd_resource_manager.h"
16 : #include "control_flow/operator_kernel_model_repeat.h"
17 :
18 : namespace AicpuSchedule {
19 : namespace {
20 : const std::string KERNEL_MODEL_POSTPARE = "modelPostpare";
21 : } // namespace
22 :
23 12 : int32_t OperatorKernelModelPostpare::Compute(const AicpuTaskInfo& kernelTaskInfo, const RunContext& taskContext)
24 : {
25 12 : auto postpareInfo = PtrToPtr<void, AicpuPostpareInfo>(ValueToPtr(kernelTaskInfo.paraBase));
26 12 : if (postpareInfo == nullptr) {
27 1 : aicpusd_err(
28 : "ModelPostpare 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 11 : if (postpareInfo->aicpuPareInfoSize != sizeof(AicpuPostpareInfo)) {
33 1 : aicpusd_err(
34 : "Failed check AicpuPostpareInfo size. msgInfo.aicpuPareInfoSize is [%u], "
35 : "calc AicpuPostpareInfo is [%zu].",
36 : postpareInfo->aicpuPareInfoSize, sizeof(AicpuPostpareInfo));
37 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
38 : }
39 10 : if (postpareInfo->outQueueNum == 0U) {
40 1 : aicpusd_err("outQueueNum is zero!");
41 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
42 : }
43 9 : if (postpareInfo->outQueueNum > MAX_SIZE_NUM) {
44 1 : aicpusd_err("outQueueNum:[%u] out of max size:[%u]!", postpareInfo->outQueueNum, MAX_SIZE_NUM);
45 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
46 : }
47 8 : if (postpareInfo->outQueueIdList == 0UL) {
48 1 : aicpusd_err("outQueueIdList pointers is nullptr!");
49 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
50 : }
51 7 : if (postpareInfo->mbufPtrlist == 0UL) {
52 1 : aicpusd_err("mbufPtrlist pointers is nullptr!");
53 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
54 : }
55 6 : if (!CheckPointListNullptr(
56 6 : PtrToPtr<void, uint64_t>(ValueToPtr(static_cast<uintptr_t>(postpareInfo->mbufPtrlist))),
57 : postpareInfo->outQueueNum)) {
58 1 : aicpusd_err("mbufPtrlist has null pointers!");
59 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
60 : }
61 5 : g_aicpuProfiler.SetEndGraph();
62 5 : return DoPostpare(*postpareInfo, taskContext);
63 : }
64 :
65 6 : bool OperatorKernelModelPostpare::CheckPointListNullptr(const uint64_t* const pointList, const uint32_t pointSize) const
66 : {
67 21 : for (uint32_t i = 0U; i < pointSize; i++) {
68 16 : if (*(pointList + i) == 0UL) {
69 1 : return false;
70 : }
71 : }
72 5 : return true;
73 : }
74 :
75 5 : int32_t OperatorKernelModelPostpare::DoPostpare(AicpuPostpareInfo& msgInfo, const RunContext& taskContext) const
76 : {
77 : // force convert to mbuf** or uint64_t *
78 5 : uint64_t* const mbufPtrlist = PtrToPtr<void, uint64_t>(ValueToPtr(static_cast<uintptr_t>(msgInfo.mbufPtrlist)));
79 : const uint32_t* const outQueueIdList =
80 5 : PtrToPtr<void, uint32_t>(ValueToPtr(static_cast<uintptr_t>(msgInfo.outQueueIdList)));
81 :
82 5 : std::vector<uint64_t> mbufPtrVector;
83 20 : for (uint32_t i = 0; i < msgInfo.outQueueNum; ++i) {
84 15 : mbufPtrVector.emplace_back(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(mbufPtrlist + i)));
85 : }
86 5 : const auto ret = BatchEnque(taskContext, mbufPtrVector.data(), outQueueIdList, msgInfo.outQueueNum);
87 5 : if (ret != AICPU_SCHEDULE_OK) {
88 2 : return ret;
89 : }
90 :
91 3 : return OperatorKernelModelRepeat::SendModelRepeatEvent(taskContext.modelId);
92 5 : }
93 :
94 6 : REGISTER_OPERATOR_KERNEL(KERNEL_MODEL_POSTPARE, OperatorKernelModelPostpare);
95 : } // namespace AicpuSchedule
|