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