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 "aicpusd_event_process.h"
12 : #include <iomanip>
13 : #include <securec.h>
14 : #include <memory>
15 : #include "aicpu_event_struct.h"
16 : #include "ascend_hal.h"
17 : #include "aicpusd_threads_process.h"
18 : #include "dump_task.h"
19 : #include "tsd.h"
20 : #include "aicpu_sched/common/aicpu_task_struct.h"
21 : #include "aicpusd_resource_manager.h"
22 : #include "aicpusd_drv_manager.h"
23 : #include "aicpusd_model_execute.h"
24 : #include "aicpusd_profiler.h"
25 : #include "aicpusd_monitor.h"
26 : #include "aicpusd_msg_send.h"
27 : #include "profiling_adp.h"
28 : #include "aicpu_context.h"
29 : #include "aicpu_engine.h"
30 : #include "common/aicpusd_util.h"
31 : #include "aicpusd_cust_so_manager.h"
32 : #include "aicpusd_model_err_process.h"
33 : #include "aicpu_async_event.h"
34 : #include "aicpusd_context.h"
35 : #include "type_def.h"
36 :
37 : namespace AicpuSchedule {
38 : /**
39 : * @ingroup AicpuEventProcess
40 : * @brief it is used to construct a object of AicpuEventProcess.
41 : */
42 1 : AicpuEventProcess::AicpuEventProcess() : exitQueueFlag_(false) {}
43 :
44 : /**
45 : * @ingroup AicpuEventProcess
46 : * @brief it is used to destructor a object of AicpuEventProcess.
47 : */
48 1 : AicpuEventProcess::~AicpuEventProcess() {}
49 :
50 6 : AicpuEventProcess& AicpuEventProcess::GetInstance()
51 : {
52 6 : static AicpuEventProcess instance;
53 6 : return instance;
54 : }
55 :
56 : /**
57 : * @ingroup AicpuEventProcess
58 : * @brief it use to process data dump event.
59 : * @param [in] ctrlMsg : the struct of control task.
60 : * @return AICPU_SCHEDULE_OK: success, other: error code
61 : */
62 2 : int32_t AicpuEventProcess::ProcessDumpDataEvent(AicpuSqeAdapter& aicpuSqeAdapter) const
63 : {
64 2 : AicpuSchedule::OpDumpTaskManager& opDumpTaskMgr = AicpuSchedule::OpDumpTaskManager::GetInstance();
65 2 : AicpuSqeAdapter::AicpuDataDumpInfo info{};
66 2 : aicpuSqeAdapter.GetAicpuDataDumpInfo(info);
67 2 : aicpusd_info(
68 : "Begin to dump data, stream id[%u], task id[%u], debug stream id[%u], debug task id[%u],"
69 : "is model[%u]",
70 : info.dump_stream_id, info.dump_task_id, info.debug_dump_stream_id, info.debug_dump_task_id, info.is_model);
71 : // reserved 是否有用??
72 2 : int32_t ret = AICPU_SCHEDULE_OK;
73 : TaskInfoExt dumpTaskInfo(
74 2 : static_cast<volatile uint32_t>(info.dump_stream_id), static_cast<volatile uint32_t>(info.dump_task_id));
75 2 : if (info.is_debug && FeatureCtrl::IsNoNeedDumpOpDebugProduct()) {
76 0 : aicpusd_warn(
77 : "Op debug dump is not supported, stream id[%u],"
78 : " task id[%u], stream id1[%u], task id1[%u], is model[%u],",
79 : info.dump_stream_id, info.dump_task_id, info.debug_dump_stream_id, info.debug_dump_task_id, info.is_model);
80 : } else {
81 2 : uint32_t fileNameTaskId = info.is_debug ? info.debug_dump_task_id : info.dump_task_id;
82 2 : uint32_t fileNameStreamId = info.is_debug ? info.debug_dump_stream_id : info.dump_stream_id;
83 2 : DumpFileName dumpFileName(fileNameStreamId, fileNameTaskId);
84 2 : ret = opDumpTaskMgr.DumpOpInfo(dumpTaskInfo, dumpFileName);
85 : }
86 2 : if (info.is_model && info.is_debug) {
87 : TaskInfoExt debugdumpTaskInfo(
88 2 : static_cast<volatile uint32_t>(info.debug_dump_stream_id),
89 2 : static_cast<volatile uint32_t>(info.debug_dump_task_id));
90 2 : DumpFileName dumpFileName(info.debug_dump_stream_id, info.debug_dump_task_id);
91 2 : const int32_t tmpRet = opDumpTaskMgr.DumpOpInfo(debugdumpTaskInfo, dumpFileName);
92 2 : ret = (ret == AICPU_SCHEDULE_OK) ? tmpRet : ret;
93 : } // 模型流溢出检测
94 4 : return SendDumpResponceInfo(aicpuSqeAdapter, ret);
95 : }
96 :
97 : /**
98 : * @ingroup AicpuEventProcess
99 : * @brief it use to process FFTSPlus data dump event.
100 : * @param [in] ctrlMsg : the struct of control task.
101 : * @return AICPU_SCHEDULE_OK: success, other: error code
102 : */
103 2 : int32_t AicpuEventProcess::ProcessDumpFFTSPlusDataEvent(AicpuSqeAdapter& aicpuSqeAdapter) const
104 : {
105 2 : AicpuSchedule::OpDumpTaskManager& opDumpTaskMgr = AicpuSchedule::OpDumpTaskManager::GetInstance();
106 2 : AicpuSqeAdapter::AicpuDumpFFTSPlusDataInfo info{};
107 2 : aicpuSqeAdapter.GetAicpuDumpFFTSPlusDataInfo(info);
108 2 : aicpusd_info(
109 : "Begin to dump FFTSPlus data, stream id[%u], task id[%u], stream id1[%u], task id1[%u], "
110 : "model id[%u], context id[%u], thread id[%u], reserved[%u].",
111 : info.i.stream_id, info.i.task_id, info.i.stream_id1, info.i.task_id1, static_cast<uint32_t>(info.i.model_id),
112 : info.i.context_id, info.i.thread_id, info.i.reserved[0]);
113 :
114 2 : int32_t ret = AICPU_SCHEDULE_OK;
115 2 : bool validDumpParam = false;
116 2 : if ((info.i.task_id != INVALID_VAL) && (info.i.stream_id != INVALID_VAL)) {
117 2 : validDumpParam = true;
118 2 : const bool isFftsPlusOverflow = (info.i.task_id1 != INVALID_VAL) && (info.i.stream_id1 != INVALID_VAL);
119 2 : uint32_t contextId = static_cast<volatile uint32_t>(info.i.context_id);
120 2 : uint32_t threadId = static_cast<volatile uint32_t>(info.i.thread_id);
121 2 : if (isFftsPlusOverflow) {
122 2 : contextId = INVALID_VAL;
123 2 : threadId = INVALID_VAL;
124 : }
125 : TaskInfoExt dumpTaskInfo(
126 2 : static_cast<volatile uint32_t>(info.i.stream_id), static_cast<volatile uint32_t>(info.i.task_id), contextId,
127 2 : threadId);
128 2 : DumpFileName dumpFileName(info.i.stream_id1, info.i.task_id1, info.i.context_id, info.i.thread_id);
129 2 : ret = opDumpTaskMgr.DumpOpInfo(dumpTaskInfo, dumpFileName);
130 : }
131 2 : if ((info.i.task_id1 != INVALID_VAL) && (info.i.stream_id1 != INVALID_VAL)) {
132 2 : validDumpParam = true;
133 : TaskInfoExt dumpTaskInfo(
134 2 : static_cast<volatile uint32_t>(info.i.stream_id1), static_cast<volatile uint32_t>(info.i.task_id1),
135 2 : static_cast<volatile uint32_t>(info.i.context_id), static_cast<volatile uint32_t>(info.i.thread_id));
136 2 : DumpFileName dumpFileName(info.i.stream_id1, info.i.task_id1, info.i.context_id, info.i.thread_id);
137 2 : const int32_t tmpRet = opDumpTaskMgr.DumpOpInfo(dumpTaskInfo, dumpFileName);
138 2 : ret = (ret == AICPU_SCHEDULE_OK) ? tmpRet : ret;
139 : }
140 :
141 2 : if (!validDumpParam) {
142 0 : aicpusd_err(
143 : "Invalid dump FFTSPlus param, stream id[%hu], task id[%hu], stream id1[%hu], task id1[%hu], "
144 : "context id[%hu], thread id[%u].",
145 : info.i.stream_id, info.i.task_id, info.i.stream_id1, info.i.task_id1, info.i.context_id, info.i.thread_id);
146 0 : ret = AICPU_SCHEDULE_ERROR_DUMP_FAILED;
147 : }
148 :
149 4 : return SendDumpResponceInfo(aicpuSqeAdapter, ret);
150 : }
151 :
152 4 : int32_t AicpuEventProcess::SendDumpResponceInfo(AicpuSqeAdapter& adapter, const int32_t& dumpRet) const
153 : {
154 4 : aicpusd_info("Begin to send response information using tsDevSendMsgAsync function.");
155 4 : auto ret = adapter.AicpuDumpResponseToTs(dumpRet);
156 4 : aicpusd_info("Finished to send dump report information, ret[%d].", ret);
157 4 : if (ret != AICPU_SCHEDULE_OK) {
158 2 : aicpusd_err("Failed to response info, ret[%d]", ret);
159 2 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
160 : }
161 2 : return AICPU_SCHEDULE_OK;
162 : }
163 :
164 : /**
165 : * @ingroup AicpuEventProcess
166 : * @brief it use to process op mapping load event.
167 : * @param [in] ctrlMsg : the struct of control task.
168 : * @return AICPU_SCHEDULE_OK: success, other: error code
169 : */
170 2 : int32_t AicpuEventProcess::ProcessLoadOpMappingEvent(AicpuSqeAdapter& aicpuSqeAdapter) const
171 : {
172 2 : aicpusd_info("Begin to load op mapping event.");
173 2 : AicpuSqeAdapter::AicpuDataDumpInfoLoad info{};
174 2 : aicpuSqeAdapter.GetAicpuDataDumpInfoLoad(info);
175 2 : const char_t* const opMappingInfo = PtrToPtr<void, char_t>(ValueToPtr(info.dumpinfoPtr));
176 2 : const uint32_t len = info.length;
177 2 : AicpuSchedule::OpDumpTaskManager& opDumpTaskMgr = AicpuSchedule::OpDumpTaskManager::GetInstance();
178 2 : int32_t ret = opDumpTaskMgr.LoadOpMappingInfo(opMappingInfo, len, aicpuSqeAdapter);
179 : // send response information to ts.
180 2 : aicpusd_info("Begin to send response information using tsDevSendMsgAsync function; load ret[%d].", ret);
181 2 : ret = aicpuSqeAdapter.AicpuDataDumpLoadResponseToTs(ret);
182 2 : aicpusd_info("Finished to send dump load info report info, ret[%d].", ret);
183 :
184 2 : if (ret != AICPU_SCHEDULE_OK) {
185 1 : aicpusd_err("Failed to response info, ret[%d]", ret);
186 1 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
187 : }
188 1 : return AICPU_SCHEDULE_OK;
189 : }
190 : } // namespace AicpuSchedule
|