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 : #include "operator_kernel_unlock_table.h"
11 :
12 : #include "aicpusd_status.h"
13 : #include "aicpusd_model_execute.h"
14 : #include "aicpusd_event_process.h"
15 : #include "aicpusd_msg_send.h"
16 : #include "aicpusd_resource_manager.h"
17 :
18 : namespace AicpuSchedule {
19 : namespace {
20 : const std::string KERNEL_UNLOCK_TABLE = "unlockTable";
21 : } // namespace
22 :
23 4 : int32_t OperatorKernelUnlockTable::Compute(const AicpuTaskInfo& kernelTaskInfo, const RunContext& taskContext)
24 : {
25 4 : aicpusd_info(
26 : "Start ModelUnlockTable. modelId=%u, streamId=%u, taskId=%u.", taskContext.modelId, kernelTaskInfo.streamID,
27 : kernelTaskInfo.taskID);
28 4 : if (kernelTaskInfo.paraBase == 0UL) {
29 1 : aicpusd_err("kernelTaskInfo.paraBase is null");
30 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
31 : }
32 :
33 : const UnlockTableTaskParam* const unlockParam =
34 3 : PtrToPtr<void, UnlockTableTaskParam>(ValueToPtr(kernelTaskInfo.paraBase));
35 3 : const uint32_t tableId = unlockParam->tableId;
36 :
37 3 : const auto model = AicpuModelManager::GetInstance().GetModel(taskContext.modelId);
38 3 : if (model == nullptr) {
39 1 : aicpusd_err(
40 : "Cannot get model by modelId:[%u], streamId[%u], taskId[%u].", taskContext.modelId, taskContext.streamId,
41 : kernelTaskInfo.taskID);
42 1 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
43 : }
44 2 : if (!model->IsTableLocked(tableId)) {
45 1 : aicpusd_warn("table[%u] has not been locked before", tableId);
46 1 : return AICPU_SCHEDULE_OK;
47 : }
48 :
49 1 : TableLockManager::GetInstance().UnLockTable(tableId);
50 1 : model->ClearLockedTable(tableId);
51 :
52 : // send unlock event
53 1 : AICPUSubEventInfo subEventInfo = {};
54 1 : subEventInfo.modelId = model->GetId();
55 1 : subEventInfo.para.unlockTableInfo.tableId = tableId;
56 1 : return AicpuMsgSend::SendAICPUSubEvent(
57 : PtrToPtr<AICPUSubEventInfo, const char_t>(&subEventInfo), static_cast<uint32_t>(sizeof(AICPUSubEventInfo)),
58 1 : AICPU_SUB_EVENT_TABLE_UNLOCK, CP_DEFAULT_GROUP_ID, true);
59 : }
60 :
61 6 : REGISTER_OPERATOR_KERNEL(KERNEL_UNLOCK_TABLE, OperatorKernelUnlockTable);
62 : } // namespace AicpuSchedule
|