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 "hwts_kernel_cust_so.h"
12 :
13 : #include "aicpusd_cust_so_manager.h"
14 : #include "aicpusd_drv_manager.h"
15 : #include "aicpusd_monitor.h"
16 : #include "hwts_kernel_common.h"
17 :
18 : namespace AicpuSchedule {
19 : namespace {
20 : const std::string LOADOP_FROM_BUFF = "loadOpFromBuf";
21 : const std::string BATCH_LOADSO_FROM_BUFF = "batchLoadsoFrombuf";
22 : const std::string DELETE_CUSTOP = "deleteCustOp";
23 :
24 : constexpr uint32_t MAX_CUSTOM_SO_NUM = 1024U;
25 : constexpr uint32_t CCPU_DEFAULT_GROUP_ID = 30U;
26 : constexpr GroupShareAttr GROUP_WITH_ALL_ATTR = {1U, 1U, 1U, 1U, 0U}; // admin + read + write + alloc
27 : } // namespace
28 :
29 : std::mutex LoadOpFromBuffTsKernel::mutexForStartCustProcess_;
30 : std::set<std::string> LoadOpFromBuffTsKernel::alreadyLoadSoName_;
31 :
32 6 : int32_t CustOperationCommon::SendCtrlCpuMsg(
33 : int32_t custAicpuPid, const uint32_t eventType, char_t* msg, const uint32_t msgLen) const
34 : {
35 6 : event_summary eventInfoSummary = {};
36 6 : eventInfoSummary.pid = custAicpuPid;
37 6 : eventInfoSummary.event_id = EVENT_CCPU_CTRL_MSG;
38 6 : eventInfoSummary.subevent_id = eventType;
39 6 : eventInfoSummary.msg = msg;
40 6 : eventInfoSummary.msg_len = msgLen;
41 6 : eventInfoSummary.grp_id = CCPU_DEFAULT_GROUP_ID;
42 6 : eventInfoSummary.dst_engine = CCPU_DEVICE;
43 6 : DeployContext deployCtx = DeployContext::DEVICE;
44 6 : (void)GetAicpuDeployContext(deployCtx);
45 6 : if (deployCtx == DeployContext::HOST) {
46 0 : eventInfoSummary.dst_engine = static_cast<uint32_t>(CCPU_HOST);
47 0 : aicpusd_info("SendCtrlCpuMsg to dst engine: %u", eventInfoSummary.dst_engine);
48 : }
49 6 : const drvError_t ret = halEschedSubmitEvent(AicpuDrvManager::GetInstance().GetDeviceId(), &eventInfoSummary);
50 6 : if (ret != DRV_ERROR_NONE) {
51 0 : aicpusd_err("Failed to submit aicpu event. ret is %d.", ret);
52 0 : return AICPU_SCHEDULE_ERROR_DRV_ERR;
53 : }
54 6 : aicpusd_info("SendCtrlCpuMsg success type:%u", eventType);
55 6 : return AICPU_SCHEDULE_OK;
56 : }
57 :
58 11 : int32_t CustOperationCommon::GetGroupNameInfo(std::vector<std::string>& groupNameList, std::string& groupNameStr) const
59 : {
60 11 : const pid_t curPid = drvDeviceGetBareTgid();
61 11 : std::map<std::string, GroupShareAttr> buffGrpInfo = {};
62 11 : const int32_t ret = AicpuDrvManager::GetInstance().QueryProcBuffInfo(static_cast<uint32_t>(curPid), buffGrpInfo);
63 11 : if (ret != AICPU_SCHEDULE_OK) {
64 1 : aicpusd_err("Fail to get group info of acipusd[%d]", curPid);
65 1 : return ret;
66 : }
67 :
68 27 : for (const auto& groupInfo : buffGrpInfo) {
69 17 : if (groupInfo.second.admin == 1U) {
70 10 : groupNameList.emplace_back(groupInfo.first);
71 10 : groupNameStr = groupNameStr + groupInfo.first + ",";
72 10 : aicpusd_info("Get aicpusd buff group[%s] succ.", groupInfo.first.c_str());
73 : }
74 : }
75 :
76 10 : return AICPU_SCHEDULE_OK;
77 11 : }
78 :
79 11 : int32_t CustOperationCommon::StartCustProcess(const uint32_t loadLibNum, const char_t* const loadLibName[]) const
80 : {
81 : // 01-Get group name of current process
82 11 : std::vector<std::string> groupNameList = {};
83 11 : std::string groupNameStr = "";
84 11 : const int32_t ret = GetGroupNameInfo(groupNameList, groupNameStr);
85 11 : if (ret != AICPU_SCHEDULE_OK) {
86 1 : return ret;
87 : }
88 :
89 10 : const uint32_t validGroupNum = static_cast<uint32_t>(groupNameList.size());
90 : // Remove comma at the end of the string
91 10 : groupNameStr = ((validGroupNum != 0U) ? groupNameStr.substr(0UL, groupNameStr.length() - 1UL) : groupNameStr);
92 : // 02-startup cust aicpusd and get cust aicpusd pid
93 10 : int32_t custAicpuPid = -1;
94 10 : bool firstStart = true;
95 10 : int32_t tdtStatus = 0;
96 10 : if (&CreateOrFindCustPidEx != nullptr) {
97 0 : aicpusd_info("Create or find custom pid by CreateOrFindCustPidEx.");
98 0 : CustAicpuPara para = {};
99 0 : para.paraVersion = static_cast<uint32_t>(CustAicpuParaVersion::CUST_AICPU_PARA_WITHOUT_SO_INFO);
100 0 : para.infoPara.paraWithoutSoInfo.deviceId = AicpuDrvManager::GetInstance().GetDeviceId();
101 0 : para.infoPara.paraWithoutSoInfo.hostPid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
102 0 : para.infoPara.paraWithoutSoInfo.vfId = AicpuDrvManager::GetInstance().GetVfId();
103 0 : para.infoPara.paraWithoutSoInfo.groupNameList = groupNameStr.c_str();
104 0 : para.infoPara.paraWithoutSoInfo.groupNameNum = validGroupNum;
105 0 : para.infoPara.paraWithoutSoInfo.custProcPid = &custAicpuPid;
106 0 : para.infoPara.paraWithoutSoInfo.firstStart = &firstStart;
107 0 : tdtStatus = CreateOrFindCustPidEx(¶);
108 : } else {
109 10 : aicpusd_info("Create or find custom pid by CreateOrFindCustPid, load so event will be send to tsd.");
110 20 : tdtStatus = CreateOrFindCustPid(
111 10 : AicpuDrvManager::GetInstance().GetDeviceId(), loadLibNum, loadLibName,
112 10 : static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid()),
113 10 : AicpuDrvManager::GetInstance().GetVfId(), groupNameStr.c_str(), validGroupNum, &custAicpuPid, &firstStart);
114 : }
115 10 : if ((tdtStatus != 0) || (custAicpuPid < 0)) {
116 4 : aicpusd_err(
117 : "Call tdt interface to create or find custom process pid failed, error[%d] pid[%d].", tdtStatus,
118 : custAicpuPid);
119 4 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
120 : }
121 :
122 6 : AicpuScheduleInterface::GetInstance().SetAicpuCustSdProcId(custAicpuPid);
123 6 : if (!firstStart) {
124 1 : aicpusd_run_info("Cust aicpu have already existed");
125 1 : return AICPU_SCHEDULE_OK;
126 : }
127 :
128 : // 03-add group for cust aicpu
129 10 : for (const auto& grpName : groupNameList) {
130 5 : const auto drvRet = halGrpAddProc(grpName.c_str(), custAicpuPid, GROUP_WITH_ALL_ATTR);
131 5 : if (drvRet != DRV_ERROR_NONE) {
132 0 : aicpusd_err("Add group[%s] for cust aicpusd failed, ret[%d]", grpName.c_str(), drvRet);
133 0 : return AICPU_SCHEDULE_ERROR_DRV_ERR;
134 : }
135 : }
136 5 : aicpusd_run_info("halGrpAddProc success, custAicpuPid[%d], validGroupNum[%u]", custAicpuPid, validGroupNum);
137 :
138 5 : if (validGroupNum > 0U) {
139 5 : if (SendCtrlCpuMsg(
140 5 : custAicpuPid, static_cast<uint32_t>(TsdSubEventType::TSD_EVENT_STOP_SUB_PROCESS_WAIT), nullptr, 0U) !=
141 : AICPU_SCHEDULE_OK) {
142 0 : aicpusd_run_info("SendCtrlCpuMsg send to custaicpu no success");
143 : }
144 5 : aicpusd_run_info("SendCtrlCpuMsg Send to custaicpu success");
145 5 : (void)StopWaitForCustAicpu();
146 5 : aicpusd_run_info("wait custaicpu attach group success");
147 : }
148 5 : if (&CreateOrFindCustPidEx != nullptr) {
149 0 : aicpusd_run_info("Begin to notify open custom so event to cust ctrl cpu, custAicpuPid[%d]", custAicpuPid);
150 0 : int32_t notifyRet = AicpuNotifyLoadSoEventToCustCtrlCpu(
151 0 : AicpuDrvManager::GetInstance().GetDeviceId(),
152 0 : static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid()),
153 0 : AicpuDrvManager::GetInstance().GetVfId(), custAicpuPid, loadLibNum, loadLibName);
154 0 : if (notifyRet != 0) {
155 0 : aicpusd_warn(
156 : "Aicpu notify open custom so event to cust ctrl aicpu failed, error[%d] pid[%d].", notifyRet,
157 : custAicpuPid);
158 : }
159 : }
160 :
161 5 : if (AicpuMonitor::GetInstance().IsMonitorClosed()) {
162 1 : const int32_t closeRet = NotifyCustCloseMonitor(custAicpuPid);
163 1 : if (closeRet != AICPU_SCHEDULE_OK) {
164 1 : aicpusd_err("Notify custaicpu to close monitor failed, ret[%d], pid[%d].", closeRet, custAicpuPid);
165 1 : return closeRet;
166 : }
167 : }
168 :
169 4 : aicpusd_run_info("StartCustProcess end");
170 4 : return AICPU_SCHEDULE_OK;
171 11 : }
172 :
173 4 : int32_t CustOperationCommon::AicpuNotifyLoadSoEventToCustCtrlCpu(
174 : const uint32_t deviceId, const uint32_t hostPid, const uint32_t vfId, const int32_t custAicpuPid,
175 : const uint32_t loadLibNum, const char_t* const loadLibName[]) const
176 : {
177 4 : if ((loadLibNum > 0U) && (loadLibName == nullptr)) {
178 1 : aicpusd_err("Load lib name is nullptr, loadLibNum=%u, hostPid=%u", loadLibNum, hostPid);
179 1 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
180 : }
181 5 : for (uint32_t i = 0U; i < loadLibNum; i++) {
182 3 : TsdSubEventInfo info = {};
183 3 : info.deviceId = deviceId;
184 3 : info.srcPid = static_cast<uint32_t>(getpid());
185 3 : info.dstPid = custAicpuPid;
186 3 : info.hostPid = hostPid;
187 3 : info.vfId = vfId;
188 3 : info.procType = 1U;
189 3 : info.eventType = static_cast<uint32_t>(AICPU_SUB_EVENT_OPEN_CUSTOM_SO);
190 3 : const errno_t errRet = strcpy_s(info.priMsg, MAX_EVENT_PRI_MSG_LENGTH, loadLibName[i]);
191 3 : if (errRet != EOK) {
192 1 : aicpusd_err("Copy %s failed, error[%d]", loadLibName[i], errRet);
193 1 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
194 : }
195 2 : event_summary event = {};
196 2 : event.dst_engine = CCPU_DEVICE;
197 2 : event.policy = ONLY;
198 2 : event.pid = custAicpuPid;
199 2 : event.grp_id = 30U;
200 2 : event.event_id = EVENT_CCPU_CTRL_MSG;
201 2 : event.subevent_id = AICPU_SUB_EVENT_OPEN_CUSTOM_SO;
202 2 : event.msg = PtrToPtr<TsdSubEventInfo, char_t>(&info);
203 2 : event.msg_len = static_cast<uint32_t>(sizeof(TsdSubEventInfo));
204 2 : aicpusd_info("msg[%s], msglen[%u]", event.msg, event.msg_len);
205 2 : const drvError_t ret = halEschedSubmitEvent(deviceId, &event);
206 2 : if (ret != DRV_ERROR_NONE) {
207 1 : aicpusd_run_warn(
208 : "Sending open custom so event to custom ctrl cpu was not successful, deviceId[%u], "
209 : "errcode[%d], please check so name length",
210 : deviceId, ret);
211 : } else {
212 1 : aicpusd_info("Aicpu send open custom so event to custom ctrl cpu success.");
213 : }
214 2 : aicpusd_run_info(
215 : "Notify custom soName info on deviceId[%u] hostpid[%u] vfId[%u] index[%u] soName[%s] success.", deviceId,
216 : hostPid, vfId, i, loadLibName[i]);
217 : }
218 2 : aicpusd_run_info(
219 : "End AicpuNotifyLoadSoEventToCustCtrlCpu on deviceId[%u] hostPid[%u] vfId[%u] soNum[%u].", deviceId, hostPid,
220 : vfId, loadLibNum);
221 2 : return AICPU_SCHEDULE_OK;
222 : }
223 :
224 2 : int32_t CustOperationCommon::NotifyCustCloseMonitor(const int32_t custAicpuPid) const
225 : {
226 2 : TsdSubEventInfo info = {};
227 2 : info.deviceId = AicpuDrvManager::GetInstance().GetDeviceId();
228 2 : info.srcPid = static_cast<uint32_t>(getpid());
229 2 : info.dstPid = static_cast<uint32_t>(custAicpuPid);
230 2 : info.hostPid = static_cast<uint32_t>(AicpuDrvManager::GetInstance().GetHostPid());
231 2 : info.vfId = static_cast<uint8_t>(AicpuDrvManager::GetInstance().GetVfId());
232 2 : info.procType = 1U;
233 2 : info.eventType = static_cast<uint32_t>(AICPU_SUB_EVENT_CUST_CLOSE_MONITOR);
234 2 : auto closeMonitorMsg = PtrToPtr<char_t, AICPUCloseMonitorEventMsg>(info.priMsg);
235 2 : closeMonitorMsg->closeFlag = 1U;
236 :
237 2 : event_summary closeMonitorEvent = {};
238 2 : closeMonitorEvent.dst_engine = CCPU_DEVICE;
239 2 : closeMonitorEvent.policy = ONLY;
240 2 : closeMonitorEvent.pid = custAicpuPid;
241 2 : closeMonitorEvent.grp_id = CCPU_DEFAULT_GROUP_ID;
242 2 : closeMonitorEvent.event_id = EVENT_CCPU_CTRL_MSG;
243 2 : closeMonitorEvent.subevent_id = static_cast<uint32_t>(AICPU_SUB_EVENT_CUST_CLOSE_MONITOR);
244 2 : closeMonitorEvent.msg = PtrToPtr<TsdSubEventInfo, char_t>(&info);
245 2 : closeMonitorEvent.msg_len = static_cast<uint32_t>(sizeof(info));
246 :
247 2 : const drvError_t ret = halEschedSubmitEvent(info.deviceId, &closeMonitorEvent);
248 2 : if (ret != DRV_ERROR_NONE) {
249 1 : aicpusd_err(
250 : "Send close monitor event to custaicpu failed, ret[%d], pid[%d], group[%u], event[%d].", ret, custAicpuPid,
251 : closeMonitorEvent.grp_id, closeMonitorEvent.event_id);
252 1 : return AICPU_SCHEDULE_ERROR_DRV_ERR;
253 : }
254 1 : aicpusd_run_info("Submit close monitor event to custaicpu success.");
255 1 : return AICPU_SCHEDULE_OK;
256 : }
257 :
258 8 : int32_t LoadOpFromBuffTsKernel::Compute(const aicpu::HwtsTsKernel& tsKernelInfo)
259 : {
260 8 : aicpusd_run_info("Begin to process ts kernel loadOpFromBuf");
261 8 : if (!AicpuCustSoManager::GetInstance().IsSupportCustAicpu()) {
262 1 : aicpusd_err("Cust aicpu scheduler is not supported in message queue mode.");
263 1 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
264 : }
265 :
266 7 : const auto paramKernelName = PtrToPtr<void, char_t>(ValueToPtr(tsKernelInfo.kernelBase.cceKernel.kernelName));
267 7 : if (paramKernelName == nullptr) {
268 0 : aicpusd_err("Process LoadOpFromBuf failed as the name of kernel is null.");
269 0 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
270 : }
271 :
272 7 : std::string realSoName;
273 : const auto loadOpFromBufArgs =
274 7 : PtrToPtr<void, LoadOpFromBufArgs>(ValueToPtr(tsKernelInfo.kernelBase.cceKernel.paramBase));
275 7 : const int32_t ret = AicpuCustSoManager::GetInstance().CheckAndCreateSoFile(loadOpFromBufArgs, realSoName);
276 7 : if (ret != AICPU_SCHEDULE_OK) {
277 4 : return ret;
278 : }
279 :
280 : // if have cust pid, create or find cust pid
281 : uint32_t runMode;
282 3 : const aicpu::status_t status = aicpu::GetAicpuRunMode(runMode);
283 3 : if (status != aicpu::AICPU_ERROR_NONE) {
284 0 : aicpusd_err("Get current aicpu ctx failed.");
285 0 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
286 : }
287 :
288 3 : if (runMode != aicpu::AicpuRunMode::THREAD_MODE) {
289 3 : const std::lock_guard<std::mutex> lk(mutexForStartCustProcess_);
290 3 : constexpr uint32_t soNum = 1U;
291 3 : const char_t* soNames[soNum] = {realSoName.data()};
292 3 : auto it = alreadyLoadSoName_.insert(realSoName);
293 3 : if (it.second == true) {
294 2 : const int32_t startRet = StartCustProcess(soNum, &soNames[0UL]);
295 2 : if (startRet != AICPU_SCHEDULE_OK) {
296 1 : aicpusd_err("Get aicpu group, start up and add group to cust aicpu failed.");
297 1 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
298 : }
299 : } else {
300 1 : aicpusd_run_info("[%s] is already loaded.", realSoName.c_str());
301 : }
302 3 : }
303 :
304 2 : aicpusd_run_info("End to process ts LoadOpFromBuf event.");
305 2 : return AICPU_SCHEDULE_OK;
306 7 : }
307 :
308 8 : int32_t BatchLoadSoFromBuffTsKernel::TryToStartCustProcess(
309 : const std::unique_ptr<const char_t*[]>& soNames, const uint32_t soNum) const
310 : {
311 : // if have cust pid, create or find cust pid
312 8 : uint32_t runMode = 0U;
313 8 : const aicpu::status_t status = aicpu::GetAicpuRunMode(runMode);
314 8 : if (status != aicpu::AICPU_ERROR_NONE) {
315 0 : aicpusd_err("Get current aicpu ctx failed.");
316 0 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
317 : }
318 :
319 8 : if (runMode != aicpu::AicpuRunMode::THREAD_MODE) {
320 8 : const int32_t ret = StartCustProcess(soNum, soNames.get());
321 8 : if (ret != AICPU_SCHEDULE_OK) {
322 5 : aicpusd_err("Get aicpu group, start up and add group to cust aicpu failed.");
323 5 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
324 : }
325 : }
326 :
327 3 : return AICPU_SCHEDULE_OK;
328 : }
329 :
330 13 : int32_t BatchLoadSoFromBuffTsKernel::Compute(const aicpu::HwtsTsKernel& tsKernelInfo)
331 : {
332 13 : aicpusd_info("Begin to process ts kernel BatchLoadOpFromBuf event.");
333 13 : if (!AicpuCustSoManager::GetInstance().IsSupportCustAicpu()) {
334 1 : aicpusd_err("Cust aicpu scheduler is not supported in message queue mode.");
335 1 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
336 : }
337 :
338 12 : const auto paramKernelName = PtrToPtr<void, char_t>(ValueToPtr(tsKernelInfo.kernelBase.cceKernel.kernelName));
339 12 : if (paramKernelName == nullptr) {
340 0 : aicpusd_err("Process BatchLoadOpFromBuf failed as the name of kernel is null.");
341 0 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
342 : }
343 :
344 : const auto batchLoadOpFromBufArgs =
345 12 : PtrToPtr<void, BatchLoadOpFromBufArgs>(ValueToPtr(tsKernelInfo.kernelBase.cceKernel.paramBase));
346 12 : if (batchLoadOpFromBufArgs == nullptr) {
347 0 : aicpusd_err("param base for batch load op from buffer is null.");
348 0 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
349 : }
350 :
351 12 : const uint64_t custSoInfo = static_cast<uint64_t>(batchLoadOpFromBufArgs->opInfoArgs);
352 12 : const uint32_t soNum = static_cast<uint32_t>(batchLoadOpFromBufArgs->soNum);
353 : // check so num
354 12 : if ((soNum == 0U) || (soNum > MAX_CUSTOM_SO_NUM)) {
355 1 : aicpusd_err("BatchLoadOpFromBuf kernel input param soNum is invalid. soNum value is %u.", soNum);
356 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
357 : }
358 :
359 11 : aicpusd_info("BatchLoadOpFromBuf soNum is %u.", soNum);
360 11 : const std::unique_ptr<const char_t*[]> soNames(new (std::nothrow) const char_t*[soNum]);
361 11 : if (soNames == nullptr) {
362 0 : aicpusd_err("BatchLoadOpFromBuf kernel malloc for so names array failed, so number[%u]", soNum);
363 0 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
364 : }
365 :
366 11 : std::vector<std::string> soNameVec;
367 27 : for (uint32_t i = 0U; i < soNum; i++) {
368 19 : std::string realSoName;
369 19 : LoadOpFromBufArgs* const custSo = PtrToPtr<void, LoadOpFromBufArgs>(ValueToPtr(custSoInfo)) + i;
370 19 : const int32_t ret = AicpuCustSoManager::GetInstance().CheckAndCreateSoFile(custSo, realSoName);
371 19 : if (ret != AICPU_SCHEDULE_OK) {
372 3 : return ret;
373 : }
374 16 : soNameVec.emplace_back(realSoName);
375 16 : const size_t index = static_cast<size_t>(i);
376 16 : soNames[index] = soNameVec[index].data();
377 19 : }
378 :
379 8 : if (TryToStartCustProcess(soNames, soNum) != AICPU_SCHEDULE_OK) {
380 5 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
381 : }
382 :
383 3 : aicpusd_info("End to process ts BatchLoadOpFromBuf event.");
384 3 : return AICPU_SCHEDULE_OK;
385 11 : }
386 :
387 10 : int32_t DeleteCustOpTsKernel::Compute(const aicpu::HwtsTsKernel& tsKernelInfo)
388 : {
389 10 : aicpusd_info("Begin to process ts kernel deleteCustOp event.");
390 10 : if (!AicpuCustSoManager::GetInstance().IsSupportCustAicpu()) {
391 1 : aicpusd_err("Cust aicpu scheduler is not supported in message queue mode.");
392 1 : return AICPU_SCHEDULE_ERROR_INNER_ERROR;
393 : }
394 :
395 : const auto batchLoadOpFromBufArgs =
396 9 : PtrToPtr<void, BatchLoadOpFromBufArgs>(ValueToPtr(tsKernelInfo.kernelBase.cceKernel.paramBase));
397 9 : if (batchLoadOpFromBufArgs == nullptr) {
398 0 : aicpusd_err("param base for delete cust op is null.");
399 0 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
400 : }
401 :
402 9 : const uint64_t custSoInfo = static_cast<uint64_t>(batchLoadOpFromBufArgs->opInfoArgs);
403 9 : const uint32_t soNum = static_cast<uint32_t>(batchLoadOpFromBufArgs->soNum);
404 : // check so num
405 9 : if ((soNum == 0U) || (soNum > MAX_CUSTOM_SO_NUM)) {
406 1 : aicpusd_err("DeleteCustOp kernel input param soNum is invalid. soNum value is %u.", soNum);
407 1 : return AICPU_SCHEDULE_ERROR_PARAMETER_NOT_VALID;
408 : }
409 19 : for (uint32_t i = 0U; i < soNum; i++) {
410 14 : LoadOpFromBufArgs* const custSo = PtrToPtr<void, LoadOpFromBufArgs>(ValueToPtr(custSoInfo)) + i;
411 14 : const int32_t ret = AicpuCustSoManager::GetInstance().CheckAndDeleteSoFile(custSo);
412 14 : if (ret != AICPU_SCHEDULE_OK) {
413 3 : return ret;
414 : }
415 : }
416 :
417 : // After delete so, check whether dir is empty
418 5 : (void)AicpuCustSoManager::GetInstance().CheckAndDeleteCustSoDir();
419 5 : aicpusd_info("End to process ts deleteCustOp event.");
420 5 : return AICPU_SCHEDULE_OK;
421 : }
422 :
423 : REGISTER_HWTS_KERNEL(LOADOP_FROM_BUFF, LoadOpFromBuffTsKernel);
424 : REGISTER_HWTS_KERNEL(BATCH_LOADSO_FROM_BUFF, BatchLoadSoFromBuffTsKernel);
425 : REGISTER_HWTS_KERNEL(DELETE_CUSTOP, DeleteCustOpTsKernel);
426 : } // namespace AicpuSchedule
|