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_batch_enqueue.h"
12 :
13 : #include "aicpusd_status.h"
14 : #include "aicpusd_profiler.h"
15 : #include "aicpusd_model_execute.h"
16 :
17 :
18 : namespace AicpuSchedule {
19 : namespace {
20 : const std::string KERNEL_MODEL_BATCH_ENQUEUE = "modelBatchEnqueue";
21 : } // namespace
22 :
23 1 : int32_t OperatorKernelModelBatchEnqueue::Compute(const AicpuTaskInfo &kernelTaskInfo, const RunContext &taskContext)
24 : {
25 1 : aicpusd_info("Start ModelBatchEnque. modelId=%u, streamId=%u, taskId=%u.",
26 : taskContext.modelId, kernelTaskInfo.streamID, kernelTaskInfo.taskID);
27 1 : if (kernelTaskInfo.paraBase == 0UL) {
28 0 : aicpusd_err("kernelTaskInfo.paraBase is null");
29 0 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
30 : }
31 :
32 1 : const BatchDequeueDesc * const param = PtrToPtr<void, BatchDequeueDesc>(ValueToPtr(kernelTaskInfo.paraBase));
33 1 : const uint64_t * const mbufPtrlist = PtrToPtr<void, uint64_t>(ValueToPtr(static_cast<uintptr_t>(param->mbufAddrsAddr)));
34 : const uint32_t * const outQueueIdList =
35 1 : PtrToPtr<void, uint32_t>(ValueToPtr(static_cast<uintptr_t>(param->queueIdsAddr)));
36 1 : const uint32_t &outputNum = param->inputNums;
37 :
38 1 : if ((outputNum > 0U) && ((mbufPtrlist == nullptr) || (outQueueIdList == nullptr))) {
39 0 : aicpusd_err("outputNum[%u], but mbufAddrsAddr or queueIdsAddr is null.", outputNum);
40 0 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
41 : }
42 :
43 1 : return BatchEnque(taskContext, mbufPtrlist, outQueueIdList, outputNum);
44 : }
45 :
46 6 : int32_t OperatorKernelModelBatchEnqueue::BatchEnque(const RunContext &taskContext, const uint64_t * const mbufPtrlist,
47 : const uint32_t * const outQueueIdList,
48 : const uint32_t outQueueNum) const
49 : {
50 : BufEnQueueInfo enqueueInfo;
51 6 : AicpuModel *const model = AicpuModelManager::GetInstance().GetModel(taskContext.modelId);
52 6 : if (model == nullptr) {
53 1 : aicpusd_err("cannot get model by modelId:[%u]!", taskContext.modelId);
54 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
55 : }
56 5 : int32_t ret = AICPU_SCHEDULE_OK;
57 5 : g_aicpuProfiler.SetEqStart();
58 5 : ModelPostpareData &postpareData = model->GetModelPostpareData();
59 13 : for (; postpareData.enqueueIndex < outQueueNum; postpareData.enqueueIndex++) {
60 10 : enqueueInfo.mBufPtr = *(mbufPtrlist + postpareData.enqueueIndex);
61 10 : enqueueInfo.queueID = outQueueIdList[postpareData.enqueueIndex];
62 :
63 10 : ret = EnqueueTask(enqueueInfo, taskContext);
64 10 : if (ret != AICPU_SCHEDULE_OK) {
65 1 : return ret;
66 : }
67 9 : if (taskContext.pending) {
68 1 : aicpusd_info("pending is true, wait for event.");
69 1 : return ret;
70 : }
71 : }
72 :
73 3 : postpareData.enqueueIndex = 0;
74 3 : g_aicpuProfiler.SetEqEnd();
75 3 : return AICPU_SCHEDULE_OK;
76 : }
77 :
78 :
79 6 : REGISTER_OPERATOR_KERNEL(KERNEL_MODEL_BATCH_ENQUEUE, OperatorKernelModelBatchEnqueue);
80 : } // namespace AicpuSchedule
|