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_stream_repeat.h"
12 :
13 : #include "aicpusd_status.h"
14 : #include "aicpusd_model_execute.h"
15 :
16 :
17 : namespace AicpuSchedule {
18 : namespace {
19 : const std::string KERNEL_STREAM_REPEAT = "streamRepeat";
20 : } // namespace
21 :
22 6 : int32_t OperatorKernelStreamRepeat::Compute(const AicpuTaskInfo &kernelTaskInfo, const RunContext &taskContext)
23 : {
24 6 : aicpusd_info("Start repeat model stream. modelId=%u, streamId=%u, taskId=%u",
25 : taskContext.modelId, kernelTaskInfo.streamID, kernelTaskInfo.taskID);
26 : const StreamRepeatTaskParam * const repeatStreamInfo =
27 6 : PtrToPtr<void, StreamRepeatTaskParam>(ValueToPtr(kernelTaskInfo.paraBase));
28 6 : if (repeatStreamInfo == nullptr) {
29 1 : aicpusd_err("Model repeat stream info is nullptr. modelId=%u, streamId=%u, taskId=%u",
30 : taskContext.modelId, kernelTaskInfo.streamID, kernelTaskInfo.taskID);
31 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
32 : }
33 :
34 5 : if ((repeatStreamInfo->modelId != taskContext.modelId) || (repeatStreamInfo->streamId != taskContext.streamId)) {
35 1 : aicpusd_warn("Model repeat stream is diff with context. rptModelId=%u, modelId=%u, rptStreamId=%u, streamId=%u",
36 : repeatStreamInfo->modelId, taskContext.modelId,
37 : repeatStreamInfo->streamId, taskContext.streamId);
38 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
39 : }
40 :
41 4 : const AicpuModel *model = AicpuModelManager::GetInstance().GetModel(taskContext.modelId);
42 4 : if ((model != nullptr) && (model->GetModelRetCode() != 0) && (model->AbnormalNeedBreak())) {
43 2 : aicpusd_err("Model stream repeat failed, model execute failed. modelId=%d.", taskContext.modelId);
44 2 : return AICPU_SCHEDULE_ERROR_TASK_EXECUTE_FAILED;
45 : }
46 2 : *(const_cast<int32_t *>(&taskContext.gotoTaskIndex)) = 0;
47 2 : return AICPU_SCHEDULE_OK;
48 : }
49 :
50 :
51 6 : REGISTER_OPERATOR_KERNEL(KERNEL_STREAM_REPEAT, OperatorKernelStreamRepeat);
52 : } // namespace AicpuSchedule
|