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