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 <vector>
14 : #include <securec.h>
15 : #include <memory>
16 : #include <new>
17 : #include <dlfcn.h>
18 : #include <set>
19 : #include "aicpu_event_struct.h"
20 : #include "aicpusd_threads_process.h"
21 : #include "dump_task.h"
22 : #include "aicpu_sched/common/aicpu_task_struct.h"
23 : #include "aicpusd_resource_manager.h"
24 : #include "aicpusd_drv_manager.h"
25 : #include "aicpusd_model_execute.h"
26 : #include "aicpusd_profiler.h"
27 : #include "aicpusd_monitor.h"
28 : #include "aicpusd_msg_send.h"
29 : #include "aicpu_context.h"
30 : #include "aicpusd_cust_so_manager.h"
31 : #include "aicpusd_model_err_process.h"
32 : #include "aicpu_async_event.h"
33 : #include "aicpusd_context.h"
34 : #include "aicpu_prof.h"
35 : #include "aicpusd_interface_process.h"
36 : #include "aicpusd_cust_dump_process.h"
37 : #include "common/aicpusd_util.h"
38 : #include "hwts_kernel_register.h"
39 : #include "hwts_kernel_common.h"
40 : #include "profiling_adp.h"
41 : #include "type_def.h"
42 : #include "tsd.h"
43 :
44 : namespace {
45 : constexpr size_t MAX_KERNEL_NAME_LEN = 30UL;
46 : constexpr uint16_t VALID_MAGIC_NUM = 0x5A5A;
47 : const std::string EXTEND_SO_PLATFORM_FUNC_NAME = "AicpuExtendKernelsLoadPlatformInfo";
48 : static constexpr uint8_t VERSION_0 = 0;
49 : static constexpr uint8_t VERSION_1 = 1;
50 : std::set<uint8_t> allVersion = {VERSION_0, VERSION_1};
51 : }
52 :
53 : namespace AicpuSchedule {
54 : /**
55 : * @ingroup AicpuEventProcess
56 : * @brief it is used to construct a object of AicpuEventProcess.
57 : */
58 2 : AicpuEventProcess::AicpuEventProcess()
59 2 : : exitQueueFlag_(false),
60 2 : platformFuncPtr_(nullptr)
61 : {
62 2 : aicpusd_info("AicpuEventProcess construct.");
63 2 : eventTaskProcess_[AICPU_SUB_EVENT_ACTIVE_STREAM] = &AicpuEventProcess::AICPUEventActiveAicpuStream;
64 2 : eventTaskProcess_[AICPU_SUB_EVENT_EXECUTE_MODEL] = &AicpuEventProcess::AICPUEventExecuteModel;
65 2 : eventTaskProcess_[AICPU_SUB_EVENT_REPEAT_MODEL] = &AicpuEventProcess::AICPUEventRepeatModel;
66 2 : eventTaskProcess_[AICPU_SUB_EVENT_RECOVERY_STREAM] = &AicpuEventProcess::AICPUEventRecoveryStream;
67 2 : eventTaskProcess_[AICPU_SUB_EVENT_UPDATE_PROFILING_MODE] = &AicpuEventProcess::AICPUEventUpdateProfilingMode;
68 2 : eventTaskProcess_[AICPU_SUB_EVENT_END_GRAPH] = &AicpuEventProcess::AICPUEventEndGraph;
69 2 : eventTaskProcess_[AICPU_SUB_EVENT_PREPARE_MEM] = &AicpuEventProcess::AICPUEventPrepareMem;
70 2 : eventTaskProcess_[AICPU_SUB_EVENT_TABLE_UNLOCK] = &AicpuEventProcess::AICPUEventTableUnlock;
71 2 : eventTaskProcess_[AICPU_SUB_EVENT_SUPPLY_ENQUEUE] = &AicpuEventProcess::AICPUEventSupplyEnque;
72 2 : }
73 :
74 : /**
75 : * @ingroup AicpuEventProcess
76 : * @brief it is used to destructor a object of AicpuEventProcess.
77 : */
78 2 : AicpuEventProcess::~AicpuEventProcess() {}
79 :
80 259 : AicpuEventProcess &AicpuEventProcess::GetInstance()
81 : {
82 259 : static AicpuEventProcess instance;
83 259 : return instance;
84 : }
85 :
86 1 : void AicpuEventProcess::InitQueueFlag()
87 : {
88 1 : exitQueueFlag_ = true;
89 1 : }
90 :
91 3 : int32_t AicpuEventProcess::AICPUEventActiveAicpuStream(const AICPUSubEventInfo &subEventInfo) const
92 : {
93 3 : const uint32_t modelId = subEventInfo.modelId;
94 3 : const uint32_t streamId = subEventInfo.para.streamInfo.streamId;
95 3 : aicpusd_info("Begin to active aicpu stream, model[%u] streamId[%u]", modelId, streamId);
96 :
97 3 : const auto model = AicpuModelManager::GetInstance().GetModel(modelId);
98 3 : if (model == nullptr) {
99 1 : aicpusd_err("Model[%u] recover event failed, no model found.", modelId);
100 1 : return AICPU_SCHEDULE_ERROR_MODEL_NOT_FOUND;
101 : }
102 :
103 2 : const int32_t ret = model->ActiveStream(streamId);
104 2 : if (ret != AICPU_SCHEDULE_OK) {
105 0 : aicpusd_err("Model[%u] active aicpu stream[%u] failed, ret[%d]", modelId, streamId, ret);
106 0 : return ret;
107 : }
108 2 : aicpusd_info("Model[%u] finish to active aicpu stream[%u]", modelId, streamId);
109 2 : return AICPU_SCHEDULE_OK;
110 : }
111 :
112 3 : int32_t AicpuEventProcess::AICPUEventExecuteModel(const AICPUSubEventInfo &subEventInfo) const
113 : {
114 3 : const uint32_t modelId = subEventInfo.modelId;
115 3 : aicpusd_info("Begin to execute model[%u]", modelId);
116 3 : AicpuModel * const model = AicpuModelManager::GetInstance().GetModel(modelId);
117 3 : if (model == nullptr) {
118 1 : aicpusd_err("Model[%u] execute model event failed, no model found.", modelId);
119 1 : return AICPU_SCHEDULE_ERROR_MODEL_NOT_FOUND;
120 : }
121 :
122 : // execute the model
123 2 : const int32_t ret = model->ModelExecute();
124 2 : if (ret != AICPU_SCHEDULE_OK) {
125 1 : aicpusd_err("Model[%u] execute failed, ret[%d]", modelId, ret);
126 1 : return ret;
127 : }
128 1 : aicpusd_info("Finish to execute model[%u]", modelId);
129 1 : return AICPU_SCHEDULE_OK;
130 : }
131 :
132 3 : int32_t AicpuEventProcess::AICPUEventRepeatModel(const AICPUSubEventInfo &subEventInfo) const
133 : {
134 3 : const uint32_t modelId = subEventInfo.modelId;
135 3 : aicpusd_info("Begin to execute repeat model[%u]", modelId);
136 3 : AicpuModel * const model = AicpuModelManager::GetInstance().GetModel(modelId);
137 3 : if (model == nullptr) {
138 1 : aicpusd_err("Model[%u] repeat event failed, as no model found.", modelId);
139 1 : return AICPU_SCHEDULE_ERROR_MODEL_NOT_FOUND;
140 : }
141 :
142 : // execute the model
143 2 : const int32_t ret = model->ModelRepeat();
144 2 : if (ret != AICPU_SCHEDULE_OK) {
145 1 : aicpusd_err("Model[%u] repeat failed, ret[%d].", modelId, ret);
146 1 : return ret;
147 : }
148 1 : aicpusd_info("Finished to execute repeat model[%u]", modelId);
149 1 : return AICPU_SCHEDULE_OK;
150 : }
151 :
152 2 : int32_t AicpuEventProcess::AICPUEventRecoveryStream(const AICPUSubEventInfo &subEventInfo) const
153 : {
154 2 : const uint32_t recoverStreamId = subEventInfo.para.streamInfo.streamId;
155 2 : const uint32_t modelId = subEventInfo.modelId;
156 2 : aicpusd_info("Begin to recovery aicpu stream, model[%u] streamId[%u]", modelId, recoverStreamId);
157 2 : AicpuModel * const model = AicpuModelManager::GetInstance().GetModel(modelId);
158 2 : if (model == nullptr) {
159 1 : aicpusd_err("Model[%u] recover event failed, as no model found.", modelId);
160 1 : return AICPU_SCHEDULE_ERROR_MODEL_NOT_FOUND;
161 : }
162 :
163 1 : const int32_t ret = model->RecoverStream(recoverStreamId);
164 1 : if (ret != AICPU_SCHEDULE_OK) {
165 0 : aicpusd_err("Model[%u] recovery aicpu stream[%u] failed, ret[%d].", modelId, recoverStreamId, ret);
166 0 : return ret;
167 : }
168 1 : aicpusd_info("Model[%u] finished recovering aicpu stream[%u]", modelId, recoverStreamId);
169 1 : return AICPU_SCHEDULE_OK;
170 : }
171 :
172 2 : int32_t AicpuEventProcess::AICPUEventUpdateProfilingMode(const AICPUSubEventInfo &subEventInfo) const
173 : {
174 2 : const uint32_t flag = subEventInfo.para.modeInfo.flag;
175 : // set or unset mode
176 2 : const bool isStart = (flag & (1U << aicpu::PROFILING_FEATURE_SWITCH)) > 0U;
177 : // if set or unset kernel profiling mode
178 2 : const bool kernelMode = (flag & (1U << aicpu::PROFILING_FEATURE_KERNEL_MODE)) > 0U;
179 : // if set or unset model profiling mode
180 2 : const bool modelMode = (flag & (1U << aicpu::PROFILING_FEATURE_MODEL_MODE)) > 0U;
181 2 : ProfilingMode mode = PROFILING_CLOSE;
182 2 : bool isModelModeOn = false;
183 2 : aicpu::SetProfilingFlagForKFC(flag);
184 2 : if (isStart) {
185 2 : mode = PROFILING_OPEN;
186 2 : isModelModeOn = true;
187 : }
188 2 : if (kernelMode) {
189 2 : AicpuSchedule::ComputeProcess::GetInstance().UpdateProfilingMode(mode);
190 : }
191 2 : if (modelMode) {
192 2 : AicpuSchedule::ComputeProcess::GetInstance().UpdateProfilingModelMode(isModelModeOn);
193 : }
194 2 : aicpusd_info("Begin to update aicpu event profiling mode, flag[%lu], isStart[%d], mode[%d],"
195 : " isModelModeOn[%d]", flag, isStart, mode, isModelModeOn);
196 2 : const std::vector<uint32_t> deviceVec = AicpuDrvManager::GetInstance().GetDeviceList();
197 2 : if (deviceVec.empty()) {
198 1 : aicpusd_err("the device vector is empty");
199 1 : return AICPU_SCHEDULE_ERROR_TASK_EXECUTE_FAILED;
200 : }
201 1 : if (SendUpdateProfilingRspToTsd(deviceVec[0],
202 : static_cast<uint32_t>(TsdWaitType::TSD_COMPUTE),
203 1 : static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid()),
204 2 : AicpuDrvManager::GetInstance().GetVfId()) != AICPU_SCHEDULE_OK) {
205 0 : aicpusd_err("send profiline response to tsd failed");
206 0 : return AICPU_SCHEDULE_ERROR_TASK_EXECUTE_FAILED;
207 : }
208 1 : return AICPU_SCHEDULE_OK;
209 2 : }
210 :
211 6 : int32_t AicpuEventProcess::AICPUEventEndGraph(const AICPUSubEventInfo &subEventInfo) const
212 : {
213 6 : const uint32_t modelId = subEventInfo.modelId;
214 6 : const uint32_t result = subEventInfo.para.endGraphInfo.result;
215 6 : aicpusd_info("AicpuEventProcess::AICPUEventEndGraph: modelId[%u], result[%u]", modelId, result);
216 6 : AicpuModel * const model = AicpuModelManager::GetInstance().GetModel(modelId);
217 6 : if (model == nullptr) {
218 3 : aicpusd_err("Receive model[%u] EndGraph msg, but no model found.", modelId);
219 3 : return AICPU_SCHEDULE_ERROR_MODEL_NOT_FOUND;
220 : }
221 3 : int32_t ret = AICPU_SCHEDULE_OK;
222 3 : if ((result == 0U) || (model->AbnormalEnabled())) {
223 2 : if (result != 0) {
224 2 : aicpusd_err("modelId[%u] execute fail, result[%u]", modelId, result);
225 2 : model->SetModelRetCode(static_cast<int32_t>(result));
226 : }
227 2 : ret = HwTsKernelCommon::ProcessEndGraph(modelId);
228 : } else {
229 1 : ret = model->ModelAbort();
230 : }
231 3 : return ret;
232 : }
233 :
234 3 : int32_t AicpuEventProcess::AICPUEventPrepareMem(const AICPUSubEventInfo &subEventInfo) const
235 : {
236 3 : const uint32_t modelId = subEventInfo.modelId;
237 :
238 3 : bool hasWait = false;
239 3 : uint32_t waitStreamId = 0U;
240 3 : EventWaitManager::PrepareMemWaitManager().Event(static_cast<size_t>(modelId), hasWait, waitStreamId);
241 3 : if (!hasWait) {
242 1 : return AICPU_SCHEDULE_OK;
243 : }
244 :
245 2 : AicpuModel * const model = AicpuModelManager::GetInstance().GetModel(modelId);
246 2 : if (model == nullptr) {
247 1 : aicpusd_err("Receive model[%u] PrepareMem msg, but no model found.", modelId);
248 1 : return AICPU_SCHEDULE_ERROR_MODEL_NOT_FOUND;
249 : }
250 :
251 1 : aicpusd_info("Begin to recover execute model[%u] stream[%u].", modelId, waitStreamId);
252 : // Recovery stream Execute.
253 1 : const auto ret = model->RecoverStream(waitStreamId);
254 1 : if (ret == AICPU_SCHEDULE_OK) {
255 0 : aicpusd_info("PrepareMem event of model[%u] recover execute stream[%u] success.", modelId, waitStreamId);
256 : } else {
257 1 : aicpusd_err("PrepareMem event of model[%u] recover execute stream[%u] failed, ret[%d].",
258 : modelId, waitStreamId, ret);
259 : }
260 1 : return ret;
261 : }
262 :
263 1 : int32_t AicpuEventProcess::AICPUEventTableUnlock(const AICPUSubEventInfo &subEventInfo) const
264 : {
265 1 : const uint32_t tableId = subEventInfo.para.unlockTableInfo.tableId;
266 2 : for (const auto model : AicpuModelManager::GetInstance().GetModelsByTableId(tableId)) {
267 1 : bool hasWait = false;
268 1 : uint32_t waitStreamId = 0U;
269 2 : EventWaitManager::TableUnlockWaitManager().Event(
270 1 : static_cast<size_t>(model->GetId()), hasWait, waitStreamId);
271 1 : if (!hasWait) {
272 0 : continue;
273 : }
274 1 : const auto ret = model->RecoverStream(waitStreamId);
275 1 : if (ret != AICPU_SCHEDULE_OK) {
276 0 : aicpusd_err("TableUnlock event to recover model[%u], stream[%u] failed, ret is [%d]",
277 : model->GetId(), waitStreamId, ret);
278 0 : return ret;
279 : }
280 1 : }
281 1 : return AICPU_SCHEDULE_OK;
282 : }
283 :
284 5 : int32_t AicpuEventProcess::AICPUEventSupplyEnque(const AICPUSubEventInfo &subEventInfo) const
285 : {
286 5 : const uint32_t modelId = subEventInfo.modelId;
287 5 : const auto model = AicpuModelManager::GetInstance().GetModel(modelId);
288 5 : if (model == nullptr) {
289 1 : aicpusd_err("Fail to find model[%u]", modelId);
290 1 : return AICPU_SCHEDULE_ERROR_STREAM_NOT_FOUND;
291 : }
292 :
293 4 : bool hasWait = false;
294 4 : uint32_t waitStreamId = INVALID_NUMBER;
295 4 : EventWaitManager::AnyQueNotEmptyWaitManager().Event(static_cast<size_t>(modelId), hasWait, waitStreamId);
296 4 : if (!hasWait) {
297 1 : aicpusd_info("AnyQueNotEmpty[%u] event don't need to recover execute stream.", modelId);
298 1 : return AICPU_SCHEDULE_OK;
299 : }
300 :
301 3 : aicpusd_info("Begin to recover execute stream[%u].", waitStreamId);
302 : // Recovery stream Execute.
303 3 : const auto ret = model->RecoverStream(waitStreamId);
304 3 : if (ret == AICPU_SCHEDULE_OK) {
305 2 : aicpusd_info("AnyQueNotEmpty[%u] event recover execute stream[%u] success.", modelId, waitStreamId);
306 : } else {
307 1 : aicpusd_err("AnyQueNotEmpty[%u] event recover execute stream[%u] failed, ret[%d].",
308 : modelId, waitStreamId, ret);
309 : }
310 3 : return ret;
311 : }
312 :
313 : /**
314 : * @ingroup AicpuEventProcess
315 : * @brief it is used to process the report of task.
316 : * @param [in] info : the information of task.
317 : * @return AICPU_SCHEDULE_OK: success, other: error code
318 : */
319 9 : int32_t AicpuEventProcess::ProcessTaskReportEvent(AicpuSqeAdapter &aicpuSqeAdapter) const
320 : {
321 9 : AicpuSqeAdapter::AicpuTaskReportInfo info{};
322 9 : aicpuSqeAdapter.GetAicpuTaskReportInfo(info);
323 9 : const uint32_t modelId = static_cast<uint32_t>(info.model_id);
324 9 : aicpusd_run_info("Begin to process task report. modelId=%u, retCode=%d.", modelId, info.result_code);
325 9 : AicpuModel * const model = AicpuModelManager::GetInstance().GetModel(modelId);
326 9 : if (model == nullptr) {
327 4 : aicpusd_err("Model[%u] task report event failed, no model found.", modelId);
328 4 : AicpuModelErrProc::GetInstance().RecordAicoreOpErrLog(info, aicpuSqeAdapter);
329 4 : return AICPU_SCHEDULE_ERROR_MODEL_NOT_FOUND;
330 : }
331 5 : if (!model->IsEndOfSequence()) {
332 5 : AicpuModelErrProc::GetInstance().RecordAicoreOpErrLog(info, aicpuSqeAdapter);
333 5 : if (static_cast<int32_t>(info.result_code) == static_cast<int32_t>(TS_MODEL_STREAM_EXE_FAILED)) {
334 1 : model->SetModelRetCode(INNER_ERROR_BASE + AICPU_SCHEDULE_ERROR_MODEL_EXECUTE_FAILED);
335 : } else {
336 4 : model->SetModelRetCode(INNER_ERROR_BASE + AICPU_SCHEDULE_ERROR_TSCH_OTHER_ERROR);
337 : }
338 : }
339 :
340 5 : AicpuMonitor::GetInstance().SetModelEndTime(modelId);
341 5 : int32_t ret = AICPU_SCHEDULE_OK;
342 5 : if (exitQueueFlag_) {
343 3 : if (model->IsEndOfSequence() || model->AbnormalEnabled()) {
344 0 : aicpusd_run_info("Begin to execute endgraph.");
345 2 : return HwTsKernelCommon::ProcessEndGraph(modelId);
346 : }
347 : // this branch is for model has queue
348 3 : ret = model->ModelAbort();
349 3 : if (ret != AICPU_SCHEDULE_OK) {
350 2 : return ret;
351 : }
352 :
353 1 : aicpusd_run_info("begin to execute ModelRepeat. modelId[%u].", modelId);
354 1 : AICPUSubEventInfo subEventInfo = {};
355 1 : subEventInfo.modelId = modelId;
356 1 : ret = AicpuMsgSend::SendAICPUSubEvent(PtrToPtr<AICPUSubEventInfo, const char_t>(&subEventInfo),
357 : static_cast<uint32_t>(sizeof(AICPUSubEventInfo)),
358 : AICPU_SUB_EVENT_REPEAT_MODEL,
359 : CP_DEFAULT_GROUP_ID,
360 : false);
361 : } else {
362 2 : ret = model->TaskReport();
363 : }
364 3 : return ret;
365 : }
366 :
367 : /**
368 : * @ingroup AicpuEventProcess
369 : * @brief it use to process data dump event.
370 : * @param [in] ctrlMsg : the struct of control task.
371 : * @return AICPU_SCHEDULE_OK: success, other: error code
372 : */
373 13 : int32_t AicpuEventProcess::ProcessSetTimeoutEvent(AicpuSqeAdapter &aicpuSqeAdapter) const
374 : {
375 13 : AicpuSqeAdapter::AicpuTimeOutConfigInfo opTimeoutCfg{};
376 13 : aicpuSqeAdapter.GetAicpuTimeOutConfigInfo(opTimeoutCfg);
377 13 : const uint32_t excTimeoutEnable = opTimeoutCfg.i.op_execute_timeout_en;
378 13 : const uint32_t excTimeoutVal = opTimeoutCfg.i.op_execute_timeout;
379 13 : const uint32_t waitTimeoutEnable = opTimeoutCfg.i.op_wait_timeout_en;
380 13 : const uint32_t waitTimeoutVal = opTimeoutCfg.i.op_wait_timeout;
381 13 : aicpusd_run_info("Get opTimeoutEnable[%u] value[%u] waitTimeoutEnable[%u] value[%u] from ts success.",
382 : excTimeoutEnable, excTimeoutVal, waitTimeoutEnable, waitTimeoutVal);
383 13 : uint32_t ret = AICPU_SCHEDULE_OK;
384 13 : bool validTimeoutParam = true;
385 :
386 13 : if (excTimeoutEnable == 1U) {
387 11 : if (AicpuUtil::IsValidTimeoutVal(excTimeoutVal)) {
388 9 : AicpuMonitor::GetInstance().SetOpExecuteTimeOut(excTimeoutEnable, excTimeoutVal);
389 9 : aicpusd_info("Config OP execute timeout success, enable[%u] timeout[%us].",
390 : excTimeoutEnable, excTimeoutVal);
391 : } else {
392 2 : validTimeoutParam = false;
393 : }
394 : }
395 :
396 13 : const uint32_t curTimeoutVal = AicpuMonitor::GetInstance().GetTaskDefaultTimeout();
397 13 : if (waitTimeoutEnable == 1U) {
398 5 : if ((waitTimeoutVal != 0U) && (waitTimeoutVal < curTimeoutVal)) {
399 : // if ts has start wait op timeout, then need disable aicpu op timer
400 : // The waitTimeoutVal is 0 indicates that the timeout never expires.
401 1 : aicpusd_run_info(
402 : "Close aicpu op timer, waitTimeVal[%us], curTimeVal[%us].", waitTimeoutVal, curTimeoutVal);
403 1 : AicpuMonitor::GetInstance().SetOpTimeoutFlag(false);
404 : } else {
405 4 : aicpusd_run_info(
406 : "Reopen aicpu op timer, waitTimeVal[%us], curTimeVal[%us].", waitTimeoutVal, curTimeoutVal);
407 4 : AicpuMonitor::GetInstance().SetOpTimeoutFlag(true);
408 : }
409 : }
410 :
411 13 : if (!validTimeoutParam) {
412 2 : aicpusd_err("valid Timeout Param opTimeoutEnable[%u] value[%u] waitTimeoutEnable[%u] value[%u]",
413 : excTimeoutEnable, excTimeoutVal, waitTimeoutEnable, waitTimeoutVal);
414 2 : ret = static_cast<uint32_t>(
415 : AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID);
416 : }
417 :
418 13 : aicpusd_info("Begin AicpuTimeOutConfigResponseToTs using tsDevSendMsgAsync function.");
419 13 : const int32_t tmpRet = aicpuSqeAdapter.AicpuTimeOutConfigResponseToTs(
420 : static_cast<uint32_t>(ret));
421 13 : aicpusd_info("Finished AicpuTimeOutConfigResponseToTs, ret[%d].", tmpRet);
422 13 : return tmpRet;
423 : }
424 :
425 : /**
426 : * @ingroup AicpuEventProcess
427 : * @brief it is used to process the msg version.
428 : * @param [in] info : the information of task.
429 : * @return AICPU_SCHEDULE_OK: success, other: error code
430 : */
431 4 : int32_t AicpuEventProcess::ProcessMsgVersionEvent(AicpuSqeAdapter &aicpuSqeAdapter) const
432 : {
433 4 : aicpusd_info("Begin to process msg version event.");
434 4 : AicpuSqeAdapter::AicpuMsgVersionInfo info {};
435 4 : aicpuSqeAdapter.GetAicpuMsgVersionInfo(info);
436 4 : int32_t ret = AICPU_SCHEDULE_OK;
437 4 : if (info.magic_num != VALID_MAGIC_NUM) {
438 2 : aicpusd_err("Magic num[%hu] is not valid.", info.magic_num);
439 2 : return AICPU_SCHEDULE_ERROR_INVALID_MAGIC_NUM;
440 : } else {
441 2 : uint16_t version = info.version;
442 2 : if (allVersion.find(version) == allVersion.end()) {
443 0 : aicpusd_err("Version is incorrect, version[%hu]", version);
444 0 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
445 : }
446 2 : FeatureCtrl::SetTsMsgVersion(version);
447 2 : aicpusd_info("Set msg version [%hu].", version);
448 : }
449 2 : aicpusd_info("Begin to send response msg version.");
450 2 : int32_t rspRet = aicpuSqeAdapter.AicpuMsgVersionResponseToTs(ret);
451 2 : aicpusd_info("Finished to send response msg version information, ret[%d].", rspRet);
452 2 : if (ret != AICPU_SCHEDULE_OK) {
453 0 : aicpusd_err("Failed to response info, ret[%d]", ret);
454 0 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
455 : }
456 2 : return AICPU_SCHEDULE_OK;
457 : }
458 : /**
459 : * @ingroup AicpuEventProcess
460 : * @brief it use to process data dump event.
461 : * @param [in] ctrlMsg : the struct of control task.
462 : * @return AICPU_SCHEDULE_OK: success, other: error code
463 : */
464 16 : int32_t AicpuEventProcess::ProcessDumpDataEvent(AicpuSqeAdapter &aicpuSqeAdapter) const
465 : {
466 16 : AicpuSchedule::OpDumpTaskManager &opDumpTaskMgr = AicpuSchedule::OpDumpTaskManager::GetInstance();
467 16 : AicpuSqeAdapter::AicpuDataDumpInfo info {};
468 16 : aicpuSqeAdapter.GetAicpuDataDumpInfo(info);
469 16 : aicpusd_info("Begin to dump data, stream id[%u], task id[%u], debug stream id[%u], debug task id[%u],"
470 : "is model[%u], file name stream id [%u], file name task id [%u]",
471 : info.dump_stream_id,
472 : info.dump_task_id,
473 : info.debug_dump_stream_id,
474 : info.debug_dump_task_id,
475 : info.is_model,
476 : info.file_name_stream_id,
477 : info.file_name_task_id);
478 16 : int32_t ret = AICPU_SCHEDULE_OK;
479 16 : TaskInfoExt dumpTaskInfo(static_cast<volatile uint32_t>(info.dump_stream_id),
480 16 : static_cast<volatile uint32_t>(info.dump_task_id));
481 16 : DumpFileName dumpFileName(info.file_name_stream_id, info.file_name_task_id);
482 16 : if (info.is_debug && FeatureCtrl::IsNoNeedDumpOpDebugProduct()) {
483 0 : aicpusd_warn("Op debug dump is not supported, stream id[%u],"
484 : " task id[%u], stream id1[%u], task id1[%u], is model[%u],",
485 : info.dump_stream_id, info.dump_task_id, info.debug_dump_stream_id, info.debug_dump_task_id,
486 : info.is_model);
487 : } else {
488 16 : ret = opDumpTaskMgr.DumpOpInfo(dumpTaskInfo, dumpFileName);
489 : }
490 16 : if (info.is_model && info.is_debug) {
491 6 : TaskInfoExt debugdumpTaskInfo(static_cast<volatile uint32_t>(info.debug_dump_stream_id),
492 6 : static_cast<volatile uint32_t>(info.debug_dump_task_id));
493 6 : const int32_t tmpRet = opDumpTaskMgr.DumpOpInfo(debugdumpTaskInfo, dumpFileName);
494 6 : ret = (ret == AICPU_SCHEDULE_OK)? tmpRet : ret;
495 : }
496 32 : return SendDumpResponceInfo(aicpuSqeAdapter, ret);
497 : }
498 :
499 : /**
500 : * @ingroup AicpuEventProcess
501 : * @brief it use to process FFTSPlus data dump event.
502 : * @param [in] ctrlMsg : the struct of control task.
503 : * @return AICPU_SCHEDULE_OK: success, other: error code
504 : */
505 6 : int32_t AicpuEventProcess::ProcessDumpFFTSPlusDataEvent(AicpuSqeAdapter &aicpuSqeAdapter) const
506 : {
507 6 : AicpuSchedule::OpDumpTaskManager &opDumpTaskMgr = AicpuSchedule::OpDumpTaskManager::GetInstance();
508 6 : AicpuSqeAdapter::AicpuDumpFFTSPlusDataInfo info {};
509 6 : aicpuSqeAdapter.GetAicpuDumpFFTSPlusDataInfo(info);
510 6 : aicpusd_info("Begin to dump FFTSPlus data, stream id[%u], task id[%u], stream id1[%u], task id1[%u], "
511 : "model id[%u], context id[%u], thread id[%u], reserved[%u].",
512 : info.i.stream_id, info.i.task_id, info.i.stream_id1, info.i.task_id1,
513 : static_cast<uint32_t>(info.i.model_id), info.i.context_id, info.i.thread_id, info.i.reserved[0]);
514 :
515 6 : int32_t ret = AICPU_SCHEDULE_OK;
516 6 : bool validDumpParam = false;
517 6 : if ((info.i.task_id != INVALID_VAL) && (info.i.stream_id != INVALID_VAL)) {
518 4 : validDumpParam = true;
519 4 : const bool isFftsPlusOverflow = (info.i.task_id1 != INVALID_VAL) && (info.i.stream_id1 != INVALID_VAL);
520 4 : uint32_t contextId = static_cast<volatile uint32_t>(info.i.context_id);
521 4 : uint32_t threadId = static_cast<volatile uint32_t>(info.i.thread_id);
522 4 : if (isFftsPlusOverflow) {
523 3 : contextId = INVALID_VAL;
524 3 : threadId = INVALID_VAL;
525 : }
526 4 : TaskInfoExt dumpTaskInfo(static_cast<volatile uint32_t>(info.i.stream_id),
527 4 : static_cast<volatile uint32_t>(info.i.task_id),
528 : contextId,
529 4 : threadId);
530 4 : DumpFileName dumpFileName(info.i.stream_id1, info.i.task_id1, info.i.context_id, info.i.thread_id);
531 4 : ret = opDumpTaskMgr.DumpOpInfo(dumpTaskInfo, dumpFileName);
532 : }
533 6 : if ((info.i.task_id1 != INVALID_VAL) && (info.i.stream_id1 != INVALID_VAL)) {
534 3 : validDumpParam = true;
535 3 : TaskInfoExt dumpTaskInfo(static_cast<volatile uint32_t>(info.i.stream_id1),
536 3 : static_cast<volatile uint32_t>(info.i.task_id1),
537 3 : static_cast<volatile uint32_t>(info.i.context_id),
538 3 : static_cast<volatile uint32_t>(info.i.thread_id));
539 3 : DumpFileName dumpFileName(info.i.stream_id1, info.i.task_id1, info.i.context_id, info.i.thread_id);
540 3 : const int32_t tmpRet = opDumpTaskMgr.DumpOpInfo(dumpTaskInfo, dumpFileName);
541 3 : ret = (ret == AICPU_SCHEDULE_OK)? tmpRet : ret;
542 : }
543 :
544 6 : if (!validDumpParam) {
545 2 : aicpusd_err("Invalid dump FFTSPlus param, stream id[%hu], task id[%hu], stream id1[%hu], task id1[%hu], " \
546 : "context id[%hu], thread id[%u].",
547 : info.i.stream_id, info.i.task_id, info.i.stream_id1,
548 : info.i.task_id1, info.i.context_id, info.i.thread_id);
549 2 : ret = AICPU_SCHEDULE_ERROR_DUMP_FAILED;
550 : }
551 :
552 12 : return SendDumpResponceInfo(aicpuSqeAdapter, ret);
553 : }
554 :
555 22 : int32_t AicpuEventProcess::SendDumpResponceInfo(AicpuSqeAdapter &adapter, const int32_t &dumpRet) const
556 : {
557 : // send response information to ts.
558 22 : aicpusd_info("Begin to send response information using tsDevSendMsgAsync function.");
559 22 : const int32_t ret = adapter.AicpuDumpResponseToTs(dumpRet);
560 22 : aicpusd_info("Finished to send dump report information, ret[%d].", ret);
561 22 : return ret;
562 : }
563 :
564 : /**
565 : * @ingroup AicpuEventProcess
566 : * @brief it use to process op mapping load event.
567 : * @param [in] ctrlMsg : the struct of control task.
568 : * @return AICPU_SCHEDULE_OK: success, other: error code
569 : */
570 9 : int32_t AicpuEventProcess::ProcessLoadOpMappingEvent(AicpuSqeAdapter &aicpuSqeAdapter) const
571 : {
572 9 : aicpusd_info("Begin to load op mapping event.");
573 9 : AicpuSqeAdapter::AicpuDataDumpInfoLoad info {};
574 9 : aicpuSqeAdapter.GetAicpuDataDumpInfoLoad(info);
575 : const char_t * const opMappingInfo =
576 9 : PtrToPtr<void, char_t>(ValueToPtr(static_cast<uintptr_t>(info.dumpinfoPtr)));
577 9 : const uint32_t len = info.length;
578 9 : AicpuSchedule::OpDumpTaskManager &opDumpTaskMgr = AicpuSchedule::OpDumpTaskManager::GetInstance();
579 9 : int32_t ret = opDumpTaskMgr.LoadOpMappingInfo(opMappingInfo, len, aicpuSqeAdapter);
580 : uint32_t runMode;
581 9 : const aicpu::status_t status = aicpu::GetAicpuRunMode(runMode);
582 9 : if (status != aicpu::AICPU_ERROR_NONE) {
583 0 : aicpusd_err("Get current aicpu ctx failed.");
584 0 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
585 : }
586 9 : const uint32_t deviceId = AicpuSchedule::AicpuDrvManager::GetInstance().GetDeviceId();
587 9 : AicpuSchedule::AicpuSdCustDumpProcess::GetInstance().InitCustDumpProcess(deviceId,
588 : static_cast<aicpu::AicpuRunMode>(runMode));
589 : // send response information to ts.
590 9 : aicpusd_info("Begin to send response information using tsDevSendMsgAsync function; load ret[%d].", ret);
591 9 : ret = aicpuSqeAdapter.AicpuDataDumpLoadResponseToTs(ret);
592 9 : aicpusd_info("Finished to send dump load info report info, ret[%d].", ret);
593 9 : return ret;
594 : }
595 :
596 : /**
597 : * @ingroup AicpuEventProcess
598 : * @brief it use to process the AICPU event.
599 : * @param [in] drvEventInfo : the event information from ts.
600 : * @return AICPU_SCHEDULE_OK: success, other: error code
601 : */
602 3 : int32_t AicpuEventProcess::ProcessAICPUEvent(const event_info &drvEventInfo)
603 : {
604 3 : if (static_cast<size_t>(drvEventInfo.priv.msg_len) != sizeof(AICPUSubEventInfo)) {
605 1 : aicpusd_err("The len[%u] is not correct[%zu].", drvEventInfo.priv.msg_len, sizeof(AICPUSubEventInfo));
606 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
607 : }
608 : // for the msg is address of array, it is not a nullptr.
609 : // so the info is not used to judge whether is nullptr;
610 2 : const AICPUSubEventInfo * const info = PtrToPtr<const char_t, const AICPUSubEventInfo>(drvEventInfo.priv.msg);
611 :
612 2 : int32_t ret = AICPU_SCHEDULE_OK;
613 : // find process function of the subevent id.
614 2 : const AICPUSubEvent drvEventId = static_cast<AICPUSubEvent>(drvEventInfo.comm.subevent_id);
615 2 : aicpusd_info("Begin to receive the aicpu event, eventId[%d], drvEventId[%d]",
616 : drvEventInfo.comm.subevent_id, drvEventId);
617 2 : if (drvEventId >= AICPU_SUB_EVENT_MAX_NUM) {
618 0 : aicpusd_err("The subevent id is invalid, id[%u].", drvEventInfo.comm.subevent_id);
619 0 : return AICPU_SCHEDULE_ERROR_UNKNOW_AICPU_EVENT;
620 : }
621 2 : const EventProcess taskProcess = eventTaskProcess_[drvEventId];
622 2 : if (taskProcess != nullptr) {
623 2 : ret = (this->*taskProcess)(*info);
624 : } else {
625 0 : aicpusd_err("The subevent id is invalid, id[%u].", drvEventInfo.comm.subevent_id);
626 0 : return AICPU_SCHEDULE_ERROR_UNKNOW_AICPU_EVENT;
627 : }
628 : // Failed to execute the task , it needs to handle error.
629 2 : if (ret != AICPU_SCHEDULE_OK) {
630 1 : aicpusd_err("failed to process aicpu event, eventId[%d].", drvEventId);
631 1 : return ret;
632 : }
633 1 : aicpusd_info("Successfully processed AICPU event, eventId[%d]", drvEventId);
634 1 : return AICPU_SCHEDULE_OK;
635 : }
636 :
637 3 : int32_t AicpuEventProcess::ProcessQueueNotEmptyEvent(const uint32_t queueId) const
638 : {
639 3 : bool hasWait = false;
640 3 : uint32_t waitStreamId = INVALID_NUMBER;
641 3 : EventWaitManager::QueueNotEmptyWaitManager().Event(static_cast<const size_t>(queueId), hasWait, waitStreamId);
642 3 : if (!hasWait) {
643 : // find model by qid
644 3 : const auto model = AicpuModelManager::GetInstance().GetModelByQueueId(queueId);
645 3 : if (model != nullptr) {
646 0 : aicpusd_info("GetModelByQueueId for %u is model %u", queueId, model->GetId());
647 0 : EventWaitManager::AnyQueNotEmptyWaitManager().Event(
648 0 : static_cast<size_t>(model->GetId()), hasWait, waitStreamId);
649 : }
650 : }
651 3 : if (!hasWait) {
652 3 : aicpusd_info("Queue[%u] non-empty event don't need to recover execute stream.", queueId);
653 : // Execute the asynchronous operator that registers the event.
654 3 : (void)aicpu::AsyncEventManager::GetInstance().ProcessEvent(EVENT_QUEUE_EMPTY_TO_NOT_EMPTY, queueId);
655 3 : return AICPU_SCHEDULE_OK;
656 : }
657 0 : const auto model = AicpuModelManager::GetInstance().GetModelByStreamId(waitStreamId);
658 0 : if (model == nullptr) {
659 0 : aicpusd_err("Queue[%u] non-empty event recover execute stream[%u] failed, as find modelId failed.",
660 : queueId, waitStreamId);
661 0 : return AICPU_SCHEDULE_ERROR_STREAM_NOT_FOUND;
662 : }
663 0 : aicpusd_info("Begin to recover execute stream[%u].", waitStreamId);
664 : // Recovery stream Execute.
665 0 : const auto ret = model->RecoverStream(waitStreamId);
666 0 : if (ret == AICPU_SCHEDULE_OK) {
667 0 : aicpusd_info("Queue[%u] non-empty event recover execute stream[%u] success.",
668 : queueId, waitStreamId);
669 : } else {
670 0 : aicpusd_err("Queue[%u] non-empty event recover execute stream[%u] failed, ret[%d].",
671 : queueId, waitStreamId, ret);
672 : }
673 0 : return ret;
674 : }
675 :
676 1 : int32_t AicpuEventProcess::ProcessEnqueueEvent(const event_info &drvEventInfo) const
677 : {
678 1 : const uint32_t drvEventId = drvEventInfo.comm.event_id;
679 1 : const uint32_t drvSubeventId = drvEventInfo.comm.subevent_id;
680 1 : aicpusd_info("ProcessEnqueue by eventId[%u] subeventId[%u] begin", drvEventId, drvSubeventId);
681 1 : if (&aicpu::DoEventCallback == nullptr) {
682 0 : aicpusd_info("Cannot find DoEventCallback symbol, skip event process");
683 0 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
684 : }
685 1 : void * const param = PtrToPtr<event_info, void>(const_cast<event_info *>(&drvEventInfo));
686 1 : const auto ret = aicpu::DoEventCallback(drvEventId, drvSubeventId, param);
687 1 : aicpusd_info("Finish to call ProcessEnqueue by eventId:[%u] subeventId:[%u] end, ret:[%d]",
688 : drvEventId, drvSubeventId, ret);
689 1 : return ret;
690 : }
691 :
692 3 : int32_t AicpuEventProcess::ProcessQueueNotFullEvent(const uint32_t queueId) const
693 : {
694 3 : bool hasWait = false;
695 3 : uint32_t waitStreamId = INVALID_NUMBER;
696 3 : EventWaitManager::QueueNotFullWaitManager().Event(static_cast<const size_t>(queueId), hasWait, waitStreamId);
697 3 : if (!hasWait) {
698 3 : aicpusd_info("Queue[%u] not full event don't need to recover execute stream.", queueId);
699 : // Execute the asynchronous operator that registers the event.
700 3 : (void)aicpu::AsyncEventManager::GetInstance().ProcessEvent(EVENT_QUEUE_FULL_TO_NOT_FULL, queueId);
701 3 : return AICPU_SCHEDULE_OK;
702 : }
703 0 : const auto model = AicpuModelManager::GetInstance().GetModelByStreamId(waitStreamId);
704 0 : if (model == nullptr) {
705 0 : aicpusd_err("Queue[%u] not full event recover execute stream[%u] failed, as find modelId failed.",
706 : queueId, waitStreamId);
707 0 : return AICPU_SCHEDULE_ERROR_STREAM_NOT_FOUND;
708 : }
709 :
710 0 : aicpusd_info("Begin to recover execute stream[%u].", waitStreamId);
711 0 : const auto ret = model->RecoverStream(waitStreamId);
712 0 : if (ret == AICPU_SCHEDULE_OK) {
713 0 : aicpusd_info("Queue[%u] not full event recover execute stream[%u] success.",
714 : queueId, waitStreamId);
715 : } else {
716 0 : aicpusd_err("Queue[%u] not full event recover execute stream[%u] failed, ret[%d].",
717 : queueId, waitStreamId, ret);
718 : }
719 0 : return ret;
720 : }
721 :
722 : /**
723 : * @ingroup AicpuEventProcess
724 : * @brief it use to process response information.
725 : * @param [in] ctrlMsg : the struct of control task.
726 : * @param [in] resultcode : the result of execute task.
727 : * @param [in] subEvent : it is used to store subeventid which is in receive struct.
728 : * @param [in] noThreadFlag : no thread flag.
729 : * @return AICPU_SCHEDULE_OK: success, other: error code
730 : */
731 4 : int32_t AicpuEventProcess::ProcessResponseInfo(AicpuSqeAdapter &adapter,
732 : const uint16_t resultCode,
733 : const uint32_t subEvent,
734 : const bool noThreadFlag) const
735 : {
736 4 : aicpusd_info("Begin to process response info.");
737 4 : AicpuSqeAdapter::AicpuModelOperateInfo info {};
738 4 : adapter.GetAicpuModelOperateInfo(info);
739 4 : if ((static_cast<int32_t>(info.cmd_type) == TS_AICPU_MODEL_ABORT) && (noThreadFlag)) {
740 : // directly to exist, it don't need to send response to ts.
741 0 : return DRV_ERROR_NONE;
742 : }
743 4 : const int32_t transedResult = AicpuSchedule::AicpuUtil::TransformInnerErrCode(static_cast<int32_t>(resultCode));
744 4 : const int32_t ret = adapter.AicpuModelOperateResponseToTs(transedResult, subEvent);
745 : // send response information to ts.
746 4 : aicpusd_info("Finished to send response information, ret[%d].", ret);
747 4 : return ret;
748 : }
749 :
750 131 : int32_t AicpuEventProcess::ExecuteTsKernelTask(aicpu::HwtsTsKernel &tsKernelInfo, const uint32_t threadIndex,
751 : const uint64_t drvSubmitTick, const uint64_t drvSchedTick,
752 : const uint64_t streamId, const uint64_t taskId)
753 : {
754 131 : const aicpu::KernelType kernelType = static_cast<const aicpu::KernelType>(tsKernelInfo.kernelType);
755 131 : if (((kernelType == aicpu::KernelType::KERNEL_TYPE_CCE) ||
756 127 : (kernelType == aicpu::KernelType::KERNEL_TYPE_AICPU)) &&
757 127 : (tsKernelInfo.kernelBase.cceKernel.kernelSo == 0UL)) {
758 4 : return ExecuteLogicKernel(tsKernelInfo);
759 : }
760 :
761 : // check cust aicpu kernel RunMode
762 127 : if ((kernelType == aicpu::KernelType::KERNEL_TYPE_AICPU_CUSTOM) &&
763 0 : (AicpuUtil::CheckCustAicpuThreadMode() != AICPU_SCHEDULE_OK)) {
764 0 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
765 : }
766 :
767 : // execute kernel
768 127 : aicpusd_info("Begin to process aicpu engine process, kernelType[%u].", tsKernelInfo.kernelType);
769 127 : std::shared_ptr<aicpu::ProfMessage> profMsg = nullptr;
770 127 : const bool profFlag = aicpu::IsProfOpen();
771 : aicpu::aicpuProfContext_t aicpuProfCtx;
772 126 : if (profFlag) {
773 : try {
774 126 : profMsg = std::make_shared<aicpu::ProfMessage>("AICPU");
775 0 : } catch (...) {
776 0 : aicpusd_err("make shared for ProfMessage failed.");
777 0 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
778 0 : }
779 128 : (void)aicpu::SetProfHandle(profMsg);
780 :
781 127 : const uint64_t tickBeforeRun = aicpu::GetSystemTick();
782 128 : aicpuProfCtx = {
783 : .tickBeforeRun = tickBeforeRun,
784 : .drvSubmitTick = drvSubmitTick,
785 : .drvSchedTick = drvSchedTick,
786 128 : .kernelType = tsKernelInfo.kernelType
787 : };
788 128 : (void)aicpu::aicpuSetProfContext(aicpuProfCtx);
789 : }
790 :
791 128 : AicpuMonitor::GetInstance().SetTaskStartTime(threadIndex);
792 128 : const int32_t retAicpu = aeCallInterface(&tsKernelInfo);
793 127 : AicpuMonitor::GetInstance().SetTaskEndTime(threadIndex);
794 126 : if (profFlag) {
795 : const ProfIdentity profIdentity = {
796 : .taskId = taskId,
797 : .streamId = streamId,
798 : .threadIndex = threadIndex,
799 126 : .deviceId = AicpuDrvManager::GetInstance().GetDeviceId()
800 126 : };
801 126 : (void)AicpuUtil::SetProfData(profMsg, aicpuProfCtx, profIdentity);
802 : }
803 :
804 127 : PostProcessTsKernelTask(retAicpu, streamId, taskId);
805 126 : return retAicpu;
806 126 : }
807 :
808 127 : void AicpuEventProcess::PostProcessTsKernelTask(const int32_t errorCode, const uint64_t streamId,
809 : const uint64_t taskId) const
810 : {
811 127 : if (errorCode == AE_STATUS_SUCCESS) {
812 115 : (void)aicpu::SetOpname("null");
813 116 : aicpusd_info("Aicpu engine process success, result[%d].", errorCode);
814 115 : return;
815 : }
816 :
817 : // This status is not error, so never print error log
818 12 : if ((errorCode == AE_STATUS_END_OF_SEQUENCE) || (errorCode == AE_STATUS_TASK_WAIT) ||
819 : (errorCode == AE_STATUS_TASK_ABORT)) {
820 1 : (void)aicpu::SetOpname("null");
821 1 : aicpusd_info("Aicpu engine process success in special status, result[%d].", errorCode);
822 1 : return;
823 : }
824 :
825 11 : std::string opname = "null";
826 11 : (void)aicpu::GetOpname(aicpu::GetAicpuThreadIndex(), opname);
827 11 : aicpusd_err("Aicpu engine process failed, result[%d], opName[%s], streamId[%llu], taskId[%llu].",
828 : errorCode, opname.c_str(), streamId, taskId);
829 11 : (void)aicpu::SetOpname("null");
830 :
831 11 : return;
832 11 : }
833 :
834 4 : int32_t AicpuEventProcess::ExecuteLogicKernel(aicpu::HwtsTsKernel &tsKernelInfo) const
835 : {
836 4 : if (static_cast<uintptr_t>(tsKernelInfo.kernelBase.cceKernel.kernelName) == 0UL) {
837 2 : aicpusd_err("ExecuteLogicKernel failed as the name of kernel is null.");
838 2 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
839 : }
840 2 : const size_t cpySize = strnlen(
841 2 : static_cast<const char_t *>(ValueToPtr(tsKernelInfo.kernelBase.cceKernel.kernelName)),
842 : MAX_KERNEL_NAME_LEN);
843 2 : char_t kernelName[MAX_KERNEL_NAME_LEN + 1UL] = {};
844 2 : const errno_t memRet = memcpy_s(&kernelName[0], MAX_KERNEL_NAME_LEN + 1UL,
845 2 : static_cast<const char_t *>(ValueToPtr(tsKernelInfo.kernelBase.cceKernel.kernelName)), cpySize);
846 2 : if (memRet != EOK) {
847 0 : aicpusd_err("memcpy_s kernel name failed ret[%d].", memRet);
848 0 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
849 : }
850 2 : aicpusd_info("Task kernel name[%s].", &kernelName[0]);
851 :
852 : // check logic kernel and run it;
853 6 : return HwTsKernelRegister::Instance().RunTsKernelTaskProcess(tsKernelInfo, kernelName);
854 : }
855 :
856 8 : AicpuExtendSoPlatformFuncPtr AicpuEventProcess::GetAicpuExtendSoPlatformFuncPtr()
857 : {
858 8 : const std::lock_guard<std::mutex> lk(mutexForPlatformPtr_);
859 8 : if (platformFuncPtr_ != nullptr) {
860 3 : return platformFuncPtr_;
861 : }
862 :
863 5 : platformFuncPtr_ = reinterpret_cast<AicpuExtendSoPlatformFuncPtr>(dlsym(RTLD_DEFAULT,
864 : EXTEND_SO_PLATFORM_FUNC_NAME.c_str()));
865 5 : if (platformFuncPtr_ == nullptr) {
866 5 : aicpusd_err("failed to find func:%s, err:%s", EXTEND_SO_PLATFORM_FUNC_NAME.c_str(), dlerror());
867 : }
868 5 : return platformFuncPtr_;
869 8 : }
870 :
871 8 : int32_t AicpuEventProcess::SendLoadPlatformFromBufMsgRsp(const int32_t resultCode,
872 : AicpuSqeAdapter &aicpuSqeAdapter) const
873 : {
874 : // send response information to ts.
875 8 : aicpusd_info("Begin send response information using tsDevSendMsgAsync function load ret[%d]", resultCode);
876 8 : const int32_t ret = aicpuSqeAdapter.AicpuInfoLoadResponseToTs(resultCode);
877 8 : aicpusd_info("Finished to send platform load info report info, ret[%d].", ret);
878 8 : return ret;
879 : }
880 :
881 6 : int32_t AicpuEventProcess::ProcessLoadPlatformFromBuf(AicpuSqeAdapter &aicpuSqeAdapter)
882 : {
883 6 : aicpusd_info("Begin to process LoadPlatformFromBuf event.");
884 6 : AicpuSqeAdapter::AicpuInfoLoad info{};
885 6 : aicpuSqeAdapter.GetAicpuInfoLoad(info);
886 6 : AicpuExtendSoPlatformFuncPtr funcPtr = GetAicpuExtendSoPlatformFuncPtr();
887 6 : if (funcPtr == nullptr) {
888 4 : aicpusd_err("failed to find func:%s", EXTEND_SO_PLATFORM_FUNC_NAME.c_str());
889 4 : SendLoadPlatformFromBufMsgRsp(AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID, aicpuSqeAdapter);
890 4 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
891 : }
892 2 : aicpusd_info("platform buf:0x%x, len:%u", info.aicpuInfoPtr, info.length);
893 2 : const int32_t ret = funcPtr(info.aicpuInfoPtr, info.length);
894 2 : if (ret != AICPU_SCHEDULE_OK) {
895 1 : aicpusd_err("func:%s process failed,ret:%u", EXTEND_SO_PLATFORM_FUNC_NAME.c_str(), ret);
896 : }
897 2 : return SendLoadPlatformFromBufMsgRsp(ret, aicpuSqeAdapter);
898 : }
899 : }
|