Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 : #include "api_error.hpp"
11 : #include "enum_desc.hpp"
12 : #include "osal.hpp"
13 : #include "program.hpp"
14 : #include "stream.hpp"
15 : #include "event.hpp"
16 : #include "elf.hpp"
17 : #include "runtime/kernel.h"
18 : #include "error_message_manage.hpp"
19 : #include "runtime/mem.h"
20 : #include "npu_driver.hpp"
21 : #include "capture_model_utils.hpp"
22 : #include "capture_adapt.hpp"
23 : #include "para_convertor.hpp"
24 : #include "global_state_manager.hpp"
25 : #include "register_memory.hpp"
26 : #include "starsv2_base.hpp"
27 : #include "mem_type.hpp"
28 : #include "utils.h"
29 : #include "runtime_handle_guard.h"
30 : #include "rt_inner_event.h"
31 :
32 : namespace cce {
33 : namespace runtime {
34 : constexpr int16_t MODEL_SCH_GROUP_ID_MIN = 0;
35 : constexpr int16_t MODEL_SCH_GROUP_ID_MAX = 4;
36 : constexpr uint32_t TASK_ABORT_TIMEOUT_MAX = (36 * 60 * 1000U); // 36min
37 : constexpr uint32_t HUGE1G_PAGE = 2U;
38 : constexpr size_t MAX_SHAPE_INFO_SIZE = 1024U * 64U;
39 : constexpr uint32_t DEVICE_TYPE = 1U;
40 : constexpr uint32_t NUMA_TYPE = 4U;
41 : constexpr uint32_t DRV_MEM_HOST_NUMA_SIDE = 2U;
42 : constexpr int32_t FEATURE_SVM_VMM_NORMAL_GRANULARITY = 6; // check drv is support alloc mem via numa id
43 : constexpr char_t MEM_SHARED_HANDLE_TYPE_EXPECT_DESC[] =
44 : "MEM_SHARE_HANDLE_TYPE_DEFAULT(1) or MEM_SHARE_HANDLE_TYPE_FABRIC(2)";
45 :
46 : ApiErrorDecorator::ApiErrorDecorator(Api* const impl) : ApiDecorator(impl) {}
47 :
48 : rtError_t ApiErrorDecorator::DevBinaryRegister(const rtDevBinary_t* const bin, Program** const prog)
49 : {
50 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(bin, RT_ERROR_INVALID_VALUE, "Registering operator binary data");
51 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(prog, RT_ERROR_INVALID_VALUE, "Registering operator binary data");
52 :
53 : const rtError_t error = impl_->DevBinaryRegister(bin, prog);
54 : ERROR_RETURN(error, "Register binary failed.");
55 : RT_LOG(RT_LOG_DEBUG, "register binary success, magic=%#x.", bin->magic);
56 : return error;
57 : }
58 :
59 : rtError_t ApiErrorDecorator::GetNotifyAddress(Notify* const notify, uint64_t* const notifyAddress)
60 : {
61 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(notify, RT_ERROR_INVALID_VALUE, "Obtaining the Notify address");
62 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(notifyAddress, RT_ERROR_INVALID_VALUE, "Obtaining the Notify address");
63 : const rtError_t error = impl_->GetNotifyAddress(notify, notifyAddress);
64 : ERROR_RETURN(error, "GetNotifyAddress failed.");
65 : RT_LOG(RT_LOG_DEBUG, "success.");
66 : return error;
67 : }
68 :
69 : rtError_t ApiErrorDecorator::RegisterAllKernel(const rtDevBinary_t* const bin, Program** const prog)
70 : {
71 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(bin, RT_ERROR_INVALID_VALUE, "Registering all kernel functions");
72 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(prog, RT_ERROR_INVALID_VALUE, "Registering all kernel functions");
73 :
74 : const uint32_t magic = bin->magic;
75 : const bool isElfProgram =
76 : ((magic == RT_DEV_BINARY_MAGIC_ELF) || (magic == RT_DEV_BINARY_MAGIC_ELF_AICUBE) ||
77 : (magic == RT_DEV_BINARY_MAGIC_ELF_AIVEC));
78 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
79 : (!isElfProgram), RT_ERROR_INVALID_VALUE, "Registering all kernel functions", magic,
80 : std::to_string(RT_DEV_BINARY_MAGIC_ELF) + " or " + std::to_string(RT_DEV_BINARY_MAGIC_ELF_AICUBE) + " or " +
81 : std::to_string(RT_DEV_BINARY_MAGIC_ELF_AIVEC));
82 :
83 : const rtError_t error = impl_->RegisterAllKernel(bin, prog);
84 : ERROR_RETURN(error, "Register binary failed.");
85 : RT_LOG(RT_LOG_DEBUG, "register binary success, magic=%#x.", bin->magic);
86 : return error;
87 : }
88 :
89 : rtError_t ApiErrorDecorator::BinaryRegisterToFastMemory(Program* const prog)
90 : {
91 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
92 : prog, RT_ERROR_INVALID_VALUE, "Setting the memory type of the operator binary handle to the fast memory type");
93 : return impl_->BinaryRegisterToFastMemory(prog);
94 : }
95 :
96 : rtError_t ApiErrorDecorator::DevBinaryUnRegister(Program* const prog)
97 : {
98 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(prog, RT_ERROR_INVALID_VALUE, "Deregistering operator binary data");
99 : return impl_->DevBinaryUnRegister(prog);
100 : }
101 :
102 : rtError_t ApiErrorDecorator::MetadataRegister(Program* const prog, const char_t* const metadata)
103 : {
104 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
105 : prog, RT_ERROR_INVALID_VALUE, "Registering the binary metadata information of the operator");
106 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
107 : metadata, RT_ERROR_INVALID_VALUE, "Registering the binary metadata information of the operator");
108 : return impl_->MetadataRegister(prog, metadata);
109 : }
110 :
111 : rtError_t ApiErrorDecorator::DependencyRegister(Program* const mProgram, Program* const sProgram)
112 : {
113 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
114 : mProgram, RT_ERROR_INVALID_VALUE, "Registering the dependency of the operator binary handle");
115 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
116 : sProgram, RT_ERROR_INVALID_VALUE, "Registering the dependency of the operator binary handle");
117 : return impl_->DependencyRegister(mProgram, sProgram);
118 : }
119 :
120 : rtError_t ApiErrorDecorator::FunctionRegister(
121 : Program* const prog, const void* const stubFunc, const char_t* const stubName, const void* const kernelInfoExt,
122 : const uint32_t funcMode)
123 : {
124 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(prog, RT_ERROR_INVALID_VALUE, "Operator kernel registration");
125 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(stubFunc, RT_ERROR_INVALID_VALUE, "Operator kernel registration");
126 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(stubName, RT_ERROR_INVALID_VALUE, "Operator kernel registration");
127 :
128 : const rtError_t error = impl_->FunctionRegister(prog, stubFunc, stubName, kernelInfoExt, funcMode);
129 : COND_PROC((error == RT_ERROR_KERNEL_DUPLICATE), return error;);
130 : ERROR_RETURN(error, "Register function failed, funcName=%s.", ((stubName != nullptr) ? stubName : "(none)"));
131 : return error;
132 : }
133 :
134 : rtError_t ApiErrorDecorator::RegisterVariable(
135 : void* const binHandle, const void* const hostVar, const char_t* const deviceVarName, const size_t size,
136 : const uint32_t flags)
137 : {
138 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
139 : binHandle, RT_ERROR_INVALID_VALUE, "Registering the device variable mapping table");
140 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
141 : hostVar, RT_ERROR_INVALID_VALUE, "Registering the device variable mapping table");
142 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
143 : deviceVarName, RT_ERROR_INVALID_VALUE, "Registering the device variable mapping table");
144 :
145 : const auto len = strnlen(deviceVarName, static_cast<size_t>(NAME_MAX_LENGTH));
146 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
147 : len >= NAME_MAX_LENGTH, RT_ERROR_INVALID_VALUE, "Registering the device variable mapping table", len,
148 : "less than " + std::to_string(NAME_MAX_LENGTH));
149 :
150 : const rtError_t error = impl_->RegisterVariable(binHandle, hostVar, deviceVarName, size, flags);
151 : ERROR_RETURN(error, "Register variable failed, hostVar=%p, deviceVarName=%s.", hostVar, deviceVarName);
152 : return error;
153 : }
154 :
155 : rtError_t ApiErrorDecorator::SymbolLookup(const void* const hostVar, void** const devPtr, size_t* const size)
156 : {
157 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
158 : devPtr, RT_ERROR_INVALID_VALUE,
159 : "Querying the address and size of the corresponding device based on the variable address on the host");
160 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
161 : size, RT_ERROR_INVALID_VALUE,
162 : "Querying the address and size of the corresponding device based on the variable address on the host");
163 : const rtError_t error = impl_->SymbolLookup(hostVar, devPtr, size);
164 : ERROR_RETURN(error, "Symbol lookup failed, hostVar=%p.", hostVar);
165 : return error;
166 : }
167 :
168 : rtError_t ApiErrorDecorator::GetFunctionByName(const char_t* const stubName, void** const stubFunc)
169 : {
170 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
171 : stubFunc, RT_ERROR_INVALID_VALUE, "Querying kernel function address based on the kernel function name");
172 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
173 : stubName, RT_ERROR_INVALID_VALUE, "Querying kernel function address based on the kernel function name");
174 : const rtError_t error = impl_->GetFunctionByName(stubName, stubFunc);
175 : COND_RETURN_ERROR_MSG_CALL(
176 : ERR_MODULE_GE, error != RT_ERROR_NONE, error, "Get stub function failed, name=%s.",
177 : ((stubName != nullptr) ? stubName : "(none)"));
178 : return error;
179 : }
180 :
181 : rtError_t ApiErrorDecorator::GetAddrByFun(const void* const stubFunc, void** const addr)
182 : {
183 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
184 : addr, RT_ERROR_INVALID_VALUE,
185 : "Querying the device execution address corresponding to the kernel function pointer");
186 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
187 : stubFunc, RT_ERROR_INVALID_VALUE,
188 : "Querying the device execution address corresponding to the kernel function pointer");
189 : const rtError_t error = impl_->GetAddrByFun(stubFunc, addr);
190 : ERROR_RETURN(error, "Get address failed.");
191 : return error;
192 : }
193 :
194 : rtError_t ApiErrorDecorator::GetAddrAndPrefCntWithHandle(
195 : void* const hdl, const void* const kernelInfoExt, void** const addr, uint32_t* const prefetchCnt)
196 : {
197 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
198 : hdl, RT_ERROR_INVALID_VALUE,
199 : "Obtaining the device address and prefetch count based on the kernel function handle");
200 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
201 : kernelInfoExt, RT_ERROR_INVALID_VALUE,
202 : "Obtaining the device address and prefetch count based on the kernel function handle");
203 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
204 : addr, RT_ERROR_INVALID_VALUE,
205 : "Obtaining the device address and prefetch count based on the kernel function handle");
206 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
207 : prefetchCnt, RT_ERROR_INVALID_VALUE,
208 : "Obtaining the device address and prefetch count based on the kernel function handle");
209 :
210 : const auto name = reinterpret_cast<const char_t*>(kernelInfoExt);
211 : const auto len = strnlen(name, static_cast<size_t>(NAME_MAX_LENGTH));
212 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
213 : len >= NAME_MAX_LENGTH, RT_ERROR_INVALID_VALUE,
214 : "Obtaining the device address and prefetch count based on the kernel function handle", len,
215 : "less than " + std::to_string(NAME_MAX_LENGTH));
216 :
217 : const rtError_t error = impl_->GetAddrAndPrefCntWithHandle(hdl, kernelInfoExt, addr, prefetchCnt);
218 : ERROR_RETURN(error, "get addr and prefCnt failed");
219 : return error;
220 : }
221 :
222 : rtError_t ApiErrorDecorator::CheckArgs(const rtArgsEx_t* const argsInfo) const
223 : {
224 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(argsInfo, RT_ERROR_INVALID_VALUE, "Operator parameter verification");
225 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(argsInfo->args, RT_ERROR_INVALID_VALUE, "Operator parameter verification");
226 : ZERO_RETURN_AND_MSG_OUTER(argsInfo->argsSize);
227 : RT_LOG(
228 : RT_LOG_DEBUG, "hostInputInfoNum=%hu, isNoNeedH2DCopy=%hhu, argsSize=%u, hasTiling=%hhu",
229 : argsInfo->hostInputInfoNum, argsInfo->isNoNeedH2DCopy, argsInfo->argsSize, argsInfo->hasTiling);
230 : if (argsInfo->isNoNeedH2DCopy == 0U) {
231 : if (argsInfo->hasTiling != 0U) {
232 : COND_RETURN_AND_MSG_OUTER(
233 : (argsInfo->tilingDataOffset >= argsInfo->argsSize), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
234 : "Operator parameter verification", "argsInfo->tilingDataOffset or argsInfo->argsSize",
235 : RtFmtMsg(
236 : "Parameter argsInfo->tilingDataOffset %u should be less than parameter argsInfo->argsSize %u",
237 : argsInfo->tilingDataOffset, argsInfo->argsSize));
238 : COND_RETURN_AND_MSG_OUTER(
239 : (argsInfo->tilingAddrOffset >= argsInfo->argsSize), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
240 : "Operator parameter verification", "argsInfo->tilingAddrOffset or argsInfo->argsSize",
241 : RtFmtMsg(
242 : "Parameter argsInfo->tilingAddrOffset %u should be less than parameter argsInfo->argsSize %u",
243 : argsInfo->tilingAddrOffset, argsInfo->argsSize));
244 : }
245 :
246 : if (argsInfo->hostInputInfoNum != 0U) {
247 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
248 : argsInfo->hostInputInfoPtr, RT_ERROR_INVALID_VALUE, "Operator parameter verification");
249 : for (uint16_t i = 0U; i < argsInfo->hostInputInfoNum; i++) {
250 : COND_RETURN_AND_MSG_OUTER(
251 : argsInfo->hostInputInfoPtr[i].addrOffset >= argsInfo->argsSize, RT_ERROR_INVALID_VALUE,
252 : ErrorCode::EE1017, "Operator parameter verification",
253 : RtFmtMsg("argsInfo->hostInputInfoPtr[%hu].addrOffset or argsInfo->argsSize", i),
254 : RtFmtMsg(
255 : "Parameter argsInfo->hostInputInfoPtr[%hu].addrOffset %u should be less than parameter"
256 : " argsInfo->argsSize %u",
257 : i, argsInfo->hostInputInfoPtr[i].addrOffset, argsInfo->argsSize));
258 : COND_RETURN_AND_MSG_OUTER(
259 : argsInfo->hostInputInfoPtr[i].dataOffset >= argsInfo->argsSize, RT_ERROR_INVALID_VALUE,
260 : ErrorCode::EE1017, "Operator parameter verification",
261 : RtFmtMsg("argsInfo->hostInputInfoPtr[%hu].dataOffset or argsInfo->argsSize", i),
262 : RtFmtMsg(
263 : "Parameter argsInfo->hostInputInfoPtr[%hu].dataOffset %u should be less than parameter"
264 : " argsInfo->argsSize %u",
265 : i, argsInfo->hostInputInfoPtr[i].dataOffset, argsInfo->argsSize));
266 : }
267 : }
268 : }
269 : return RT_ERROR_NONE;
270 : }
271 :
272 : rtError_t ApiErrorDecorator::CheckNonArgsHandle(const RtArgsHandle* const argsHandle) const
273 : {
274 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
275 : argsHandle, RT_ERROR_INVALID_VALUE, "Verifying the validity of the kernel parameter handle");
276 : // 如果Finalize后,再update,只有update完成后再次调用Finalize,isParamUpdating重置为0,表示更新完成
277 : COND_RETURN_AND_MSG_OUTER(
278 : (argsHandle->isFinalized == 0U) || (argsHandle->isParamUpdating == 1U), RT_ERROR_INVALID_VALUE,
279 : ErrorCode::EE1017, "Verifying the validity of the kernel parameter handle", "argsHandle",
280 : "The argsHandle is not finalized or is currently being updated");
281 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
282 : argsHandle->buffer, RT_ERROR_INVALID_VALUE, "Verifying the validity of the kernel parameter handle");
283 : ZERO_RETURN_AND_MSG_OUTER(argsHandle->argsSize);
284 :
285 : for (uint16_t i = 0U; i < argsHandle->realUserParamNum; i++) {
286 : if (argsHandle->para[i].type == 0U) { // 0 is Common param, 1 is place holder param
287 : continue;
288 : }
289 : COND_RETURN_AND_MSG_OUTER(
290 : argsHandle->para[i].paraOffset >= argsHandle->argsSize, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
291 : "Verifying the validity of the kernel parameter handle",
292 : RtFmtMsg("argsHandle->para[%hu].paraOffset or argsHandle->argsSize", i),
293 : RtFmtMsg(
294 : "Parameter argsHandle->para[%hu].paraOffset %zu must be less than parameter argsHandle->argsSize %zu",
295 : i, argsHandle->para[i].paraOffset, argsHandle->argsSize));
296 : COND_RETURN_AND_MSG_OUTER(
297 : argsHandle->para[i].dataOffset >= argsHandle->argsSize, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
298 : "Verifying the validity of the kernel parameter handle",
299 : RtFmtMsg("argsHandle->para[%hu].dataOffset or argsHandle->argsSize", i),
300 : RtFmtMsg(
301 : "Parameter argsHandle->para[%hu].dataOffset %zu must be less than parameter argsHandle->argsSize %zu",
302 : i, argsHandle->para[i].dataOffset, argsHandle->argsSize));
303 : }
304 :
305 : return RT_ERROR_NONE;
306 : }
307 :
308 : static rtError_t CheckCpuArgsInfo(const rtCpuKernelArgs_t* const argsInfo)
309 : {
310 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
311 : argsInfo, RT_ERROR_INVALID_VALUE, "Checking the parameter information of the AI CPU operator");
312 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
313 : argsInfo->baseArgs.args, RT_ERROR_INVALID_VALUE, "Checking the parameter information of the AI CPU operator");
314 : ZERO_RETURN_AND_MSG_OUTER(argsInfo->baseArgs.argsSize);
315 :
316 : return RT_ERROR_NONE;
317 : }
318 :
319 : static rtError_t CheckSimtArgsArray(const Kernel* kernel, const RtArgsWithType* const argsWithType)
320 : {
321 : const uint32_t kernelVfType = kernel->KernelVfType_();
322 : const bool isSimtKernel = (kernelVfType == static_cast<uint32_t>(AivTypeFlag::AIV_TYPE_SIMT_VF_ONLY)) ||
323 : (kernelVfType == static_cast<uint32_t>(AivTypeFlag::AIV_TYPE_SIMD_SIMT_MIX_VF));
324 : COND_RETURN_AND_MSG_OUTER(
325 : !isSimtKernel, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Checking SIMT parameters", "kernel",
326 : "current API only supports SIMT kernel");
327 : COND_RETURN_AND_MSG_OUTER(
328 : !kernel->HasParamSummary(), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Checking SIMT parameters", "kernel",
329 : "Kernel does not have param info, please check whether kernel version is matched");
330 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
331 : argsWithType->args.simtArgsArray, RT_ERROR_INVALID_VALUE, "Checking SIMT parameters");
332 : const SimtArgsArray* simtArgs = argsWithType->args.simtArgsArray;
333 : COND_RETURN_AND_MSG_OUTER(
334 : (simtArgs->gridDim.x == 0U) || (simtArgs->gridDim.y == 0U) || (simtArgs->gridDim.z == 0U),
335 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Checking SIMT parameters", "gridDim",
336 : RtFmtMsg(
337 : "gridDim.x, gridDim.y, gridDim.z must all be greater than 0, actual gridDim=[%u,%u,%u]",
338 : simtArgs->gridDim.x, simtArgs->gridDim.y, simtArgs->gridDim.z));
339 : COND_RETURN_AND_MSG_OUTER(
340 : (simtArgs->blockDim.x == 0U) || (simtArgs->blockDim.y == 0U) || (simtArgs->blockDim.z == 0U),
341 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Checking SIMT parameters", "blockDim",
342 : RtFmtMsg(
343 : "blockDim.x, blockDim.y, blockDim.z must all be greater than 0, actual blockDim=[%u,%u,%u]",
344 : simtArgs->blockDim.x, simtArgs->blockDim.y, simtArgs->blockDim.z));
345 : if (kernel->GetParamCount() > 0U) {
346 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
347 : argsWithType->args.simtArgsArray->argsArrayInfo, RT_ERROR_INVALID_VALUE, "Checking SIMT parameters");
348 : }
349 : return RT_ERROR_NONE;
350 : }
351 :
352 : static rtError_t CheckSimtArgsHost(const Kernel* kernel, const RtArgsWithType* const argsWithType)
353 : {
354 : const uint32_t kernelVfType = kernel->KernelVfType_();
355 : const bool isSimtKernel = (kernelVfType == static_cast<uint32_t>(AivTypeFlag::AIV_TYPE_SIMT_VF_ONLY)) ||
356 : (kernelVfType == static_cast<uint32_t>(AivTypeFlag::AIV_TYPE_SIMD_SIMT_MIX_VF));
357 : COND_RETURN_AND_MSG_OUTER(
358 : !isSimtKernel, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Checking SIMT parameters", "kernel",
359 : "current API only supports SIMT kernel");
360 : COND_RETURN_AND_MSG_OUTER(
361 : !kernel->HasParamSummary(), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Checking SIMT parameters", "kernel",
362 : "Kernel does not have param info, please check whether kernel version is matched");
363 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
364 : argsWithType->args.simtArgsHost, RT_ERROR_INVALID_VALUE, "Checking SIMT parameters");
365 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
366 : argsWithType->args.simtArgsHost->hostArgs, RT_ERROR_INVALID_VALUE, "Checking SIMT parameters");
367 : ZERO_RETURN_AND_MSG_OUTER(argsWithType->args.simtArgsHost->argsSize);
368 : const SimtArgsHost* simtArgs = argsWithType->args.simtArgsHost;
369 : COND_RETURN_AND_MSG_OUTER(
370 : (simtArgs->gridDim.x == 0U) || (simtArgs->gridDim.y == 0U) || (simtArgs->gridDim.z == 0U),
371 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Checking SIMT parameters", "gridDim",
372 : "gridDim.x, gridDim.y, gridDim.z must all be greater than 0");
373 : COND_RETURN_AND_MSG_OUTER(
374 : (simtArgs->blockDim.x == 0U) || (simtArgs->blockDim.y == 0U) || (simtArgs->blockDim.z == 0U),
375 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Checking SIMT parameters", "blockDim",
376 : "blockDim.x, blockDim.y, blockDim.z must all be greater than 0");
377 : const uint32_t argsSize = argsWithType->args.simtArgsHost->argsSize;
378 : const uint32_t placeHolderNum = argsWithType->args.simtArgsHost->placeHolderNum;
379 : if (placeHolderNum > 0U) {
380 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
381 : argsWithType->args.simtArgsHost->placeHolderArray, RT_ERROR_INVALID_VALUE, "Checking SIMT parameters");
382 : for (uint32_t i = 0U; i < placeHolderNum; i++) {
383 : COND_RETURN_AND_MSG_OUTER(
384 : argsWithType->args.simtArgsHost->placeHolderArray[i].addrOffset >= argsSize, RT_ERROR_INVALID_VALUE,
385 : ErrorCode::EE1017, "Checking SIMT parameters",
386 : RtFmtMsg("placeHolderArray[%u].addrOffset or argsSize", i),
387 : RtFmtMsg(
388 : "Parameter placeHolderArray[%u].addrOffset %u should be less than parameter argsSize %u", i,
389 : argsWithType->args.simtArgsHost->placeHolderArray[i].addrOffset, argsSize));
390 : COND_RETURN_AND_MSG_OUTER(
391 : argsWithType->args.simtArgsHost->placeHolderArray[i].dataOffset >= argsSize, RT_ERROR_INVALID_VALUE,
392 : ErrorCode::EE1017, "Checking SIMT parameters",
393 : RtFmtMsg("placeHolderArray[%u].dataOffset or argsSize", i),
394 : RtFmtMsg(
395 : "Parameter placeHolderArray[%u].dataOffset %u should be less than parameter argsSize %u", i,
396 : argsWithType->args.simtArgsHost->placeHolderArray[i].dataOffset, argsSize));
397 : }
398 : }
399 : return RT_ERROR_NONE;
400 : }
401 :
402 : rtError_t ApiErrorDecorator::CheckArgsWithType(const Kernel* kernel, const RtArgsWithType* const argsWithType) const
403 : {
404 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(argsWithType, RT_ERROR_INVALID_VALUE, "Operator parameter verification");
405 :
406 : rtError_t error = RT_ERROR_NONE;
407 : switch (argsWithType->type) {
408 : case RT_ARGS_NON_CPU_EX:
409 : error = CheckArgs(argsWithType->args.nonCpuArgsInfo);
410 : break;
411 : case RT_ARGS_CPU_EX:
412 : error = CheckCpuArgsInfo(argsWithType->args.cpuArgsInfo);
413 : break;
414 : case RT_ARGS_HANDLE:
415 : error = CheckNonArgsHandle(argsWithType->args.argHandle);
416 : break;
417 : case RT_ARGS_ARRAY: {
418 : COND_RETURN_WARN(
419 : kernel->GetKernelRegisterType() == RT_KERNEL_REG_TYPE_CPU, RT_ERROR_FEATURE_NOT_SUPPORT,
420 : "AICPU kernel is not supported.");
421 : COND_RETURN_AND_MSG_OUTER(
422 : !kernel->HasParamSummary(), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
423 : "Operator parameter verification", "kernel", "Kernel does not have parameter information");
424 : if (kernel->GetParamCount() > 0U) {
425 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
426 : argsWithType->args.argsArrayInfo, RT_ERROR_INVALID_VALUE, "Operator parameter verification");
427 : }
428 : break;
429 : }
430 : case RT_SIMT_ARGS_ARRAY: {
431 : error = CheckSimtArgsArray(kernel, argsWithType);
432 : break;
433 : }
434 : case RT_SIMT_ARGS_HOST: {
435 : error = CheckSimtArgsHost(kernel, argsWithType);
436 : break;
437 : }
438 : default:
439 : RT_LOG(RT_LOG_ERROR, "check args failed. type=%u", static_cast<uint32_t>(argsWithType->type));
440 : error = RT_ERROR_INVALID_VALUE;
441 : break;
442 : }
443 :
444 : return error;
445 : }
446 :
447 : rtError_t ApiErrorDecorator::CheckMemcpyCfg(const RtMemcpyCfgInfo* const configInfo, const bool isAsync) const
448 : {
449 : if (isAsync) {
450 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
451 : (configInfo->checkBitmap >= NOT_CHECK_KIND_BUT_CHECK_PINNED), RT_ERROR_INVALID_VALUE,
452 : configInfo->checkBitmap, "[0, 2]");
453 : } else {
454 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
455 : (configInfo->checkBitmap > NOT_CHECK_KIND_BUT_CHECK_PINNED), RT_ERROR_INVALID_VALUE,
456 : configInfo->checkBitmap, "[0, 3]");
457 : }
458 :
459 : return RT_ERROR_NONE;
460 : }
461 :
462 : rtError_t ApiErrorDecorator::GetMemcpyConfigInfo(
463 : RtMemcpyCfgInfo* configInfo, const rtMemcpyConfig_t* const memcpyConfig, const bool isAsync)
464 : {
465 : rtError_t error = RT_ERROR_NONE;
466 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
467 : memcpyConfig->attrs, RT_ERROR_INVALID_VALUE, "Obtaining configurations of memory copy");
468 : for (uint32_t i = 0U; i < memcpyConfig->numAttrs; i++) {
469 : rtMemcpyAttribute_t* attr = &(memcpyConfig->attrs[i]);
470 : error = GetMemcpyConfigAttr(attr, configInfo);
471 : COND_RETURN_WITH_NOLOG((error != RT_ERROR_NONE), error);
472 : }
473 :
474 : error = CheckMemcpyCfg(configInfo, isAsync);
475 : return error;
476 : }
477 :
478 : rtError_t ApiErrorDecorator::GetMemcpyConfigAttr(rtMemcpyAttribute_t* attr, RtMemcpyCfgInfo* configInfo) const
479 : {
480 : rtError_t error = RT_ERROR_NONE;
481 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
482 : attr, RT_ERROR_INVALID_VALUE, "Obtaining configuration attributes of memory copy");
483 : switch (attr->id) {
484 : case RT_MEMCPY_ATTRIBUTE_CHECK:
485 : configInfo->checkBitmap = attr->value.checkBitmap;
486 : break;
487 : default:
488 : RT_LOG_OUTER_MSG_INVALID_PARAM_WITH_DESC("Obtaining configuration attributes of memory copy", attr->id, 1);
489 : error = RT_ERROR_INVALID_VALUE;
490 : break;
491 : }
492 : return error;
493 : }
494 :
495 : rtError_t ApiErrorDecorator::KernelGetAddrAndPrefCnt(
496 : void* const hdl, const uint64_t tilingKey, const void* const stubFunc, const uint32_t flag, void** const addr,
497 : uint32_t* const prefetchCnt)
498 : {
499 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
500 : addr, RT_ERROR_INVALID_VALUE,
501 : "Obtaining the on-device execution address and instruction prefetch count of the kernel function");
502 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
503 : prefetchCnt, RT_ERROR_INVALID_VALUE,
504 : "Obtaining the on-device execution address and instruction prefetch count of the kernel function");
505 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
506 : (flag > RT_DYNAMIC_SHAPE_KERNEL), RT_ERROR_INVALID_VALUE,
507 : "Obtaining the on-device execution address and instruction prefetch count of the kernel function", flag,
508 : "[0, " + std::to_string(RT_DYNAMIC_SHAPE_KERNEL) + "]");
509 :
510 : if (flag == RT_STATIC_SHAPE_KERNEL) {
511 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
512 : stubFunc, RT_ERROR_INVALID_VALUE,
513 : "Obtaining the on-device execution address and instruction prefetch count of the kernel function");
514 : } else {
515 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
516 : hdl, RT_ERROR_INVALID_VALUE,
517 : "Obtaining the on-device execution address and instruction prefetch count of the kernel function");
518 : }
519 :
520 : const rtError_t error = impl_->KernelGetAddrAndPrefCnt(hdl, tilingKey, stubFunc, flag, addr, prefetchCnt);
521 : ERROR_RETURN_MSG_INNER(error, "get addr and prefCnt failed, tilingKey=%" PRIu64, tilingKey);
522 : return error;
523 : }
524 :
525 : rtError_t ApiErrorDecorator::KernelGetAddrAndPrefCntV2(
526 : void* const hdl, const uint64_t tilingKey, const void* const stubFunc, const uint32_t flag,
527 : rtKernelDetailInfo_t* const kernelInfo)
528 : {
529 : bool invalidFlag = false;
530 : if (flag == RT_STATIC_SHAPE_KERNEL) {
531 : if (stubFunc == nullptr) {
532 : invalidFlag = true;
533 : }
534 : } else {
535 : if (hdl == nullptr) {
536 : invalidFlag = true;
537 : }
538 : }
539 :
540 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
541 : kernelInfo, RT_ERROR_INVALID_VALUE,
542 : "Obtaining the on-device execution address and instruction prefetch count of the kernel function");
543 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
544 : (flag > RT_DYNAMIC_SHAPE_KERNEL), RT_ERROR_INVALID_VALUE,
545 : "Obtaining the on-device execution address and instruction prefetch count of the kernel function", flag,
546 : "[0, " + std::to_string(RT_DYNAMIC_SHAPE_KERNEL) + "]");
547 : COND_RETURN_AND_MSG_OUTER(
548 : invalidFlag == true, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
549 : "Obtaining the on-device execution address and instruction prefetch count of the kernel function",
550 : "stubFunc or hdl",
551 : "If parameter flag is RT_STATIC_SHAPE_KERNEL(0x00U), stubFunc cannot be nullptr; "
552 : "If parameter flag is not equal to RT_STATIC_SHAPE_KERNEL(0x00U), parameter hdl cannot be nullptr");
553 :
554 : const rtError_t error = impl_->KernelGetAddrAndPrefCntV2(hdl, tilingKey, stubFunc, flag, kernelInfo);
555 : ERROR_RETURN(error, "get addr and prefCnt failed, tilingKey=%" PRIu64, tilingKey);
556 : return error;
557 : }
558 :
559 : rtError_t ApiErrorDecorator::QueryFunctionRegistered(const char_t* const stubName)
560 : {
561 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
562 : stubName, RT_ERROR_INVALID_VALUE, "Checking whether the kernel function is registered");
563 : return impl_->QueryFunctionRegistered(stubName);
564 : }
565 :
566 : rtError_t ApiErrorDecorator::CheckCfg(const rtTaskCfgInfo_t* const cfgInfo) const
567 : {
568 : if ((cfgInfo != nullptr) && (cfgInfo->schemMode > RT_SCHEM_MODE_END)) {
569 : RT_LOG_OUTER_MSG_INVALID_PARAM(
570 : cfgInfo->schemMode,
571 : "[" + std::to_string(RT_SCHEM_MODE_NORMAL) + ", " + std::to_string(RT_SCHEM_MODE_END) + ")");
572 : return RT_ERROR_INVALID_VALUE;
573 : }
574 : return RT_ERROR_NONE;
575 : }
576 :
577 : rtError_t ApiErrorDecorator::AppendLaunchAddrInfo(rtLaunchArgs_t* const hdl, void* const addrInfo)
578 : {
579 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
580 : hdl, RT_ERROR_INVALID_VALUE, "Adding an address to the parameter buffer of the kernel");
581 : /* addrInfo == nullptr is an empty tensor scenario. No error is returned. */
582 : if (addrInfo == nullptr) {
583 : RT_LOG(RT_LOG_WARNING, "addrInfo == nullptr.");
584 : }
585 : const uint32_t offset = static_cast<uint32_t>(hdl->argsAddrOffset + sizeof(uint64_t));
586 : COND_RETURN_AND_MSG_OUTER(
587 : offset > hdl->argsDataOffset, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
588 : "Adding an address to the parameter buffer of the kernel", "hdl->argsAddrOffset or hdl->argsDataOffset",
589 : RtFmtMsg(
590 : "Parameter hdl->argsDataOffset %u should be greater than or equal to the sum of parameter"
591 : " hdl->argsAddrOffset %u and %zu",
592 : hdl->argsDataOffset, hdl->argsAddrOffset, sizeof(uint64_t)));
593 : return impl_->AppendLaunchAddrInfo(hdl, addrInfo);
594 : }
595 :
596 : rtError_t ApiErrorDecorator::AppendLaunchHostInfo(
597 : rtLaunchArgs_t* const hdl, size_t const hostInfoSize, void** const hostInfo)
598 : {
599 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
600 : hdl, RT_ERROR_INVALID_VALUE, "Adding host data to the parameter buffer of the kernel");
601 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
602 : hostInfo, RT_ERROR_INVALID_VALUE, "Adding host data to the parameter buffer of the kernel");
603 : COND_RETURN_AND_MSG_OUTER(
604 : hdl->argsInfo.hostInputInfoNum >= hdl->hostInfoMaxNum, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
605 : "Adding host data to the parameter buffer of the kernel",
606 : "hdl->argsInfo.hostInputInfoNum or hdl->hostInfoMaxNum",
607 : RtFmtMsg(
608 : "Parameter hdl->argsInfo.hostInputInfoNum %u should be less than parameter hdl->hostInfoMaxNum %u",
609 : hdl->argsInfo.hostInputInfoNum, hdl->hostInfoMaxNum));
610 : ZERO_RETURN_AND_MSG_OUTER(hostInfoSize);
611 : uint32_t currentDataOffset = static_cast<uint32_t>(hdl->argsHostInputOffset + hostInfoSize);
612 : COND_RETURN_AND_MSG_OUTER(
613 : currentDataOffset > hdl->argsInfo.argsSize, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
614 : "Adding host data to the parameter buffer of the kernel",
615 : "hdl->argsHostInputOffset, hostInfoSize or hdl->argsInfo.argsSize",
616 : RtFmtMsg(
617 : "Parameter hdl->argsInfo.argsSize %u should be greater than or equal to the sum of parameter"
618 : " hdl->argsHostInputOffset %u and parameter hostInfoSize %zu",
619 : hdl->argsInfo.argsSize, hdl->argsHostInputOffset, hostInfoSize));
620 :
621 : return impl_->AppendLaunchHostInfo(hdl, hostInfoSize, hostInfo);
622 : }
623 :
624 : rtError_t ApiErrorDecorator::CalcLaunchArgsSize(
625 : size_t const argsSize, size_t const hostInfoTotalSize, size_t hostInfoNum, size_t* const launchArgsSize)
626 : {
627 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
628 : launchArgsSize, RT_ERROR_INVALID_VALUE,
629 : "Obtaining the actual memory size required by the parameter list during kernel launch");
630 : ZERO_RETURN_AND_MSG_OUTER(argsSize);
631 : ZERO_RETURN_AND_MSG_OUTER(hostInfoTotalSize);
632 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
633 : (hostInfoNum == 0U || hostInfoNum > static_cast<size_t>(UINT16_MAX)), RT_ERROR_INVALID_VALUE,
634 : "Obtaining the actual memory size required by the parameter list during kernel launch", hostInfoNum,
635 : "[1, " + std::to_string(static_cast<size_t>(UINT16_MAX)) + "]");
636 :
637 : return impl_->CalcLaunchArgsSize(argsSize, hostInfoTotalSize, hostInfoNum, launchArgsSize);
638 : }
639 :
640 : rtError_t ApiErrorDecorator::CreateLaunchArgs(
641 : size_t const argsSize, size_t const hostInfoTotalSize, size_t hostInfoNum, void* const argsData,
642 : rtLaunchArgs_t** const argsHandle)
643 : {
644 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
645 : argsData, RT_ERROR_INVALID_VALUE, "Creating a parameter handle for kernel launch");
646 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
647 : argsHandle, RT_ERROR_INVALID_VALUE, "Creating a parameter handle for kernel launch");
648 : ZERO_RETURN_AND_MSG_OUTER(argsSize);
649 : ZERO_RETURN_AND_MSG_OUTER(hostInfoTotalSize);
650 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
651 : (hostInfoNum == 0U || hostInfoNum > static_cast<size_t>(UINT16_MAX)), RT_ERROR_INVALID_VALUE,
652 : "Creating a parameter handle for kernel launch", hostInfoNum,
653 : "[1, " + std::to_string(static_cast<size_t>(UINT16_MAX)) + "]");
654 : const rtError_t error = impl_->CreateLaunchArgs(argsSize, hostInfoTotalSize, hostInfoNum, argsData, argsHandle);
655 : ERROR_RETURN(
656 : error, "CreateLaunchArgs, argsSize=%zu, hostInfoTotalSize=%zu, hostInfoNum=%zu, argsData=0x%x", argsSize,
657 : hostInfoTotalSize, hostInfoNum, argsData);
658 : return error;
659 : }
660 :
661 : rtError_t ApiErrorDecorator::DestroyLaunchArgs(rtLaunchArgs_t* argsHandle)
662 : {
663 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
664 : argsHandle, RT_ERROR_INVALID_VALUE, "Destroying the boot parameter handle of the kernel function");
665 : return impl_->DestroyLaunchArgs(argsHandle);
666 : }
667 :
668 : rtError_t ApiErrorDecorator::ResetLaunchArgs(rtLaunchArgs_t* argsHandle)
669 : {
670 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
671 : argsHandle, RT_ERROR_INVALID_VALUE, "Resetting the parameter handle for kernel launch");
672 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
673 : argsHandle->argsInfo.args, RT_ERROR_INVALID_VALUE, "Resetting the parameter handle for kernel launch");
674 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
675 : argsHandle->argsInfo.hostInputInfoPtr, RT_ERROR_INVALID_VALUE,
676 : "Resetting the parameter handle for kernel launch");
677 : const rtError_t error = impl_->ResetLaunchArgs(argsHandle);
678 : ERROR_RETURN(error, "ResetLaunchArgs argsHandle = 0x%x", argsHandle);
679 : return error;
680 : }
681 :
682 : rtError_t ApiErrorDecorator::BinaryLoad(const rtDevBinary_t* const bin, Program** const prog)
683 : {
684 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
685 : bin, RT_ERROR_INVALID_VALUE, "Parsing and loading the operator binary file");
686 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
687 : prog, RT_ERROR_INVALID_VALUE, "Parsing and loading the operator binary file");
688 : ZERO_RETURN_AND_MSG_OUTER(bin->length);
689 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
690 : bin->data, RT_ERROR_INVALID_VALUE, "Parsing and loading the operator binary file");
691 :
692 : const uint32_t magic = bin->magic;
693 : const bool isElfProgram =
694 : ((magic == RT_DEV_BINARY_MAGIC_ELF) || (magic == RT_DEV_BINARY_MAGIC_ELF_AICUBE) ||
695 : (magic == RT_DEV_BINARY_MAGIC_ELF_AIVEC));
696 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
697 : (!isElfProgram), RT_ERROR_INVALID_VALUE, "Parsing and loading the operator binary file", magic,
698 : std::to_string(RT_DEV_BINARY_MAGIC_ELF) + " or " + std::to_string(RT_DEV_BINARY_MAGIC_ELF_AICUBE) + " or " +
699 : std::to_string(RT_DEV_BINARY_MAGIC_ELF_AIVEC));
700 : const rtError_t error = impl_->BinaryLoad(bin, prog);
701 : ERROR_RETURN(error, "BinaryLoad failed.");
702 : return error;
703 : }
704 :
705 : rtError_t ApiErrorDecorator::BinaryGetFunction(
706 : const Program* const prog, const uint64_t tilingKey, Kernel** const funcHandle)
707 : {
708 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
709 : prog, RT_ERROR_INVALID_VALUE, "Searching for a kernel function based on its name");
710 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
711 : funcHandle, RT_ERROR_INVALID_VALUE, "Searching for a kernel function based on its name");
712 :
713 : const rtError_t error = impl_->BinaryGetFunction(prog, tilingKey, funcHandle);
714 : ERROR_RETURN(error, "BinaryGetFunction failed.");
715 : return error;
716 : }
717 :
718 : rtError_t ApiErrorDecorator::BinaryLoadWithoutTilingKey(const void* data, const uint64_t length, Program** const prog)
719 : {
720 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
721 : data, RT_ERROR_INVALID_VALUE, "Loading the operator binary data without the tiling key");
722 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
723 : prog, RT_ERROR_INVALID_VALUE, "Loading the operator binary data without the tiling key");
724 : ZERO_RETURN_AND_MSG_OUTER(length);
725 :
726 : const rtError_t error = impl_->BinaryLoadWithoutTilingKey(data, length, prog);
727 : ERROR_RETURN(error, "BinaryLoadWithoutTilingKey failed.");
728 : return error;
729 : }
730 :
731 : rtError_t ApiErrorDecorator::BinaryGetFunctionByName(
732 : const Program* const binHandle, const char_t* kernelName, Kernel** const funcHandle)
733 : {
734 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
735 : binHandle, RT_ERROR_INVALID_VALUE, "Searching for a kernel function based on its name");
736 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
737 : kernelName, RT_ERROR_INVALID_VALUE, "Searching for a kernel function based on its name");
738 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
739 : funcHandle, RT_ERROR_INVALID_VALUE, "Searching for a kernel function based on its name");
740 :
741 : const rtError_t error = impl_->BinaryGetFunctionByName(binHandle, kernelName, funcHandle);
742 : ERROR_RETURN(error, "BinaryGetFunction failed.");
743 : return error;
744 : }
745 :
746 : rtError_t ApiErrorDecorator::BinaryGetFunctionByEntry(
747 : const Program* const binHandle, const uint64_t funcEntry, Kernel** const funcHandle)
748 : {
749 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
750 : binHandle, RT_ERROR_INVALID_VALUE, "Obtaining the kernel function handle based on the function entry");
751 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
752 : funcHandle, RT_ERROR_INVALID_VALUE, "Obtaining the kernel function handle based on the function entry");
753 : const KernelRegisterType kernelRegType = binHandle->GetKernelRegType();
754 : COND_RETURN_AND_MSG_OUTER(
755 : kernelRegType != RT_KERNEL_REG_TYPE_NON_CPU, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
756 : "Obtaining the kernel function handle based on the function entry", "binHandle->kernelRegType_",
757 : "The binHandle obtained after registering the AI CPU operator is not supported");
758 :
759 : return impl_->BinaryGetFunctionByEntry(binHandle, funcEntry, funcHandle);
760 : }
761 :
762 : rtError_t ApiErrorDecorator::BinaryGetMetaNum(Program* const binHandle, const rtBinaryMetaType type, size_t* numOfMeta)
763 : {
764 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
765 : binHandle, RT_ERROR_INVALID_VALUE,
766 : "Obtaining the number of metadata records of a specific type in the operator binary file");
767 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
768 : numOfMeta, RT_ERROR_INVALID_VALUE,
769 : "Obtaining the number of metadata records of a specific type in the operator binary file");
770 : COND_RETURN_AND_MSG_OUTER(
771 : binHandle->GetKernelRegType() != RT_KERNEL_REG_TYPE_NON_CPU, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
772 : "Obtaining the number of metadata records of a specific type in the operator binary file", "binHandle",
773 : "The binHandle obtained after registering the AI CPU operator is not supported");
774 : return impl_->BinaryGetMetaNum(binHandle, type, numOfMeta);
775 : }
776 :
777 : rtError_t ApiErrorDecorator::BinaryGetMetaInfo(
778 : Program* const binHandle, const rtBinaryMetaType type, const size_t numOfMeta, void** data, const size_t* dataSize)
779 : {
780 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
781 : binHandle, RT_ERROR_INVALID_VALUE, "Obtaining the metadata of the operator binary file");
782 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
783 : data, RT_ERROR_INVALID_VALUE, "Obtaining the metadata of the operator binary file");
784 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
785 : dataSize, RT_ERROR_INVALID_VALUE, "Obtaining the metadata of the operator binary file");
786 : COND_RETURN_AND_MSG_OUTER(
787 : binHandle->GetKernelRegType() != RT_KERNEL_REG_TYPE_NON_CPU, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
788 : "Obtaining the metadata of the operator binary file", "binHandle",
789 : "The binHandle obtained after registering the AI CPU operator is not supported");
790 : return impl_->BinaryGetMetaInfo(binHandle, type, numOfMeta, data, dataSize);
791 : }
792 :
793 : rtError_t ApiErrorDecorator::FunctionGetMetaInfo(
794 : const Kernel* const funcHandle, const rtFunctionMetaType type, void* data, const uint32_t length)
795 : {
796 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
797 : funcHandle, RT_ERROR_INVALID_VALUE, "Querying metadata information of a kernel function");
798 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
799 : data, RT_ERROR_INVALID_VALUE, "Querying metadata information of a kernel function");
800 : return impl_->FunctionGetMetaInfo(funcHandle, type, data, length);
801 : }
802 :
803 : rtError_t ApiErrorDecorator::GetFunctionBySymbol(const void* symbol, Kernel** const funcHandle)
804 : {
805 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
806 : symbol, RT_ERROR_INVALID_VALUE, "Obtaining the kernel function handle based on the function symbol name");
807 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
808 : funcHandle, RT_ERROR_INVALID_VALUE, "Obtaining the kernel function handle based on the function symbol name");
809 : return impl_->GetFunctionBySymbol(symbol, funcHandle);
810 : }
811 :
812 : rtError_t ApiErrorDecorator::RegisterFuncSymbol(
813 : void* const binHandle, const void* const symbol, const char_t* const kernelName)
814 : {
815 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
816 : binHandle, RT_ERROR_INVALID_VALUE, "Registering the variable mapping table of the kernel function");
817 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
818 : symbol, RT_ERROR_INVALID_VALUE, "Registering the variable mapping table of the kernel function");
819 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
820 : kernelName, RT_ERROR_INVALID_VALUE, "Registering the variable mapping table of the kernel function");
821 :
822 : const rtError_t error = impl_->RegisterFuncSymbol(binHandle, symbol, kernelName);
823 : ERROR_RETURN(error, "Register function symbol failed, symbol=%p.", symbol);
824 : return error;
825 : }
826 :
827 : rtError_t ApiErrorDecorator::FunctionGetMetaInfoSize(
828 : const Kernel* const funcHandle, const rtFunctionMetaType type, size_t* size)
829 : {
830 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
831 : funcHandle, RT_ERROR_INVALID_VALUE,
832 : "Querying the size of the metadata of a specific type in a kernel function");
833 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
834 : size, RT_ERROR_INVALID_VALUE, "Querying the size of the metadata of a specific type in a kernel function");
835 : return impl_->FunctionGetMetaInfoSize(funcHandle, type, size);
836 : }
837 : rtError_t ApiErrorDecorator::RegisterCpuFunc(
838 : rtBinHandle binHandle, const char_t* const funcName, const char_t* const kernelName, rtFuncHandle* funcHandle)
839 : {
840 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
841 : binHandle, RT_ERROR_INVALID_VALUE, "Registering AI CPU operator information");
842 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
843 : funcName, RT_ERROR_INVALID_VALUE, "Registering AI CPU operator information");
844 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
845 : kernelName, RT_ERROR_INVALID_VALUE, "Registering AI CPU operator information");
846 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
847 : funcHandle, RT_ERROR_INVALID_VALUE, "Registering AI CPU operator information");
848 :
849 : return impl_->RegisterCpuFunc(binHandle, funcName, kernelName, funcHandle);
850 : }
851 :
852 : rtError_t ApiErrorDecorator::BinaryUnLoad(Program* const binHandle)
853 : {
854 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
855 : binHandle, RT_ERROR_INVALID_VALUE, "Deleting the operator binary data pointed to by binHandle");
856 :
857 : const rtError_t error = impl_->BinaryUnLoad(binHandle);
858 : ERROR_RETURN(error, "BinaryUnLoad failed.");
859 : return error;
860 : }
861 :
862 : rtError_t ApiErrorDecorator::BinaryLoadFromFile(
863 : const char_t* const binPath, const rtLoadBinaryConfig_t* const optionalCfg, Program** handle)
864 : {
865 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
866 : binPath, RT_ERROR_INVALID_VALUE, "Loading and parsing the operator binary data from the file");
867 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
868 : handle, RT_ERROR_INVALID_VALUE, "Loading and parsing the operator binary data from the file");
869 :
870 : const rtError_t error = impl_->BinaryLoadFromFile(binPath, optionalCfg, handle);
871 : ERROR_RETURN(error, "Binary load from file failed.");
872 : return error;
873 : }
874 :
875 : rtError_t ApiErrorDecorator::BinaryLoadFromData(
876 : const void* const data, const uint64_t length, const rtLoadBinaryConfig_t* const optionalCfg, Program** handle)
877 : {
878 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
879 : data, RT_ERROR_INVALID_VALUE, "Loading and parsing the operator binary data from the memory");
880 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
881 : handle, RT_ERROR_INVALID_VALUE, "Loading and parsing the operator binary data from the memory");
882 : ZERO_RETURN_AND_MSG_OUTER(length);
883 :
884 : const rtError_t error = impl_->BinaryLoadFromData(data, length, optionalCfg, handle);
885 : ERROR_RETURN(error, "Binary load from data failed.");
886 : return error;
887 : }
888 :
889 : rtError_t ApiErrorDecorator::FuncGetAddr(const Kernel* const funcHandle, void** const aicAddr, void** const aivAddr)
890 : {
891 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
892 : funcHandle, RT_ERROR_INVALID_VALUE, "Obtaining the execution address of a specified kernel on the device");
893 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
894 : aicAddr, RT_ERROR_INVALID_VALUE, "Obtaining the execution address of a specified kernel on the device");
895 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
896 : aivAddr, RT_ERROR_INVALID_VALUE, "Obtaining the execution address of a specified kernel on the device");
897 : const KernelRegisterType kernelRegType = funcHandle->GetKernelRegisterType();
898 : COND_RETURN_AND_MSG_OUTER(
899 : kernelRegType != RT_KERNEL_REG_TYPE_NON_CPU, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
900 : "Obtaining the execution address of a specified kernel on the device", "funcHandle",
901 : "The funcHandle obtained after registering the AI CPU operator is not supported");
902 : const rtError_t error = impl_->FuncGetAddr(funcHandle, aicAddr, aivAddr);
903 : ERROR_RETURN(error, "Get func addr by function handle failed.");
904 : return error;
905 : }
906 :
907 : rtError_t ApiErrorDecorator::FuncGetSize(const Kernel* const funcHandle, size_t* const aicSize, size_t* const aivSize)
908 : {
909 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
910 : funcHandle, RT_ERROR_INVALID_VALUE, "Obtaining the size of the kernel function code segment");
911 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
912 : aicSize, RT_ERROR_INVALID_VALUE, "Obtaining the size of the kernel function code segment");
913 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
914 : aivSize, RT_ERROR_INVALID_VALUE, "Obtaining the size of the kernel function code segment");
915 : const KernelRegisterType kernelRegType = funcHandle->GetKernelRegisterType();
916 : COND_RETURN_AND_MSG_OUTER(
917 : kernelRegType != RT_KERNEL_REG_TYPE_NON_CPU, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
918 : "Obtaining the size of the kernel function code segment", "funcHandle",
919 : "The funcHandle obtained after registering the AI CPU operator is not supported");
920 : const rtError_t error = impl_->FuncGetSize(funcHandle, aicSize, aivSize);
921 : ERROR_RETURN(error, "Get func size by function handle failed.");
922 : return error;
923 : }
924 :
925 : rtError_t ApiErrorDecorator::LaunchKernel(
926 : Kernel* const kernel, uint32_t blockDim, const rtArgsEx_t* const argsInfo, Stream* const stm,
927 : const rtTaskCfgInfo_t* const cfgInfo)
928 : {
929 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
930 : kernel, RT_ERROR_INVALID_VALUE, "Starting the compute task of the corresponding operator");
931 : ZERO_RETURN_AND_MSG_OUTER(blockDim);
932 : rtError_t error = CheckArgs(argsInfo);
933 : ERROR_RETURN(error, "check argsInfo failed, retCode=%#x.", error);
934 : error = CheckCfg(cfgInfo);
935 : ERROR_RETURN(error, "check cfgInfo failed, retCode=%#x.", error);
936 : error = impl_->LaunchKernel(kernel, blockDim, argsInfo, stm, cfgInfo);
937 : ERROR_RETURN(error, "LaunchKernel failed.");
938 : return error;
939 : }
940 :
941 : static rtError_t CheckKernelLaunchCfg(const rtKernelLaunchCfg_t* const cfg, const Kernel* const kernel)
942 : {
943 : const rtChipType_t chipType = Runtime::Instance()->GetChipType();
944 : const uint8_t mixType = kernel->GetMixType();
945 : const KernelRegisterType kernelRegType = kernel->GetKernelRegisterType();
946 : static const bool isVectorCoreEnable =
947 : IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_DEVICE_EXTRA_VECTOR_CORE);
948 : // CHIP_DC的MIX算子只用于Vector core使能,按照最新约束必须得有engineType和blockDimOffset,否则校验失败
949 : if (isVectorCoreEnable && (kernelRegType != RT_KERNEL_REG_TYPE_CPU) && (mixType != NO_MIX)) {
950 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
951 : cfg, RT_ERROR_INVALID_VALUE, "Checking the parameter configuration before kernel delivery");
952 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
953 : cfg->attrs, RT_ERROR_INVALID_VALUE, "Checking the parameter configuration before kernel delivery");
954 : ZERO_RETURN_AND_MSG_OUTER(cfg->numAttrs); // numAttrs=0表示没有TV参数
955 : } else {
956 : // cfg support nullptr, no need process
957 : NULL_PTR_RETURN_NOLOG(cfg, RT_ERROR_NONE);
958 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
959 : cfg->attrs, RT_ERROR_INVALID_VALUE, "Checking the parameter configuration before kernel delivery");
960 : }
961 :
962 : uint8_t schedMode = static_cast<uint8_t>(RT_SCHEM_MODE_NORMAL);
963 : uint8_t isDataDump = DATA_DUMP_DISABLE;
964 : uint8_t isBlockPrefetch = BLOCK_PREFETCH_DISABLE;
965 : bool blockDimOffsetExist = false;
966 : bool engineTypeExist = false;
967 : bool timeoutFlag = false;
968 : bool timeoutUsFlag = false;
969 : for (size_t idx = 0U; idx < cfg->numAttrs; idx++) {
970 : switch (cfg->attrs[idx].id) {
971 : case RT_LAUNCH_KERNEL_ATTR_SCHEM_MODE:
972 : schedMode = cfg->attrs[idx].value.schemMode;
973 : break;
974 : case RT_LAUNCH_KERNEL_ATTR_ENGINE_TYPE:
975 : engineTypeExist = true;
976 : break;
977 : case RT_LAUNCH_KERNEL_ATTR_BLOCKDIM_OFFSET:
978 : blockDimOffsetExist = true;
979 : break;
980 : case RT_LAUNCH_KERNEL_ATTR_BLOCK_TASK_PREFETCH:
981 : isBlockPrefetch = cfg->attrs[idx].value.isBlockTaskPrefetch; // 0: disable, 1: enable
982 : break;
983 : case RT_LAUNCH_KERNEL_ATTR_DATA_DUMP:
984 : isDataDump = cfg->attrs[idx].value.isDataDump; // 0: disable, 1: enable
985 : break;
986 : case RT_LAUNCH_KERNEL_ATTR_TIMEOUT:
987 : timeoutFlag = true;
988 : break;
989 : case RT_LAUNCH_KERNEL_ATTR_TIMEOUT_US:
990 : timeoutUsFlag = true;
991 : break;
992 : default:
993 : break;
994 : }
995 : }
996 :
997 : COND_RETURN_AND_MSG_OUTER(
998 : (timeoutFlag && timeoutUsFlag), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
999 : "Checking the parameter configuration before kernel delivery", "cfg->attrs",
1000 : "The RT_LAUNCH_KERNEL_ATTR_TIMEOUT(7) and RT_LAUNCH_KERNEL_ATTR_TIMEOUT_US(8) attributes cannot be carried at "
1001 : "the same time");
1002 :
1003 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1004 : schedMode >= static_cast<uint8_t>(RT_SCHEM_MODE_END), RT_ERROR_INVALID_VALUE,
1005 : "Checking the parameter configuration before kernel delivery", schedMode,
1006 : "[0, " + std::to_string(RT_SCHEM_MODE_END) + ")");
1007 :
1008 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1009 : (isBlockPrefetch != BLOCK_PREFETCH_DISABLE) && (isBlockPrefetch != BLOCK_PREFETCH_ENABLE),
1010 : RT_ERROR_INVALID_VALUE, "Checking the parameter configuration before kernel delivery", isBlockPrefetch,
1011 : "[0, 1]");
1012 :
1013 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1014 : (isDataDump != DATA_DUMP_ENABLE) && (isDataDump != DATA_DUMP_DISABLE), RT_ERROR_INVALID_VALUE,
1015 : "Checking the parameter configuration before kernel delivery", isDataDump, "[0, 1]");
1016 :
1017 : // 如果是CHIP_DC vector使能场景,需要校验如果有相应TV参数, 非CHIP_DC、CPU算子、非MIX场景不做校验
1018 : COND_RETURN_WITH_NOLOG(
1019 : !isVectorCoreEnable || (kernelRegType == RT_KERNEL_REG_TYPE_CPU) || (mixType == NO_MIX), RT_ERROR_NONE);
1020 :
1021 : COND_RETURN_AND_MSG_OUTER(
1022 : (!blockDimOffsetExist || !engineTypeExist), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
1023 : "Checking the parameter configuration before kernel delivery", "cfg->attrs",
1024 : "Insufficient parameters in the vector core enabled scenario");
1025 :
1026 : return RT_ERROR_NONE;
1027 : }
1028 :
1029 : rtError_t ApiErrorDecorator::LaunchKernelV2(
1030 : Kernel* const kernel, uint32_t blockDim, const RtArgsWithType* const argsWithType, Stream* const stm,
1031 : const rtKernelLaunchCfg_t* const cfg)
1032 : {
1033 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1034 : kernel, RT_ERROR_INVALID_VALUE, "Starting the compute task of the corresponding operator");
1035 : rtError_t error = CheckArgsWithType(kernel, argsWithType);
1036 : ERROR_RETURN(error, "check args with type failed, retCode=%#x.", error);
1037 : ZERO_RETURN_AND_MSG_OUTER(blockDim);
1038 : error = CheckKernelLaunchCfg(cfg, kernel);
1039 : ERROR_RETURN(error, "check cfgInfo failed, retCode=%#x.", error);
1040 : error = impl_->LaunchKernelV2(kernel, blockDim, argsWithType, stm, cfg);
1041 : COND_PROC((error == RT_ERROR_KERNEL_INVALID), return error;);
1042 : ERROR_RETURN(error, "LaunchKernel failed.");
1043 : return error;
1044 : }
1045 :
1046 : rtError_t ApiErrorDecorator::KernelLaunch(
1047 : const void* const stubFunc, const uint32_t coreDim, const rtArgsEx_t* const argsInfo, Stream* const stm,
1048 : const rtTaskCfgInfo_t* const cfgInfo, const bool isLaunchVec)
1049 : {
1050 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1051 : stubFunc, RT_ERROR_INVALID_VALUE, "Starting the compute task of the corresponding operator");
1052 : ZERO_RETURN_AND_MSG_OUTER(coreDim);
1053 : // coreDim is defined uint16_t by sqe
1054 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1055 : coreDim > static_cast<uint32_t>(UINT16_MAX), RT_ERROR_INVALID_VALUE,
1056 : "Starting the compute task of the corresponding operator", coreDim,
1057 : "less than or equal to " + std::to_string(UINT16_MAX));
1058 : rtError_t error = CheckArgs(argsInfo);
1059 : ERROR_RETURN(error, "check argsInfo failed, retCode=%#x.", error);
1060 : error = CheckCfg(cfgInfo);
1061 : ERROR_RETURN(error, "check cfgInfo failed, retCode=%#x.", error);
1062 : error = impl_->KernelLaunch(stubFunc, coreDim, argsInfo, stm, cfgInfo, isLaunchVec);
1063 : ERROR_RETURN(error, "Launch kernel failed, dim=%u.", coreDim);
1064 : return error;
1065 : }
1066 :
1067 : rtError_t ApiErrorDecorator::KernelLaunchWithHandle(
1068 : void* const hdl, const uint64_t tilingKey, const uint32_t coreDim, const rtArgsEx_t* const argsInfo,
1069 : Stream* const stm, const rtTaskCfgInfo_t* const cfgInfo, const bool isLaunchVec)
1070 : {
1071 : ZERO_RETURN_AND_MSG_OUTER(coreDim);
1072 : rtError_t error = CheckArgs(argsInfo);
1073 : ERROR_RETURN(error, "check argsInfo failed, retCode=%#x.", error);
1074 : error = CheckCfg(cfgInfo);
1075 : ERROR_RETURN(error, "check cfgInfo failed, retCode=%#x.", error);
1076 : error = impl_->KernelLaunchWithHandle(hdl, tilingKey, coreDim, argsInfo, stm, cfgInfo, isLaunchVec);
1077 : ERROR_RETURN(error, "Launch kernel with hdl failed, dim=%u.", coreDim);
1078 : return error;
1079 : }
1080 :
1081 : rtError_t ApiErrorDecorator::KernelLaunchEx(
1082 : const char_t* const opName, const void* const args, const uint32_t argsSize, const uint32_t flags,
1083 : Stream* const stm)
1084 : {
1085 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1086 : opName, RT_ERROR_INVALID_VALUE, "Starting the compute task of the corresponding operator");
1087 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1088 : args, RT_ERROR_INVALID_VALUE, "Starting the compute task of the corresponding operator");
1089 : ZERO_RETURN_AND_MSG_OUTER(argsSize);
1090 :
1091 : const rtError_t error = impl_->KernelLaunchEx(opName, args, argsSize, flags, stm);
1092 : ERROR_RETURN(
1093 : error, "Launch kernel[extend] failed, opName=%s, argsSize=%u(bytes), flags=%u.", opName, argsSize, flags);
1094 : return error;
1095 : }
1096 :
1097 : rtError_t ApiErrorDecorator::CpuKernelLaunch(
1098 : const rtKernelLaunchNames_t* const launchNames, const uint32_t coreDim, const rtArgsEx_t* const argsInfo,
1099 : Stream* const stm, const uint32_t flag)
1100 : {
1101 : // So name of control task is null. No need to check.
1102 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1103 : launchNames, RT_ERROR_INVALID_VALUE, "Starting the compute task of an AI CPU operator");
1104 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1105 : launchNames->opName, RT_ERROR_INVALID_VALUE, "Starting the compute task of an AI CPU operator");
1106 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1107 : launchNames->kernelName, RT_ERROR_INVALID_VALUE, "Starting the compute task of an AI CPU operator");
1108 : ZERO_RETURN_AND_MSG_OUTER(coreDim);
1109 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1110 : coreDim >= 0x10000U, RT_ERROR_INVALID_VALUE, "Starting the compute task of an AI CPU operator", coreDim,
1111 : "less than or equal to 0xffff");
1112 : rtError_t error = CheckArgs(argsInfo);
1113 : ERROR_RETURN_MSG_CALL(ERR_MODULE_GE, error, "check argsInfo failed, retCode=%#x.", static_cast<uint32_t>(error));
1114 :
1115 : error = impl_->CpuKernelLaunch(launchNames, coreDim, argsInfo, stm, flag);
1116 : const char_t* soName = (launchNames->soName == nullptr) ? "" : launchNames->soName;
1117 : ERROR_RETURN(
1118 : error,
1119 : "Launch cpu kernel failed, soName=%s, kernel_name=%s, opName=%s, coreDim=%u,"
1120 : " argsSize=%u(bytes), hostInputLen=%hu, flag=%u.",
1121 : soName, launchNames->kernelName, launchNames->opName, coreDim, argsInfo->argsSize, argsInfo->hostInputInfoNum,
1122 : flag);
1123 : return error;
1124 : }
1125 :
1126 : rtError_t ApiErrorDecorator::MultipleTaskInfoLaunch(
1127 : const rtMultipleTaskInfo_t* const taskInfo, Stream* const stm, const uint32_t flag)
1128 : {
1129 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(taskInfo, RT_ERROR_INVALID_VALUE, "Delivering a DVPP Multiple task");
1130 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1131 : taskInfo->taskDesc, RT_ERROR_INVALID_VALUE, "Delivering a DVPP Multiple task");
1132 : ZERO_RETURN_AND_MSG_OUTER(taskInfo->taskNum);
1133 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1134 : (taskInfo->taskNum > MULTIPLE_TASK_MAX_NUM), RT_ERROR_INVALID_VALUE, "Delivering a DVPP Multiple task",
1135 : taskInfo->taskNum, "less than or equal to " + std::to_string(MULTIPLE_TASK_MAX_NUM));
1136 : // MultipleTaskInfoLaunch only support RT_KERNEL_DEFAULT and RT_KERNEL_CMDLIST_NOT_FREE
1137 : constexpr uint32_t permitFlag = (RT_KERNEL_DEFAULT | RT_KERNEL_CMDLIST_NOT_FREE);
1138 : if ((flag & (~permitFlag)) != 0U) {
1139 : RT_LOG(RT_LOG_ERROR, "unsupported flag : %u", flag);
1140 : return RT_ERROR_FEATURE_NOT_SUPPORT;
1141 : }
1142 : for (size_t idx = 0U; idx < taskInfo->taskNum; idx++) {
1143 : if (taskInfo->taskDesc[idx].type == RT_MULTIPLE_TASK_TYPE_DVPP) {
1144 : const uint16_t type = taskInfo->taskDesc[idx].u.dvppTaskDesc.sqe.sqeHeader.type;
1145 : COND_RETURN_AND_MSG_OUTER(
1146 : !IsDvppTask(type), RT_ERROR_INVALID_VALUE, ErrorCode::EE1003, "Delivering a DVPP Multiple task", type,
1147 : "SQE type", "RT_STARS_SQE_TYPE_VPC(12), RT_STARS_SQE_TYPE_JPEGE(13), RT_STARS_SQE_TYPE_JPEGD(14)");
1148 : const uint32_t pos = taskInfo->taskDesc[idx].u.dvppTaskDesc.aicpuTaskPos;
1149 : COND_RETURN_AND_MSG_OUTER(
1150 : pos >= stm->GetSqDepth(), RT_ERROR_INVALID_VALUE, ErrorCode::EE1003, "Delivering a DVPP Multiple task",
1151 : pos, RtFmtMsg("taskInfo->taskDesc[%u].u.dvppTaskDesc.aicpuTaskPos", idx),
1152 : RtFmtMsg("must be less than %u", stm->GetSqDepth()));
1153 : } else if (taskInfo->taskDesc[idx].type == RT_MULTIPLE_TASK_TYPE_AICPU) {
1154 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1155 : taskInfo->taskDesc[idx].u.aicpuTaskDesc.kernelLaunchNames.soName, RT_ERROR_INVALID_VALUE,
1156 : "Delivering a DVPP Multiple task");
1157 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1158 : taskInfo->taskDesc[idx].u.aicpuTaskDesc.kernelLaunchNames.opName, RT_ERROR_INVALID_VALUE,
1159 : "Delivering a DVPP Multiple task");
1160 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1161 : taskInfo->taskDesc[idx].u.aicpuTaskDesc.kernelLaunchNames.kernelName, RT_ERROR_INVALID_VALUE,
1162 : "Delivering a DVPP Multiple task");
1163 : const uint32_t coreDim = taskInfo->taskDesc[idx].u.aicpuTaskDesc.blockDim;
1164 : ZERO_RETURN_AND_MSG_OUTER(coreDim);
1165 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1166 : coreDim > static_cast<uint32_t>(UINT16_MAX), RT_ERROR_INVALID_VALUE, "Delivering a DVPP Multiple task",
1167 : coreDim, "less than or equal to " + std::to_string(UINT16_MAX));
1168 : const rtError_t error = CheckArgs(&(taskInfo->taskDesc[idx].u.aicpuTaskDesc.argsInfo));
1169 : ERROR_RETURN_MSG_CALL(
1170 : ERR_MODULE_GE, error, "check argsInfo failed, retCode=%#x.", static_cast<uint32_t>(error));
1171 : } else if (taskInfo->taskDesc[idx].type == RT_MULTIPLE_TASK_TYPE_AICPU_BY_HANDLE) {
1172 : Kernel* realKernel = nullptr;
1173 : const rtError_t handleRet =
1174 : GetValidatedObject<Kernel>(taskInfo->taskDesc[idx].u.aicpuTaskDescByHandle.funcHdl, realKernel);
1175 : ERROR_RETURN_MSG_CALL(
1176 : ERR_MODULE_GE, handleRet, "check funcHdl failed, retCode=%#x.", static_cast<uint32_t>(handleRet));
1177 : taskInfo->taskDesc[idx].u.aicpuTaskDescByHandle.funcHdl = realKernel;
1178 : Kernel* hdl = RtPtrToPtr<Kernel*>(taskInfo->taskDesc[idx].u.aicpuTaskDescByHandle.funcHdl);
1179 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(hdl, RT_ERROR_INVALID_VALUE, "Delivering a DVPP Multiple task");
1180 : const uint32_t coreDim = taskInfo->taskDesc[idx].u.aicpuTaskDescByHandle.blockDim;
1181 : ZERO_RETURN_AND_MSG_OUTER(coreDim);
1182 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1183 : coreDim > static_cast<uint32_t>(UINT16_MAX), RT_ERROR_INVALID_VALUE, "Delivering a DVPP Multiple task",
1184 : coreDim, "less than or equal to " + std::to_string(UINT16_MAX));
1185 : const rtError_t error = CheckArgs(&(taskInfo->taskDesc[idx].u.aicpuTaskDescByHandle.argsInfo));
1186 : ERROR_RETURN_MSG_CALL(
1187 : ERR_MODULE_GE, error, "check argsInfo failed, retCode=%#x.", static_cast<uint32_t>(error));
1188 : } else {
1189 : RT_LOG_OUTER_MSG_WITH_FUNC_DESC(
1190 : ErrorCode::EE1003, "Delivering a DVPP Multiple task", taskInfo->taskDesc[idx].type,
1191 : "taskInfo->taskDesc[" + std::to_string(idx) + "].type",
1192 : "[0, " + std::to_string(RT_MULTIPLE_TASK_TYPE_MAX) + ")");
1193 : return RT_ERROR_INVALID_VALUE;
1194 : }
1195 : }
1196 : const rtError_t error = impl_->MultipleTaskInfoLaunch(taskInfo, stm, flag);
1197 : return error;
1198 : }
1199 :
1200 : rtError_t ApiErrorDecorator::CpuKernelLaunchExWithArgs(
1201 : const char_t* const opName, const uint32_t coreDim, const rtAicpuArgsEx_t* const argsInfo, Stream* const stm,
1202 : const uint32_t flag, const uint32_t kernelType)
1203 : {
1204 : // So name of control task is null. No need to check.
1205 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1206 : opName, RT_ERROR_INVALID_VALUE, "Starting the compute task of an AI CPU operator");
1207 : ZERO_RETURN_AND_MSG_OUTER(coreDim);
1208 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1209 : coreDim >= 0x10000U, RT_ERROR_INVALID_VALUE, "Starting the compute task of an AI CPU operator", coreDim,
1210 : "less than or equal to 0xffff");
1211 : COND_RETURN_AND_MSG_OUTER(
1212 : (stm != nullptr) && ((stm->Flags() & RT_STREAM_CP_PROCESS_USE) != 0U), RT_ERROR_STREAM_INVALID,
1213 : ErrorCode::EE1006, "Starting the compute task of an AI CPU operator",
1214 : "Stream flags value " + std::to_string(stm->Flags()),
1215 : RtFmtMsg(
1216 : "Stream (stream_id=%d) with the flag RT_STREAM_CP_PROCESS_USE(0x800U) cannot be used for kernel launch",
1217 : stm->Id_()));
1218 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1219 : argsInfo, RT_ERROR_INVALID_VALUE, "Starting the compute task of an AI CPU operator");
1220 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1221 : argsInfo->args, RT_ERROR_INVALID_VALUE, "Starting the compute task of an AI CPU operator");
1222 : ZERO_RETURN_AND_MSG_OUTER(argsInfo->argsSize);
1223 :
1224 : const rtError_t error = impl_->CpuKernelLaunchExWithArgs(opName, coreDim, argsInfo, stm, flag, kernelType);
1225 : ERROR_RETURN(
1226 : error,
1227 : "Launch cpu kernel ex failed, coreDim=%u,"
1228 : " argsSize=%u(bytes), hostInputLen=%hu, flag=%u, kernelType=%u.",
1229 : coreDim, argsInfo->argsSize, argsInfo->hostInputInfoNum, flag, kernelType);
1230 : return error;
1231 : }
1232 :
1233 : rtError_t ApiErrorDecorator::DatadumpInfoLoad(const void* const dumpInfo, const uint32_t length, const uint32_t flag)
1234 : {
1235 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(dumpInfo, RT_ERROR_INVALID_VALUE, "Dump information loading");
1236 : ZERO_RETURN_AND_MSG_OUTER(length);
1237 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME(
1238 : ((flag != RT_KERNEL_DEFAULT) && (flag != RT_KERNEL_CUSTOM_AICPU)), RT_ERROR_INVALID_VALUE,
1239 : KernelFlagToString(flag), "flag", "RT_KERNEL_DEFAULT(0) or RT_KERNEL_CUSTOM_AICPU(8)");
1240 :
1241 : const rtError_t error = impl_->DatadumpInfoLoad(dumpInfo, length, flag);
1242 : ERROR_RETURN(error, "Load data dump info failed, length=%u, flag=%u.", length, flag);
1243 : return error;
1244 : }
1245 :
1246 : rtError_t ApiErrorDecorator::AicpuInfoLoad(const void* const aicpuInfo, const uint32_t length)
1247 : {
1248 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1249 : aicpuInfo, RT_ERROR_INVALID_VALUE, "Delivering load information required by the AI CPU operator to the device");
1250 : ZERO_RETURN_AND_MSG_OUTER(length);
1251 :
1252 : const rtChipType_t chipType = Runtime::Instance()->GetChipType();
1253 : if (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_KERNEL_TILING_KEY_SINK)) {
1254 : RT_LOG(RT_LOG_WARNING, "unsupported chip type (%d)", chipType);
1255 : return RT_ERROR_FEATURE_NOT_SUPPORT;
1256 : }
1257 :
1258 : Context* curCtx = Runtime::Instance()->CurrentContext();
1259 : CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL);
1260 :
1261 : const uint32_t tschVersion = curCtx->Device_()->GetTschVersion();
1262 : const bool isSupport = curCtx->Device_()->CheckFeatureSupport(TS_FEATURE_TILING_KEY_SINK);
1263 : if (!isSupport) {
1264 : RT_LOG(
1265 : RT_LOG_WARNING, "unsupported task type (AicpuInfoLoad) in current ts version, tschVersion=%u", tschVersion);
1266 : return RT_ERROR_FEATURE_NOT_SUPPORT;
1267 : }
1268 :
1269 : const rtError_t error = impl_->AicpuInfoLoad(aicpuInfo, length);
1270 : ERROR_RETURN(error, "Load aicpu info failed, length=%u.", length);
1271 : return error;
1272 : }
1273 :
1274 : rtError_t ApiErrorDecorator::SetupArgument(const void* const setupArg, const uint32_t size, const uint32_t offset)
1275 : {
1276 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(setupArg, RT_ERROR_INVALID_VALUE, "Setting kernel launch parameters");
1277 : ZERO_RETURN_AND_MSG_OUTER(size);
1278 :
1279 : const rtError_t error = impl_->SetupArgument(setupArg, size, offset);
1280 : ERROR_RETURN(error, "Setup argument failed, size=%u(bytes), offset=%u.", size, offset);
1281 : return error;
1282 : }
1283 :
1284 : rtError_t ApiErrorDecorator::KernelTransArgSet(
1285 : const void* const ptr, const uint64_t size, const uint32_t flag, void** const setupArg)
1286 : {
1287 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1288 : ptr, RT_ERROR_INVALID_VALUE,
1289 : "Setting the parameter pointer delivered by the kernel and refreshing the device cache");
1290 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1291 : setupArg, RT_ERROR_INVALID_VALUE,
1292 : "Setting the parameter pointer delivered by the kernel and refreshing the device cache");
1293 : ZERO_RETURN_AND_MSG_OUTER(size);
1294 :
1295 : return impl_->KernelTransArgSet(ptr, size, flag, setupArg);
1296 : }
1297 :
1298 : rtError_t ApiErrorDecorator::KernelFusionStart(Stream* const stm)
1299 : {
1300 : const rtError_t error = impl_->KernelFusionStart(stm);
1301 : ERROR_RETURN(error, "Start kernel fusion failed.");
1302 : return error;
1303 : }
1304 :
1305 : rtError_t ApiErrorDecorator::KernelFusionEnd(Stream* const stm)
1306 : {
1307 : const rtError_t error = impl_->KernelFusionEnd(stm);
1308 : ERROR_RETURN(error, "End kernel fusion failed.");
1309 : return error;
1310 : }
1311 :
1312 : rtError_t ApiErrorDecorator::StreamCreate(
1313 : Stream** const stm, const int32_t priority, const uint32_t flags, DvppGrp* grp)
1314 : {
1315 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(stm, RT_ERROR_INVALID_VALUE, "Stream creation");
1316 :
1317 : const rtError_t ret = CheckStreamFlags(flags);
1318 : if (ret != RT_ERROR_NONE) {
1319 : return ret;
1320 : }
1321 :
1322 : int32_t validPriority = priority;
1323 :
1324 : if (priority < RT_STREAM_GREATEST_PRIORITY) {
1325 : validPriority = RT_STREAM_GREATEST_PRIORITY;
1326 : } else if (priority > RT_STREAM_LEAST_PRIORITY) {
1327 : validPriority = RT_STREAM_LEAST_PRIORITY;
1328 : } else {
1329 : // no operation
1330 : }
1331 :
1332 : if (priority != validPriority) {
1333 : RT_LOG(
1334 : RT_LOG_INFO, "Input priority=%d is out of range [%d, %d], adjusted to %d", priority,
1335 : RT_STREAM_GREATEST_PRIORITY, RT_STREAM_LEAST_PRIORITY, validPriority);
1336 : }
1337 :
1338 : return impl_->StreamCreate(stm, validPriority, flags, grp);
1339 : }
1340 :
1341 : rtError_t ApiErrorDecorator::CheckStreamFlags(const uint32_t flags) const
1342 : {
1343 : const Runtime* const rtInstance = Runtime::Instance();
1344 : const rtChipType_t chipType = rtInstance->GetChipType();
1345 : if (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_STREAM_HUGE_DEPTH)) {
1346 : COND_RETURN_AND_MSG_OUTER(
1347 : (flags & RT_STREAM_HUGE) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT, ErrorCode::EE1006, "Checking stream flags",
1348 : "Parameter flags value " + std::to_string(flags),
1349 : "The current SoC supports only streams with a normal number of tasks and does not support huge streams");
1350 : }
1351 :
1352 : constexpr uint32_t maxFlags =
1353 : (RT_STREAM_DEFAULT | RT_STREAM_PERSISTENT | RT_STREAM_FORCE_COPY | RT_STREAM_HUGE | RT_STREAM_AICPU |
1354 : RT_STREAM_FORBIDDEN_DEFAULT | RT_STREAM_HEAD | RT_STREAM_OVERFLOW | RT_STREAM_FAST_LAUNCH |
1355 : RT_STREAM_FAST_SYNC | RT_STREAM_CP_PROCESS_USE | RT_STREAM_VECTOR_CORE_USE | RT_STREAM_ACSQ_LOCK |
1356 : RT_STREAM_DQS_CTRL | RT_STREAM_DQS_INTER_CHIP);
1357 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1358 : flags > maxFlags, RT_ERROR_INVALID_VALUE, "Checking stream flags", flags,
1359 : "[0, " + std::to_string(maxFlags) + "]");
1360 :
1361 : COND_RETURN_AND_MSG_OUTER(
1362 : ((flags & static_cast<uint32_t>(RT_STREAM_CP_PROCESS_USE)) != 0U) &&
1363 : (((flags | static_cast<uint32_t>(RT_STREAM_ACSQ_LOCK)) !=
1364 : (RT_STREAM_ACSQ_LOCK | RT_STREAM_CP_PROCESS_USE))),
1365 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1006, "Checking stream flags",
1366 : "Parameter flags value " + std::to_string(flags),
1367 : "The flag RT_STREAM_CP_PROCESS_USE(0x800U) must be used together with RT_STREAM_ACSQ_LOCK(0x2000U)");
1368 :
1369 : return RT_ERROR_NONE;
1370 : }
1371 :
1372 : rtError_t ApiErrorDecorator::StreamDestroy(Stream* const stm, bool flag)
1373 : {
1374 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(stm, RT_ERROR_INVALID_VALUE, "Stream destruction");
1375 :
1376 : COND_RETURN_AND_MSG_OUTER(
1377 : stm->IsCapturing(), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016, "Stream destruction",
1378 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stm->Id_()));
1379 :
1380 : return impl_->StreamDestroy(stm, flag);
1381 : }
1382 :
1383 : rtError_t ApiErrorDecorator::StreamWaitEvent(
1384 : Stream* const stm, Event* const evt, const uint32_t timeout, const uint32_t flag)
1385 : {
1386 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Triggering event waiting");
1387 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1388 : ((flag != RT_EVENT_WAIT_DEFAULT) && (flag != RT_EVENT_WAIT_EXTERNAL)), RT_ERROR_INVALID_VALUE,
1389 : "Triggering event waiting", flag, "RT_EVENT_WAIT_DEFAULT(0) or RT_EVENT_WAIT_EXTERNAL(1)");
1390 : COND_RETURN_AND_MSG_OUTER(
1391 : ((evt->GetEventFlag() == static_cast<uint32_t>(RT_EVENT_MC2)) ||
1392 : (((evt->GetEventFlag() & static_cast<uint32_t>(RT_EVENT_MC2)) != 0U) &&
1393 : ((evt->GetEventFlag() & (~static_cast<uint32_t>(RT_EVENT_MC2))) != 0U))),
1394 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1006, "Triggering event waiting",
1395 : "Parameter evt.eventFlag_ value " + std::to_string(evt->GetEventFlag()),
1396 : "Device-only events can be called only on the device");
1397 : COND_RETURN_WARN(
1398 : ((evt->GetEventFlag() == static_cast<uint32_t>(RT_EVENT_IPC)) && (stm != nullptr) && (stm->IsCapturing())),
1399 : RT_ERROR_FEATURE_NOT_SUPPORT, "IPC event is not supported when the capture stream flag is set.");
1400 : COND_RETURN_WARN(
1401 : evt->IsEventWithoutWaitTask(), RT_ERROR_FEATURE_NOT_SUPPORT,
1402 : "flag=%" PRIu64 " is not supported, and there is no need to wait for the event.", evt->GetEventFlag());
1403 : if (flag == RT_EVENT_WAIT_EXTERNAL) {
1404 : COND_RETURN_AND_MSG_OUTER(
1405 : (!evt->IsNewMode()) || (evt->GetEventFlag() != RT_EVENT_DDSYNC_NS), RT_ERROR_FEATURE_NOT_SUPPORT,
1406 : ErrorCode::EE1016, "Triggering external event waiting",
1407 : "Only events created by rtEventCreateExWithFlag with RT_EVENT_DDSYNC_NS are supported when flag is "
1408 : "RT_EVENT_WAIT_EXTERNAL");
1409 : }
1410 : // Wait flag一致性仅由ApiError层检查,其他位置不读写该状态。
1411 : const uint32_t currentFlag = evt->GetWaitFlag();
1412 : COND_RETURN_AND_MSG_OUTER(
1413 : ((currentFlag != UINT32_MAX) && (currentFlag != flag)), RT_ERROR_INVALID_VALUE, ErrorCode::EE1018,
1414 : "Triggering event waiting",
1415 : RtFmtMsg(
1416 : "The wait flag must remain consistent for the same event, current flag is %s, input flag is %s",
1417 : EventOperationFlagToString(currentFlag, false).c_str(), EventOperationFlagToString(flag, false).c_str()));
1418 : evt->SetWaitFlag(flag);
1419 : return impl_->StreamWaitEvent(stm, evt, timeout, flag);
1420 : }
1421 :
1422 : rtError_t ApiErrorDecorator::StreamSynchronize(Stream* const stm, const int32_t timeout)
1423 : {
1424 : // timeout >=-1, -1:no limited
1425 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1426 : (timeout < -1) || (timeout == 0), RT_ERROR_INVALID_VALUE, "Synchronizing a stream", timeout,
1427 : "greater than or equal to -1 and not equal to 0");
1428 :
1429 : COND_RETURN_AND_MSG_OUTER(
1430 : ((stm != nullptr) && (stm->IsCapturing())), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016,
1431 : "Synchronizing a stream",
1432 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stm->Id_()));
1433 :
1434 : if ((stm != nullptr) &&
1435 : ((stm->Flags() & (RT_STREAM_AICPU | RT_STREAM_CP_PROCESS_USE | RT_STREAM_PERSISTENT)) != 0U)) {
1436 : const uint32_t deviceId = (stm->Device_() != nullptr) ? stm->Device_()->Id_() : UINT32_MAX;
1437 : RT_LOG(
1438 : RT_LOG_EVENT, "stream synchronize return, device_id=%u, stream_id=%d, stream_flag=%d.", deviceId,
1439 : stm->Id_(), stm->Flags());
1440 : return RT_ERROR_NONE;
1441 : }
1442 :
1443 : int32_t streamId = 0;
1444 : if (stm != nullptr) {
1445 : streamId = stm->Id_();
1446 : }
1447 : RT_LOG(RT_LOG_DEBUG, "stream synchronize entry, stream_id=%d, timeout=%dms.", streamId, timeout);
1448 :
1449 : const rtError_t error = impl_->StreamSynchronize(stm, timeout);
1450 : if ((error != RT_ERROR_END_OF_SEQUENCE) && (error != RT_ERROR_MODEL_ABORT_NORMAL) &&
1451 : (error != RT_ERROR_TSFW_AICORE_OVER_FLOW_FAIL) && (error != RT_ERROR_TSFW_AIVEC_OVER_FLOW_FAIL) &&
1452 : (error != RT_ERROR_TSFW_AICPU_OVER_FLOW_FAIL) && (error != RT_ERROR_TSFW_SDMA_OVER_FLOW_FAIL)) {
1453 : #ifndef CFG_DEV_PLATFORM_PC
1454 : ERROR_RETURN(error, "Stream synchronize failed, stream_id=%d, timeout=%dms.", streamId, timeout);
1455 : #else
1456 : return error;
1457 : #endif
1458 : }
1459 :
1460 : RT_LOG(RT_LOG_INFO, "stream synchronize exit, stream_id=%d, result=0x%x", streamId, error);
1461 : return error;
1462 : }
1463 :
1464 : rtError_t ApiErrorDecorator::StreamQuery(Stream* const stm)
1465 : {
1466 : COND_RETURN_AND_MSG_OUTER(
1467 : ((stm != nullptr) && (stm->IsCapturing())), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016, "Querying a stream",
1468 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stm->Id_()));
1469 :
1470 : if ((stm != nullptr) &&
1471 : ((stm->Flags() & (RT_STREAM_AICPU | RT_STREAM_CP_PROCESS_USE | RT_STREAM_PERSISTENT)) != 0U)) {
1472 : const uint32_t deviceId = (stm->Device_() != nullptr) ? stm->Device_()->Id_() : UINT32_MAX;
1473 : RT_LOG(
1474 : RT_LOG_EVENT, "stream query return, device_id=%u, stream_id=%d, stream_flag=%d.", deviceId, stm->Id_(),
1475 : stm->Flags());
1476 : return RT_ERROR_NONE;
1477 : }
1478 :
1479 : return impl_->StreamQuery(stm);
1480 : }
1481 :
1482 : rtError_t ApiErrorDecorator::GetStreamId(Stream* const stm, int32_t* const streamId)
1483 : {
1484 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1485 : streamId, RT_ERROR_INVALID_VALUE, "Obtaining the ID of a specified stream");
1486 : return impl_->GetStreamId(stm, streamId);
1487 : }
1488 :
1489 : rtError_t ApiErrorDecorator::GetSqId(Stream* const stm, uint32_t* const sqId)
1490 : {
1491 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
1492 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(sqId, RT_ERROR_INVALID_VALUE, "Obtaining the SQ ID");
1493 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(curStm, RT_ERROR_INVALID_VALUE, "Obtaining the SQ ID");
1494 : return impl_->GetSqId(curStm, sqId);
1495 : }
1496 :
1497 : rtError_t ApiErrorDecorator::GetCqId(Stream* const stm, uint32_t* const cqId, uint32_t* const logicCqId)
1498 : {
1499 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
1500 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(curStm, RT_ERROR_INVALID_VALUE, "Obtaining the completion queue (CQ) ID");
1501 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(cqId, RT_ERROR_INVALID_VALUE, "Obtaining the completion queue (CQ) ID");
1502 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1503 : logicCqId, RT_ERROR_INVALID_VALUE, "Obtaining the completion queue (CQ) ID");
1504 : return impl_->GetCqId(curStm, cqId, logicCqId);
1505 : }
1506 :
1507 : rtError_t ApiErrorDecorator::StreamGetPriority(Stream* const stm, uint32_t* const priority)
1508 : {
1509 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(priority, RT_ERROR_INVALID_VALUE, "Obtaining the stream priority");
1510 : return impl_->StreamGetPriority(stm, priority);
1511 : }
1512 :
1513 : rtError_t ApiErrorDecorator::StreamGetFlags(Stream* const stm, uint32_t* const flags)
1514 : {
1515 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(flags, RT_ERROR_INVALID_VALUE, "Querying the flag in a stream");
1516 : return impl_->StreamGetFlags(stm, flags);
1517 : }
1518 :
1519 : rtError_t ApiErrorDecorator::GetMaxStreamAndTask(
1520 : const uint32_t streamType, uint32_t* const maxStrCount, uint32_t* const maxTaskCount)
1521 : {
1522 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME(
1523 : (streamType != RT_NORMAL_STREAM) && (streamType != RT_HUGE_STREAM), RT_ERROR_INVALID_VALUE,
1524 : StreamTypeToString(streamType), "streamType",
1525 : "[" + std::to_string(RT_NORMAL_STREAM) + ", " + std::to_string(RT_HUGE_STREAM) + "]");
1526 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1527 : maxStrCount, RT_ERROR_INVALID_VALUE, "Querying the maximum numbers of streams and tasks supported by a stream");
1528 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1529 : maxTaskCount, RT_ERROR_INVALID_VALUE,
1530 : "Querying the maximum numbers of streams and tasks supported by a stream");
1531 :
1532 : RT_LOG(RT_LOG_DEBUG, "streamType=%u.", streamType);
1533 : const rtError_t error = impl_->GetMaxStreamAndTask(streamType, maxStrCount, maxTaskCount);
1534 : COND_RETURN_ERROR(
1535 : (error != RT_ERROR_NONE) && (error != RT_ERROR_FEATURE_NOT_SUPPORT), error,
1536 : "Get max stream and task failed, streamType=%u.", streamType);
1537 : return error;
1538 : }
1539 :
1540 : rtError_t ApiErrorDecorator::GetAvailStreamNum(const uint32_t streamType, uint32_t* const streamCount)
1541 : {
1542 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME(
1543 : (streamType != RT_NORMAL_STREAM) && (streamType != RT_HUGE_STREAM), RT_ERROR_INVALID_VALUE,
1544 : StreamTypeToString(streamType), "streamType",
1545 : "[" + std::to_string(RT_NORMAL_STREAM) + ", " + std::to_string(RT_HUGE_STREAM) + "]");
1546 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1547 : streamCount, RT_ERROR_INVALID_VALUE, "Obtaining the number of available streams on the current device");
1548 : const rtError_t error = impl_->GetAvailStreamNum(streamType, streamCount);
1549 : ERROR_RETURN(error, "Get available stream failed, streamType=%u.", streamType);
1550 : return error;
1551 : }
1552 :
1553 : rtError_t ApiErrorDecorator::GetFreeStreamNum(uint32_t* const streamCount)
1554 : {
1555 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1556 : streamCount, RT_ERROR_INVALID_VALUE, "Obtaining the number of idle streams on the current device");
1557 : const rtError_t error = impl_->GetFreeStreamNum(streamCount);
1558 : ERROR_RETURN(error, "Get free stream failed.");
1559 : return error;
1560 : }
1561 :
1562 : rtError_t ApiErrorDecorator::GetAvailEventNum(uint32_t* const eventCount)
1563 : {
1564 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1565 : eventCount, RT_ERROR_INVALID_VALUE, "Querying the number of available events on the current device");
1566 : const rtError_t error = impl_->GetAvailEventNum(eventCount);
1567 : ERROR_RETURN(error, "Query event num failed.");
1568 : return error;
1569 : }
1570 :
1571 : rtError_t ApiErrorDecorator::GetTaskIdAndStreamID(uint32_t* const taskId, uint32_t* const streamId)
1572 : {
1573 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(taskId, RT_ERROR_INVALID_VALUE, "Obtaining the task ID and stream ID");
1574 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(streamId, RT_ERROR_INVALID_VALUE, "Obtaining the task ID and stream ID");
1575 : return impl_->GetTaskIdAndStreamID(taskId, streamId);
1576 : }
1577 :
1578 : rtError_t ApiErrorDecorator::SetDeviceFailureMode(uint64_t failureMode)
1579 : {
1580 : return impl_->SetDeviceFailureMode(failureMode);
1581 : }
1582 :
1583 : rtError_t ApiErrorDecorator::StreamSetMode(Stream* const stm, const uint64_t stmMode)
1584 : {
1585 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
1586 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1587 : curStm, RT_ERROR_INVALID_VALUE, "Setting the error handling mode of a stream");
1588 : COND_RETURN_WARN(
1589 : (curStm->Flags() & RT_STREAM_CP_PROCESS_USE) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT,
1590 : "Coprocessor stream flag=%u is not supported, stream_id=%d", curStm->Flags(), curStm->Id_());
1591 : #ifndef CFG_DEV_PLATFORM_PC
1592 : const rtError_t error = impl_->StreamSetMode(curStm, stmMode);
1593 : ERROR_RETURN(error, "set stream mode failed.");
1594 : return error;
1595 : #else
1596 : RT_LOG(RT_LOG_DEBUG, "no need set stream mode.");
1597 : return RT_ERROR_NONE;
1598 : #endif
1599 : }
1600 :
1601 : rtError_t ApiErrorDecorator::StreamGetMode(const Stream* const stm, uint64_t* const stmMode)
1602 : {
1603 : Stream* curStm = Runtime::Instance()->GetCurStream(const_cast<Stream*>(stm));
1604 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1605 : curStm, RT_ERROR_INVALID_VALUE, "Obtaining the error handling mode of a stream");
1606 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1607 : stmMode, RT_ERROR_INVALID_VALUE, "Obtaining the error handling mode of a stream");
1608 : return impl_->StreamGetMode(curStm, stmMode);
1609 : }
1610 :
1611 : rtError_t ApiErrorDecorator::EventCreate(Event** const evt, const uint64_t flag)
1612 : {
1613 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Event creation");
1614 :
1615 : constexpr uint32_t maxFlag = RT_EVENT_FLAG_MAX;
1616 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1617 : ((flag & maxFlag) == 0U) || (flag > maxFlag), RT_ERROR_INVALID_VALUE, "Event creation", flag,
1618 : "an OR combination of RT_EVENT_DDSYNC_NS(0x1U), RT_EVENT_STREAM_MARK(0x2U),"
1619 : " RT_EVENT_DDSYNC(0x4U), and RT_EVENT_TIME_LINE(0x8U);"
1620 : " or RT_EVENT_MC2(0x10U) or RT_EVENT_EXTERNAL(0x20U) used alone");
1621 :
1622 : constexpr uint64_t solelyFlag[] = {RT_EVENT_MC2, RT_EVENT_EXTERNAL};
1623 : for (const uint64_t itemFlag : solelyFlag) {
1624 : COND_RETURN_AND_MSG_OUTER(
1625 : (((flag & (itemFlag)) != 0UL) && ((flag & (~itemFlag)) != 0UL)), RT_ERROR_INVALID_VALUE, ErrorCode::EE1006,
1626 : "Event creation", "Parameter flag value " + std::to_string(flag),
1627 : "RT_EVENT_MC2(0x10U) and RT_EVENT_EXTERNAL(0x20U) do not support OR combination with other flags");
1628 : }
1629 :
1630 : const rtError_t error = impl_->EventCreate(evt, flag);
1631 : ERROR_RETURN(error, "Create event failed.");
1632 : RT_LOG(RT_LOG_DEBUG, "event create success, flag = %" PRIu64 "", flag);
1633 : return error;
1634 : }
1635 :
1636 : rtError_t ApiErrorDecorator::EventCreateEx(Event** const evt, const uint64_t flag)
1637 : {
1638 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Event creation");
1639 : const rtChipType_t chipType = Runtime::Instance()->GetChipType();
1640 : constexpr uint64_t solelyFlag[] = {RT_EVENT_MC2, RT_EVENT_EXTERNAL, RT_EVENT_IPC};
1641 : for (const uint64_t itemFlag : solelyFlag) {
1642 : COND_RETURN_AND_MSG_OUTER(
1643 : (((flag & itemFlag) != 0UL) && ((flag & (~itemFlag)) != 0UL)), RT_ERROR_INVALID_VALUE, ErrorCode::EE1006,
1644 : "Event creation", "Parameter flag value " + std::to_string(flag),
1645 : "RT_EVENT_MC2(0x10U) and RT_EVENT_EXTERNAL(0x20U) do not support OR combination with other flags");
1646 : }
1647 : if ((flag == RT_EVENT_IPC) && (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_IPC_EVENT))) {
1648 : RT_LOG(RT_LOG_WARNING, "chip type(%d) does not support ipc event.", static_cast<int32_t>(chipType));
1649 : return RT_ERROR_FEATURE_NOT_SUPPORT;
1650 : }
1651 : constexpr uint32_t maxFlag =
1652 : (RT_EVENT_DDSYNC_NS | RT_EVENT_STREAM_MARK | RT_EVENT_DDSYNC | RT_EVENT_TIME_LINE | RT_EVENT_IPC);
1653 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1654 : ((flag & maxFlag) == 0U) || (flag > maxFlag), RT_ERROR_INVALID_VALUE, "Event creation", flag,
1655 : "an OR combination of RT_EVENT_DDSYNC_NS(0x1U), RT_EVENT_STREAM_MARK(0x2U),"
1656 : " RT_EVENT_DDSYNC(0x4U), and RT_EVENT_TIME_LINE(0x8U); or RT_EVENT_IPC(0x40U) used alone");
1657 :
1658 : const rtError_t error = impl_->EventCreateEx(evt, flag);
1659 : ERROR_RETURN(error, "Create event failed.");
1660 : RT_LOG(RT_LOG_DEBUG, "event create success, flag = %" PRIu64 "", flag);
1661 : return error;
1662 : }
1663 :
1664 : rtError_t ApiErrorDecorator::EventDestroy(Event* evt)
1665 : {
1666 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Event destruction");
1667 : return impl_->EventDestroy(evt);
1668 : }
1669 :
1670 : rtError_t ApiErrorDecorator::EventDestroySync(Event* evt)
1671 : {
1672 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Synchronous event destruction");
1673 : COND_RETURN_WARN(
1674 : evt->GetEventFlag() == static_cast<uint32_t>(RT_EVENT_IPC), RT_ERROR_FEATURE_NOT_SUPPORT,
1675 : "IPC events are not supported by the rtEventDestroySync API");
1676 : return impl_->EventDestroySync(evt);
1677 : }
1678 :
1679 : rtError_t ApiErrorDecorator::EventRecord(Event* const evt, Stream* const stm, const uint32_t flag)
1680 : {
1681 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Event recording");
1682 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1683 : ((flag != RT_EVENT_RECORD_DEFAULT) && (flag != RT_EVENT_RECORD_EXTERNAL)), RT_ERROR_INVALID_VALUE,
1684 : "Event recording", flag, "RT_EVENT_RECORD_DEFAULT(0) or RT_EVENT_RECORD_EXTERNAL(1)");
1685 : COND_RETURN_AND_MSG_OUTER(
1686 : ((evt->GetEventFlag() == static_cast<uint32_t>(RT_EVENT_MC2)) ||
1687 : (((evt->GetEventFlag() & static_cast<uint32_t>(RT_EVENT_MC2)) != 0U) &&
1688 : ((evt->GetEventFlag() & (~static_cast<uint32_t>(RT_EVENT_MC2))) != 0U))),
1689 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1006, "Event recording",
1690 : "Parameter evt.eventFlag_ value " + std::to_string(evt->GetEventFlag()),
1691 : "Device-only events can be called only on the device");
1692 : COND_RETURN_WARN(
1693 : ((evt->GetEventFlag() == static_cast<uint32_t>(RT_EVENT_IPC)) && (stm != nullptr) && (stm->IsCapturing())),
1694 : RT_ERROR_FEATURE_NOT_SUPPORT, "IPC events are not supported when the capture stream flag is set.");
1695 : if (flag == RT_EVENT_RECORD_EXTERNAL) {
1696 : COND_RETURN_AND_MSG_OUTER(
1697 : (!evt->IsNewMode()) || (evt->GetEventFlag() != RT_EVENT_DDSYNC_NS), RT_ERROR_FEATURE_NOT_SUPPORT,
1698 : ErrorCode::EE1016, "Event recording external",
1699 : "Only events created by rtEventCreateExWithFlag with RT_EVENT_DDSYNC_NS are supported when flag is "
1700 : "RT_EVENT_RECORD_EXTERNAL");
1701 : }
1702 : // Record flag一致性仅由ApiError层检查,其他位置不读写该状态。
1703 : const uint32_t currentFlag = evt->GetRecordFlag();
1704 : COND_RETURN_AND_MSG_OUTER(
1705 : ((currentFlag != UINT32_MAX) && (currentFlag != flag)), RT_ERROR_INVALID_VALUE, ErrorCode::EE1018,
1706 : "Event recording",
1707 : RtFmtMsg(
1708 : "The record flag must remain consistent for the same event, current flag is %s, input flag is %s",
1709 : EventOperationFlagToString(currentFlag, true).c_str(), EventOperationFlagToString(flag, true).c_str()));
1710 : evt->SetRecordFlag(flag);
1711 : const rtError_t error = impl_->EventRecord(evt, stm, flag);
1712 : COND_RETURN_ERROR(
1713 : (error != RT_ERROR_NONE) && (error != RT_ERROR_FEATURE_NOT_SUPPORT), error, "Record event failed.");
1714 : return error;
1715 : }
1716 :
1717 : rtError_t ApiErrorDecorator::GetEventID(Event* const evt, uint32_t* const evtId)
1718 : {
1719 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Obtaining the event ID");
1720 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evtId, RT_ERROR_INVALID_VALUE, "Obtaining the event ID");
1721 : COND_RETURN_WARN(
1722 : evt->GetEventFlag() == static_cast<uint32_t>(RT_EVENT_IPC), RT_ERROR_FEATURE_NOT_SUPPORT,
1723 : "IPC events are not supported by the rtGetEventID API");
1724 : return impl_->GetEventID(evt, evtId);
1725 : }
1726 :
1727 : rtError_t ApiErrorDecorator::EventReset(Event* const evt, Stream* const stm)
1728 : {
1729 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Event reset");
1730 : COND_RETURN_AND_MSG_OUTER(
1731 : ((evt->GetEventFlag() == static_cast<uint32_t>(RT_EVENT_MC2)) ||
1732 : (((evt->GetEventFlag() & static_cast<uint32_t>(RT_EVENT_MC2)) != 0U) &&
1733 : ((evt->GetEventFlag() & (~static_cast<uint32_t>(RT_EVENT_MC2))) != 0U))),
1734 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1006, "Event reset",
1735 : "Parameter evt.eventFlag_ value " + std::to_string(evt->GetEventFlag()),
1736 : "Device-only events can be called only on the device");
1737 : COND_RETURN_WARN(
1738 : evt->GetEventFlag() == static_cast<uint32_t>(RT_EVENT_IPC), RT_ERROR_FEATURE_NOT_SUPPORT,
1739 : "IPC events are not supported by the rtEventReset API");
1740 : COND_RETURN_WARN(
1741 : evt->IsEventWithoutWaitTask(), RT_ERROR_FEATURE_NOT_SUPPORT,
1742 : "flag=%" PRIu64 " is not supported, and there is no need to reset the event.", evt->GetEventFlag());
1743 : const rtError_t error = impl_->EventReset(evt, stm);
1744 : COND_RETURN_ERROR(
1745 : (error != RT_ERROR_NONE) && (error != RT_ERROR_FEATURE_NOT_SUPPORT), error, "Reset event failed.");
1746 : return error;
1747 : }
1748 :
1749 : rtError_t ApiErrorDecorator::EventSynchronize(Event* const evt, const int32_t timeout)
1750 : {
1751 : // timeout >=-1, -1:no limited
1752 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
1753 : (timeout < -1) || (timeout == 0), RT_ERROR_INVALID_VALUE, "Event synchronization", timeout,
1754 : "greater than or equal to -1 and not equal to 0");
1755 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Event synchronization");
1756 : COND_RETURN_WARN(
1757 : evt->GetEventFlag() == RT_EVENT_EXTERNAL, RT_ERROR_FEATURE_NOT_SUPPORT,
1758 : "The external event does not support synchronization.");
1759 : COND_RETURN_AND_MSG_OUTER(
1760 : evt->IsCapturing(), RT_ERROR_EVENT_CAPTURED, ErrorCode::EE1016, "Event synchronization",
1761 : RtFmtMsg("Event (event_id=%d) during the capture stage is not supported", evt->EventId_()));
1762 : COND_RETURN_AND_MSG_OUTER(
1763 : evt->IsEventInModel(), RT_ERROR_INVALID_VALUE, ErrorCode::EE1016, "Event synchronization",
1764 : RtFmtMsg("The event (event_id=%d) in the stream bound to the model is not supported", evt->EventId_()));
1765 : return impl_->EventSynchronize(evt, timeout);
1766 : }
1767 :
1768 : rtError_t ApiErrorDecorator::EventQuery(Event* const evt)
1769 : {
1770 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Event query");
1771 : COND_RETURN_WARN(
1772 : evt->IsNewMode(), RT_ERROR_FEATURE_NOT_SUPPORT, "The current mode is not supported, mode=%d",
1773 : static_cast<int32_t>(evt->IsNewMode()));
1774 : COND_RETURN_WARN(
1775 : evt->GetEventFlag() == RT_EVENT_EXTERNAL, RT_ERROR_FEATURE_NOT_SUPPORT,
1776 : "The external event does not support querying status.");
1777 : COND_RETURN_WARN(
1778 : evt->GetEventFlag() == static_cast<uint32_t>(RT_EVENT_IPC), RT_ERROR_FEATURE_NOT_SUPPORT,
1779 : "IPC events are not supported by the rtEventQuery API");
1780 : COND_RETURN_AND_MSG_OUTER(
1781 : evt->IsCapturing(), RT_ERROR_EVENT_CAPTURED, ErrorCode::EE1016, "Event query",
1782 : RtFmtMsg("Event (event_id=%d) during the capture stage is not supported", evt->EventId_()));
1783 : return impl_->EventQuery(evt);
1784 : }
1785 :
1786 : rtError_t ApiErrorDecorator::EventQueryStatus(Event* const evt, rtEventStatus_t* const status)
1787 : {
1788 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Event status query");
1789 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(status, RT_ERROR_INVALID_VALUE, "Event status query");
1790 : COND_RETURN_WARN(
1791 : evt->GetEventFlag() == RT_EVENT_EXTERNAL, RT_ERROR_FEATURE_NOT_SUPPORT,
1792 : "The external event does not support querying status.");
1793 : COND_RETURN_AND_MSG_OUTER(
1794 : evt->IsCapturing(), RT_ERROR_EVENT_CAPTURED, ErrorCode::EE1016, "Event status query",
1795 : RtFmtMsg("Event (event_id=%d) during the capture stage is not supported", evt->EventId_()));
1796 : return impl_->EventQueryStatus(evt, status);
1797 : }
1798 :
1799 : rtError_t ApiErrorDecorator::EventQueryWaitStatus(Event* const evt, rtEventWaitStatus_t* const status)
1800 : {
1801 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Event waiting status query");
1802 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(status, RT_ERROR_INVALID_VALUE, "Event waiting status query");
1803 : COND_RETURN_WARN(
1804 : evt->IsNewMode(), RT_ERROR_FEATURE_NOT_SUPPORT, "The current mode is not supported, mode=%d",
1805 : static_cast<int32_t>(evt->IsNewMode()));
1806 : COND_RETURN_WARN(
1807 : evt->GetEventFlag() == RT_EVENT_EXTERNAL, RT_ERROR_FEATURE_NOT_SUPPORT,
1808 : "The external event does not support querying status.");
1809 : COND_RETURN_WARN(
1810 : evt->GetEventFlag() == static_cast<uint32_t>(RT_EVENT_IPC), RT_ERROR_FEATURE_NOT_SUPPORT,
1811 : "IPC events are not supported by the rtEventQueryWaitStatus API");
1812 : COND_RETURN_AND_MSG_OUTER(
1813 : evt->IsCapturing(), RT_ERROR_EVENT_CAPTURED, ErrorCode::EE1016, "Event waiting status query",
1814 : RtFmtMsg("Event (event_id=%d) during the capture stage is not supported", evt->EventId_()));
1815 : return impl_->EventQueryWaitStatus(evt, status);
1816 : }
1817 :
1818 : rtError_t ApiErrorDecorator::EventElapsedTime(float32_t* const retTime, Event* const startEvt, Event* const endEvt)
1819 : {
1820 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1821 : retTime, RT_ERROR_INVALID_VALUE, "Computing the elapsed time between two events");
1822 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1823 : startEvt, RT_ERROR_INVALID_VALUE, "Computing the elapsed time between two events");
1824 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1825 : endEvt, RT_ERROR_INVALID_VALUE, "Computing the elapsed time between two events");
1826 : COND_RETURN_AND_MSG_OUTER(
1827 : startEvt->IsCapturing(), RT_ERROR_EVENT_CAPTURED, ErrorCode::EE1016,
1828 : "Computing the elapsed time between two events",
1829 : RtFmtMsg("StartEvent %d during the capture stage is not supported", startEvt->EventId_()));
1830 : COND_RETURN_AND_MSG_OUTER(
1831 : endEvt->IsCapturing(), RT_ERROR_EVENT_CAPTURED, ErrorCode::EE1016,
1832 : "Computing the elapsed time between two events",
1833 : RtFmtMsg("EndEvent %d during the capture stage is not supported", endEvt->EventId_()));
1834 : COND_RETURN_WARN(
1835 : (startEvt->GetEventFlag() == RT_EVENT_EXTERNAL || endEvt->GetEventFlag() == RT_EVENT_EXTERNAL),
1836 : RT_ERROR_FEATURE_NOT_SUPPORT, "The external event does not support getting elapsed time.");
1837 : COND_RETURN_WARN(
1838 : (startEvt->GetEventFlag() == static_cast<uint32_t>(RT_EVENT_IPC) ||
1839 : endEvt->GetEventFlag() == static_cast<uint32_t>(RT_EVENT_IPC)),
1840 : RT_ERROR_FEATURE_NOT_SUPPORT, "IPC events are not supported by the rtEventElapsedTime API");
1841 : return impl_->EventElapsedTime(retTime, startEvt, endEvt);
1842 : }
1843 :
1844 : rtError_t ApiErrorDecorator::EventGetTimeStamp(uint64_t* const retTime, Event* const evt)
1845 : {
1846 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(retTime, RT_ERROR_INVALID_VALUE, "Obtaining the event execution end time");
1847 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Obtaining the event execution end time");
1848 : COND_RETURN_WARN(
1849 : evt->GetEventFlag() == RT_EVENT_EXTERNAL, RT_ERROR_FEATURE_NOT_SUPPORT,
1850 : "The external event does not support getting timestamp.");
1851 : COND_RETURN_WARN(
1852 : evt->GetEventFlag() == static_cast<uint32_t>(RT_EVENT_IPC), RT_ERROR_FEATURE_NOT_SUPPORT,
1853 : "IPC events are not supported by the rtEventGetTimeStamp API");
1854 : COND_RETURN_AND_MSG_OUTER(
1855 : evt->IsCapturing(), RT_ERROR_EVENT_CAPTURED, ErrorCode::EE1016, "Obtaining the event execution end time",
1856 : RtFmtMsg("Event %d during the capture stage is not supported", evt->EventId_()));
1857 : return impl_->EventGetTimeStamp(retTime, evt);
1858 : }
1859 :
1860 : rtError_t ApiErrorDecorator::DevMallocCached(
1861 : void** const devPtr, const uint64_t size, const rtMemType_t type, const uint16_t moduleId)
1862 : {
1863 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1864 : devPtr, RT_ERROR_INVALID_VALUE, "Allocating device memory with the cache attribute");
1865 : ZERO_RETURN_AND_MSG_OUTER(size);
1866 : const uint16_t moduleIdCov = (moduleId > DEFAULT_MODULEID) ? static_cast<uint16_t>(APP) : moduleId;
1867 : const rtError_t error = impl_->DevMallocCached(devPtr, size, type, moduleIdCov);
1868 : ERROR_RETURN(error, "Device malloc cached failed, size=%" PRIu64 "(bytes), type=%u.", size, type);
1869 : RT_LOG(RT_LOG_INFO, "dev cached memory alloc success, size=%" PRIu64 ", type=%u.", size, type);
1870 : return error;
1871 : }
1872 :
1873 : rtError_t ApiErrorDecorator::DevMalloc(
1874 : void** const devPtr, const uint64_t size, const rtMemType_t type, const uint16_t moduleId)
1875 : {
1876 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(devPtr, RT_ERROR_INVALID_VALUE, "Allocating device memory");
1877 :
1878 : const uint16_t moduleIdCov = (moduleId > DEFAULT_MODULEID) ? static_cast<uint16_t>(APP) : moduleId;
1879 : const rtError_t error = impl_->DevMalloc(devPtr, size, type, moduleIdCov);
1880 : RT_LOG(
1881 : RT_LOG_INFO,
1882 : "device malloc, size=%" PRIu64 "(bytes), type=%d, moduleId=%hu, start ptr=0x%llx, "
1883 : "end ptr=0x%llx",
1884 : size, type, moduleId, RtPtrToValue(*devPtr), (RtPtrToValue(*devPtr) + size));
1885 : return error;
1886 : }
1887 :
1888 : rtError_t ApiErrorDecorator::DevFree(void* const devPtr)
1889 : {
1890 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(devPtr, RT_ERROR_INVALID_VALUE, "Releasing device memory");
1891 :
1892 : const rtError_t error = impl_->DevFree(devPtr);
1893 : ERROR_RETURN(error, "Free device failed, mem=0x%llx", RtPtrToValue(devPtr));
1894 : return error;
1895 : }
1896 :
1897 : rtError_t ApiErrorDecorator::DevDvppMalloc(
1898 : void** const devPtr, const uint64_t size, const uint32_t flag, const uint16_t moduleId)
1899 : {
1900 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(devPtr, RT_ERROR_INVALID_VALUE, "Allocating DVPP device memory");
1901 :
1902 : const uint16_t moduleIdCov = (moduleId > DEFAULT_MODULEID) ? static_cast<uint16_t>(APP) : moduleId;
1903 : return impl_->DevDvppMalloc(devPtr, size, flag, moduleIdCov);
1904 : }
1905 :
1906 : rtError_t ApiErrorDecorator::DevDvppFree(void* const devPtr)
1907 : {
1908 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(devPtr, RT_ERROR_INVALID_VALUE, "Releasing DVPP device memory");
1909 : return impl_->DevDvppFree(devPtr);
1910 : }
1911 :
1912 : rtError_t ApiErrorDecorator::HostMalloc(void** const hostPtr, const uint64_t size, const uint16_t moduleId)
1913 : {
1914 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(hostPtr, RT_ERROR_INVALID_VALUE, "Host memory allocation");
1915 : ZERO_RETURN_AND_MSG_OUTER(size);
1916 : const uint16_t moduleIdCov = (moduleId > DEFAULT_MODULEID) ? static_cast<uint16_t>(APP) : moduleId;
1917 : const rtError_t error = impl_->HostMalloc(hostPtr, size, moduleIdCov);
1918 : ERROR_RETURN(error, "Host memory malloc failed, size=%" PRIu64 "(bytes), moduleId=%hu.", size, moduleId);
1919 : RT_LOG(
1920 : RT_LOG_INFO, "Host memory malloc succeed, size=%" PRIu64 ", moduleId=%hu, host addr=%#" PRIx64 ".", size,
1921 : moduleId, RtPtrToValue(*hostPtr));
1922 : return error;
1923 : }
1924 :
1925 : rtError_t ApiErrorDecorator::HostMallocWithCfg(void** const hostPtr, const uint64_t size, const rtMallocConfig_t* cfg)
1926 : {
1927 : return impl_->HostMallocWithCfg(hostPtr, size, cfg);
1928 : }
1929 :
1930 : rtError_t ApiErrorDecorator::HostFree(void* const hostPtr)
1931 : {
1932 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(hostPtr, RT_ERROR_INVALID_VALUE, "Host memory release");
1933 :
1934 : const rtError_t error = impl_->HostFree(hostPtr);
1935 : ERROR_RETURN(error, "Free host memory failed, host addr=%#" PRIx64 ".", RtPtrToValue(hostPtr));
1936 : RT_LOG(RT_LOG_INFO, "Free host memory succeed, host addr=%#" PRIx64 ".", RtPtrToValue(hostPtr));
1937 : return error;
1938 : }
1939 :
1940 : rtError_t ApiErrorDecorator::MallocHostSharedMemory(
1941 : rtMallocHostSharedMemoryIn* const in, rtMallocHostSharedMemoryOut* const out)
1942 : {
1943 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(in, RT_ERROR_INVALID_VALUE, "Shared memory allocation");
1944 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(out, RT_ERROR_INVALID_VALUE, "Shared memory allocation");
1945 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(in->name, RT_ERROR_INVALID_VALUE, "Shared memory allocation");
1946 : ZERO_RETURN_AND_MSG_OUTER(in->size);
1947 :
1948 : const rtError_t error = impl_->MallocHostSharedMemory(in, out);
1949 : ERROR_RETURN(
1950 : error,
1951 : "Malloc host shared memory failed, hostPtr=%s, sharedMemSize=%" PRIu64 "(bytes), flag=%u,"
1952 : "fd=%u.",
1953 : in->name, in->size, in->flag, out->fd);
1954 : return error;
1955 : }
1956 :
1957 : rtError_t ApiErrorDecorator::FreeHostSharedMemory(rtFreeHostSharedMemoryIn* const in)
1958 : {
1959 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(in, RT_ERROR_INVALID_VALUE, "Releasing host shared memory");
1960 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(in->name, RT_ERROR_INVALID_VALUE, "Releasing host shared memory");
1961 : ZERO_RETURN_AND_MSG_OUTER(in->size);
1962 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(in->ptr, RT_ERROR_INVALID_VALUE, "Releasing host shared memory");
1963 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(in->devPtr, RT_ERROR_INVALID_VALUE, "Releasing host shared memory");
1964 :
1965 : const rtError_t error = impl_->FreeHostSharedMemory(in);
1966 : ERROR_RETURN(
1967 : error, "Free host shared memory failed, sharedMemName=%s, sharedMemSize=%" PRIu64 "(bytes), fd=%u.", in->name,
1968 : in->size, in->fd);
1969 : return error;
1970 : }
1971 :
1972 : rtError_t ApiErrorDecorator::HostRegister(void* ptr, uint64_t size, rtHostRegisterType type, void** devPtr)
1973 : {
1974 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1975 : ptr, RT_ERROR_INVALID_VALUE, "Registering the host memory as device-accessible memory");
1976 : ZERO_RETURN_AND_MSG_OUTER(size);
1977 : constexpr uint32_t validFlags = RT_HOST_REGISTER_IOMEMORY | RT_HOST_REGISTER_READONLY;
1978 : if ((static_cast<uint32_t>(type) & (~validFlags)) != 0U) {
1979 : RT_LOG(
1980 : RT_LOG_WARNING, "Current type=%u is not supported. Valid flags are combinations of [%u, %u] or 0", type,
1981 : RT_HOST_REGISTER_IOMEMORY, RT_HOST_REGISTER_READONLY);
1982 : return RT_ERROR_FEATURE_NOT_SUPPORT;
1983 : }
1984 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
1985 : devPtr, RT_ERROR_INVALID_VALUE, "Registering the host memory as device-accessible memory");
1986 :
1987 : const rtError_t error = impl_->HostRegister(ptr, size, type, devPtr);
1988 : ERROR_RETURN(error, "Malloc host memory failed, MemSize=%" PRIu64 "(bytes)", size);
1989 : return error;
1990 : }
1991 :
1992 : rtError_t ApiErrorDecorator::HostRegisterV2(void* ptr, uint64_t size, uint32_t flag)
1993 : {
1994 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(ptr, RT_ERROR_INVALID_VALUE, "Host memory address registration");
1995 : ZERO_RETURN_AND_MSG_OUTER(size);
1996 : constexpr uint32_t validFlags = RT_MEM_HOST_REGISTER_MAPPED | RT_MEM_HOST_REGISTER_IOMEMORY |
1997 : RT_MEM_HOST_REGISTER_READONLY | RT_MEM_HOST_REGISTER_PINNED;
1998 : const bool isValidFlag = ((flag & validFlags) != 0U) && ((flag & (~validFlags)) == 0U);
1999 : COND_RETURN_AND_MSG_OUTER(
2000 : !isValidFlag, RT_ERROR_INVALID_VALUE, ErrorCode::EE1011, "Host memory address registration", flag, "flag",
2001 : "The valid flag is an OR combination of RT_MEM_HOST_REGISTER_MAPPED(0x2U), RT_MEM_HOST_REGISTER_IOMEMORY(0x4U),"
2002 : " RT_MEM_HOST_REGISTER_READONLY(0x8U), and RT_MEM_HOST_REGISTER_PINNED(0x10000000U)");
2003 :
2004 : rtError_t error = CheckMemoryRangeRegistered(ptr, size);
2005 : COND_RETURN_WITH_NOLOG(error != RT_ERROR_NONE, error);
2006 :
2007 : error = impl_->HostRegisterV2(ptr, size, flag);
2008 : ERROR_RETURN(error, "Register host memory failed, MemSize=%" PRIu64 "(bytes), flag=%#x.", size, flag);
2009 : return error;
2010 : }
2011 :
2012 : rtError_t ApiErrorDecorator::HostUnregister(void* ptr)
2013 : {
2014 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(ptr, RT_ERROR_INVALID_VALUE, "Host memory deregistration");
2015 :
2016 : const rtError_t error = impl_->HostUnregister(ptr);
2017 : ERROR_RETURN(error, "Malloc host memory failed.");
2018 : return error;
2019 : }
2020 :
2021 : rtError_t ApiErrorDecorator::HostGetDevicePointer(void* pHost, void** pDevice, uint32_t flag)
2022 : {
2023 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2024 : pHost, RT_ERROR_INVALID_VALUE, "Obtaining the on-device memory pointer based on the on-host virtual address");
2025 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2026 : pDevice, RT_ERROR_INVALID_VALUE, "Obtaining the on-device memory pointer based on the on-host virtual address");
2027 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2028 : (flag != 0), RT_ERROR_INVALID_VALUE,
2029 : "Obtaining the on-device memory pointer based on the on-host virtual address", flag, "equal to 0");
2030 :
2031 : const rtError_t error = impl_->HostGetDevicePointer(pHost, pDevice, flag);
2032 : ERROR_RETURN(error, "Host get device memory failed.");
2033 : return error;
2034 : }
2035 :
2036 : rtError_t ApiErrorDecorator::HostMemMapCapabilities(
2037 : uint32_t deviceId, rtHacType hacType, rtHostMemMapCapability* capabilities)
2038 : {
2039 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2040 : capabilities, RT_ERROR_INVALID_VALUE, "Querying the host memory mapping capability on a specified device");
2041 : uint32_t realDeviceId;
2042 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(deviceId, &realDeviceId);
2043 : COND_RETURN_ERROR(
2044 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", deviceId);
2045 :
2046 : error = CheckDeviceIdIsValid(static_cast<int32_t>(realDeviceId));
2047 : COND_RETURN_ERROR_MSG_INNER(
2048 : error != RT_ERROR_NONE, error, "Device ID is invalid, drv devId=%u, retCode=%#x", realDeviceId,
2049 : static_cast<uint32_t>(error));
2050 :
2051 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2052 : hacType >= RT_HAC_TYPE_MAX, RT_ERROR_INVALID_VALUE,
2053 : "Querying the host memory mapping capability on a specified device", hacType,
2054 : "[0, " + std::to_string(RT_HAC_TYPE_MAX) + ")");
2055 : error = impl_->HostMemMapCapabilities(realDeviceId, hacType, capabilities);
2056 : if (error == RT_ERROR_FEATURE_NOT_SUPPORT) {
2057 : RT_LOG(RT_LOG_WARNING, "HostMemMapCapabilities is not supported on drv deviceId %u", realDeviceId);
2058 : } else {
2059 : ERROR_RETURN(error, "query host memory capabilities failed.");
2060 : }
2061 : return error;
2062 : }
2063 :
2064 : rtError_t ApiErrorDecorator::ManagedMemAlloc(
2065 : void** const ptr, const uint64_t size, const uint32_t flag, const uint16_t moduleId)
2066 : {
2067 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(ptr, RT_ERROR_INVALID_VALUE, "Unified virtual memory (UVM) allocation");
2068 : ZERO_RETURN_AND_MSG_OUTER(size);
2069 : const uint16_t moduleIdCov = (moduleId > DEFAULT_MODULEID) ? static_cast<uint16_t>(APP) : moduleId;
2070 : const rtError_t error = impl_->ManagedMemAlloc(ptr, size, flag, moduleIdCov);
2071 : RT_LOG(RT_LOG_INFO, "managed memory alloc, size=%" PRIu64 "(bytes), flag=%u", size, flag);
2072 : return error;
2073 : }
2074 :
2075 : rtError_t ApiErrorDecorator::ManagedMemFree(const void* const ptr)
2076 : {
2077 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(ptr, RT_ERROR_INVALID_VALUE, "Unified virtual memory (UVM) release");
2078 : const rtError_t error = impl_->ManagedMemFree(ptr);
2079 : ERROR_RETURN(error, "Free managed memory failed");
2080 : return error;
2081 : }
2082 :
2083 : rtError_t ApiErrorDecorator::MemAdvise(void* devPtr, uint64_t count, uint32_t advise)
2084 : {
2085 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(devPtr, RT_ERROR_INVALID_VALUE, "Providing the memory access policy");
2086 : ZERO_RETURN_AND_MSG_OUTER(count);
2087 : const rtError_t error = impl_->MemAdvise(devPtr, count, advise);
2088 : ERROR_RETURN(error, "memory advise failed, count=%" PRIu64 ", advise=%u", count, advise);
2089 : return error;
2090 : }
2091 :
2092 : rtError_t ApiErrorDecorator::FlushCache(const uint64_t base, const size_t len)
2093 : {
2094 : const rtError_t error = impl_->FlushCache(base, len);
2095 : ERROR_RETURN(error, "Flush cache failed, base=%" PRIu64 "(bytes), len=%zu(bytes)", base, len);
2096 : return error;
2097 : }
2098 :
2099 : rtError_t ApiErrorDecorator::InvalidCache(const uint64_t base, const size_t len)
2100 : {
2101 : const rtError_t error = impl_->InvalidCache(base, len);
2102 : ERROR_RETURN(error, "Invalid cache failed, base=%" PRIu64 "(bytes), len=%zu(bytes).", base, len);
2103 : return error;
2104 : }
2105 :
2106 : rtError_t ApiErrorDecorator::MemCopySync(
2107 : void* const dst, const uint64_t destMax, const void* const src, const uint64_t cnt, const rtMemcpyKind_t kind,
2108 : const uint32_t checkKind)
2109 : {
2110 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(dst, RT_ERROR_INVALID_VALUE, "Synchronous memory copy");
2111 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(src, RT_ERROR_INVALID_VALUE, "Synchronous memory copy");
2112 : ZERO_RETURN_AND_MSG_OUTER(destMax);
2113 : ZERO_RETURN_AND_MSG_OUTER(cnt);
2114 :
2115 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2116 : cnt > destMax, RT_ERROR_INVALID_VALUE, "Synchronous memory copy", cnt, "(0, " + std::to_string(destMax) + "]");
2117 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME(
2118 : (kind >= RT_MEMCPY_RESERVED) || (kind < RT_MEMCPY_HOST_TO_HOST), RT_ERROR_INVALID_VALUE, MemcpyKindToStr(kind),
2119 : "kind", "[" + std::to_string(RT_MEMCPY_HOST_TO_HOST) + ", " + std::to_string(RT_MEMCPY_RESERVED) + ")");
2120 : COND_RETURN_WARN((dst == src), RT_ERROR_NONE, "The src and dst are the same, no need to copy, return.");
2121 :
2122 : const rtError_t error = impl_->MemCopySync(dst, destMax, src, cnt, kind, checkKind);
2123 : COND_RETURN_ERROR(
2124 : (error != RT_ERROR_NONE) && (error != RT_ERROR_DRV_NOT_SUPPORT), error,
2125 : "Memory copy sync failed, cnt=%" PRIu64 ", kind=%s.", cnt, MemcpyKindToStr(kind));
2126 : return error;
2127 : }
2128 :
2129 : rtError_t ApiErrorDecorator::MemCopySyncEx(
2130 : void* const dst, const uint64_t destMax, const void* const src, const uint64_t cnt, const rtMemcpyKind_t kind)
2131 : {
2132 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(dst, RT_ERROR_INVALID_VALUE, "Synchronous memory copy");
2133 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(src, RT_ERROR_INVALID_VALUE, "Synchronous memory copy");
2134 : ZERO_RETURN_AND_MSG_OUTER(destMax);
2135 : ZERO_RETURN_AND_MSG_OUTER(cnt);
2136 :
2137 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2138 : cnt > destMax, RT_ERROR_INVALID_VALUE, "Synchronous memory copy", cnt, "(0, " + std::to_string(destMax) + "]");
2139 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME(
2140 : (kind >= RT_MEMCPY_RESERVED) || (kind < RT_MEMCPY_HOST_TO_HOST), RT_ERROR_INVALID_VALUE, MemcpyKindToStr(kind),
2141 : "kind", "[" + std::to_string(RT_MEMCPY_HOST_TO_HOST) + ", " + std::to_string(RT_MEMCPY_RESERVED) + ")");
2142 : COND_RETURN_WARN((dst == src), RT_ERROR_NONE, "The src and dst are the same, no need to copy, return.");
2143 :
2144 : const rtError_t error = impl_->MemCopySyncEx(dst, destMax, src, cnt, kind);
2145 : COND_RETURN_ERROR(
2146 : (error != RT_ERROR_NONE) && (error != RT_ERROR_DRV_NOT_SUPPORT), error,
2147 : "Memory copy sync failed, cnt=%" PRIu64 ", kind=%s.", cnt, MemcpyKindToStr(kind));
2148 : return error;
2149 : }
2150 :
2151 : rtError_t ApiErrorDecorator::MemcpyAsync(
2152 : void* const dst, const uint64_t destMax, const void* const src, const uint64_t cnt, const rtMemcpyKind_t kind,
2153 : Stream* const stm, const rtTaskCfgInfo_t* const cfgInfo, const rtD2DAddrCfgInfo_t* const addrCfg, bool checkKind,
2154 : const rtMemcpyConfig_t* const memcpyConfig)
2155 : {
2156 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(dst, RT_ERROR_INVALID_VALUE, "Asynchronous memory copy");
2157 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(src, RT_ERROR_INVALID_VALUE, "Asynchronous memory copy");
2158 : ZERO_RETURN_AND_MSG_OUTER(cnt);
2159 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2160 : cnt > destMax, RT_ERROR_INVALID_VALUE, "Asynchronous memory copy", cnt, "(0, " + std::to_string(destMax) + "]");
2161 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME(
2162 : (kind >= RT_MEMCPY_RESERVED) || (kind < RT_MEMCPY_HOST_TO_HOST), RT_ERROR_INVALID_VALUE, MemcpyKindToStr(kind),
2163 : "kind", "[" + std::to_string(RT_MEMCPY_HOST_TO_HOST) + ", " + std::to_string(RT_MEMCPY_RESERVED) + ")");
2164 : COND_RETURN_AND_MSG_OUTER(
2165 : ((kind == RT_MEMCPY_ADDR_DEVICE_TO_DEVICE) && (cnt > MAX_MEMCPY_SIZE_OF_D2D)), RT_ERROR_INVALID_VALUE,
2166 : ErrorCode::EE1011, "Asynchronous memory copy", cnt, "cnt",
2167 : RtFmtMsg(
2168 : "If parameter kind equals RT_MEMCPY_ADDR_DEVICE_TO_DEVICE(5),"
2169 : " the range of parameter cnt should be (0, %u]",
2170 : MAX_MEMCPY_SIZE_OF_D2D));
2171 : rtError_t error = MemcpyAsyncCheckParam(kind, stm);
2172 : ERROR_RETURN_MSG_CALL(
2173 : ERR_MODULE_GE, error, "check memcpy async param failure, retCode=%#x.", static_cast<uint32_t>(error));
2174 : if (addrCfg != nullptr) {
2175 : error = MemcpyAsyncCheckAddrCfg(destMax, cnt, addrCfg);
2176 : COND_RETURN_WITH_NOLOG(error != RT_ERROR_NONE, error);
2177 : }
2178 :
2179 : const int32_t streamId = (stm != nullptr) ? stm->Id_() : -1;
2180 : RtMemcpyCfgInfo configInfo;
2181 : (void)memset_s(&configInfo, sizeof(RtMemcpyCfgInfo), 0, sizeof(RtMemcpyCfgInfo));
2182 : if (memcpyConfig != nullptr) {
2183 : error = GetMemcpyConfigInfo(&configInfo, memcpyConfig, true);
2184 : COND_RETURN_AND_MSG_INNER(
2185 : error != RT_ERROR_NONE, RT_ERROR_INVALID_VALUE, "Failed to get memcpyConfig in MemcpyAsync, stream_id=%d.",
2186 : streamId);
2187 : }
2188 :
2189 : rtMemcpyKind_t copyKind = kind;
2190 : checkKind = (configInfo.checkBitmap == WITHOUT_CHECK_KIND) ? false : checkKind;
2191 : COND_RETURN_AND_MSG_OUTER(
2192 : !checkKind && (kind == RT_MEMCPY_DEFAULT), RT_ERROR_INVALID_VALUE, ErrorCode::EE1011,
2193 : "Asynchronous memory copy", "MEMCPY_DEFAULT(8)", "kind",
2194 : "If parameter checkKind is false, parameter kind cannot be MEMCPY_DEFAULT(8)");
2195 : bool isD2HorH2DInvolvePageableMemory = false;
2196 : Context* curCtx = Runtime::Instance()->CurrentContext();
2197 : CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL);
2198 : NULL_PTR_RETURN_MSG(curCtx->Device_(), RT_ERROR_DEVICE_NULL);
2199 : const uint32_t runMode = curCtx->Device_()->Driver_()->GetRunMode();
2200 : if ((kind == RT_MEMCPY_HOST_TO_DEVICE_EX) || (kind == RT_MEMCPY_DEVICE_TO_HOST_EX)) {
2201 : if (runMode == RT_RUN_MODE_ONLINE) {
2202 : error = MemcpyAsyncCheckExLocation(checkKind, kind, src, dst);
2203 : COND_RETURN_ERROR_MSG_INNER(
2204 : error != RT_ERROR_NONE, error, "MemcpyAsync EX check src or dst location failed, stream_id=%d, kind=%s",
2205 : streamId, MemcpyKindToStr(kind));
2206 : } else {
2207 : // no operation
2208 : }
2209 : } else {
2210 : const bool isUserRequireToCheckPinnedMem = (configInfo.checkBitmap == CHECK_MEMORY_PINNED);
2211 : error = MemcpyAsyncCheckLocation(
2212 : checkKind, copyKind, src, dst, isUserRequireToCheckPinnedMem,
2213 : isD2HorH2DInvolvePageableMemory); /* 会更新copykind */
2214 : COND_RETURN_ERROR_MSG_INNER(
2215 : error != RT_ERROR_NONE, error,
2216 : "MemcpyAsync check src or dst location failed, stream_id=%d, checkKind=%d, copyKind=%s", streamId,
2217 : checkKind, MemcpyKindToStr(copyKind));
2218 : }
2219 :
2220 : COND_RETURN_WARN(
2221 : ((copyKind == RT_MEMCPY_HOST_TO_HOST) && (runMode == RT_RUN_MODE_ONLINE)), RT_ERROR_FEATURE_NOT_SUPPORT,
2222 : "H2H is not supported");
2223 : COND_RETURN_WARN(
2224 : ((addrCfg == nullptr) && (dst == src)), /* 在check kind/loc之后校验(校验顺序会影响return值) */
2225 : RT_ERROR_NONE, "The src and dst are the same, no need to copy, return.");
2226 :
2227 : COND_RETURN_WARN(
2228 : IsUbDmaWithSubModel(stm, kind, src, dst), RT_ERROR_FEATURE_NOT_SUPPORT,
2229 : "stream belongs to sub ACL Graph, does not support asynchronous memory copy.");
2230 : if (isD2HorH2DInvolvePageableMemory) {
2231 : COND_RETURN_AND_MSG_OUTER(
2232 : ((stm != nullptr) && (stm->IsCapturing())), RT_ERROR_INVALID_VALUE, ErrorCode::EE1016,
2233 : "Asynchronous copy task", "The pageable memory copy task does not support graph capture");
2234 : /* 把异步拷贝转化为隐式流同步 + 同步拷贝,以避免异步访问pageable内存引起的PA异常 */
2235 : error = StreamSynchronize(stm, -1);
2236 : COND_RETURN_ERROR(error != RT_ERROR_NONE, error, "StreamSynchronize failed, stream_id=%d.", streamId);
2237 :
2238 : error = impl_->MemCopySync(dst, destMax, src, cnt, copyKind);
2239 : error = (error == RT_ERROR_STREAM_CAPTURE_MODE_NOT_SUPPORT) ? RT_ERROR_STREAM_CAPTURE_MODE_BLOCK_ASYNC : error;
2240 : COND_RETURN_AND_MSG_OUTER(
2241 : error == RT_ERROR_STREAM_CAPTURE_MODE_BLOCK_ASYNC, error, ErrorCode::EE1016, "Asynchronous memory copy",
2242 : "the operation has been converted to a synchronous operation. "
2243 : "operation not permitted when a stream is capturing and the specified capture mode is not relaxed");
2244 : } else {
2245 : error = impl_->MemcpyAsync(dst, destMax, src, cnt, copyKind, stm, cfgInfo, addrCfg, checkKind);
2246 : }
2247 :
2248 : COND_RETURN_ERROR(
2249 : (error != RT_ERROR_NONE) && (error != RT_ERROR_FEATURE_NOT_SUPPORT), error,
2250 : "Memcpy async failed, count=%" PRIu64 ", kind=%s, isInvolvePageableMemory=%d", cnt, MemcpyKindToStr(copyKind),
2251 : isD2HorH2DInvolvePageableMemory);
2252 : return error;
2253 : }
2254 :
2255 : rtError_t ApiErrorDecorator::LaunchSqeUpdateTask(
2256 : uint32_t streamId, uint32_t taskId, void* src, uint64_t cnt, Stream* const stm, bool needCpuTask)
2257 : {
2258 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2259 : src, RT_ERROR_INVALID_VALUE, "Delivering the Submission Queue Entry (SQE) update task");
2260 : if (needCpuTask) {
2261 : COND_RETURN_AND_MSG_OUTER(
2262 : cnt != sizeof(rtRandomNumTaskInfo_t), RT_ERROR_INVALID_VALUE, ErrorCode::EE1011,
2263 : "Delivering the Submission Queue Entry (SQE) update task", cnt, "cnt",
2264 : RtFmtMsg(
2265 : "If parameter needCpuTask is equal to %u, the value of parameter cnt should be %zu(bytes)", needCpuTask,
2266 : sizeof(rtRandomNumTaskInfo_t)));
2267 : } else {
2268 : constexpr uint32_t dsaCopySize = 40U;
2269 : COND_RETURN_AND_MSG_OUTER(
2270 : cnt != static_cast<uint64_t>(dsaCopySize), RT_ERROR_INVALID_VALUE, ErrorCode::EE1011,
2271 : "Delivering the Submission Queue Entry (SQE) update task", cnt, "cnt",
2272 : RtFmtMsg(
2273 : "If parameter needCpuTask is not equal to %u, the value of parameter cnt should be %u(bytes)",
2274 : needCpuTask, dsaCopySize));
2275 : }
2276 : RT_LOG(RT_LOG_DEBUG, "update dsa sqe, cnt=%" PRIu64 "Byte, streamId=%u, taskId=%u", cnt, streamId, taskId);
2277 : const rtError_t error = impl_->LaunchSqeUpdateTask(streamId, taskId, src, cnt, stm, needCpuTask);
2278 : ERROR_RETURN(error, "update dsa failed, cnt=%" PRIu64 "Byte, streamId=%u, taskId=%u", cnt, streamId, taskId);
2279 : return error;
2280 : }
2281 :
2282 : rtError_t ApiErrorDecorator::MemcpyAsyncPtr(
2283 : void* const memcpyAddrInfo, const uint64_t destMax, const uint64_t count, Stream* stm,
2284 : const rtTaskCfgInfo_t* const cfgInfo, const bool isMemcpyDesc)
2285 : {
2286 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2287 : memcpyAddrInfo, RT_ERROR_INVALID_VALUE,
2288 : "Performing asynchronous memory copy using the address description on the device");
2289 : ZERO_RETURN_AND_MSG_OUTER(count);
2290 : COND_RETURN_AND_MSG_OUTER(
2291 : count > destMax, RT_ERROR_INVALID_VALUE, ErrorCode::EE1011,
2292 : "Performing asynchronous memory copy using the address description on the device", count, "count",
2293 : RtFmtMsg("The count cannot exceed the maximum value destMax %u", destMax));
2294 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2295 : (count > MAX_MEMCPY_SIZE_OF_D2D), RT_ERROR_INVALID_VALUE,
2296 : "Performing asynchronous memory copy using the address description on the device", count,
2297 : RtFmtMsg("(0, %u]", MAX_MEMCPY_SIZE_OF_D2D));
2298 : COND_RETURN_AND_MSG_OUTER(
2299 : (RtPtrToValue(memcpyAddrInfo) % 64ULL) != 0ULL, RT_ERROR_INVALID_VALUE, ErrorCode::EE1011,
2300 : "Performing asynchronous memory copy using the address description on the device", memcpyAddrInfo,
2301 : "memcpyAddrInfo", "memcpyAddrInfo is not 64-byte aligned");
2302 :
2303 : if (isMemcpyDesc == false) {
2304 : Context* curCtx = nullptr;
2305 :
2306 : rtError_t error = impl_->ContextGetCurrent(&curCtx);
2307 : COND_RETURN_ERROR_MSG_CALL(
2308 : ERR_MODULE_GE, error != RT_ERROR_NONE, error, "Get current context failed, retCode=%#x",
2309 : static_cast<uint32_t>(error));
2310 : CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL);
2311 : if ((curCtx->Device_()->Driver_()->GetRunMode() == RT_RUN_MODE_ONLINE)) {
2312 : rtPtrAttributes_t attributes;
2313 : error = impl_->PtrGetAttributes(memcpyAddrInfo, &attributes);
2314 : COND_RETURN_ERROR_MSG_CALL(
2315 : ERR_MODULE_GE, error != RT_ERROR_NONE, error,
2316 : "Memory async ptr failed, get pointer attributes failed, retCode=%#x", static_cast<uint32_t>(error));
2317 : const rtMemLocationType srcLocationType = attributes.location.type;
2318 2 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_DESC(
2319 : srcLocationType != RT_MEMORY_LOC_DEVICE, RT_ERROR_INVALID_VALUE,
2320 : "Performing asynchronous memory copy using the address description on the device",
2321 : MemLocationTypeToString(srcLocationType), "srcLocationType",
2322 : MemLocationTypeToString(RT_MEMORY_LOC_DEVICE));
2323 : }
2324 : }
2325 : const rtError_t error = impl_->MemcpyAsyncPtr(memcpyAddrInfo, destMax, count, stm, cfgInfo, isMemcpyDesc);
2326 : ERROR_RETURN_MSG_INNER(error, "Memcpy async ptr failed, stream=%p, count=%" PRIu64 ".", stm, count);
2327 : return error;
2328 : }
2329 :
2330 : rtError_t ApiErrorDecorator::CheckMemcpyAttribute(
2331 : const rtMemcpyKind kind, const void* const dst, const void* const src) const
2332 : {
2333 : rtPtrAttributes_t srcAttributes = {};
2334 : rtPtrAttributes_t destAttributes = {};
2335 : rtError_t error = impl_->PtrGetAttributes(dst, &destAttributes);
2336 : COND_RETURN_AND_MSG_OUTER(
2337 : error != RT_ERROR_NONE, error, ErrorCode::EE1017, "Memory copy attribute check", "desc",
2338 : "Failed to get dst pointer memory attributes");
2339 :
2340 : error = impl_->PtrGetAttributes(src, &srcAttributes);
2341 : COND_RETURN_AND_MSG_OUTER(
2342 : error != RT_ERROR_NONE, error, ErrorCode::EE1017, "Memory copy attribute check", "desc",
2343 : "Failed to get src pointer memory attributes");
2344 :
2345 : COND_RETURN_AND_MSG_OUTER(
2346 : ((kind == RT_MEMCPY_KIND_INNER_DEVICE_TO_DEVICE) && (destAttributes.location.id != srcAttributes.location.id)),
2347 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1011, "Memory copy attribute check", MemcpyNewKindToString(kind), "kind",
2348 : "DstAddr and srcAddr do not match with the kind RT_MEMCPY_KIND_INNER_DEVICE_TO_DEVICE, dstAddr DeviceId=" +
2349 : std::to_string(destAttributes.location.id) +
2350 : ", srcAddr DeviceId=" + std::to_string(srcAttributes.location.id));
2351 :
2352 : COND_RETURN_AND_MSG_OUTER(
2353 : ((kind == RT_MEMCPY_KIND_INTER_DEVICE_TO_DEVICE) && (destAttributes.location.id == srcAttributes.location.id)),
2354 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1011, "Memory copy attribute check", MemcpyNewKindToString(kind), "kind",
2355 : "DstAddr and srcAddr do not match with the kind RT_MEMCPY_KIND_INTER_DEVICE_TO_DEVICE. dstAddr DeviceId=" +
2356 : std::to_string(destAttributes.location.id) +
2357 : ", srcAddr DeviceId=" + std::to_string(srcAttributes.location.id));
2358 :
2359 : return RT_ERROR_NONE;
2360 : }
2361 :
2362 : rtError_t ApiErrorDecorator::RtsMemcpyAsync(
2363 : void* const dst, const uint64_t destMax, const void* const src, const uint64_t cnt, const rtMemcpyKind kind,
2364 : rtMemcpyConfig_t* const config, Stream* const stm)
2365 : {
2366 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(dst, RT_ERROR_INVALID_VALUE, "Asynchronous memory copy");
2367 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(src, RT_ERROR_INVALID_VALUE, "Asynchronous memory copy");
2368 :
2369 : rtError_t error = CheckMemcpyAttribute(kind, dst, src);
2370 : ERROR_RETURN(error, "Check attributes failed.");
2371 :
2372 : if (cnt == 0UL) {
2373 : RT_LOG(RT_LOG_WARNING, "Memcpy count is 0, no need to copy, return.");
2374 : return RT_ERROR_NONE;
2375 : }
2376 :
2377 : RtMemcpyCfgInfo cfgInfo;
2378 : (void)memset_s(&cfgInfo, sizeof(RtMemcpyCfgInfo), 0, sizeof(RtMemcpyCfgInfo));
2379 : if (config != nullptr) {
2380 : error = GetMemcpyConfigInfo(&cfgInfo, config, true);
2381 : COND_RETURN_AND_MSG_INNER(error != RT_ERROR_NONE, RT_ERROR_INVALID_VALUE, "Failed to get memcpyConfig.");
2382 : }
2383 :
2384 : COND_RETURN_AND_MSG_OUTER(
2385 : ((cfgInfo.checkBitmap == WITHOUT_CHECK_KIND) && (kind == RT_MEMCPY_KIND_DEFAULT)), RT_ERROR_INVALID_VALUE,
2386 : ErrorCode::EE1011, "Asynchronous memory copy", "RT_MEMCPY_KIND_DEFAULT(4)", "kind",
2387 : "When the kind check is disabled, parameter kind cannot be RT_MEMCPY_KIND_DEFAULT(4)");
2388 :
2389 : const rtMemcpyKind_t curKind = GetMemCpyKind(RT_MEMCPY_RESERVED, kind);
2390 : if (cfgInfo.checkBitmap == INVALID_CHECK_KIND) {
2391 : return MemcpyAsync(dst, destMax, src, cnt, curKind, stm, nullptr, nullptr, true);
2392 : } else {
2393 : return MemcpyAsync(dst, destMax, src, cnt, curKind, stm, nullptr, nullptr, true, config);
2394 : }
2395 : }
2396 :
2397 : rtError_t ApiErrorDecorator::RtsMemcpy(
2398 : void* const dst, const uint64_t destMax, const void* const src, const uint64_t cnt, const rtMemcpyKind kind,
2399 : rtMemcpyConfig_t* const config)
2400 : {
2401 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(dst, RT_ERROR_INVALID_VALUE, "Synchronous memory copy");
2402 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(src, RT_ERROR_INVALID_VALUE, "Synchronous memory copy");
2403 :
2404 : rtError_t error = CheckMemcpyAttribute(kind, dst, src);
2405 : ERROR_RETURN(error, "Check memcpy attribute failed.");
2406 :
2407 : if (cnt == 0UL) {
2408 : RT_LOG(RT_LOG_WARNING, "Memcpy count is 0, no need to copy, return.");
2409 : return RT_ERROR_NONE;
2410 : }
2411 :
2412 : RtMemcpyCfgInfo cfgInfo;
2413 : (void)memset_s(&cfgInfo, sizeof(RtMemcpyCfgInfo), 0, sizeof(RtMemcpyCfgInfo));
2414 : if (config != nullptr) {
2415 : error = GetMemcpyConfigInfo(&cfgInfo, config, false);
2416 : COND_RETURN_AND_MSG_INNER(error != RT_ERROR_NONE, RT_ERROR_INVALID_VALUE, "Failed to get memcpyConfig.");
2417 : }
2418 :
2419 : const Runtime* const rtInstance = Runtime::Instance();
2420 : const rtChipType_t chipType = rtInstance->GetChipType();
2421 : COND_RETURN_WARN(
2422 : ((!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_MEM_MBUF_COPY)) &&
2423 : ((cfgInfo.checkBitmap == WITHOUT_CHECK_KIND) || (cfgInfo.checkBitmap == NOT_CHECK_KIND_BUT_CHECK_PINNED))),
2424 : ACL_ERROR_RT_FEATURE_NOT_SUPPORT, "Chip type(%d) does not support mbuf copy. Return.",
2425 : static_cast<int32_t>(chipType));
2426 :
2427 : COND_RETURN_AND_MSG_OUTER(
2428 : ((kind == RT_MEMCPY_KIND_DEFAULT) &&
2429 : ((cfgInfo.checkBitmap == WITHOUT_CHECK_KIND) || (cfgInfo.checkBitmap == NOT_CHECK_KIND_BUT_CHECK_PINNED))),
2430 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1011, "Synchronous memory copy", "RT_MEMCPY_KIND_DEFAULT(4)", "kind",
2431 : "When the kind check is disabled, parameter kind cannot be RT_MEMCPY_KIND_DEFAULT(4)");
2432 :
2433 : const rtMemcpyKind_t curKind = GetMemCpyKind(RT_MEMCPY_RESERVED, kind);
2434 : return MemCopySync(dst, destMax, src, cnt, curKind, cfgInfo.checkBitmap);
2435 : }
2436 :
2437 : rtError_t ApiErrorDecorator::SetMemcpyDesc(
2438 : rtMemcpyDesc_t desc, const void* const srcAddr, const void* const dstAddr, const size_t count,
2439 : const rtMemcpyKind kind, rtMemcpyConfig_t* const config)
2440 : {
2441 : COND_RETURN_WARN(
2442 : (kind != RT_MEMCPY_KIND_INNER_DEVICE_TO_DEVICE), RT_ERROR_FEATURE_NOT_SUPPORT,
2443 : "Kind should be %s, but now is %s.", "MEMCPY_KIND_INNER_DEVICE_TO_DEVICE(6)",
2444 : MemcpyNewKindToString(kind).c_str());
2445 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(srcAddr, RT_ERROR_INVALID_VALUE, "Setting the memory copy descriptor");
2446 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(dstAddr, RT_ERROR_INVALID_VALUE, "Setting the memory copy descriptor");
2447 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(desc, RT_ERROR_INVALID_VALUE, "Setting the memory copy descriptor");
2448 : COND_RETURN_AND_MSG_RESERVED_PARAM(
2449 : (config != nullptr), RT_ERROR_INVALID_VALUE, "config", "config is reserved parameter and must be null");
2450 : ZERO_RETURN_AND_MSG_OUTER(count);
2451 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2452 : (count > MAX_MEMCPY_SIZE_OF_D2D), RT_ERROR_INVALID_VALUE, "Setting the memory copy descriptor", count,
2453 : RtFmtMsg("(0, %u]", MAX_MEMCPY_SIZE_OF_D2D));
2454 : COND_RETURN_AND_MSG_OUTER(
2455 : (RtPtrToValue(desc) % 64ULL) != 0ULL, RT_ERROR_INVALID_VALUE, ErrorCode::EE1011,
2456 : "Setting the memory copy descriptor", desc, "desc", "desc is not 64-byte aligned");
2457 : rtPtrAttributes_t srcAttributes;
2458 : rtPtrAttributes_t destAttributes;
2459 : rtPtrAttributes_t descAttributes;
2460 : rtError_t error = impl_->PtrGetAttributes(desc, &descAttributes);
2461 : COND_RETURN_AND_MSG_OUTER(
2462 : error != RT_ERROR_NONE, error, ErrorCode::EE1017, "Setting the memory copy descriptor", "desc",
2463 : "Failed to get desc pointer memory attributes");
2464 :
2465 : error = impl_->PtrGetAttributes(dstAddr, &destAttributes);
2466 : COND_RETURN_AND_MSG_OUTER(
2467 : error != RT_ERROR_NONE, error, ErrorCode::EE1017, "Setting the memory copy descriptor", "dstAddr",
2468 : "Failed to get dstAddr pointer memory attributes");
2469 :
2470 : error = impl_->PtrGetAttributes(srcAddr, &srcAttributes);
2471 : COND_RETURN_AND_MSG_OUTER(
2472 : error != RT_ERROR_NONE, error, ErrorCode::EE1017, "Setting the memory copy descriptor", "srcAddr",
2473 : "Failed to get srcAddr pointer memory attributes");
2474 :
2475 : COND_RETURN_ERROR_MSG_INNER(
2476 : descAttributes.location.type != RT_MEMORY_LOC_DEVICE, RT_ERROR_INVALID_VALUE,
2477 : "rtsSetMemcpyDesc failed, desc addr type=%s is invalid!",
2478 : MemLocationTypeToString(descAttributes.location.type).c_str());
2479 :
2480 : COND_RETURN_AND_MSG_OUTER(
2481 : ((destAttributes.location.id != srcAttributes.location.id) ||
2482 : (destAttributes.location.type != RT_MEMORY_LOC_DEVICE) ||
2483 : (srcAttributes.location.type != RT_MEMORY_LOC_DEVICE)),
2484 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Setting the memory copy descriptor", "dstAddr or srcAddr",
2485 : RtFmtMsg(
2486 : "DstAddr and srcAddr do not match with the kind RT_MEMCPY_KIND_INNER_DEVICE_TO_DEVICE, "
2487 : "dstAddr DeviceId=%d, srcAddr DeviceId=%d, dstAddr type=%s, srcAddr type=%s",
2488 : destAttributes.location.id, srcAttributes.location.id,
2489 : MemLocationTypeToString(destAttributes.location.type).c_str(),
2490 : MemLocationTypeToString(srcAttributes.location.type).c_str()));
2491 :
2492 : error = impl_->SetMemcpyDesc(desc, srcAddr, dstAddr, count, kind, config);
2493 : ERROR_RETURN_MSG_INNER(error, "Failed to set memcpy desc, retCode=%#x.", static_cast<uint32_t>(error));
2494 : return error;
2495 : }
2496 :
2497 : rtError_t ApiErrorDecorator::MemcpyAsyncWithDesc(
2498 : rtMemcpyDesc_t desc, Stream* stm, const rtMemcpyKind kind, rtMemcpyConfig_t* const config)
2499 : {
2500 : COND_RETURN_WARN(
2501 : (kind != RT_MEMCPY_KIND_INNER_DEVICE_TO_DEVICE), RT_ERROR_FEATURE_NOT_SUPPORT,
2502 : "Kind should be %s, but now is %s.", "MEMCPY_KIND_INNER_DEVICE_TO_DEVICE(6)",
2503 : MemcpyNewKindToString(kind).c_str());
2504 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2505 : desc, RT_ERROR_INVALID_VALUE, "Performing asynchronous memory copy using the memory copy descriptor");
2506 : COND_RETURN_AND_MSG_RESERVED_PARAM(
2507 : (config != nullptr), RT_ERROR_INVALID_VALUE, "config", "config is reserved parameter and must be null");
2508 :
2509 : rtPtrAttributes_t descAttributes;
2510 : const rtError_t error = impl_->PtrGetAttributes(desc, &descAttributes);
2511 : COND_RETURN_ERROR_MSG_INNER(
2512 : error != RT_ERROR_NONE, error, "Get desc pointer attributes failed, retCode=%#x.",
2513 : static_cast<uint32_t>(error));
2514 : COND_RETURN_ERROR_MSG_INNER(
2515 : descAttributes.location.type != RT_MEMORY_LOC_DEVICE, RT_ERROR_INVALID_VALUE,
2516 : "rtsMemcpyAsyncWithDesc failed, desc addr type=%s is invalid!",
2517 : MemLocationTypeToString(descAttributes.location.type).c_str());
2518 :
2519 : rtTaskCfgInfo_t cfgInfo = {};
2520 : (void)memset_s(&cfgInfo, sizeof(rtTaskCfgInfo_t), 0, sizeof(rtTaskCfgInfo_t));
2521 :
2522 : return MemcpyAsyncPtr(reinterpret_cast<rtMemcpyAddrInfo*>(desc), UINT32_MAX, UINT32_MAX, stm, &cfgInfo, true);
2523 : }
2524 :
2525 : rtError_t ApiErrorDecorator::GetDevArgsAddr(Stream* stm, rtArgsEx_t* argsInfo, void** devArgsAddr, void** argsHandle)
2526 : {
2527 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
2528 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(curStm, RT_ERROR_INVALID_VALUE, "Obtaining the device parameter address");
2529 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2530 : argsInfo, RT_ERROR_INVALID_VALUE, "Obtaining the device parameter address");
2531 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2532 : devArgsAddr, RT_ERROR_INVALID_VALUE, "Obtaining the device parameter address");
2533 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2534 : argsHandle, RT_ERROR_INVALID_VALUE, "Obtaining the device parameter address");
2535 : const rtError_t error = impl_->GetDevArgsAddr(curStm, argsInfo, devArgsAddr, argsHandle);
2536 : ERROR_RETURN_MSG_INNER(error, "GetDevArgsAddr failed, stream_id=%d.", curStm->Id_());
2537 : return error;
2538 : }
2539 :
2540 : rtError_t ApiErrorDecorator::MemcpyAsyncCheckParam(const rtMemcpyKind_t kind, const Stream* const stm) const
2541 : {
2542 : if ((kind == RT_MEMCPY_HOST_TO_DEVICE_EX) || (kind == RT_MEMCPY_DEVICE_TO_HOST_EX)) {
2543 : if (stm != nullptr) {
2544 : COND_RETURN_AND_MSG_OUTER(
2545 : stm->IsModelStream(), RT_ERROR_INVALID_VALUE, ErrorCode::EE1016,
2546 : "Checking asynchronous memory copy parameters",
2547 : RtFmtMsg(
2548 : "If the stream is a model stream,"
2549 : " the memcpy kind %s is not supported",
2550 : MemcpyKindToStr(kind)));
2551 : }
2552 : }
2553 : return RT_ERROR_NONE;
2554 : }
2555 :
2556 : rtError_t ApiErrorDecorator::MemcpyAsyncCheckAddrCfg(
2557 : const uint64_t destMax, const uint64_t cnt, const rtD2DAddrCfgInfo_t* const addrCfg) const
2558 : {
2559 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
2560 : addrCfg->srcOffset > 0xFFFFFFFFFFFFUL, RT_ERROR_INVALID_VALUE, addrCfg->srcOffset,
2561 : "less than or equal to 0xFFFFFFFFFFFFUL");
2562 :
2563 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
2564 : addrCfg->dstOffset > 0xFFFFFFFFFFFFUL, RT_ERROR_INVALID_VALUE, addrCfg->dstOffset,
2565 : "less than or equal to 0xFFFFFFFFFFFFUL");
2566 :
2567 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
2568 : addrCfg->dstOffset >= destMax, RT_ERROR_INVALID_VALUE, addrCfg->dstOffset,
2569 : "[0, " + std::to_string(destMax) + ")");
2570 :
2571 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
2572 : cnt > (destMax - addrCfg->dstOffset), RT_ERROR_INVALID_VALUE, cnt,
2573 : "(0, " + std::to_string(destMax - addrCfg->dstOffset) + "]");
2574 : return RT_ERROR_NONE;
2575 : }
2576 :
2577 : rtError_t ApiErrorDecorator::GetLocationType(
2578 : const void* const src, const void* const dst, rtMemLocationType& srcLocationType,
2579 : rtMemLocationType& srcRealLocation, rtMemLocationType& dstLocationType, rtMemLocationType& dstRealLocation) const
2580 : {
2581 : rtError_t error = RT_ERROR_NONE;
2582 : Context* curCtx = Runtime::Instance()->CurrentContext();
2583 : CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL);
2584 : NULL_PTR_RETURN_MSG(curCtx->Device_(), RT_ERROR_DEVICE_NULL);
2585 :
2586 : error = curCtx->Device_()->Driver_()->PtrGetRealLocation(src, srcLocationType, srcRealLocation);
2587 : if (error == RT_ERROR_NONE) {
2588 : error = curCtx->Device_()->Driver_()->PtrGetRealLocation(dst, dstLocationType, dstRealLocation);
2589 : } /* 在调用者打印异常信息 */
2590 : return error;
2591 : }
2592 :
2593 : // Helper inline function: check if vector contains element
2594 : static inline bool contains(const std::vector<rtMemcpyKind_t>& v, rtMemcpyKind_t k)
2595 : {
2596 : return std::find(v.begin(), v.end(), k) != v.end();
2597 : }
2598 :
2599 : // helper: convert allowedKinds to comma list string (for logs)
2600 : static std::string allowed_list_to_string(const std::vector<rtMemcpyKind_t>& v)
2601 : {
2602 : if (v.empty()) {
2603 : return "{}";
2604 : }
2605 : std::ostringstream oss;
2606 : oss << "{";
2607 : for (size_t i = 0; i < v.size(); ++i) {
2608 : oss << static_cast<int32_t>(v[i]);
2609 : if (i + 1U < v.size()) {
2610 : oss << ", ";
2611 : }
2612 : }
2613 : oss << "}";
2614 : return oss.str();
2615 : }
2616 :
2617 : // ===============================================
2618 : // Define Key Structure for Hash Map Lookup
2619 : // ===============================================
2620 : class MemcpyKindKey {
2621 : public:
2622 : rtMemLocationType src;
2623 : rtMemLocationType dst;
2624 : };
2625 :
2626 : static bool operator==(MemcpyKindKey lhs, MemcpyKindKey rhs) noexcept
2627 : {
2628 : return lhs.src == rhs.src && lhs.dst == rhs.dst;
2629 : }
2630 :
2631 : // ===============================================
2632 : // Define Hash Function for MemcpyKindKey
2633 : // ===============================================
2634 : // ===== hash (single consistent implementation) =====
2635 : class MemcpyKindKeyHash {
2636 : public:
2637 : std::size_t operator()(MemcpyKindKey k) const noexcept
2638 : {
2639 : // combine two small enums into a size_t deterministically
2640 : // shift by 8 bits is safe because enum values are small
2641 : return (static_cast<std::size_t>(k.src) << 8U) | static_cast<std::size_t>(k.dst);
2642 : }
2643 : };
2644 :
2645 : // ===== rule struct (as you requested) =====
2646 : // - expectKind == RT_MEMCPY_RESERVED -> no forced override
2647 : // - allowedKinds: allowed incoming kinds when not forced (include RT_MEMCPY_DEFAULT if allowed)
2648 : // - defaultKind: what to set when incoming is RT_MEMCPY_DEFAULT
2649 : class MemcpyKindReviseRule {
2650 : public:
2651 : rtMemcpyKind_t expectKind;
2652 : std::vector<rtMemcpyKind_t> allowedKinds;
2653 : rtMemcpyKind_t defaultKind;
2654 : // Constructor for MemcpyKindReviseRule
2655 : MemcpyKindReviseRule(
2656 : rtMemcpyKind_t expectKind_, const std::vector<rtMemcpyKind_t>& allowedKinds_, rtMemcpyKind_t defaultKind_)
2657 : : expectKind(expectKind_), allowedKinds(allowedKinds_), defaultKind(defaultKind_)
2658 : {}
2659 : };
2660 :
2661 : static const std::unordered_map<MemcpyKindKey, MemcpyKindReviseRule, MemcpyKindKeyHash> MemcpyKindReviseMap = {
2662 : // 1. Host -> Device
2663 : {MemcpyKindKey{RT_MEMORY_LOC_HOST, RT_MEMORY_LOC_DEVICE},
2664 : MemcpyKindReviseRule{RT_MEMCPY_HOST_TO_DEVICE, {}, RT_MEMCPY_HOST_TO_DEVICE}},
2665 :
2666 : // 2. Device -> Host
2667 : {MemcpyKindKey{RT_MEMORY_LOC_DEVICE, RT_MEMORY_LOC_HOST},
2668 : MemcpyKindReviseRule{RT_MEMCPY_DEVICE_TO_HOST, {}, RT_MEMCPY_DEVICE_TO_HOST}},
2669 :
2670 : // 3. Host -> Host
2671 : {MemcpyKindKey{RT_MEMORY_LOC_HOST, RT_MEMORY_LOC_HOST},
2672 : MemcpyKindReviseRule{RT_MEMCPY_HOST_TO_HOST, {}, RT_MEMCPY_HOST_TO_HOST}},
2673 :
2674 : // 4. Device -> Device
2675 : {MemcpyKindKey{RT_MEMORY_LOC_DEVICE, RT_MEMORY_LOC_DEVICE},
2676 : MemcpyKindReviseRule{RT_MEMCPY_DEVICE_TO_DEVICE, {}, RT_MEMCPY_DEVICE_TO_DEVICE}},
2677 :
2678 : // 5. Unregistered -> Device
2679 : {MemcpyKindKey{RT_MEMORY_LOC_UNREGISTERED, RT_MEMORY_LOC_DEVICE},
2680 : MemcpyKindReviseRule{
2681 : RT_MEMCPY_RESERVED, {RT_MEMCPY_HOST_TO_DEVICE, RT_MEMCPY_DEVICE_TO_DEVICE}, RT_MEMCPY_HOST_TO_DEVICE}},
2682 :
2683 : // 6. Device -> Unregistered
2684 : {MemcpyKindKey{RT_MEMORY_LOC_DEVICE, RT_MEMORY_LOC_UNREGISTERED},
2685 : MemcpyKindReviseRule{
2686 : RT_MEMCPY_RESERVED, {RT_MEMCPY_DEVICE_TO_HOST, RT_MEMCPY_DEVICE_TO_DEVICE}, RT_MEMCPY_DEVICE_TO_HOST}},
2687 :
2688 : // 7. Host -> Unregistered
2689 : {MemcpyKindKey{RT_MEMORY_LOC_HOST, RT_MEMORY_LOC_UNREGISTERED},
2690 : MemcpyKindReviseRule{
2691 : RT_MEMCPY_RESERVED, {RT_MEMCPY_HOST_TO_HOST, RT_MEMCPY_HOST_TO_DEVICE}, RT_MEMCPY_HOST_TO_HOST}},
2692 :
2693 : // 8. Unregistered -> Host
2694 : {MemcpyKindKey{RT_MEMORY_LOC_UNREGISTERED, RT_MEMORY_LOC_HOST},
2695 : MemcpyKindReviseRule{
2696 : RT_MEMCPY_RESERVED, {RT_MEMCPY_HOST_TO_HOST, RT_MEMCPY_DEVICE_TO_HOST}, RT_MEMCPY_HOST_TO_HOST}},
2697 :
2698 : // 9. Unregistered -> Unregistered
2699 : {MemcpyKindKey{RT_MEMORY_LOC_UNREGISTERED, RT_MEMORY_LOC_UNREGISTERED},
2700 : MemcpyKindReviseRule{
2701 : RT_MEMCPY_RESERVED,
2702 : {RT_MEMCPY_HOST_TO_HOST, RT_MEMCPY_HOST_TO_DEVICE, RT_MEMCPY_DEVICE_TO_HOST, RT_MEMCPY_DEVICE_TO_DEVICE},
2703 : RT_MEMCPY_HOST_TO_HOST}}};
2704 :
2705 : rtError_t ApiErrorDecorator::MemcpyKindAutoCorrect(
2706 : const rtMemLocationType srcLocationType, const rtMemLocationType dstLocationType, rtMemcpyKind_t* kind) const
2707 : {
2708 : if (*kind != RT_MEMCPY_HOST_TO_HOST && *kind != RT_MEMCPY_HOST_TO_DEVICE && *kind != RT_MEMCPY_DEVICE_TO_HOST &&
2709 : *kind != RT_MEMCPY_DEVICE_TO_DEVICE && *kind != RT_MEMCPY_DEFAULT) {
2710 : return RT_ERROR_NONE;
2711 : }
2712 : MemcpyKindKey key{srcLocationType, dstLocationType};
2713 : auto it = MemcpyKindReviseMap.find(key);
2714 : if (it == MemcpyKindReviseMap.end()) {
2715 : // Uncovered combinations: return success, kind unchanged.
2716 : RT_LOG(
2717 : RT_LOG_INFO, "MemcpyKindAutoCorrect: undefined memory combination src=%s, dst=%s, kind=%s.",
2718 : MemLocationTypeToString(srcLocationType).c_str(), MemLocationTypeToString(dstLocationType).c_str(),
2719 : MemcpyKindToStr(*kind));
2720 : return RT_ERROR_NONE;
2721 : }
2722 : const MemcpyKindReviseRule& rule = it->second;
2723 : // 1) Forced mapping (expectKind != RT_MEMCPY_RESERVED)
2724 : if (rule.expectKind != RT_MEMCPY_RESERVED) {
2725 : if (*kind != rule.expectKind) {
2726 : RT_LOG(
2727 : RT_LOG_INFO, "MemcpyKindAutoCorrect: kind changed from %s to %s for src=%s, dst=%s.",
2728 : std::string(MemcpyKindToStr(*kind)).c_str(), std::string(MemcpyKindToStr(rule.expectKind)).c_str(),
2729 : MemLocationTypeToString(srcLocationType).c_str(), MemLocationTypeToString(dstLocationType).c_str());
2730 : *kind = rule.expectKind;
2731 : }
2732 : return RT_ERROR_NONE;
2733 : }
2734 : // 2) If incoming is DEFAULT -> replace with defaultKind
2735 : if (*kind == RT_MEMCPY_DEFAULT) {
2736 : RT_LOG(
2737 : RT_LOG_INFO, "MemcpyKindAutoCorrect: kind changed from %s to %s for src=%s, dst=%s (default case).",
2738 : std::string(MemcpyKindToStr(*kind)).c_str(), std::string(MemcpyKindToStr(rule.defaultKind)).c_str(),
2739 : MemLocationTypeToString(srcLocationType).c_str(), MemLocationTypeToString(dstLocationType).c_str());
2740 : *kind = rule.defaultKind;
2741 : return RT_ERROR_NONE;
2742 : }
2743 : // 3) If kind is in allowedKinds -> accept
2744 : if (contains(rule.allowedKinds, *kind)) {
2745 : return RT_ERROR_NONE;
2746 : }
2747 : // 4) Otherwise illegal -> log expected set and return error
2748 : std::string expected = allowed_list_to_string(rule.allowedKinds);
2749 : RT_LOG(
2750 : RT_LOG_ERROR, "MemcpyKindAutoCorrect: invalid kind=%s for src=%s, dst=%s; expected one of [%s], actual=%s.",
2751 : MemcpyKindToStr(*kind), MemLocationTypeToString(srcLocationType).c_str(),
2752 : MemLocationTypeToString(dstLocationType).c_str(), expected.c_str(), MemcpyKindToStr(*kind));
2753 : return RT_ERROR_INVALID_VALUE;
2754 : }
2755 :
2756 : static bool JudgeIsInvolvePageableMemory(
2757 : bool checkKind, const rtMemcpyKind_t kind, rtMemLocationType srcLocationType, rtMemLocationType dstLocationType)
2758 : {
2759 : /*
2760 : * 当device内存为mbuf(不是从svm申请)时,drvMemGetAttribute会返回为host内存,转化为同步拷贝后底软会异常
2761 : * 使用mbuf的场景:checkKind = false
2762 : */
2763 : if (checkKind && (kind != RT_MEMCPY_HOST_TO_HOST) && (kind != RT_MEMCPY_DEVICE_TO_DEVICE) &&
2764 : (kind != RT_MEMCPY_ADDR_DEVICE_TO_DEVICE) &&
2765 : ((srcLocationType == RT_MEMORY_LOC_UNREGISTERED) || (dstLocationType == RT_MEMORY_LOC_UNREGISTERED))) {
2766 : return true;
2767 : }
2768 :
2769 : return false;
2770 : }
2771 :
2772 : rtError_t ApiErrorDecorator::MemcpyAsyncCheckLocation(
2773 : bool checkKind, rtMemcpyKind_t& copyKind, const void* const src, const void* const dst,
2774 : bool isUserRequireToCheckPinnedMem, bool& isD2HorH2DInvolvePageableMemory) const
2775 : {
2776 : Context* curCtx = Runtime::Instance()->CurrentContext();
2777 : CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL);
2778 : NULL_PTR_RETURN_MSG(curCtx->Device_(), RT_ERROR_DEVICE_NULL);
2779 : const bool isSupportUserMem = curCtx->Device_()->IsSupportUserMem();
2780 : if (!isSupportUserMem) {
2781 : if (isUserRequireToCheckPinnedMem) {
2782 : /* 用户指定CHECK_MEMORY_PINNED,如果驱动不支持GET_USER_MALLOC_ATTR,则返回特性不支持 */
2783 : ERROR_RETURN(
2784 : RT_ERROR_FEATURE_NOT_SUPPORT, "Failed to check pinned memory required by the user because the "
2785 : "GET_USER_MALLOC_ATTR feature is not supported.");
2786 : } else {
2787 : /*
2788 : * 用户未指定CHECK_MEMORY_PINNED,如果驱动不支持GET_USER_MALLOC_ATTR,则打印Info,流程继续。
2789 : * 如果用GetLocationType获取new/malloc内存的Location,drvMemGetAttribute会报错;因此无法校验该场景的Location。
2790 : */
2791 : RT_LOG(RT_LOG_INFO, "GET_USER_MALLOC_ATTR is not supported. Continue.");
2792 : return RT_ERROR_NONE;
2793 : }
2794 : }
2795 :
2796 : rtError_t error = RT_ERROR_NONE;
2797 : const rtMemcpyKind_t kind = copyKind;
2798 :
2799 : /* 1) get location type of src and dst ptr */
2800 : rtMemLocationType srcLocationType = RT_MEMORY_LOC_MAX;
2801 : rtMemLocationType dstLocationType = RT_MEMORY_LOC_MAX;
2802 : rtMemLocationType srcRealLocation = RT_MEMORY_LOC_MAX;
2803 : rtMemLocationType dstRealLocation = RT_MEMORY_LOC_MAX;
2804 : error = GetLocationType(src, dst, srcLocationType, srcRealLocation, dstLocationType, dstRealLocation);
2805 : COND_RETURN_ERROR_MSG_CALL(
2806 : ERR_MODULE_DRV, error != RT_ERROR_NONE, error, "GetLocationType Failed, retCode=%#x, src=%p, dst=%p",
2807 : static_cast<uint32_t>(error), src, dst);
2808 :
2809 : /* 2) check memory copy kind and real location */
2810 : const uint32_t runMode = curCtx->Device_()->Driver_()->GetRunMode();
2811 : if ((checkKind) && (runMode == RT_RUN_MODE_ONLINE)) {
2812 : error = MemcpyKindAutoCorrect(srcLocationType, dstLocationType, ©Kind);
2813 : COND_RETURN_ERROR_MSG_CALL(
2814 : ERR_MODULE_GE, error != RT_ERROR_NONE, error,
2815 : "Memory async check kind and loc failed, retCode=%#x, copyKind=%s, srcLoc=%s, dstLoc=%s",
2816 : static_cast<uint32_t>(error), MemcpyKindToStr(copyKind), MemLocationTypeToString(srcLocationType).c_str(),
2817 : MemLocationTypeToString(dstLocationType).c_str());
2818 : }
2819 :
2820 : /* 3) check whether involve pageable host memory */
2821 : isD2HorH2DInvolvePageableMemory =
2822 : JudgeIsInvolvePageableMemory(checkKind, copyKind, srcLocationType, dstLocationType);
2823 :
2824 : RT_LOG(
2825 : RT_LOG_INFO,
2826 : "kind=%s, checkKind= %d, copyKind=%s, srcLocType=%s, srcRealLocType=%s, dstLocType=%s, "
2827 : "dstRealLocType=%s, isSupportUserMem=%d, isD2HorH2DInvolvePageableMemory=%d.",
2828 : std::string(MemcpyKindToStr(kind)).c_str(), checkKind, std::string(MemcpyKindToStr(copyKind)).c_str(),
2829 : MemLocationTypeToString(srcLocationType).c_str(), MemLocationTypeToString(srcRealLocation).c_str(),
2830 : MemLocationTypeToString(dstLocationType).c_str(), MemLocationTypeToString(dstRealLocation).c_str(),
2831 : isSupportUserMem, isD2HorH2DInvolvePageableMemory);
2832 :
2833 : return error;
2834 : }
2835 :
2836 : rtError_t ApiErrorDecorator::MemcpyKindAutoUpdate(
2837 : const rtMemLocationType srcType, const rtMemLocationType dstType, rtMemcpyKind_t* kind) const
2838 : {
2839 : // registered memory should be treated as host memory
2840 : if ((srcType == RT_MEMORY_LOC_HOST)) {
2841 : if (dstType == RT_MEMORY_LOC_HOST) {
2842 : *kind = RT_MEMCPY_HOST_TO_HOST;
2843 : } else {
2844 : *kind = RT_MEMCPY_HOST_TO_DEVICE;
2845 : }
2846 : } else {
2847 : if (dstType == RT_MEMORY_LOC_HOST) {
2848 : *kind = RT_MEMCPY_DEVICE_TO_HOST;
2849 : } else {
2850 : *kind = RT_MEMCPY_DEVICE_TO_DEVICE;
2851 : }
2852 : }
2853 : RT_LOG(
2854 : RT_LOG_DEBUG, "auto infer copy srcType=%s, dstType=%s, dir=%s", MemLocationTypeToString(srcType).c_str(),
2855 : MemLocationTypeToString(dstType).c_str(), MemcpyKindToStr(*kind));
2856 : return RT_ERROR_NONE;
2857 : }
2858 :
2859 : rtError_t ApiErrorDecorator::ReduceAsync(
2860 : void* const dst, const void* const src, const uint64_t cnt, const rtRecudeKind_t kind, const rtDataType_t type,
2861 : Stream* const stm, const rtTaskCfgInfo_t* const cfgInfo)
2862 : {
2863 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2864 : dst, RT_ERROR_INVALID_VALUE, "Asynchronously performing the Reduce operation");
2865 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2866 : src, RT_ERROR_INVALID_VALUE, "Asynchronously performing the Reduce operation");
2867 : ZERO_RETURN_AND_MSG_OUTER(cnt);
2868 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2869 : (kind >= RT_RECUDE_KIND_END) || (kind < RT_MEMCPY_SDMA_AUTOMATIC_ADD), RT_ERROR_INVALID_VALUE,
2870 : "Asynchronously performing the Reduce operation", kind,
2871 : RtFmtMsg("[%u, %u)", RT_MEMCPY_SDMA_AUTOMATIC_ADD, RT_RECUDE_KIND_END));
2872 : COND_RETURN_AND_MSG_OUTER(
2873 : (kind == RT_MEMCPY_SDMA_AUTOMATIC_ADD) && (cnt > MAX_MEMCPY_SIZE_OF_D2D), RT_ERROR_INVALID_VALUE,
2874 : ErrorCode::EE1011, "Asynchronously performing the Reduce operation", cnt, "cnt",
2875 : RtFmtMsg(
2876 : "If parameter kind equals RT_MEMCPY_SDMA_AUTOMATIC_ADD(10), the range of parameter cnt should be (0, %u]",
2877 : MAX_MEMCPY_SIZE_OF_D2D));
2878 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2879 : (type >= RT_DATA_TYPE_END) || (type < RT_DATA_TYPE_FP32), RT_ERROR_INVALID_VALUE,
2880 : "Asynchronously performing the Reduce operation", type,
2881 : "[" + std::to_string(RT_DATA_TYPE_FP32) + ", " + std::to_string(RT_DATA_TYPE_END) + ")");
2882 :
2883 : const rtError_t error = impl_->ReduceAsync(dst, src, cnt, kind, type, stm, cfgInfo);
2884 : ERROR_RETURN(error, "Reduce async failed, count=%" PRIu64 ", kind=%s.", cnt, ReduceKindToString(kind).c_str());
2885 : return error;
2886 : }
2887 :
2888 : rtError_t ApiErrorDecorator::ReduceAsyncV2(
2889 : void* const dst, const void* const src, const uint64_t cnt, const rtRecudeKind_t kind, const rtDataType_t type,
2890 : Stream* const stm, void* const overflowAddr)
2891 : {
2892 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2893 : dst, RT_ERROR_INVALID_VALUE, "Asynchronously performing the Reduce operation");
2894 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2895 : src, RT_ERROR_INVALID_VALUE, "Asynchronously performing the Reduce operation");
2896 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2897 : overflowAddr, RT_ERROR_INVALID_VALUE, "Asynchronously performing the Reduce operation");
2898 : ZERO_RETURN_AND_MSG_OUTER(cnt);
2899 1 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_DESC(
2900 : (kind != RT_MEMCPY_SDMA_AUTOMATIC_ADD), RT_ERROR_INVALID_VALUE,
2901 : "Asynchronously performing the Reduce operation", ReduceKindToString(kind), "kind",
2902 : ReduceKindToString(RT_MEMCPY_SDMA_AUTOMATIC_ADD));
2903 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2904 : (cnt > MAX_MEMCPY_SIZE_OF_D2D), RT_ERROR_INVALID_VALUE, "Asynchronously performing the Reduce operation", cnt,
2905 : "(0, " + std::to_string(MAX_MEMCPY_SIZE_OF_D2D) + "]");
2906 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2907 : (type >= RT_DATA_TYPE_END) || (type < RT_DATA_TYPE_FP32), RT_ERROR_INVALID_VALUE,
2908 : "Asynchronously performing the Reduce operation", type,
2909 : "[" + std::to_string(RT_DATA_TYPE_FP32) + ", " + std::to_string(RT_DATA_TYPE_END) + ")");
2910 :
2911 : const rtError_t error = impl_->ReduceAsyncV2(dst, src, cnt, kind, type, stm, overflowAddr);
2912 : ERROR_RETURN(error, "Reduce async v2 failed, count=%" PRIu64 ", kind=%s.", cnt, ReduceKindToString(kind).c_str());
2913 : return error;
2914 : }
2915 :
2916 : rtMemcpyKind_t ApiErrorDecorator::GetMemCpyKind(const rtMemcpyKind_t kind, const rtMemcpyKind newKind) const
2917 : {
2918 : if (newKind == RT_MEMCPY_KIND_MAX) { // 如果新枚举没传或者传的是最大值,则使用老枚举
2919 : return kind;
2920 : }
2921 :
2922 : static const std::unordered_map<rtMemcpyKind, rtMemcpyKind_t> KIND_MAP = {
2923 : {RT_MEMCPY_KIND_HOST_TO_HOST, RT_MEMCPY_HOST_TO_HOST},
2924 : {RT_MEMCPY_KIND_HOST_TO_DEVICE, RT_MEMCPY_HOST_TO_DEVICE},
2925 : {RT_MEMCPY_KIND_DEVICE_TO_HOST, RT_MEMCPY_DEVICE_TO_HOST},
2926 : {RT_MEMCPY_KIND_DEVICE_TO_DEVICE, RT_MEMCPY_DEVICE_TO_DEVICE},
2927 : {RT_MEMCPY_KIND_DEFAULT, RT_MEMCPY_DEFAULT},
2928 : {RT_MEMCPY_KIND_HOST_TO_BUF_TO_DEVICE, RT_MEMCPY_HOST_TO_DEVICE_EX},
2929 : {RT_MEMCPY_KIND_INNER_DEVICE_TO_DEVICE, RT_MEMCPY_DEVICE_TO_DEVICE},
2930 : {RT_MEMCPY_KIND_INTER_DEVICE_TO_DEVICE, RT_MEMCPY_DEVICE_TO_DEVICE},
2931 : {RT_MEMCPY_KIND_MAX, RT_MEMCPY_RESERVED}};
2932 : const auto iter = KIND_MAP.find(newKind);
2933 : if (iter != KIND_MAP.end()) {
2934 : return iter->second;
2935 : } else {
2936 : return RT_MEMCPY_RESERVED;
2937 : }
2938 : }
2939 :
2940 : rtError_t ApiErrorDecorator::MemCopy2DCheckParam(
2941 : const void* const dst, const uint64_t dstPitch, const void* const src, const uint64_t srcPitch,
2942 : const uint64_t width, const uint64_t height, const rtMemcpyKind_t kind) const
2943 : {
2944 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2945 : dst, RT_ERROR_INVALID_VALUE, "Checking the validity of 2D memory copy parameters");
2946 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
2947 : src, RT_ERROR_INVALID_VALUE, "Checking the validity of 2D memory copy parameters");
2948 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2949 : height == 0U, RT_ERROR_INVALID_VALUE, "Checking the validity of 2D memory copy parameters", height,
2950 : "greater than 0");
2951 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2952 : dstPitch == 0U, RT_ERROR_INVALID_VALUE, "Checking the validity of 2D memory copy parameters", dstPitch,
2953 : "greater than 0");
2954 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2955 : srcPitch == 0U, RT_ERROR_INVALID_VALUE, "Checking the validity of 2D memory copy parameters", srcPitch,
2956 : "greater than 0");
2957 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2958 : width == 0U, RT_ERROR_INVALID_VALUE, "Checking the validity of 2D memory copy parameters", width,
2959 : "greater than 0");
2960 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2961 : (width > dstPitch), RT_ERROR_INVALID_VALUE, "Checking the validity of 2D memory copy parameters", width,
2962 : "less than or equal to dstPitch");
2963 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2964 : (width > srcPitch), RT_ERROR_INVALID_VALUE, "Checking the validity of 2D memory copy parameters", width,
2965 : "less than or equal to srcPitch");
2966 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2967 : height > RT_MAX_MEMCPY2D_HEIGHT, RT_ERROR_INVALID_VALUE, "Checking the validity of 2D memory copy parameters",
2968 : height, "less than or equal to " + std::to_string(RT_MAX_MEMCPY2D_HEIGHT));
2969 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
2970 : width > RT_MAX_MEMCPY2D_WIDTH, RT_ERROR_INVALID_VALUE, "Checking the validity of 2D memory copy parameters",
2971 : width, "less than or equal to " + std::to_string(RT_MAX_MEMCPY2D_WIDTH));
2972 : COND_RETURN_WARN(
2973 : ((kind != RT_MEMCPY_DEFAULT) && (kind != RT_MEMCPY_HOST_TO_DEVICE) && (kind != RT_MEMCPY_DEVICE_TO_HOST) &&
2974 : (kind != RT_MEMCPY_DEVICE_TO_DEVICE)),
2975 : RT_ERROR_FEATURE_NOT_SUPPORT,
2976 : "This memcpy2d feature supports only host2device, device2host, or device2device kinds.");
2977 :
2978 : return RT_ERROR_NONE;
2979 : }
2980 :
2981 : rtError_t ApiErrorDecorator::MemCopy2DSync(
2982 : void* const dst, const uint64_t dstPitch, const void* const src, const uint64_t srcPitch, const uint64_t width,
2983 : const uint64_t height, const rtMemcpyKind_t kind, const rtMemcpyKind newKind)
2984 : {
2985 : const auto curKind = GetMemCpyKind(kind, newKind);
2986 : rtError_t error = MemCopy2DCheckParam(dst, dstPitch, src, srcPitch, width, height, curKind);
2987 : ERROR_RETURN_MSG_CALL(
2988 : ERR_MODULE_GE, error, "check memcpy2d param failure, retCode=%#x.", static_cast<uint32_t>(error));
2989 : COND_RETURN_WARN(
2990 : ((curKind != RT_MEMCPY_DEFAULT) && (curKind != RT_MEMCPY_HOST_TO_DEVICE) &&
2991 : (curKind != RT_MEMCPY_DEVICE_TO_HOST)),
2992 : RT_ERROR_FEATURE_NOT_SUPPORT, "This memcpy2d feature supports only host2device or device2host kinds.");
2993 : rtMemcpyKind_t copyKind = curKind;
2994 : rtMemLocationType srcLocationType = RT_MEMORY_LOC_MAX;
2995 : rtMemLocationType dstLocationType = RT_MEMORY_LOC_MAX;
2996 : rtMemLocationType srcRealLocation = RT_MEMORY_LOC_MAX;
2997 : rtMemLocationType dstRealLocation = RT_MEMORY_LOC_MAX;
2998 : error = GetLocationType(src, dst, srcLocationType, srcRealLocation, dstLocationType, dstRealLocation);
2999 : COND_RETURN_ERROR_MSG_CALL(
3000 : ERR_MODULE_DRV, error != RT_ERROR_NONE, error, "GetLocationType Failed, retCode=%#x, src=%p, dst=%p",
3001 : static_cast<uint32_t>(error), src, dst);
3002 :
3003 : /* MemcpyKindAutoUpdate需使用realLocation */
3004 : error = MemcpyKindAutoCorrect(srcLocationType, dstLocationType, ©Kind);
3005 : COND_PROC_RETURN_AND_MSG_OUTER(
3006 : (error != RT_ERROR_NONE) || ((copyKind != RT_MEMCPY_HOST_TO_DEVICE) && (copyKind != RT_MEMCPY_DEVICE_TO_HOST)),
3007 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
3008 : RT_LOG(
3009 : RT_LOG_ERROR, "srcLocType=%s, srcRealLocType=%s, dstLocType=%s, dstRealLocType=%s.",
3010 : MemLocationTypeToString(srcLocationType).c_str(), MemLocationTypeToString(srcRealLocation).c_str(),
3011 : MemLocationTypeToString(dstLocationType).c_str(), MemLocationTypeToString(dstRealLocation).c_str()),
3012 : __func__, "kind or newKind",
3013 : RtFmtMsg(
3014 : "Memcpy2dSync supports only H2D or D2H. Parameter kind is %s, and newKind is %s", MemcpyKindToStr(kind),
3015 : MemcpyNewKindToString(newKind).c_str()));
3016 : error = impl_->MemCopy2DSync(dst, dstPitch, src, srcPitch, width, height, copyKind);
3017 : ERROR_RETURN(
3018 : error,
3019 : "Memcpy2d sync failed, dstPitch=%" PRIu64 ", srcPitch=%" PRIu64 ", width=%" PRIu64 ", height=%" PRIu64
3020 : ", kind=%s",
3021 : dstPitch, srcPitch, width, height, MemcpyKindToStr(copyKind));
3022 : return error;
3023 : }
3024 :
3025 : rtError_t ApiErrorDecorator::MemCopy2DAsync(
3026 : void* const dst, const uint64_t dstPitch, const void* const src, const uint64_t srcPitch, const uint64_t width,
3027 : const uint64_t height, Stream* const stm, const rtMemcpyKind_t kind, const rtMemcpyKind newKind)
3028 : {
3029 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
3030 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(curStm, RT_ERROR_INVALID_VALUE, "Asynchronous 2D memory copy");
3031 : rtMemcpyKind_t copyKind = GetMemCpyKind(kind, newKind);
3032 : rtError_t error = MemCopy2DCheckParam(dst, dstPitch, src, srcPitch, width, height, copyKind);
3033 : COND_RETURN_WITH_NOLOG(error == RT_ERROR_FEATURE_NOT_SUPPORT, RT_ERROR_FEATURE_NOT_SUPPORT);
3034 : ERROR_RETURN_MSG_CALL(
3035 : ERR_MODULE_GE, error, "check memcpy2d param failure, retCode=%#x.", static_cast<uint32_t>(error));
3036 :
3037 : bool isD2HorH2DInvolvePageableMemory = false;
3038 : error =
3039 : MemcpyAsyncCheckLocation(true, copyKind, src, dst, false, isD2HorH2DInvolvePageableMemory); /* 会更新copykind */
3040 : COND_RETURN_ERROR_MSG_INNER(
3041 : error != RT_ERROR_NONE, error, "MemcpyAsync check src or dst location failed, stream_id=%d.", curStm->Id_());
3042 : COND_RETURN_AND_MSG_OUTER(
3043 : (error != RT_ERROR_NONE) || ((copyKind != RT_MEMCPY_HOST_TO_DEVICE) && (copyKind != RT_MEMCPY_DEVICE_TO_HOST) &&
3044 : (copyKind != RT_MEMCPY_DEVICE_TO_DEVICE)),
3045 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Asynchronous 2D memory copy", "kind or newKind",
3046 : RtFmtMsg(
3047 : "Memcpy2dAsync supports only H2D, D2H, or D2D. Parameter kind is %s, and reviseKind is %s",
3048 : std::string(MemcpyKindToStr(kind)).c_str(), std::string(MemcpyKindToStr(copyKind)).c_str()));
3049 :
3050 : COND_RETURN_WARN(
3051 : ((copyKind != RT_MEMCPY_HOST_TO_DEVICE) && (copyKind != RT_MEMCPY_DEVICE_TO_HOST) &&
3052 : (copyKind != RT_MEMCPY_DEVICE_TO_DEVICE)),
3053 : RT_ERROR_FEATURE_NOT_SUPPORT, "Only H2D, D2H, or D2D are supported");
3054 :
3055 : COND_RETURN_WARN(
3056 : IsUbDmaWithSubModel(stm, kind, src, dst), RT_ERROR_FEATURE_NOT_SUPPORT,
3057 : "stream belongs to sub ACL Graph, does not support asynchronous memory copy.");
3058 : if (isD2HorH2DInvolvePageableMemory) {
3059 : COND_RETURN_AND_MSG_OUTER(
3060 : curStm->IsCapturing(), RT_ERROR_INVALID_VALUE, ErrorCode::EE1016, "Asynchronous 2D memory copy task",
3061 : "The pageable memory copy task does not support graph capture");
3062 : /* 把异步拷贝转化为隐式流同步 + 同步拷贝,以避免异步访问pageable内存引起的PA异常 */
3063 : error = StreamSynchronize(curStm, -1);
3064 : COND_RETURN_ERROR(error != RT_ERROR_NONE, error, "StreamSynchronize failed, stream_id=%d.", curStm->Id_());
3065 :
3066 : error = impl_->MemCopy2DSync(dst, dstPitch, src, srcPitch, width, height, copyKind, newKind);
3067 : error = (error == RT_ERROR_STREAM_CAPTURE_MODE_NOT_SUPPORT) ? RT_ERROR_STREAM_CAPTURE_MODE_BLOCK_ASYNC : error;
3068 : COND_RETURN_AND_MSG_OUTER(
3069 : error == RT_ERROR_STREAM_CAPTURE_MODE_BLOCK_ASYNC, error, ErrorCode::EE1016, "Asynchronous 2D memory copy",
3070 : "the operation has been converted to a synchronous operation. "
3071 : "operation not permitted when a stream is capturing and the specified capture mode is not relaxed");
3072 : } else {
3073 : error = impl_->MemCopy2DAsync(dst, dstPitch, src, srcPitch, width, height, curStm, copyKind, newKind);
3074 : }
3075 :
3076 : ERROR_RETURN(
3077 : error,
3078 : "Memcpy2d async failed, dstPitch=%" PRIu64 ", srcPitch=%" PRIu64 ", width=%" PRIu64 ", height=%" PRIu64
3079 : ", kind=%s, isInvolvePageableMemory=%d",
3080 : dstPitch, srcPitch, width, height, MemcpyKindToStr(copyKind), isD2HorH2DInvolvePageableMemory);
3081 : return error;
3082 : }
3083 :
3084 : rtError_t ApiErrorDecorator::MemSetSync(
3085 : const void* const devPtr, const uint64_t destMax, const uint32_t val, const uint64_t cnt)
3086 : {
3087 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(devPtr, RT_ERROR_INVALID_VALUE, "Memory setting synchronization");
3088 : ZERO_RETURN_AND_MSG_OUTER(cnt);
3089 :
3090 : const rtError_t error = impl_->MemSetSync(devPtr, destMax, val, cnt);
3091 : ERROR_RETURN(error, "Memset sync failed, destMax=%" PRIu64 ", value=%u, count=%" PRIu64, destMax, val, cnt);
3092 : return error;
3093 : }
3094 :
3095 : rtError_t ApiErrorDecorator::MemsetAsync(
3096 : void* const ptr, const uint64_t destMax, const uint32_t val, const uint64_t cnt, Stream* const stm)
3097 : {
3098 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3099 : ptr, RT_ERROR_INVALID_VALUE, "Asynchronously setting the memory content to a specified value");
3100 : ZERO_RETURN_AND_MSG_OUTER(cnt);
3101 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3102 : cnt > destMax, RT_ERROR_INVALID_VALUE, "Asynchronously setting the memory content to a specified value", cnt,
3103 : "(0, " + std::to_string(destMax) + "]");
3104 :
3105 : const rtError_t error = impl_->MemsetAsync(ptr, destMax, val, cnt, stm);
3106 : ERROR_RETURN(error, "Memset async failed, destMax=%" PRIu64 ", value=%u, count=%" PRIu64 ".", destMax, val, cnt);
3107 : return error;
3108 : }
3109 :
3110 : rtError_t ApiErrorDecorator::MemGetInfo(size_t* const freeSize, size_t* const totalSize)
3111 : {
3112 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(freeSize, RT_ERROR_INVALID_VALUE, "Obtaining memory information");
3113 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(totalSize, RT_ERROR_INVALID_VALUE, "Obtaining memory information");
3114 :
3115 : const rtError_t error = impl_->MemGetInfo(freeSize, totalSize);
3116 : ERROR_RETURN(error, "Get memory info failed, free=%zu, total=%zu.", *freeSize, *totalSize);
3117 : return error;
3118 : }
3119 :
3120 : rtError_t ApiErrorDecorator::MemGetInfoByType(const int32_t devId, const rtMemType_t type, rtMemInfo_t* const info)
3121 : {
3122 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3123 : (devId < 0), RT_ERROR_DEVICE_ID, "Querying information about different types of memory", devId,
3124 : "greater than or equal to 0");
3125 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3126 : (type >= RT_MEM_INFO_TYPE_MAX), RT_ERROR_INVALID_VALUE, "Querying information about different types of memory",
3127 : type, "[" + std::to_string(RT_MEM_INFO_TYPE_DDR_SIZE) + ", " + std::to_string(RT_MEM_INFO_TYPE_MAX) + ")");
3128 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3129 : info, RT_ERROR_INVALID_VALUE, "Querying information about different types of memory");
3130 : rtError_t error;
3131 : int32_t realDeviceId;
3132 : error =
3133 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
3134 : COND_RETURN_ERROR(
3135 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
3136 : error = CheckDeviceIdIsValid(realDeviceId);
3137 : COND_RETURN_ERROR_MSG_INNER(
3138 : error != RT_ERROR_NONE, error, "Device ID is invalid, drv devId=%d, retCode=%#x", realDeviceId,
3139 : static_cast<uint32_t>(error));
3140 : error = impl_->MemGetInfoByType(realDeviceId, type, info);
3141 : ERROR_RETURN(error, "Failed to get memory info by type, devId=%d, type=%u.", devId, type);
3142 : return error;
3143 : }
3144 :
3145 : rtError_t ApiErrorDecorator::MemGetInfoEx(
3146 : const rtMemInfoType_t memInfoType, size_t* const freeSize, size_t* const totalSize)
3147 : {
3148 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3149 : freeSize, RT_ERROR_INVALID_VALUE, "Obtaining the memory information of the current device");
3150 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3151 : totalSize, RT_ERROR_INVALID_VALUE, "Obtaining the memory information of the current device");
3152 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME(
3153 : (memInfoType < RT_MEMORYINFO_DDR) || (memInfoType > RT_MEMORYINFO_P2P_HUGE1G), RT_ERROR_INVALID_MEMORY_TYPE,
3154 : MemInfoTypeToString(memInfoType), "memInfoType",
3155 : "[" + std::to_string(RT_MEMORYINFO_DDR) + ", " + std::to_string(RT_MEMORYINFO_P2P_HUGE1G) + "]");
3156 : const rtError_t error = impl_->MemGetInfoEx(memInfoType, freeSize, totalSize);
3157 : ERROR_RETURN(
3158 : error, "Get Memory extend info failed, memInfoType=%s, free=%zu, total=%zu.",
3159 : MemInfoTypeToString(memInfoType).c_str(), *freeSize, *totalSize);
3160 : return error;
3161 : }
3162 :
3163 : rtError_t ApiErrorDecorator::PointerGetAttributes(rtPointerAttributes_t* const attributes, const void* const ptr)
3164 : {
3165 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(attributes, RT_ERROR_INVALID_VALUE, "Obtaining memory attributes");
3166 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(ptr, RT_ERROR_INVALID_VALUE, "Obtaining memory attributes");
3167 :
3168 : rtError_t error = impl_->PointerGetAttributes(attributes, ptr);
3169 : ERROR_RETURN(error, "Get pointer attributes failed");
3170 : RT_LOG(
3171 : RT_LOG_DEBUG, "get memory attribute locationType=%d, memoryType=%d, [1:HOST,2:DEVICE,3:SVM,4:DVPP].",
3172 : static_cast<int32_t>(attributes->locationType), static_cast<int32_t>(attributes->memoryType));
3173 : if (attributes->locationType == RT_MEMORY_LOC_DEVICE) {
3174 : const uint32_t drvDeviceId = attributes->deviceID;
3175 : error = Runtime::Instance()->GetUserDevIdByDeviceId(drvDeviceId, &attributes->deviceID);
3176 : ERROR_RETURN_MSG_INNER(
3177 : error, "Failed to convert the driver device ID %u to user device ID, retCode=%#x", drvDeviceId,
3178 : static_cast<uint32_t>(error));
3179 : }
3180 : return RT_ERROR_NONE;
3181 : }
3182 :
3183 : rtError_t ApiErrorDecorator::PtrGetAttributes(const void* const ptr, rtPtrAttributes_t* const attributes)
3184 : {
3185 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(attributes, RT_ERROR_INVALID_VALUE, "Obtaining memory attributes");
3186 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(ptr, RT_ERROR_INVALID_VALUE, "Obtaining memory attributes");
3187 :
3188 : const rtError_t error = impl_->PtrGetAttributes(ptr, attributes);
3189 : ERROR_RETURN(error, "Get pointer attributes failed");
3190 : RT_LOG(
3191 : RT_LOG_DEBUG, "get memory attribute locationType=%s.",
3192 : MemLocationTypeToString(attributes->location.type).c_str());
3193 : return RT_ERROR_NONE;
3194 : }
3195 :
3196 : rtError_t ApiErrorDecorator::MemPrefetchToDevice(const void* const devPtr, const uint64_t len, const int32_t devId)
3197 : {
3198 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3199 : devPtr, RT_ERROR_INVALID_VALUE, "Prefetching memory data to a specified device");
3200 : ZERO_RETURN_AND_MSG_OUTER(len);
3201 : // PS:这个接口不能做内外dev id的转换
3202 : NULL_PTR_RETURN_MSG(Runtime::Instance()->driverFactory_.GetDriver(NPU_DRIVER), RT_ERROR_INVALID_VALUE);
3203 : int32_t cnt = 1;
3204 : rtError_t error = Runtime::Instance()->driverFactory_.GetDriver(NPU_DRIVER)->GetDeviceCount(&cnt);
3205 : ERROR_RETURN_MSG_INNER(error, "GetDeviceCount failed, retCode=%#x", static_cast<uint32_t>(error));
3206 :
3207 : error = impl_->MemPrefetchToDevice(devPtr, len, devId);
3208 : ERROR_RETURN(error, "Memory prefetch to device failed, len=%" PRIu64 "(bytes), devId=%d.", len, devId);
3209 : return error;
3210 : }
3211 :
3212 : rtError_t ApiErrorDecorator::GetDeviceIDs(uint32_t* const devId, const uint32_t len)
3213 : {
3214 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(devId, RT_ERROR_INVALID_VALUE, "Obtaining the number of devices");
3215 :
3216 : return impl_->GetDeviceIDs(devId, len);
3217 : }
3218 :
3219 : rtError_t ApiErrorDecorator::OpenNetService(const rtNetServiceOpenArgs* args)
3220 : {
3221 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(args, RT_ERROR_INVALID_VALUE, "Starting the HCCP process");
3222 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(args->extParamList, RT_ERROR_INVALID_VALUE, "Starting the HCCP process");
3223 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3224 : (args->extParamCnt <= 0U) || (args->extParamCnt > RT_EXT_PARAM_CNT_MAX), RT_ERROR_INVALID_VALUE,
3225 : "Starting the HCCP process", args->extParamCnt, "(0, " + std::to_string(RT_EXT_PARAM_CNT_MAX) + "]");
3226 :
3227 : return impl_->OpenNetService(args);
3228 : }
3229 :
3230 : rtError_t ApiErrorDecorator::CloseNetService() { return impl_->CloseNetService(); }
3231 :
3232 : rtError_t ApiErrorDecorator::GetDeviceCount(int32_t* const cnt)
3233 : {
3234 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(cnt, RT_ERROR_INVALID_VALUE, "Obtaining the number of devices");
3235 :
3236 : return impl_->GetDeviceCount(cnt);
3237 : }
3238 :
3239 : rtError_t ApiErrorDecorator::SetDevice(const int32_t devId)
3240 : {
3241 : Runtime* const rt = Runtime::Instance();
3242 : driverType_t rawDrvType = rt->GetDriverType();
3243 : Driver* const rawDrv = rt->driverFactory_.GetDriver(rawDrvType);
3244 : NULL_PTR_RETURN_MSG(rawDrv, RT_ERROR_DRV_NULL);
3245 : int32_t deviceCnt;
3246 : int32_t realDeviceId;
3247 :
3248 : rtError_t error =
3249 : rt->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId), true);
3250 : COND_RETURN_ERROR(
3251 : error != RT_ERROR_NONE, RT_ERROR_DEVICE_ID,
3252 : "Failed to convert the user device ID %d to driver device ID. The input visible device is %s.", devId,
3253 : rt->inputDeviceStr);
3254 :
3255 : error = rawDrv->GetDeviceCount(&deviceCnt);
3256 : ERROR_RETURN_MSG_CALL(ERR_MODULE_DRV, error, "Get device cnt failed, retCode=%#x", static_cast<uint32_t>(error));
3257 : if ((realDeviceId < 0) || (realDeviceId >= deviceCnt)) {
3258 : RT_LOG_OUTER_MSG_WITH_FUNC_DESC(
3259 : ErrorCode::EE1003, "Specifying the device used for computation by the current thread", realDeviceId,
3260 : "drv devId", "[0, " + std::to_string(deviceCnt) + ")");
3261 : return RT_ERROR_DEVICE_ID;
3262 : }
3263 :
3264 : error = impl_->SetDevice(realDeviceId);
3265 : std::string inputSocVersion = GlobalContainer::GetUserSocVersion();
3266 : ERROR_RETURN(
3267 : error, "Set device failed, device_id=%d, the current input soc version is %s.", devId,
3268 : inputSocVersion.empty() ? "null" : inputSocVersion.c_str());
3269 : return error;
3270 : }
3271 :
3272 : rtError_t ApiErrorDecorator::GetDevice(int32_t* const devId)
3273 : {
3274 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(devId, RT_ERROR_INVALID_VALUE, "Obtaining the ID of the device in use");
3275 :
3276 : return impl_->GetDevice(devId);
3277 : }
3278 :
3279 : rtError_t ApiErrorDecorator::GetDevicePhyIdByIndex(const uint32_t devIndex, uint32_t* const phyId)
3280 : {
3281 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3282 : phyId, RT_ERROR_INVALID_VALUE, "Querying the physical ID of a device based on its logical ID");
3283 :
3284 : uint32_t realDeviceId;
3285 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(devIndex, &realDeviceId);
3286 : COND_RETURN_ERROR(
3287 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", devIndex);
3288 : error = impl_->GetDevicePhyIdByIndex(realDeviceId, phyId);
3289 : ERROR_RETURN(error, "Get device physical id by index failed, index=%u.", devIndex);
3290 : return error;
3291 : }
3292 :
3293 : rtError_t ApiErrorDecorator::GetDeviceIndexByPhyId(const uint32_t phyId, uint32_t* const devIndex)
3294 : {
3295 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3296 : devIndex, RT_ERROR_INVALID_VALUE, "Querying the logical ID of a device based on its physical ID");
3297 :
3298 : uint32_t realDeviceId = 0;
3299 : rtError_t error = impl_->GetDeviceIndexByPhyId(phyId, &realDeviceId);
3300 : if (error != RT_ERROR_NONE) {
3301 : RT_LOG(RT_LOG_ERROR, "Get device index by physical id failed, phyId:%u, realDeviceId=%u", phyId, realDeviceId);
3302 : return error;
3303 : }
3304 :
3305 : error = Runtime::Instance()->GetUserDevIdByDeviceId(realDeviceId, devIndex);
3306 : COND_RETURN_ERROR_MSG_INNER(
3307 : error != RT_ERROR_NONE, error,
3308 : "Failed to convert the driver device ID %u to user device ID, phyId=%u, retCode=%#x", realDeviceId, phyId,
3309 : static_cast<uint32_t>(error));
3310 : RT_LOG(RT_LOG_DEBUG, "realDeviceId:%u, phyId=%u, devIndex=%u.", realDeviceId, phyId, (*devIndex));
3311 : return RT_ERROR_NONE;
3312 : }
3313 :
3314 : rtError_t ApiErrorDecorator::EnableP2P(const uint32_t devIdDes, const uint32_t phyIdSrc, const uint32_t flag)
3315 : {
3316 : uint32_t realDeviceId;
3317 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(devIdDes, &realDeviceId);
3318 : COND_RETURN_ERROR(
3319 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", devIdDes);
3320 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
3321 : realDeviceId >= RT_MAX_DEV_NUM, RT_ERROR_INVALID_VALUE, realDeviceId,
3322 : "[0, " + std::to_string(RT_MAX_DEV_NUM) + ")");
3323 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
3324 : phyIdSrc >= RT_MAX_DEV_NUM, RT_ERROR_INVALID_VALUE, phyIdSrc, "[0, " + std::to_string(RT_MAX_DEV_NUM) + ")");
3325 :
3326 : error = impl_->EnableP2P(realDeviceId, phyIdSrc, flag);
3327 : ERROR_RETURN(error, "Enable P2P failed, devIdDes=%u, phyIdSrc=%u.", devIdDes, phyIdSrc);
3328 : return error;
3329 : }
3330 :
3331 : rtError_t ApiErrorDecorator::DisableP2P(const uint32_t devIdDes, const uint32_t phyIdSrc)
3332 : {
3333 : uint32_t realDeviceId;
3334 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(devIdDes, &realDeviceId);
3335 : COND_RETURN_ERROR(
3336 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", devIdDes);
3337 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
3338 : realDeviceId >= RT_MAX_DEV_NUM, RT_ERROR_INVALID_VALUE, realDeviceId,
3339 : "[0, " + std::to_string(RT_MAX_DEV_NUM) + ")");
3340 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
3341 : phyIdSrc >= RT_MAX_DEV_NUM, RT_ERROR_INVALID_VALUE, phyIdSrc, "[0, " + std::to_string(RT_MAX_DEV_NUM) + ")");
3342 : error = impl_->DisableP2P(realDeviceId, phyIdSrc);
3343 : ERROR_RETURN(error, "Disable P2P failed, dest deviceId=%u, src phyId=%u.", devIdDes, phyIdSrc);
3344 : return error;
3345 : }
3346 :
3347 : rtError_t ApiErrorDecorator::DeviceCanAccessPeer(
3348 : int32_t* const canAccessPeer, const uint32_t devId, const uint32_t peerDevice)
3349 : {
3350 : uint32_t realDeviceId;
3351 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(devId, &realDeviceId);
3352 : COND_RETURN_ERROR(
3353 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", devId);
3354 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3355 : realDeviceId >= RT_MAX_DEV_NUM, RT_ERROR_INVALID_VALUE,
3356 : "Checking whether data exchange is supported between devices", realDeviceId,
3357 : "[0, " + std::to_string(RT_MAX_DEV_NUM) + ")");
3358 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3359 : canAccessPeer, RT_ERROR_INVALID_VALUE, "Checking whether data exchange is supported between devices");
3360 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3361 : peerDevice >= RT_MAX_DEV_NUM, RT_ERROR_INVALID_VALUE,
3362 : "Checking whether data exchange is supported between devices", peerDevice,
3363 : "[0, " + std::to_string(RT_MAX_DEV_NUM) + ")");
3364 : error = impl_->DeviceCanAccessPeer(canAccessPeer, realDeviceId, peerDevice);
3365 : ERROR_RETURN(error, "Device can access peer failed, devId=%u, peerDevice=%u.", devId, peerDevice);
3366 : return error;
3367 : }
3368 :
3369 : rtError_t ApiErrorDecorator::GetP2PStatus(const uint32_t devIdDes, const uint32_t phyIdSrc, uint32_t* const status)
3370 : {
3371 : uint32_t realDeviceId;
3372 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(devIdDes, &realDeviceId);
3373 : COND_RETURN_ERROR(
3374 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", devIdDes);
3375 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3376 : realDeviceId >= RT_MAX_DEV_NUM, RT_ERROR_INVALID_VALUE, "Obtaining the P2P status", realDeviceId,
3377 : "[0, " + std::to_string(RT_MAX_DEV_NUM) + ")");
3378 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3379 : phyIdSrc >= RT_MAX_DEV_NUM, RT_ERROR_INVALID_VALUE, "Obtaining the P2P status", phyIdSrc,
3380 : "[0, " + std::to_string(RT_MAX_DEV_NUM) + ")");
3381 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(status, RT_ERROR_INVALID_VALUE, "Obtaining the P2P status");
3382 :
3383 : error = impl_->GetP2PStatus(realDeviceId, phyIdSrc, status);
3384 : ERROR_RETURN(error, "Get P2P status failed, dest devId=%u, src phyId=%u.", devIdDes, phyIdSrc);
3385 : return error;
3386 : }
3387 :
3388 : rtError_t ApiErrorDecorator::DeviceGetBareTgid(uint32_t* const pid)
3389 : {
3390 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(pid, RT_ERROR_INVALID_VALUE, "Obtaining the ID of the current process");
3391 :
3392 : return impl_->DeviceGetBareTgid(pid);
3393 : }
3394 :
3395 : rtError_t ApiErrorDecorator::DeviceReset(const int32_t devId, const bool isForceReset)
3396 : {
3397 : int32_t realDeviceId;
3398 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
3399 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId), true);
3400 : COND_RETURN_ERROR(
3401 : error != RT_ERROR_NONE, RT_ERROR_DEVICE_ID, "Failed to convert the user device ID %d to driver device ID.",
3402 : devId);
3403 : error = CheckDeviceIdIsValid(realDeviceId);
3404 : COND_RETURN_ERROR_MSG_INNER(
3405 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%d, retCode=%#x", realDeviceId,
3406 : static_cast<uint32_t>(error));
3407 :
3408 : error = impl_->DeviceReset(realDeviceId, isForceReset);
3409 : ERROR_RETURN(error, "Device reset failed, device_id=%d.", devId);
3410 : return error;
3411 : }
3412 :
3413 : rtError_t ApiErrorDecorator::DeviceSetLimit(const int32_t devId, const rtLimitType_t type, const uint32_t val)
3414 : {
3415 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
3416 : (devId < 0) || (devId >= static_cast<int32_t>(RT_MAX_DEV_NUM)), RT_ERROR_INVALID_VALUE, devId,
3417 : "[0, " + std::to_string(RT_MAX_DEV_NUM) + ")");
3418 : int32_t realDeviceId;
3419 : rtError_t error =
3420 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
3421 : COND_RETURN_ERROR(
3422 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
3423 : error = impl_->DeviceSetLimit(realDeviceId, type, val);
3424 : ERROR_RETURN(
3425 : error, "Device set limit failed, device_id=%d, type=%s, value=%u.", devId, LimitTypeToString(type).c_str(),
3426 : val);
3427 : return error;
3428 : }
3429 :
3430 : rtError_t ApiErrorDecorator::DeviceGetLimit(const rtLimitType_t type, uint32_t* val)
3431 : {
3432 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(val == nullptr, RT_ERROR_INVALID_VALUE, val, "non-null");
3433 : rtError_t error = impl_->DeviceGetLimit(type, val);
3434 : ERROR_RETURN(error, "Device get limit failed, type=%s.", LimitTypeToString(type).c_str());
3435 : return error;
3436 : }
3437 :
3438 : rtError_t ApiErrorDecorator::DeviceSynchronize(const int32_t timeout)
3439 : {
3440 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
3441 : (timeout < -1) || (timeout == 0), RT_ERROR_INVALID_VALUE, timeout,
3442 : "greater than or equal to -1 and not equal to 0");
3443 : const rtError_t error = impl_->DeviceSynchronize(timeout);
3444 : ERROR_RETURN(error, "Device synchronize failed.");
3445 : return error;
3446 : }
3447 :
3448 : rtError_t ApiErrorDecorator::DeviceTaskAbort(const int32_t devId, const uint32_t timeout)
3449 : {
3450 : Runtime* const rt = Runtime::Instance();
3451 : const driverType_t rawDrvType = rt->GetDriverType();
3452 : Driver* const rawDrv = rt->driverFactory_.GetDriver(rawDrvType);
3453 : NULL_PTR_RETURN_MSG(rawDrv, RT_ERROR_DRV_NULL);
3454 : int32_t deviceCnt;
3455 : int32_t realDeviceId;
3456 : COND_RETURN_WITH_NOLOG(
3457 : !IS_SUPPORT_CHIP_FEATURE(rt->GetChipType(), RtOptionalFeatureType::RT_FEATURE_DFX_FAST_RECOVER),
3458 : ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
3459 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
3460 : (timeout > TASK_ABORT_TIMEOUT_MAX), RT_ERROR_INVALID_VALUE, timeout,
3461 : "[0, " + std::to_string(TASK_ABORT_TIMEOUT_MAX) + "]");
3462 :
3463 : rtError_t error = rt->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
3464 : COND_RETURN_ERROR(
3465 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
3466 :
3467 : error = rawDrv->GetDeviceCount(&deviceCnt);
3468 : ERROR_RETURN_MSG_CALL(ERR_MODULE_DRV, error, "Get device cnt failed, retCode=%#x", static_cast<uint32_t>(error));
3469 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
3470 : ((realDeviceId < 0) || (realDeviceId >= deviceCnt)), RT_ERROR_DEVICE_ID, realDeviceId,
3471 : "[0, " + std::to_string(deviceCnt) + ")");
3472 :
3473 : return impl_->DeviceTaskAbort(realDeviceId, timeout);
3474 : }
3475 :
3476 : rtError_t ApiErrorDecorator::SnapShotProcessLock() { return impl_->SnapShotProcessLock(); }
3477 :
3478 : rtError_t ApiErrorDecorator::SnapShotProcessUnlock() { return impl_->SnapShotProcessUnlock(); }
3479 :
3480 : rtError_t ApiErrorDecorator::SnapShotCallbackRegister(rtSnapShotStage stage, rtSnapShotCallBack callback, void* args)
3481 : {
3482 : return impl_->SnapShotCallbackRegister(stage, callback, args);
3483 : }
3484 :
3485 : rtError_t ApiErrorDecorator::SnapShotCallbackUnregister(rtSnapShotStage stage, rtSnapShotCallBack callback)
3486 : {
3487 : return impl_->SnapShotCallbackUnregister(stage, callback);
3488 : }
3489 :
3490 : rtError_t ApiErrorDecorator::SnapShotProcessBackup()
3491 : {
3492 : GlobalStateManager& globalStateManagerInstance = GlobalStateManager::GetInstance();
3493 : std::unique_lock<std::mutex> lock(globalStateManagerInstance.GetStateMtx());
3494 : if (globalStateManagerInstance.GetCurrentState() != RT_PROCESS_STATE_LOCKED) {
3495 : RT_LOG(
3496 : RT_LOG_ERROR, "current state is not the locked state, current state is %s",
3497 : GlobalStateManager::StateToString(globalStateManagerInstance.GetCurrentState()));
3498 : return RT_ERROR_SNAPSHOT_BACKUP_FAILED;
3499 : }
3500 : return impl_->SnapShotProcessBackup();
3501 : }
3502 :
3503 : rtError_t ApiErrorDecorator::SnapShotProcessRestore()
3504 : {
3505 : GlobalStateManager& globalStateManagerInstance = GlobalStateManager::GetInstance();
3506 : std::unique_lock<std::mutex> lock(globalStateManagerInstance.GetStateMtx());
3507 : if (globalStateManagerInstance.GetCurrentState() != RT_PROCESS_STATE_BACKED_UP) {
3508 : RT_LOG(
3509 : RT_LOG_ERROR, "current state is not the RT_PROCESS_STATE_BACKED_UP state, current state is %s",
3510 : GlobalStateManager::StateToString(globalStateManagerInstance.GetCurrentState()));
3511 : return RT_ERROR_SNAPSHOT_RESTORE_FAILED;
3512 : }
3513 : return impl_->SnapShotProcessRestore();
3514 : }
3515 :
3516 : rtError_t ApiErrorDecorator::DeviceGetStreamPriorityRange(int32_t* const leastPriority, int32_t* const greatestPriority)
3517 : {
3518 : if (leastPriority == nullptr && greatestPriority == nullptr) {
3519 : RT_LOG(RT_LOG_INFO, "Both leastPriority and greatestPriority are null. No values returned");
3520 : }
3521 : return impl_->DeviceGetStreamPriorityRange(leastPriority, greatestPriority);
3522 : }
3523 :
3524 : rtError_t ApiErrorDecorator::GetDeviceInfo(
3525 : const uint32_t deviceId, const int32_t moduleType, const int32_t infoType, int64_t* const val)
3526 : {
3527 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3528 : moduleType == MODULE_TYPE_HOST_AICPU, RT_ERROR_INVALID_VALUE, "Obtaining information about a specified device",
3529 : moduleType, "not equal to " + std::to_string(MODULE_TYPE_HOST_AICPU));
3530 : uint32_t realDeviceId;
3531 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(deviceId, &realDeviceId);
3532 : COND_RETURN_ERROR(
3533 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", deviceId);
3534 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3535 : val, RT_ERROR_INVALID_VALUE, "Obtaining information about a specified device");
3536 : const auto npuDrv = Runtime::Instance()->driverFactory_.GetDriver(NPU_DRIVER);
3537 : NULL_PTR_RETURN_MSG(npuDrv, RT_ERROR_DRV_NULL);
3538 : int32_t cnt = 1;
3539 : error = npuDrv->GetDeviceCount(&cnt);
3540 : COND_RETURN_ERROR_MSG_CALL(
3541 : ERR_MODULE_DRV, error != RT_ERROR_NONE, error, "Get device info failed, get device count failed, retCode=%#x",
3542 : static_cast<uint32_t>(error));
3543 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3544 : realDeviceId >= static_cast<uint32_t>(cnt), RT_ERROR_INVALID_VALUE,
3545 : "Obtaining information about a specified device", realDeviceId, "[0, " + std::to_string(cnt) + ")");
3546 :
3547 : error = impl_->GetDeviceInfo(realDeviceId, moduleType, infoType, val);
3548 : ERROR_RETURN(error, "Get device info failed, deviceId=%u.", deviceId);
3549 : return error;
3550 : }
3551 :
3552 : rtError_t ApiErrorDecorator::GetPhyDeviceInfo(
3553 : const uint32_t phyId, const int32_t moduleType, const int32_t infoType, int64_t* const val)
3554 : {
3555 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(val, RT_ERROR_INVALID_VALUE, "Obtaining physical device information");
3556 : const auto npuDrv = Runtime::Instance()->driverFactory_.GetDriver(NPU_DRIVER);
3557 : NULL_PTR_RETURN_MSG(npuDrv, RT_ERROR_DRV_NULL);
3558 :
3559 : const rtError_t error = impl_->GetPhyDeviceInfo(phyId, moduleType, infoType, val);
3560 : ERROR_RETURN(error, "Get phy device info failed, phyId=%u.", phyId);
3561 : return error;
3562 : }
3563 :
3564 : rtError_t ApiErrorDecorator::DeviceSetTsId(const uint32_t tsId)
3565 : {
3566 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
3567 : tsId > RT_MAX_TS_ID, RT_ERROR_INVALID_VALUE, tsId, "[0, " + std::to_string(RT_MAX_TS_ID) + "]");
3568 : return impl_->DeviceSetTsId(tsId);
3569 : }
3570 :
3571 : rtError_t ApiErrorDecorator::DeviceGetTsId(uint32_t* tsId)
3572 : {
3573 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3574 : tsId, RT_ERROR_INVALID_VALUE, "Obtaining the task scheduler (TS) service ID");
3575 :
3576 : return impl_->DeviceGetTsId(tsId);
3577 : }
3578 :
3579 : rtError_t ApiErrorDecorator::ContextCreate(Context** const inCtx, const int32_t devId)
3580 : {
3581 : uint32_t realDeviceId = static_cast<uint32_t>(devId);
3582 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), &realDeviceId);
3583 : COND_RETURN_ERROR(
3584 : error != RT_ERROR_NONE, RT_ERROR_DEVICE_ID, "Failed to convert the user device ID %d to driver device ID.",
3585 : devId);
3586 :
3587 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(inCtx, RT_ERROR_INVALID_VALUE, "Context creation");
3588 : error = impl_->ContextCreate(inCtx, static_cast<int32_t>(realDeviceId));
3589 : ERROR_RETURN(error, "Create context failed, devId=%d.", devId);
3590 : RT_LOG(RT_LOG_DEBUG, "create context success.");
3591 : return error;
3592 : }
3593 :
3594 : rtError_t ApiErrorDecorator::ContextDestroy(Context* const inCtx)
3595 : {
3596 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(inCtx, RT_ERROR_INVALID_VALUE, "Context destruction");
3597 :
3598 : const rtError_t error = impl_->ContextDestroy(inCtx);
3599 : ERROR_RETURN(error, "Destroy context failed.");
3600 : return error;
3601 : }
3602 :
3603 : rtError_t ApiErrorDecorator::ContextSetCurrent(Context* const inCtx)
3604 : {
3605 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(inCtx, RT_ERROR_INVALID_VALUE, "Thread context setting");
3606 : CHECK_CONTEXT_VALID_WITH_RETURN(inCtx, RT_ERROR_INVALID_VALUE);
3607 : const rtError_t error = impl_->ContextSetCurrent(inCtx);
3608 : ERROR_RETURN(error, "Set current context failed.");
3609 : return error;
3610 : }
3611 :
3612 : rtError_t ApiErrorDecorator::ContextGetCurrent(Context** const inCtx)
3613 : {
3614 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(inCtx, RT_ERROR_INVALID_VALUE, "Thread context obtaining");
3615 :
3616 : return impl_->ContextGetCurrent(inCtx);
3617 : }
3618 :
3619 : rtError_t ApiErrorDecorator::ContextGetDevice(int32_t* const devId)
3620 : {
3621 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3622 : devId, RT_ERROR_INVALID_VALUE, "Obtaining the device ID associated with the current thread context");
3623 :
3624 : return impl_->ContextGetDevice(devId);
3625 : }
3626 :
3627 : rtError_t ApiErrorDecorator::NameStream(Stream* const stm, const char_t* const name)
3628 : {
3629 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
3630 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(curStm, RT_ERROR_INVALID_VALUE, "Setting the stream name");
3631 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(name, RT_ERROR_INVALID_VALUE, "Setting the stream name");
3632 :
3633 : return impl_->NameStream(curStm, name);
3634 : }
3635 :
3636 : rtError_t ApiErrorDecorator::ProfilerStart(
3637 : const uint64_t profConfig, const int32_t numsDev, uint32_t* const deviceList, const uint32_t cacheFlag,
3638 : const uint64_t profSwitchHi)
3639 : {
3640 : ZERO_RETURN_AND_MSG_OUTER(profConfig);
3641 : COND_RETURN_AND_MSG_OUTER(
3642 : (numsDev != -1) && (numsDev != 0) && (deviceList == nullptr), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
3643 : "Starting profiling analysis", "profiler config",
3644 : RtFmtMsg("The deviceList can be null only when numsDev is -1 or 0, but numsDev is %u", numsDev));
3645 : return impl_->ProfilerStart(profConfig, numsDev, deviceList, cacheFlag, profSwitchHi);
3646 : }
3647 :
3648 : rtError_t ApiErrorDecorator::ProfilerStop(
3649 : const uint64_t profConfig, const int32_t numsDev, uint32_t* const deviceList, const uint64_t profSwitchHi)
3650 : {
3651 : ZERO_RETURN_AND_MSG_OUTER(profConfig);
3652 : COND_RETURN_AND_MSG_OUTER(
3653 : (numsDev != -1) && (numsDev != 0) && (deviceList == nullptr), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
3654 : "Stopping profiling analysis", "profiler config",
3655 : RtFmtMsg("The deviceList can be null only when numsDev is -1 or 0, but numsDev is %u", numsDev));
3656 : return impl_->ProfilerStop(profConfig, numsDev, deviceList, profSwitchHi);
3657 : }
3658 :
3659 : rtError_t ApiErrorDecorator::ProfilerTrace(
3660 : const uint64_t id, const bool notifyFlag, const uint32_t flags, Stream* const stm)
3661 : {
3662 : return impl_->ProfilerTrace(id, notifyFlag, flags, stm);
3663 : }
3664 :
3665 : rtError_t ApiErrorDecorator::ProfilerTraceEx(
3666 : const uint64_t id, const uint64_t modelId, const uint16_t tagId, Stream* const stm)
3667 : {
3668 : return impl_->ProfilerTraceEx(id, modelId, tagId, stm);
3669 : }
3670 :
3671 : rtError_t ApiErrorDecorator::StartOnlineProf(Stream* const stm, const uint32_t sampleNum)
3672 : {
3673 : const rtError_t error = impl_->StartOnlineProf(stm, sampleNum);
3674 : ERROR_RETURN(error, "Start online profiling failed, sample_num=%u.", sampleNum);
3675 : return error;
3676 : }
3677 :
3678 : rtError_t ApiErrorDecorator::StopOnlineProf(Stream* const stm)
3679 : {
3680 : const rtError_t error = impl_->StopOnlineProf(stm);
3681 : ERROR_RETURN(error, "Stop online profiling failed.");
3682 : return error;
3683 : }
3684 :
3685 : rtError_t ApiErrorDecorator::AdcProfiler(const uint64_t addr, const uint32_t length)
3686 : {
3687 : return impl_->AdcProfiler(addr, length);
3688 : }
3689 :
3690 : rtError_t ApiErrorDecorator::SetMsprofReporterCallback(const MsprofReporterCallback callback)
3691 : {
3692 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3693 : callback, RT_ERROR_INVALID_VALUE, "Setting the callback function for msproftx data reporting");
3694 : return impl_->SetMsprofReporterCallback(callback);
3695 : }
3696 :
3697 : rtError_t ApiErrorDecorator::GetOnlineProfData(
3698 : Stream* const stm, rtProfDataInfo_t* const pProfData, const uint32_t profDataNum)
3699 : {
3700 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3701 : pProfData, RT_ERROR_INVALID_VALUE, "Obtaining online profile data from a specified stream");
3702 : const rtError_t error = impl_->GetOnlineProfData(stm, pProfData, profDataNum);
3703 : ERROR_RETURN(error, "Get online profiling data failed, data number=%u.", profDataNum);
3704 : return error;
3705 : }
3706 :
3707 : rtError_t ApiErrorDecorator::IpcSetMemoryName(
3708 : const void* const ptr, const uint64_t byteCount, char_t* const name, const uint32_t len, const uint64_t flags)
3709 : {
3710 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3711 : ptr, RT_ERROR_INVALID_VALUE, "Setting the memory to be shared between processes");
3712 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3713 : name, RT_ERROR_INVALID_VALUE, "Setting the memory to be shared between processes");
3714 : ZERO_RETURN_AND_MSG_OUTER(byteCount);
3715 : ZERO_RETURN_AND_MSG_OUTER(len);
3716 :
3717 : constexpr uint64_t maxFlag = RT_IPC_MEM_EXPORT_FLAG_DISABLE_PID_VALIDATION;
3718 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3719 : (flags > maxFlag), RT_ERROR_INVALID_VALUE, "Setting the memory to be shared between processes", flags,
3720 : "[0, " + std::to_string(maxFlag) + "]");
3721 :
3722 : const rtError_t error = impl_->IpcSetMemoryName(ptr, byteCount, name, len, flags);
3723 : ERROR_RETURN(
3724 : error, "Ipc set memory name failed, name=%s, byteCount=%#" PRIx64 ", len=%u(bytes)", name, byteCount, len);
3725 : return error;
3726 : }
3727 :
3728 : rtError_t ApiErrorDecorator::IpcSetMemoryAttr(const char* name, uint32_t type, uint64_t attr)
3729 : {
3730 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3731 : name, RT_ERROR_INVALID_VALUE, "Setting the attribute for IPC-based memory sharing");
3732 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3733 : (type >= RT_ATTR_TYPE_MAX), RT_ERROR_INVALID_VALUE, "Setting the attribute for IPC-based memory sharing", type,
3734 : "[0, " + std::to_string(RT_ATTR_TYPE_MAX) + ")");
3735 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3736 : (attr >= RT_IPC_MEM_ATTR_MAX), RT_ERROR_INVALID_VALUE, "Setting the attribute for IPC-based memory sharing",
3737 : attr, "[0, " + std::to_string(RT_IPC_MEM_ATTR_MAX) + ")");
3738 : return impl_->IpcSetMemoryAttr(name, type, attr);
3739 : }
3740 :
3741 : rtError_t ApiErrorDecorator::NopTask(Stream* const stm)
3742 : {
3743 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
3744 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(curStm, RT_ERROR_INVALID_VALUE, "Executing a No-Operation (NOP) task");
3745 : return impl_->NopTask(curStm);
3746 : }
3747 :
3748 : rtError_t ApiErrorDecorator::IpcDestroyMemoryName(const char_t* const name)
3749 : {
3750 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(name, RT_ERROR_INVALID_VALUE, "Destroying the IPC shared memory");
3751 :
3752 : const rtError_t error = impl_->IpcDestroyMemoryName(name);
3753 : ERROR_RETURN(error, "Ipc destroy memory name failed, name=%s.", name);
3754 : return error;
3755 : }
3756 :
3757 : rtError_t ApiErrorDecorator::SetIpcNotifyPid(const char_t* const name, int32_t pid[], const int32_t num)
3758 : {
3759 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3760 : name, RT_ERROR_INVALID_VALUE, "Setting the trustlist of processes that can share a Notify object");
3761 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3762 : pid, RT_ERROR_INVALID_VALUE, "Setting the trustlist of processes that can share a Notify object");
3763 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3764 : num <= 0, RT_ERROR_INVALID_VALUE, "Setting the trustlist of processes that can share a Notify object", num,
3765 : "(0, " + std::to_string(MAX_INT32_NUM) + "]");
3766 : return impl_->SetIpcNotifyPid(name, pid, num);
3767 : }
3768 :
3769 : rtError_t ApiErrorDecorator::SetIpcMemPid(const char_t* const name, int32_t pid[], const int32_t num)
3770 : {
3771 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3772 : name, RT_ERROR_INVALID_VALUE, "Setting the trustlist of processes that can share memory through IPC");
3773 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3774 : pid, RT_ERROR_INVALID_VALUE, "Setting the trustlist of processes that can share memory through IPC");
3775 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3776 : num <= 0, RT_ERROR_INVALID_VALUE, "Setting the trustlist of processes that can share memory through IPC", num,
3777 : "(0, " + std::to_string(MAX_INT32_NUM) + "]");
3778 : return impl_->SetIpcMemPid(name, pid, num);
3779 : }
3780 :
3781 : rtError_t ApiErrorDecorator::IpcOpenMemory(void** const ptr, const char_t* const name, const uint64_t flags)
3782 : {
3783 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3784 : ptr, RT_ERROR_INVALID_VALUE, "Opening the shared memory between processes");
3785 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3786 : name, RT_ERROR_INVALID_VALUE, "Opening the shared memory between processes");
3787 :
3788 : constexpr uint64_t maxFlag = RT_IPC_MEM_IMPORT_FLAG_ENABLE_PEER_ACCESS;
3789 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3790 : (flags > maxFlag), RT_ERROR_INVALID_VALUE, "Opening the shared memory between processes", flags,
3791 : "[0, " + std::to_string(maxFlag) + "]");
3792 :
3793 : const rtError_t error = impl_->IpcOpenMemory(ptr, name, flags);
3794 : COND_RETURN_WITH_NOLOG(error == RT_ERROR_FEATURE_NOT_SUPPORT, error);
3795 : ERROR_RETURN(error, "Ipc open memory failed, name=%s.", name);
3796 : return error;
3797 : }
3798 :
3799 : rtError_t ApiErrorDecorator::IpcCloseMemory(const void* const ptr)
3800 : {
3801 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(ptr, RT_ERROR_INVALID_VALUE, "Closing the IPC shared memory");
3802 :
3803 : const rtError_t error = impl_->IpcCloseMemory(ptr);
3804 : ERROR_RETURN(error, "Ipc close memory failed.");
3805 : return error;
3806 : }
3807 :
3808 : rtError_t ApiErrorDecorator::IpcCloseMemoryByName(const char_t* const name)
3809 : {
3810 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(name, RT_ERROR_INVALID_VALUE, "Closing the IPC shared memory");
3811 :
3812 : const rtError_t error = impl_->IpcCloseMemoryByName(name);
3813 : ERROR_RETURN(error, "Ipc close memory failed.");
3814 : return error;
3815 : }
3816 :
3817 : rtError_t ApiErrorDecorator::ModelCreate(Model** const mdl, const uint32_t flag)
3818 : {
3819 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(mdl, RT_ERROR_INVALID_VALUE, "Model running instance creation");
3820 :
3821 : const rtError_t error = impl_->ModelCreate(mdl, flag);
3822 : ERROR_RETURN(error, "Create model failed, flag=%#x.", flag);
3823 : RT_LOG(RT_LOG_INFO, "model create success, modelId=%d", (*mdl)->Id_());
3824 : return error;
3825 : }
3826 :
3827 : rtError_t ApiErrorDecorator::ModelSetExtId(Model* const mdl, const uint32_t extId)
3828 : {
3829 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(mdl, RT_ERROR_INVALID_VALUE, "Setting the model extension ID");
3830 : COND_RETURN_AND_MSG_OUTER(
3831 : mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL, RT_ERROR_INVALID_VALUE, ErrorCode::EE1016,
3832 : "Setting the model extension ID", "ACL Graph mode is not supported");
3833 :
3834 : return impl_->ModelSetExtId(mdl, extId);
3835 : }
3836 :
3837 : rtError_t ApiErrorDecorator::ModelDestroy(Model* const mdl)
3838 : {
3839 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(mdl, RT_ERROR_INVALID_VALUE, "Destroying a model running instance");
3840 : if (mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL) {
3841 : CaptureModel* captureModel = dynamic_cast<CaptureModel*>(mdl);
3842 : COND_RETURN_WARN(
3843 : ((captureModel != nullptr) && captureModel->IsSubCaptureModel()), RT_ERROR_FEATURE_NOT_SUPPORT,
3844 : "sub ACL Graph does not support destroying model");
3845 : }
3846 :
3847 : const uint32_t modelId = mdl->Id_();
3848 : RT_LOG(RT_LOG_INFO, "model_id=%u.", modelId);
3849 :
3850 : const rtError_t error = impl_->ModelDestroy(mdl);
3851 : ERROR_RETURN(error, "Destroy model failed, model_id=%u.", modelId);
3852 : return error;
3853 : }
3854 :
3855 : rtError_t ApiErrorDecorator::ModelBindStream(Model* const mdl, Stream* const stm, const uint32_t flag)
3856 : {
3857 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
3858 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3859 : mdl, RT_ERROR_INVALID_VALUE, "Binding a model running instance to a stream");
3860 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3861 : curStm, RT_ERROR_INVALID_VALUE, "Binding a model running instance to a stream");
3862 : COND_RETURN_AND_MSG_OUTER(
3863 : mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL, RT_ERROR_INVALID_VALUE, ErrorCode::EE1016,
3864 : "Binding a model running instance to a stream", "ACL Graph mode is not supported");
3865 : COND_RETURN_AND_MSG_OUTER(
3866 : curStm->IsCapturing(), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016,
3867 : "Binding a model running instance to a stream",
3868 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", curStm->Id_()));
3869 :
3870 : COND_RETURN_AND_MSG_OUTER(
3871 : (curStm->Flags() & RT_STREAM_CP_PROCESS_USE) != 0U, RT_ERROR_STREAM_INVALID, ErrorCode::EE1011,
3872 : "Binding a model running instance to a stream", "ACL_STREAM_DEVICE_USE_ONLY", "stream flag",
3873 : RtFmtMsg(
3874 : "Stream (stream_id=%d) with the flag ACL_STREAM_DEVICE_USE_ONLY cannot be bound to a model",
3875 : curStm->Id_()));
3876 : COND_RETURN_ERROR_MSG_INNER(
3877 : curStm->IsBindDvppGrp(), RT_ERROR_STREAM_BIND_GRP,
3878 : "Stream (stream_id=%d) of the specified DVPP group cannot be bound to a model", curStm->Id_());
3879 : COND_RETURN_AND_MSG_OUTER(
3880 : curStm->GetFailureMode() == STOP_ON_FAILURE, RT_ERROR_FEATURE_NOT_SUPPORT, ErrorCode::EE1016,
3881 : "Binding a model running instance to a stream",
3882 : RtFmtMsg("Stop mode for stream (stream_id=%d) is not supported", curStm->Id_()));
3883 : COND_RETURN_AND_MSG_OUTER(
3884 : curStm->GetFailureMode() == ABORT_ON_FAILURE, RT_ERROR_FEATURE_NOT_SUPPORT, ErrorCode::EE1016,
3885 : "Binding a model running instance to a stream",
3886 : RtFmtMsg("Abort mode for stream (stream_id=%d) is not supported", curStm->Id_()));
3887 :
3888 : COND_RETURN_AND_MSG_OUTER(
3889 : (curStm->Flags() & RT_STREAM_FAST_LAUNCH) != 0, RT_ERROR_FEATURE_NOT_SUPPORT, ErrorCode::EE1011,
3890 : "Binding a model running instance to a stream", "ACL_STREAM_FAST_LAUNCH", "stream flag",
3891 : RtFmtMsg(
3892 : "Stream (stream_id=%d) with the flag ACL_STREAM_FAST_LAUNCH cannot be bound to a model", curStm->Id_()));
3893 :
3894 : COND_RETURN_AND_MSG_OUTER(
3895 : (curStm->Device_()->IsSupportFeature(RtOptionalFeatureType::RT_FEATURE_MODEL_STREAM_DOT_SYNC)) &&
3896 : ((curStm->Flags() & (RT_STREAM_PERSISTENT | RT_STREAM_AICPU)) == 0),
3897 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1011, "Binding a model running instance to a stream", curStm->Flags(),
3898 : "stream flag", RtFmtMsg("Non-persistent stream (stream_id=%d) cannot be bound to a model", curStm->Id_()));
3899 :
3900 : const uint32_t modelId = mdl->Id_();
3901 : const int32_t streamId = curStm->Id_();
3902 : RT_LOG(
3903 : RT_LOG_EVENT, "model_id=%u, stream_id=%d, model_name=%s, flag=%u, group_id=%u.", modelId, streamId,
3904 : mdl->GetName().c_str(), flag, curStm->GetGroupId());
3905 :
3906 : const rtError_t error = impl_->ModelBindStream(mdl, curStm, flag);
3907 : ERROR_RETURN(error, "Bind model stream failed, model_id=%u, stream_id=%d, flag=%u.", modelId, streamId, flag);
3908 : return error;
3909 : }
3910 :
3911 : rtError_t ApiErrorDecorator::ModelUnbindStream(Model* const mdl, Stream* const stm)
3912 : {
3913 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
3914 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3915 : mdl, RT_ERROR_INVALID_VALUE, "Unbinding a model running instance from a stream");
3916 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3917 : curStm, RT_ERROR_INVALID_VALUE, "Unbinding a model running instance from a stream");
3918 : COND_RETURN_AND_MSG_OUTER(
3919 : mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL, RT_ERROR_INVALID_VALUE, ErrorCode::EE1016,
3920 : "Unbinding a model running instance from a stream", "ACL Graph mode is not supported");
3921 : COND_RETURN_AND_MSG_OUTER(
3922 : curStm->IsCapturing(), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016,
3923 : "Unbinding a model running instance from a stream",
3924 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", curStm->Id_()));
3925 :
3926 : const uint32_t modelId = mdl->Id_();
3927 : const int32_t streamId = curStm->Id_();
3928 : RT_LOG(
3929 : RT_LOG_EVENT, "model_id=%u, stream_id=%d, model_name=%s, group_id=%u.", modelId, streamId,
3930 : mdl->GetName().c_str(), curStm->GetGroupId());
3931 : const rtError_t error = impl_->ModelUnbindStream(mdl, curStm);
3932 : ERROR_RETURN(error, "Unbind model stream failed, model_id=%u, stream_id=%d.", modelId, streamId);
3933 : return error;
3934 : }
3935 :
3936 : rtError_t ApiErrorDecorator::ModelLoadComplete(Model* const mdl)
3937 : {
3938 : COND_RETURN_AND_MSG_OUTER(
3939 : (mdl != nullptr) && (mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL), RT_ERROR_INVALID_VALUE, ErrorCode::EE1016,
3940 : "Ending the build of a model running instance", "ACL Graph mode is not supported");
3941 :
3942 : const rtError_t error = impl_->ModelLoadComplete(mdl);
3943 : ERROR_RETURN(error, "Load model complete failed.");
3944 : return error;
3945 : }
3946 :
3947 : rtError_t ApiErrorDecorator::ModelExecute(Model* const mdl, Stream* const stm, const uint32_t flag, int32_t timeout)
3948 : {
3949 : // timeout >=-1, -1:no limited
3950 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3951 : (timeout < -1) || (timeout == 0), RT_ERROR_INVALID_VALUE, "Executing the model running instance", timeout,
3952 : "greater than or equal to -1 and not equal to 0");
3953 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(mdl, RT_ERROR_INVALID_VALUE, "Executing the model running instance");
3954 : COND_RETURN_AND_MSG_OUTER(
3955 : (stm != nullptr) && stm->IsModelStream(), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
3956 : "Executing the model running instance", "stm", "The current stream cannot be the same as the model stream");
3957 : COND_RETURN_AND_MSG_OUTER(
3958 : (stm != nullptr) && (stm->IsCapturing()), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016,
3959 : "Executing the model running instance",
3960 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stm->Id_()));
3961 :
3962 : if ((stm != nullptr) &&
3963 : (stm->Device_()->IsSupportFeature(RtOptionalFeatureType::RT_FEATURE_MODEL_STREAM_DOT_SYNC))) {
3964 : COND_RETURN_AND_MSG_OUTER(
3965 : ((stm->Flags() & RT_STREAM_AICPU) != 0), RT_ERROR_INVALID_VALUE, ErrorCode::EE1006,
3966 : "Executing the model running instance", "Stream flag value " + std::to_string(stm->Flags()),
3967 : "The current stream is used to carry AI CPU scheduling tasks and does not support execution models");
3968 : COND_RETURN_AND_MSG_OUTER(
3969 : ((stm->Flags() & RT_STREAM_PERSISTENT) != 0), RT_ERROR_INVALID_VALUE, ErrorCode::EE1006,
3970 : "Executing the model running instance", "Stream flag value " + std::to_string(stm->Flags()),
3971 : "Sink streams do not support execution models");
3972 : COND_RETURN_AND_MSG_OUTER(
3973 : ((stm->Flags() & RT_STREAM_CP_PROCESS_USE) != 0), RT_ERROR_INVALID_VALUE, ErrorCode::EE1006,
3974 : "Executing the model running instance", "Stream flag value " + std::to_string(stm->Flags()),
3975 : RtFmtMsg("Stream (stream_id=%d) can be called only on the device", stm->Id_()));
3976 : }
3977 :
3978 : if (mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL) {
3979 : CaptureModel* captureModel = dynamic_cast<CaptureModel*>(mdl);
3980 : COND_RETURN_WARN(
3981 : ((captureModel != nullptr) && captureModel->IsSubCaptureModel()), RT_ERROR_FEATURE_NOT_SUPPORT,
3982 : "sub ACL Graph does not support executing model");
3983 : }
3984 :
3985 : const rtError_t error = impl_->ModelExecute(mdl, stm, flag, timeout);
3986 : ERROR_RETURN(error, "Execute model failed.");
3987 : return error;
3988 : }
3989 :
3990 : rtError_t ApiErrorDecorator::ModelExecuteSync(Model* const mdl, int32_t timeout)
3991 : {
3992 : // timeout >=-1, -1:no limited
3993 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
3994 : (timeout < -1) || (timeout == 0), RT_ERROR_INVALID_VALUE, "Synchronously executing the model running instance",
3995 : timeout, "greater than or equal to -1 and not equal to 0");
3996 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
3997 : mdl, RT_ERROR_INVALID_VALUE, "Synchronously executing the model running instance");
3998 :
3999 : COND_RETURN_AND_MSG_OUTER(
4000 : mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL, RT_ERROR_INVALID_VALUE, ErrorCode::EE1016,
4001 : "Synchronously executing the model running instance", "ACL Graph mode is not supported");
4002 :
4003 : const rtError_t error = impl_->ModelExecuteSync(mdl, timeout);
4004 : ERROR_RETURN(error, "Execute model failed.");
4005 : return error;
4006 : }
4007 :
4008 : rtError_t ApiErrorDecorator::ModelExecuteAsync(Model* const mdl, Stream* const stm)
4009 : {
4010 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4011 : mdl, RT_ERROR_INVALID_VALUE, "Asynchronously executing the model running instance");
4012 : COND_RETURN_AND_MSG_OUTER(
4013 : (stm != nullptr) && stm->IsModelStream(), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
4014 : "Asynchronously executing the model running instance", "stm",
4015 : "The current stream cannot be the same as the model stream");
4016 : COND_RETURN_AND_MSG_OUTER(
4017 : (stm != nullptr) && (stm->IsCapturing()), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016,
4018 : "Asynchronously executing the model running instance",
4019 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stm->Id_()));
4020 :
4021 : const rtError_t error = impl_->ModelExecuteAsync(mdl, stm);
4022 : ERROR_RETURN(error, "Execute model failed.");
4023 : return error;
4024 : }
4025 :
4026 : rtError_t ApiErrorDecorator::ModelGetTaskId(Model* const mdl, uint32_t* const taskId, uint32_t* const streamId)
4027 : {
4028 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(mdl, RT_ERROR_INVALID_VALUE, "Obtaining the last task ID held by a model");
4029 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4030 : taskId, RT_ERROR_INVALID_VALUE, "Obtaining the last task ID held by a model");
4031 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4032 : streamId, RT_ERROR_INVALID_VALUE, "Obtaining the last task ID held by a model");
4033 : return impl_->ModelGetTaskId(mdl, taskId, streamId);
4034 : }
4035 :
4036 : rtError_t ApiErrorDecorator::ModelGetId(Model* const mdl, uint32_t* const modelId)
4037 : {
4038 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4039 : mdl, RT_ERROR_INVALID_VALUE, "Obtaining the ID of a model running instance");
4040 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4041 : modelId, RT_ERROR_INVALID_VALUE, "Obtaining the ID of a model running instance");
4042 : return impl_->ModelGetId(mdl, modelId);
4043 : }
4044 :
4045 : rtError_t ApiErrorDecorator::DebugRegister(
4046 : Model* const mdl, const uint32_t flag, const void* const addr, uint32_t* const streamId, uint32_t* const taskId)
4047 : {
4048 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4049 : mdl, RT_ERROR_INVALID_VALUE, "Registering a debugging callback for a model");
4050 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4051 : addr, RT_ERROR_INVALID_VALUE, "Registering a debugging callback for a model");
4052 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4053 : streamId, RT_ERROR_INVALID_VALUE, "Registering a debugging callback for a model");
4054 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4055 : taskId, RT_ERROR_INVALID_VALUE, "Registering a debugging callback for a model");
4056 : COND_RETURN_WARN(
4057 : (mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL), RT_ERROR_FEATURE_NOT_SUPPORT,
4058 : "Capture model does not support debug registration.");
4059 :
4060 : const rtError_t error = impl_->DebugRegister(mdl, flag, addr, streamId, taskId);
4061 : const uint32_t modelId = mdl->Id_();
4062 : RT_LOG(RT_LOG_INFO, "model_id=%u, flag=%u, streamId=%u, taskId=%u", modelId, flag, *streamId, *taskId);
4063 : ERROR_RETURN(
4064 : error, "Debug registration failed, model_id=%u, flag=%u, streamId=%u, taskId=%u.", modelId, flag, *streamId,
4065 : *taskId);
4066 : return error;
4067 : }
4068 :
4069 : rtError_t ApiErrorDecorator::DebugUnRegister(Model* const mdl)
4070 : {
4071 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4072 : mdl, RT_ERROR_INVALID_VALUE, "Registering a debugging callback for a stream");
4073 : const uint32_t modelId = mdl->Id_();
4074 : RT_LOG(RT_LOG_INFO, "model_id=%u.", modelId);
4075 : COND_RETURN_WARN(
4076 : (mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL), RT_ERROR_FEATURE_NOT_SUPPORT,
4077 : "Capture model does not support debug unregistration.");
4078 :
4079 : const rtError_t error = impl_->DebugUnRegister(mdl);
4080 : ERROR_RETURN(error, "Debug unregistration failed, model_id=%u.", modelId);
4081 : return error;
4082 : }
4083 :
4084 : rtError_t ApiErrorDecorator::DebugRegisterForStream(
4085 : Stream* const stm, const uint32_t flag, const void* const addr, uint32_t* const streamId, uint32_t* const taskId)
4086 : {
4087 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
4088 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4089 : curStm, RT_ERROR_INVALID_VALUE, "Registering a debugging callback for a stream");
4090 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4091 : addr, RT_ERROR_INVALID_VALUE, "Registering a debugging callback for a stream");
4092 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4093 : streamId, RT_ERROR_INVALID_VALUE, "Registering a debugging callback for a stream");
4094 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4095 : taskId, RT_ERROR_INVALID_VALUE, "Registering a debugging callback for a stream");
4096 :
4097 : const int32_t id = curStm->Id_();
4098 : RT_LOG(RT_LOG_INFO, "stream_id = %d, flag = %u", id, flag);
4099 :
4100 : COND_RETURN_WARN(
4101 : curStm->IsCapturing(), RT_ERROR_FEATURE_NOT_SUPPORT,
4102 : "Debug registration for stream tasks cannot be delivered in capture mode.");
4103 :
4104 : const rtError_t error = impl_->DebugRegisterForStream(curStm, flag, addr, streamId, taskId);
4105 : ERROR_RETURN(
4106 : error,
4107 : "Debug registration for stream failed, stream_id=%d, flag=%u, "
4108 : "streamId=%u, taskId=%u.",
4109 : id, flag, *streamId, *taskId);
4110 : return error;
4111 : }
4112 :
4113 : rtError_t ApiErrorDecorator::DebugUnRegisterForStream(Stream* const stm)
4114 : {
4115 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
4116 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4117 : curStm, RT_ERROR_INVALID_VALUE, "Deregistering the debugging callback of a stream");
4118 : const int32_t id = curStm->Id_();
4119 : RT_LOG(RT_LOG_INFO, "stream_id=%d.", id);
4120 :
4121 : COND_RETURN_WARN(
4122 : curStm->IsCapturing(), RT_ERROR_FEATURE_NOT_SUPPORT,
4123 : "Debug unregistration for stream tasks cannot be delivered in capture mode.");
4124 :
4125 : const rtError_t error = impl_->DebugUnRegisterForStream(curStm);
4126 : ERROR_RETURN(error, "Debug unregistration for stream failed, stream_id=%u.", id);
4127 : return error;
4128 : }
4129 :
4130 : rtError_t ApiErrorDecorator::ModelSetSchGroupId(Model* const mdl, const int16_t schGrpId)
4131 : {
4132 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(mdl, RT_ERROR_INVALID_VALUE, "Setting the scheduling group ID of a model");
4133 : if ((schGrpId < MODEL_SCH_GROUP_ID_MIN) || (schGrpId > MODEL_SCH_GROUP_ID_MAX)) {
4134 : RT_LOG_OUTER_MSG_INVALID_PARAM_WITH_DESC(
4135 : "Setting the scheduling group ID of a model", schGrpId,
4136 : "[" + std::to_string(MODEL_SCH_GROUP_ID_MIN) + ", " + std::to_string(MODEL_SCH_GROUP_ID_MAX) + "]");
4137 : return RT_ERROR_INVALID_VALUE;
4138 : }
4139 : const rtError_t error = impl_->ModelSetSchGroupId(mdl, schGrpId);
4140 : ERROR_RETURN(error, "ModelSetSchGroupId failed, schGrpId=%hd.", schGrpId);
4141 : return error;
4142 : }
4143 :
4144 : rtError_t ApiErrorDecorator::ModelTaskUpdate(
4145 : Stream* desStm, uint32_t desTaskId, Stream* sinkStm, rtMdlTaskUpdateInfo_t* para)
4146 : {
4147 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4148 : desStm, RT_ERROR_INVALID_VALUE, "Updating PC and other information of the target SQE in the target stream");
4149 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4150 : sinkStm, RT_ERROR_INVALID_VALUE, "Updating PC and other information of the target SQE in the target stream");
4151 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4152 : para, RT_ERROR_INVALID_VALUE, "Updating PC and other information of the target SQE in the target stream");
4153 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4154 : para->tilingKeyAddr, RT_ERROR_INVALID_VALUE,
4155 : "Updating PC and other information of the target SQE in the target stream");
4156 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4157 : para->blockDimAddr, RT_ERROR_INVALID_VALUE,
4158 : "Updating PC and other information of the target SQE in the target stream");
4159 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4160 : para->hdl, RT_ERROR_INVALID_VALUE, "Updating PC and other information of the target SQE in the target stream");
4161 :
4162 : const rtChipType_t chipType = Runtime::Instance()->GetChipType();
4163 :
4164 : if (!sinkStm->Device_()->IsSupportFeature(RtOptionalFeatureType::RT_FEATURE_MODEL_UPDATE_SQE_TILING_KEY)) {
4165 : RT_LOG(RT_LOG_WARNING, "unsupported chip type (%d)", chipType);
4166 : return RT_ERROR_FEATURE_NOT_SUPPORT;
4167 : }
4168 :
4169 : const uint32_t tschVersion = sinkStm->Device_()->GetTschVersion();
4170 : const bool isSupport = sinkStm->Device_()->CheckFeatureSupport(TS_FEATURE_TILING_KEY_SINK);
4171 : if (!isSupport) {
4172 : RT_LOG(
4173 : RT_LOG_WARNING, "unsupported task type (ModelTaskUpdate) in current ts version, tschVersion=%u",
4174 : tschVersion);
4175 : return RT_ERROR_FEATURE_NOT_SUPPORT;
4176 : }
4177 :
4178 : if ((desStm->GetBindFlag() != true) || (sinkStm->GetBindFlag() != true)) {
4179 : RT_LOG(RT_LOG_ERROR, "model update task does not support non-model scenario.");
4180 : return RT_ERROR_STREAM_MODEL;
4181 : }
4182 :
4183 : const rtError_t error = impl_->ModelTaskUpdate(desStm, desTaskId, sinkStm, para);
4184 : ERROR_RETURN(
4185 : error, "ModelTaskUpdate failed, desStm=%d.desTaskId=%u,sinkStm=%d", desStm->Id_(), desTaskId, sinkStm->Id_());
4186 : return error;
4187 : }
4188 :
4189 : rtError_t ApiErrorDecorator::ModelEndGraph(Model* const mdl, Stream* const stm, const uint32_t flags)
4190 : {
4191 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
4192 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4193 : mdl, RT_ERROR_INVALID_VALUE, "Delivering the EndGraph flag to the stream of a model");
4194 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4195 : curStm, RT_ERROR_INVALID_VALUE, "Delivering the EndGraph flag to the stream of a model");
4196 : COND_RETURN_AND_MSG_OUTER(
4197 : mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL, RT_ERROR_INVALID_VALUE, ErrorCode::EE1016,
4198 : "Delivering the EndGraph flag to the stream of a model", "ACL Graph mode is not supported");
4199 : COND_RETURN_AND_MSG_OUTER(
4200 : curStm->IsCapturing(), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016,
4201 : "Delivering the EndGraph flag to the stream of a model",
4202 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", curStm->Id_()));
4203 :
4204 : const rtError_t error = impl_->ModelEndGraph(mdl, curStm, flags);
4205 : ERROR_RETURN(error, "Add model end graph failed, flags=%u.", flags);
4206 : return error;
4207 : }
4208 :
4209 : rtError_t ApiErrorDecorator::ModelExecutorSet(Model* const mdl, const uint8_t flags)
4210 : {
4211 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(mdl, RT_ERROR_INVALID_VALUE, "Setting the executor type of a model");
4212 : COND_RETURN_AND_MSG_OUTER(
4213 : mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL, RT_ERROR_INVALID_VALUE, ErrorCode::EE1016,
4214 : "Setting the executor type of a model", "ACL Graph mode is not supported");
4215 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
4216 : !((flags == EXECUTOR_TS) || (flags == EXECUTOR_AICPU)), RT_ERROR_INVALID_VALUE,
4217 : "Setting the executor type of a model", flags,
4218 : std::to_string(EXECUTOR_TS) + " or " + std::to_string(EXECUTOR_AICPU));
4219 : const rtError_t error = impl_->ModelExecutorSet(mdl, flags);
4220 : ERROR_RETURN(error, "Set model executor failed flags=%hhu.", flags);
4221 : return error;
4222 : }
4223 :
4224 : rtError_t ApiErrorDecorator::ModelAbort(Model* const mdl)
4225 : {
4226 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(mdl, RT_ERROR_INVALID_VALUE, "Aborting the model running instance");
4227 : if (mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL) {
4228 : CaptureModel* captureModel = dynamic_cast<CaptureModel*>(mdl);
4229 : COND_RETURN_WARN(
4230 : ((captureModel != nullptr) && captureModel->IsSubCaptureModel()), RT_ERROR_FEATURE_NOT_SUPPORT,
4231 : "sub ACL Graph does not support aborting model");
4232 : }
4233 : const rtError_t error = impl_->ModelAbort(mdl);
4234 : ERROR_RETURN(error, "Abort model failed.");
4235 : return error;
4236 : }
4237 :
4238 : rtError_t ApiErrorDecorator::ModelExit(Model* const mdl, Stream* const stm)
4239 : {
4240 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
4241 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(mdl, RT_ERROR_INVALID_VALUE, "Model exiting");
4242 : if (mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL) {
4243 : CaptureModel* captureModel = dynamic_cast<CaptureModel*>(mdl);
4244 : COND_RETURN_WARN(
4245 : ((captureModel != nullptr) && captureModel->IsSubCaptureModel()), RT_ERROR_FEATURE_NOT_SUPPORT,
4246 : "sub ACL Graph does not support exiting model");
4247 : }
4248 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(curStm, RT_ERROR_INVALID_VALUE, "Model exiting");
4249 : const rtError_t error = impl_->ModelExit(mdl, curStm);
4250 : if (error != RT_ERROR_MODEL_ABORT_NORMAL) {
4251 : ERROR_RETURN(error, "Model exit report error.");
4252 : }
4253 : return error;
4254 : }
4255 :
4256 : rtError_t ApiErrorDecorator::MemcpyAsyncCheckExLocation(
4257 : bool checkKind, const rtMemcpyKind_t kind, const void* const src, const void* const dst) const
4258 : {
4259 : if (!checkKind) {
4260 : return RT_ERROR_NONE;
4261 : }
4262 : rtMemLocationType srcLocationType = RT_MEMORY_LOC_MAX;
4263 : rtMemLocationType dstLocationType = RT_MEMORY_LOC_MAX;
4264 : rtMemLocationType srcRealLocation = RT_MEMORY_LOC_MAX;
4265 : rtMemLocationType dstRealLocation = RT_MEMORY_LOC_MAX;
4266 : rtError_t error = GetLocationType(src, dst, srcLocationType, srcRealLocation, dstLocationType, dstRealLocation);
4267 : COND_RETURN_ERROR_MSG_CALL(
4268 : ERR_MODULE_DRV, error != RT_ERROR_NONE, error, "GetLocationType failed, retCode=%#x, src=%p, dst=%p",
4269 : static_cast<uint32_t>(error), src, dst);
4270 :
4271 : if (kind == RT_MEMCPY_HOST_TO_DEVICE_EX) {
4272 : COND_RETURN_AND_MSG_OUTER(
4273 : (srcRealLocation == RT_MEMORY_LOC_DEVICE) || (dstRealLocation != RT_MEMORY_LOC_DEVICE),
4274 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1011, "Checking the extended location for asynchronous memory copy",
4275 : RtFmtMsg(
4276 : "%s/%s", MemLocationTypeToString(srcRealLocation).c_str(),
4277 : MemLocationTypeToString(dstRealLocation).c_str()),
4278 : "src/dst address location",
4279 : "The src address must be a host address and the dst address must be a device address");
4280 : } else {
4281 : COND_RETURN_AND_MSG_OUTER(
4282 : (srcRealLocation != RT_MEMORY_LOC_DEVICE) || (dstRealLocation == RT_MEMORY_LOC_DEVICE),
4283 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1011, "Checking the extended location for asynchronous memory copy",
4284 : RtFmtMsg(
4285 : "%s/%s", MemLocationTypeToString(srcRealLocation).c_str(),
4286 : MemLocationTypeToString(dstRealLocation).c_str()),
4287 : "src/dst address location",
4288 : "The src address must be a device address and the dst address must be a host address");
4289 : }
4290 :
4291 : RT_LOG(
4292 : RT_LOG_INFO,
4293 : "MemcpyAsync EX location check passed, kind=%s, srcLocType=%s, srcRealLocType=%s, "
4294 : "dstLocType=%s, dstRealLocType=%s.",
4295 : MemcpyKindToStr(kind), MemLocationTypeToString(srcLocationType).c_str(),
4296 : MemLocationTypeToString(srcRealLocation).c_str(), MemLocationTypeToString(dstLocationType).c_str(),
4297 : MemLocationTypeToString(dstRealLocation).c_str());
4298 : return RT_ERROR_NONE;
4299 : }
4300 :
4301 : rtError_t ApiErrorDecorator::ModelBindQueue(Model* const mdl, const uint32_t queueId, const rtModelQueueFlag_t flag)
4302 : {
4303 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(mdl, RT_ERROR_INVALID_VALUE, "Binding a queue to a model");
4304 : COND_RETURN_AND_MSG_OUTER(
4305 : mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL, RT_ERROR_INVALID_VALUE, ErrorCode::EE1016,
4306 : "Binding a queue to a model", "ACL Graph mode is not supported");
4307 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
4308 : (flag != RT_MODEL_INPUT_QUEUE) && (flag != RT_MODEL_OUTPUT_QUEUE), RT_ERROR_INVALID_VALUE,
4309 : "Binding a queue to a model", flag,
4310 : std::to_string(RT_MODEL_INPUT_QUEUE) + " or " + std::to_string(RT_MODEL_OUTPUT_QUEUE));
4311 : const rtError_t error = impl_->ModelBindQueue(mdl, queueId, flag);
4312 : ERROR_RETURN(error, "Model bind queue failed, queueId=%u, flag=%d.", queueId, static_cast<int32_t>(flag));
4313 : return error;
4314 : }
4315 :
4316 : rtError_t ApiErrorDecorator::NotifyCreate(const int32_t deviceId, Notify** const retNotify, uint64_t flag)
4317 : {
4318 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(retNotify, RT_ERROR_INVALID_VALUE, "Notify creation");
4319 :
4320 : int32_t realDeviceId;
4321 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
4322 : static_cast<uint32_t>(deviceId), RtPtrToPtr<uint32_t*>(&realDeviceId));
4323 : COND_RETURN_ERROR(
4324 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", deviceId);
4325 :
4326 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
4327 : (flag & static_cast<uint32_t>(~static_cast<uint32_t>(RT_NOTIFY_FLAG_MAX))) != 0U, RT_ERROR_INVALID_VALUE,
4328 : "Notify creation", flag,
4329 : std::to_string(RT_NOTIFY_FLAG_DEFAULT) + " , " + std::to_string(RT_NOTIFY_FLAG_DOWNLOAD_TO_DEV) + " , " +
4330 : std::to_string(RT_NOTIFY_FLAG_SHR_ID_SHADOW) + " or " + std::to_string(RT_NOTIFY_FLAG_MAX));
4331 :
4332 : error = impl_->NotifyCreate(realDeviceId, retNotify, flag);
4333 : ERROR_RETURN(error, "Create notify failed, device id=%d.", deviceId);
4334 : RT_LOG(RT_LOG_INFO, "notify create success");
4335 : return error;
4336 : }
4337 :
4338 : rtError_t ApiErrorDecorator::NotifyDestroy(Notify* const inNotify)
4339 : {
4340 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(inNotify, RT_ERROR_INVALID_VALUE, "Notify destruction");
4341 :
4342 : const rtError_t error = impl_->NotifyDestroy(inNotify);
4343 : ERROR_RETURN(error, "Destroy notify failed.");
4344 : return error;
4345 : }
4346 :
4347 : rtError_t ApiErrorDecorator::NotifyRecord(Notify* const inNotify, Stream* const stm)
4348 : {
4349 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(inNotify, RT_ERROR_INVALID_VALUE, "Notify recording");
4350 :
4351 : const rtError_t error = impl_->NotifyRecord(inNotify, stm);
4352 : ERROR_RETURN(error, "Record notify failed.");
4353 : return error;
4354 : }
4355 :
4356 : rtError_t ApiErrorDecorator::NotifyReset(Notify* const inNotify)
4357 : {
4358 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(inNotify, RT_ERROR_INVALID_VALUE, "Notify resetting");
4359 :
4360 : const rtError_t error = impl_->NotifyReset(inNotify);
4361 : ERROR_RETURN(error, "Reset notify failed.");
4362 : return error;
4363 : }
4364 :
4365 : rtError_t ApiErrorDecorator::ResourceClean(int32_t devId, rtIdType_t type)
4366 : {
4367 : if (type != RT_NOTIFY_ID) {
4368 : RT_LOG(RT_LOG_WARNING, "unsupported current type is %u, valid type is %u", type, RT_NOTIFY_ID);
4369 : return RT_ERROR_FEATURE_NOT_SUPPORT;
4370 : }
4371 : Runtime* const rt = Runtime::Instance();
4372 : const driverType_t rawDrvType = rt->GetDriverType();
4373 : Driver* const rawDrv = rt->driverFactory_.GetDriver(rawDrvType);
4374 : NULL_PTR_RETURN_MSG(rawDrv, RT_ERROR_DRV_NULL);
4375 : COND_RETURN_WITH_NOLOG(
4376 : !IS_SUPPORT_CHIP_FEATURE(
4377 : rt->GetChipType(), RtOptionalFeatureType::RT_FEATURE_DFX_FAST_RECOVER_DOT_RESOURCE_CLEAN),
4378 : RT_ERROR_FEATURE_NOT_SUPPORT);
4379 : int32_t deviceCnt;
4380 : int32_t realDeviceId;
4381 : rtError_t error = rt->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
4382 : COND_RETURN_ERROR(
4383 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
4384 :
4385 : error = rawDrv->GetDeviceCount(&deviceCnt);
4386 : ERROR_RETURN_MSG_CALL(ERR_MODULE_DRV, error, "Get device cnt failed, retCode=%#x", static_cast<uint32_t>(error));
4387 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
4388 : ((realDeviceId < 0) || (realDeviceId >= deviceCnt)), RT_ERROR_DEVICE_ID, realDeviceId,
4389 : "[0, " + std::to_string(deviceCnt) + ")");
4390 :
4391 : error = impl_->ResourceClean(realDeviceId, type);
4392 : ERROR_RETURN(error, "resource clean.");
4393 : return error;
4394 : }
4395 :
4396 : rtError_t ApiErrorDecorator::NotifyWait(Notify* const inNotify, Stream* const stm, const uint32_t timeOut)
4397 : {
4398 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(inNotify, RT_ERROR_INVALID_VALUE, "Waiting for a Notify");
4399 : const rtError_t error = impl_->NotifyWait(inNotify, stm, timeOut);
4400 : ERROR_RETURN(error, "NotifyWait failed, timeout=%us", timeOut);
4401 : return error;
4402 : }
4403 :
4404 : rtError_t ApiErrorDecorator::GetNotifyID(Notify* const inNotify, uint32_t* const notifyID)
4405 : {
4406 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(inNotify, RT_ERROR_INVALID_VALUE, "Obtaining the Notify ID");
4407 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(notifyID, RT_ERROR_INVALID_VALUE, "Obtaining the Notify ID");
4408 :
4409 : const rtError_t error = impl_->GetNotifyID(inNotify, notifyID);
4410 : ERROR_RETURN(error, "Get notify ID failed.");
4411 : return error;
4412 : }
4413 :
4414 : rtError_t ApiErrorDecorator::GetNotifyPhyInfo(Notify* const inNotify, rtNotifyPhyInfo* notifyInfo)
4415 : {
4416 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4417 : inNotify, RT_ERROR_INVALID_VALUE, "Obtaining underlying physical hardware information of Notify");
4418 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4419 : notifyInfo, RT_ERROR_INVALID_VALUE, "Obtaining underlying physical hardware information of Notify");
4420 :
4421 : return impl_->GetNotifyPhyInfo(inNotify, notifyInfo);
4422 : }
4423 :
4424 : rtError_t ApiErrorDecorator::IpcSetNotifyName(
4425 : Notify* const inNotify, char_t* const name, const uint32_t len, const uint64_t flag)
4426 : {
4427 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(inNotify, RT_ERROR_INVALID_VALUE, "Setting a Notify as an IPC Notify");
4428 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(name, RT_ERROR_INVALID_VALUE, "Setting a Notify as an IPC Notify");
4429 : ZERO_RETURN_AND_MSG_OUTER(len);
4430 :
4431 : const Runtime* const rtInstance = Runtime::Instance();
4432 : const rtChipType_t chipType = rtInstance->GetChipType();
4433 : if (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_IPC_NOTIFY)) {
4434 : RT_LOG(RT_LOG_WARNING, "chipType=%d is not supported. Return.", chipType);
4435 : return RT_ERROR_FEATURE_NOT_SUPPORT;
4436 : }
4437 :
4438 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
4439 : ((flag != RT_NOTIFY_EXPORT_FLAG_DISABLE_PID_VALIDATION) && (flag != RT_NOTIFY_FLAG_DEFAULT)),
4440 : RT_ERROR_INVALID_VALUE, "Setting a Notify as an IPC Notify", flag,
4441 : std::to_string(RT_NOTIFY_FLAG_DEFAULT) + " or " + std::to_string(RT_NOTIFY_EXPORT_FLAG_DISABLE_PID_VALIDATION));
4442 :
4443 : const rtError_t error = impl_->IpcSetNotifyName(inNotify, name, len, flag);
4444 : ERROR_RETURN(error, "Ipc set notify name failed, name=%s, len=%u(bytes).", name, len);
4445 : return error;
4446 : }
4447 :
4448 : rtError_t ApiErrorDecorator::IpcOpenNotify(Notify** const retNotify, const char_t* const name, uint32_t flag)
4449 : {
4450 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(retNotify, RT_ERROR_INVALID_VALUE, "Enabling IPC Notify");
4451 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(name, RT_ERROR_INVALID_VALUE, "Enabling IPC Notify");
4452 :
4453 : constexpr uint32_t maxFlag = (RT_NOTIFY_FLAG_DOWNLOAD_TO_DEV | RT_NOTIFY_IMPORT_FLAG_ENABLE_PEER_ACCESS);
4454 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
4455 : (flag > maxFlag), RT_ERROR_INVALID_VALUE, "Enabling IPC Notify", flag, "[0, " + std::to_string(maxFlag) + "]");
4456 : const rtError_t error = impl_->IpcOpenNotify(retNotify, name, flag);
4457 : ERROR_RETURN(error, "Ipc open notify failed, name=%s.", name);
4458 : return error;
4459 : }
4460 :
4461 : rtError_t ApiErrorDecorator::NotifyGetAddrOffset(Notify* const inNotify, uint64_t* const devAddrOffset)
4462 : {
4463 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4464 : inNotify, RT_ERROR_INVALID_VALUE, "Obtaining the physical address offset of a Notify object");
4465 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4466 : devAddrOffset, RT_ERROR_INVALID_VALUE, "Obtaining the physical address offset of a Notify object");
4467 :
4468 : const rtError_t error = impl_->NotifyGetAddrOffset(inNotify, devAddrOffset);
4469 : ERROR_RETURN(error, "Get notify address offset failed.");
4470 : return error;
4471 : }
4472 :
4473 : rtError_t ApiErrorDecorator::StreamSwitchEx(
4474 : void* const ptr, const rtCondition_t condition, void* const valuePtr, Stream* const trueStream, Stream* const stm,
4475 : const rtSwitchDataType_t dataType)
4476 : {
4477 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
4478 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4479 : ptr, RT_ERROR_INVALID_VALUE, "Switching between streams based on conditions");
4480 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4481 : valuePtr, RT_ERROR_INVALID_VALUE, "Switching between streams based on conditions");
4482 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4483 : trueStream, RT_ERROR_INVALID_VALUE, "Switching between streams based on conditions");
4484 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4485 : curStm, RT_ERROR_INVALID_VALUE, "Switching between streams based on conditions");
4486 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_DESC(
4487 : (condition > RT_LESS_OR_EQUAL) || (condition < 0), RT_ERROR_INVALID_VALUE,
4488 : "Switching between streams based on conditions", RtFmtMsg("UNKNOWN(%d)", static_cast<int32_t>(condition)),
4489 : "condition", "[0, " + std::to_string(RT_LESS_OR_EQUAL) + "]");
4490 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME(
4491 : (dataType > RT_SWITCH_INT64) || (dataType < 0), RT_ERROR_INVALID_VALUE, SwitchDataTypeToString(dataType),
4492 : "dataType", "[0, " + std::to_string(RT_SWITCH_INT64) + "]");
4493 : const rtError_t error = impl_->StreamSwitchEx(ptr, condition, valuePtr, trueStream, curStm, dataType);
4494 : ERROR_RETURN(
4495 : error, "Stream switch[extend] failed, condition=%s, dataType=%s.", ConditionToString(condition).c_str(),
4496 : SwitchDataTypeToString(dataType).c_str());
4497 : return error;
4498 : }
4499 :
4500 : rtError_t ApiErrorDecorator::StreamSwitchN(
4501 : void* const ptr, const uint32_t size, void* const valuePtr, Stream** const trueStreamPtr,
4502 : const uint32_t elementSize, Stream* const stm, const rtSwitchDataType_t dataType)
4503 : {
4504 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
4505 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4506 : ptr, RT_ERROR_INVALID_VALUE, "Switching between multi-dimensional streams based on conditional operators");
4507 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4508 : valuePtr, RT_ERROR_INVALID_VALUE, "Switching between multi-dimensional streams based on conditional operators");
4509 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4510 : trueStreamPtr, RT_ERROR_INVALID_VALUE,
4511 : "Switching between multi-dimensional streams based on conditional operators");
4512 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4513 : curStm, RT_ERROR_INVALID_VALUE, "Switching between multi-dimensional streams based on conditional operators");
4514 :
4515 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
4516 : (size == 0U), RT_ERROR_INVALID_VALUE,
4517 : "Switching between multi-dimensional streams based on conditional operators", size, "not equal to 0");
4518 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
4519 : (elementSize == 0U), RT_ERROR_INVALID_VALUE,
4520 : "Switching between multi-dimensional streams based on conditional operators", elementSize, "not equal to 0");
4521 : COND_RETURN_AND_MSG_OUTER(
4522 : ((UINT32_MAX / size) <= elementSize), RT_ERROR_INVALID_VALUE, ErrorCode::EE1011,
4523 : "Switching between multi-dimensional streams based on conditional operators", elementSize, "elementSize",
4524 : RtFmtMsg(
4525 : "Parameter elementSize should be less than the quotient of %u and parameter size %u", UINT32_MAX, size));
4526 :
4527 : for (uint32_t i = 0U; i < elementSize; i++) {
4528 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4529 : trueStreamPtr[i], RT_ERROR_INVALID_VALUE,
4530 : "Switching between multi-dimensional streams based on conditional operators");
4531 : }
4532 :
4533 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME(
4534 : (dataType > RT_SWITCH_INT64) || (dataType < 0), RT_ERROR_INVALID_VALUE, SwitchDataTypeToString(dataType),
4535 : "dataType", "[0, " + std::to_string(RT_SWITCH_INT64) + "]");
4536 : const rtError_t error = impl_->StreamSwitchN(ptr, size, valuePtr, trueStreamPtr, elementSize, curStm, dataType);
4537 : ERROR_RETURN(
4538 : error, "Stream switchN failed, size=%u(bytes), elementSize=%u(bytes) dataType=%s", size, elementSize,
4539 : SwitchDataTypeToString(dataType).c_str());
4540 : return error;
4541 : }
4542 :
4543 : rtError_t ApiErrorDecorator::StreamActive(Stream* const activeStream, Stream* const stm)
4544 : {
4545 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
4546 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(curStm, RT_ERROR_INVALID_VALUE, "Stream activation");
4547 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(activeStream, RT_ERROR_INVALID_VALUE, "Stream activation");
4548 : const rtError_t error = impl_->StreamActive(activeStream, curStm);
4549 : ERROR_RETURN(error, "Stream active failed.");
4550 : return error;
4551 : }
4552 :
4553 : rtError_t ApiErrorDecorator::LabelCreate(Label** const lbl, Model* const mdl)
4554 : {
4555 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(lbl, RT_ERROR_INVALID_VALUE, "Label creation");
4556 : COND_RETURN_AND_MSG_OUTER(
4557 : (mdl != nullptr) && (mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL), RT_ERROR_INVALID_VALUE, ErrorCode::EE1016,
4558 : "Label creation", "ACL Graph mode is not supported");
4559 : const rtError_t error = impl_->LabelCreate(lbl, mdl);
4560 : ERROR_RETURN(error, "Label create failed.");
4561 : RT_LOG(RT_LOG_DEBUG, "label create success, labelId = %hu", (*lbl)->Id_());
4562 : return error;
4563 : }
4564 :
4565 : rtError_t ApiErrorDecorator::LabelDestroy(Label* const lbl)
4566 : {
4567 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(lbl, RT_ERROR_INVALID_VALUE, "Label destruction");
4568 :
4569 : const rtError_t error = impl_->LabelDestroy(lbl);
4570 : ERROR_RETURN(error, "Label destroy failed.");
4571 : return error;
4572 : }
4573 :
4574 : rtError_t ApiErrorDecorator::LabelSet(Label* const lbl, Stream* const stm)
4575 : {
4576 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
4577 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(lbl, RT_ERROR_INVALID_VALUE, "Label setting");
4578 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(curStm, RT_ERROR_INVALID_VALUE, "Label setting");
4579 : const rtError_t error = impl_->LabelSet(lbl, curStm);
4580 : ERROR_RETURN(error, "Set label failed.");
4581 : return error;
4582 : }
4583 :
4584 : rtError_t ApiErrorDecorator::LabelGoto(Label* const lbl, Stream* const stm)
4585 : {
4586 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
4587 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(lbl, RT_ERROR_INVALID_VALUE, "Label redirection");
4588 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(curStm, RT_ERROR_INVALID_VALUE, "Label redirection");
4589 : const rtError_t error = impl_->LabelSet(lbl, curStm);
4590 : ERROR_RETURN(error, "Label goto failed.");
4591 : return error;
4592 : }
4593 :
4594 : rtError_t ApiErrorDecorator::SetExceptCallback(const rtErrorCallback callback)
4595 : {
4596 : return impl_->SetExceptCallback(callback);
4597 : }
4598 :
4599 : rtError_t ApiErrorDecorator::SetTaskAbortCallBack(
4600 : const char* regName, void* callback, void* args, TaskAbortCallbackType type)
4601 : {
4602 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4603 : regName, RT_ERROR_INVALID_VALUE, "Registering the aborting callback function of a task");
4604 : return impl_->SetTaskAbortCallBack(regName, callback, args, type);
4605 : }
4606 :
4607 : rtError_t ApiErrorDecorator::RegDeviceStateCallback(
4608 : const char_t* regName, void* callback, void* args, DeviceStateCallback type, rtDevCallBackDir_t notifyPos)
4609 : {
4610 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4611 : regName, RT_ERROR_INVALID_VALUE, "Registering the device status callback function");
4612 : COND_RETURN_AND_MSG_OUTER(
4613 : (type == DeviceStateCallback::RT_DEVICE_STATE_CALLBACK) &&
4614 : ((notifyPos < DEV_CB_POS_FRONT) || (notifyPos >= DEV_CB_POS_END)),
4615 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1011, "Registering the device status callback function", notifyPos,
4616 : "notifyPos",
4617 : RtFmtMsg(
4618 : "If parameter type equals RT_DEVICE_STATE_CALLBACK(0),"
4619 : " the range of parameter notifyPos should be [%u, %u)",
4620 : DEV_CB_POS_FRONT, DEV_CB_POS_END));
4621 : return impl_->RegDeviceStateCallback(regName, callback, args, type, notifyPos);
4622 : }
4623 :
4624 : rtError_t ApiErrorDecorator::RegProfCtrlCallback(const uint32_t moduleId, const rtProfCtrlHandle callback)
4625 : {
4626 : return impl_->RegProfCtrlCallback(moduleId, callback);
4627 : }
4628 :
4629 : rtError_t ApiErrorDecorator::GetL2CacheOffset(uint32_t deviceId, uint64_t* offset)
4630 : {
4631 : COND_RETURN_ERROR((offset == nullptr), RT_ERROR_INVALID_VALUE, "offset is null");
4632 : uint32_t realDeviceId = 0;
4633 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(deviceId, &realDeviceId);
4634 : COND_RETURN_ERROR(
4635 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", deviceId);
4636 : error = CheckDeviceIdIsValid(static_cast<int32_t>(realDeviceId));
4637 : COND_RETURN_ERROR_MSG_INNER(
4638 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%u, retCode=%#x", realDeviceId,
4639 : static_cast<uint32_t>(error));
4640 :
4641 : error = impl_->GetL2CacheOffset(realDeviceId, offset);
4642 : COND_RETURN_WARN(
4643 : error == RT_ERROR_FEATURE_NOT_SUPPORT, RT_ERROR_FEATURE_NOT_SUPPORT,
4644 : "Get L2Cache Offset fail deviceId=%u, drv devId=%u.", deviceId, realDeviceId);
4645 : ERROR_RETURN(error, "get l2cache offset fail, deviceId=%u, drv devId=%u.", deviceId, realDeviceId);
4646 : return error;
4647 : }
4648 :
4649 : rtError_t ApiErrorDecorator::RegTaskFailCallbackByModule(
4650 : const char_t* regName, void* callback, void* args, TaskFailCallbackType type)
4651 : {
4652 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4653 : regName, RT_ERROR_INVALID_VALUE, "Registering the callback function for task execution errors");
4654 :
4655 : return impl_->RegTaskFailCallbackByModule(regName, callback, args, type);
4656 : }
4657 :
4658 : rtError_t ApiErrorDecorator::SubscribeReport(const uint64_t threadId, Stream* const stm)
4659 : {
4660 : COND_RETURN_AND_MSG_OUTER(
4661 : (stm != nullptr) && (stm->GetSubscribeFlag() == StreamSubscribeFlag::SUBSCRIBE_RUNTIME),
4662 : RT_ERROR_SUBSCRIBE_STREAM, ErrorCode::EE1016,
4663 : "Specifying the thread for processing the callback function in stream",
4664 : RtFmtMsg(
4665 : "The stream (stream_id=%d) is in the host callback process and cannot call rtSubscribeReport", stm->Id_()));
4666 : return impl_->SubscribeReport(threadId, stm);
4667 : }
4668 :
4669 : rtError_t ApiErrorDecorator::CallbackLaunch(
4670 : const rtCallback_t callBackFunc, void* const fnData, Stream* const stm, const bool isBlock)
4671 : {
4672 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4673 : callBackFunc, RT_ERROR_INVALID_VALUE, "Delivering an on-host callback function task in a stream");
4674 : COND_RETURN_AND_MSG_OUTER(
4675 : (stm != nullptr) && (stm->GetSubscribeFlag() == StreamSubscribeFlag::SUBSCRIBE_RUNTIME),
4676 : RT_ERROR_SUBSCRIBE_STREAM, ErrorCode::EE1016, "Delivering an on-host callback function task in a stream",
4677 : RtFmtMsg(
4678 : "The stream (stream_id=%d) is in the host callback process and cannot call rtCallbackLaunch", stm->Id_()));
4679 : return impl_->CallbackLaunch(callBackFunc, fnData, stm, isBlock);
4680 : }
4681 :
4682 : rtError_t ApiErrorDecorator::ProcessReport(const int32_t timeout, const bool noLog)
4683 : {
4684 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
4685 : (timeout < -1) || (timeout == 0), RT_ERROR_INVALID_VALUE, timeout,
4686 : "-1 or (0, " + std::to_string(MAX_INT32_NUM) + "]");
4687 :
4688 : return impl_->ProcessReport(timeout, noLog);
4689 : }
4690 :
4691 : rtError_t ApiErrorDecorator::UnSubscribeReport(const uint64_t threadId, Stream* const stm)
4692 : {
4693 : COND_RETURN_AND_MSG_OUTER(
4694 : (stm != nullptr) && (stm->GetSubscribeFlag() == StreamSubscribeFlag::SUBSCRIBE_RUNTIME),
4695 : RT_ERROR_SUBSCRIBE_STREAM, ErrorCode::EE1016, "Cancelling thread registration",
4696 : RtFmtMsg(
4697 : "The stream (stream_id=%d) is in the host callback process and cannot call rtUnSubscribeReport",
4698 : stm->Id_()));
4699 : return impl_->UnSubscribeReport(threadId, stm);
4700 : }
4701 :
4702 : rtError_t ApiErrorDecorator::GetRunMode(rtRunMode* const runMode)
4703 : {
4704 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4705 : runMode, RT_ERROR_INVALID_VALUE, "Obtaining the current run mode of the AI software stack");
4706 :
4707 : return impl_->GetRunMode(runMode);
4708 : }
4709 :
4710 : rtError_t ApiErrorDecorator::LabelSwitchByIndex(
4711 : void* const ptr, const uint32_t maxVal, void* const labelInfoPtr, Stream* const stm)
4712 : {
4713 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
4714 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4715 : ptr, RT_ERROR_INVALID_VALUE, "Redirecting to the corresponding label position based on the label index");
4716 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4717 : labelInfoPtr, RT_ERROR_INVALID_VALUE,
4718 : "Redirecting to the corresponding label position based on the label index");
4719 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4720 : curStm, RT_ERROR_INVALID_VALUE, "Redirecting to the corresponding label position based on the label index");
4721 :
4722 : return impl_->LabelSwitchByIndex(ptr, maxVal, labelInfoPtr, curStm);
4723 : }
4724 :
4725 : rtError_t ApiErrorDecorator::LabelGotoEx(Label* const lbl, Stream* const stm)
4726 : {
4727 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
4728 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(lbl, RT_ERROR_INVALID_VALUE, "Label redirection");
4729 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(curStm, RT_ERROR_INVALID_VALUE, "Label redirection");
4730 :
4731 : return impl_->LabelGotoEx(lbl, curStm);
4732 : }
4733 :
4734 : rtError_t ApiErrorDecorator::LabelListCpy(
4735 : Label** const lbl, const uint32_t labelNumber, void* const dst, const uint32_t dstMax)
4736 : {
4737 : ZERO_RETURN_AND_MSG_OUTER(labelNumber);
4738 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(lbl, RT_ERROR_INVALID_VALUE, "Label list copy");
4739 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(dst, RT_ERROR_INVALID_VALUE, "Label list copy");
4740 :
4741 : const uint64_t labelSize = sizeof(rtLabelDevInfo) * labelNumber;
4742 : COND_RETURN_AND_MSG_OUTER(
4743 : labelSize != static_cast<uint64_t>(dstMax), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Label list copy",
4744 : "labelNumber or dstMax",
4745 : RtFmtMsg(
4746 : "Parameter dstMax %u should be equal to the product of parameter"
4747 : " labelNumber %u and %zu",
4748 : dstMax, labelNumber, sizeof(rtLabelDevInfo)));
4749 :
4750 : return impl_->LabelListCpy(lbl, labelNumber, dst, dstMax);
4751 : }
4752 :
4753 : rtError_t ApiErrorDecorator::LabelCreateEx(Label** const lbl, Model* const mdl, Stream* const stm)
4754 : {
4755 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
4756 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(lbl, RT_ERROR_INVALID_VALUE, "Label creation");
4757 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(curStm, RT_ERROR_INVALID_VALUE, "Label creation");
4758 : COND_RETURN_AND_MSG_OUTER(
4759 : (mdl != nullptr) && (mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL), RT_ERROR_INVALID_VALUE, ErrorCode::EE1016,
4760 : "Label creation", "ACL Graph mode is not supported");
4761 : COND_RETURN_AND_MSG_OUTER(
4762 : curStm->IsCapturing(), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016, "Label creation",
4763 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", curStm->Id_()));
4764 :
4765 : return impl_->LabelCreateEx(lbl, mdl, curStm);
4766 : }
4767 :
4768 : rtError_t ApiErrorDecorator::LabelSwitchListCreate(Label** const labels, const size_t num, void** const labelList)
4769 : {
4770 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(labels, RT_ERROR_INVALID_VALUE, "Label list creation");
4771 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(labelList, RT_ERROR_INVALID_VALUE, "Label list creation");
4772 : return impl_->LabelSwitchListCreate(labels, num, labelList);
4773 : }
4774 :
4775 : rtError_t ApiErrorDecorator::GetAicpuDeploy(rtAicpuDeployType_t* const deployType)
4776 : {
4777 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4778 : deployType, RT_ERROR_INVALID_VALUE, "Obtaining the AI CPU deployment type");
4779 :
4780 : return impl_->GetAicpuDeploy(deployType);
4781 : }
4782 :
4783 : rtError_t ApiErrorDecorator::GetAiCoreCount(uint32_t* const aiCoreCnt)
4784 : {
4785 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(aiCoreCnt, RT_ERROR_INVALID_VALUE, "Obtaining the number of AI Cores");
4786 :
4787 : return impl_->GetAiCoreCount(aiCoreCnt);
4788 : }
4789 :
4790 : rtError_t ApiErrorDecorator::GetAiCpuCount(uint32_t* const aiCpuCnt)
4791 : {
4792 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(aiCpuCnt, RT_ERROR_INVALID_VALUE, "Obtaining the number of AI CPUs");
4793 :
4794 : return impl_->GetAiCpuCount(aiCpuCnt);
4795 : }
4796 :
4797 : rtError_t ApiErrorDecorator::GetPairDevicesInfo(
4798 : const uint32_t devId, const uint32_t otherDevId, const int32_t infoType, int64_t* const val)
4799 : {
4800 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4801 : val, RT_ERROR_INVALID_VALUE, "Querying the pairing information between two logical devices");
4802 : uint32_t realDeviceId;
4803 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(devId, &realDeviceId);
4804 : COND_RETURN_ERROR(
4805 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", devId);
4806 : uint32_t readOtherDeviceId;
4807 : error = Runtime::Instance()->ChgUserDevIdToDeviceId(otherDevId, &readOtherDeviceId);
4808 : COND_RETURN_ERROR(
4809 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", otherDevId);
4810 : return impl_->GetPairDevicesInfo(realDeviceId, readOtherDeviceId, infoType, val);
4811 : }
4812 :
4813 : rtError_t ApiErrorDecorator::GetPairPhyDevicesInfo(
4814 : const uint32_t devId, const uint32_t otherDevId, const int32_t infoType, int64_t* const val)
4815 : {
4816 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4817 : val, RT_ERROR_INVALID_VALUE, "Querying the pairing information between two physical devices");
4818 : RT_LOG(
4819 : RT_LOG_INFO, "input physical devId=%u, input physical otherDevId=%u, infoType=%d", devId, otherDevId, infoType);
4820 : return impl_->GetPairPhyDevicesInfo(devId, otherDevId, infoType, val);
4821 : }
4822 :
4823 : rtError_t ApiErrorDecorator::GetRtCapability(
4824 : const rtFeatureType_t featureType, const int32_t featureInfo, int64_t* const val)
4825 : {
4826 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
4827 : featureInfo < 0, RT_ERROR_INVALID_VALUE, "Querying device features and capabilities", featureInfo,
4828 : "greater than or equal to 0");
4829 :
4830 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(val, RT_ERROR_INVALID_VALUE, "Querying device features and capabilities");
4831 :
4832 : return impl_->GetRtCapability(featureType, featureInfo, val);
4833 : }
4834 :
4835 : rtError_t GetModTaskUpIsSupport(int32_t* const val)
4836 : {
4837 : const rtChipType_t chipType = Runtime::Instance()->GetChipType();
4838 : *val = static_cast<int32_t>(RT_DEV_CAP_NOT_SUPPORT);
4839 : if (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_MODEL_UPDATE_SQE_TILING_KEY)) {
4840 : RT_LOG(RT_LOG_INFO, "chipType = %u", static_cast<uint32_t>(chipType));
4841 : return RT_ERROR_NONE;
4842 : }
4843 :
4844 : const bool isSupport = CheckSupportTilingKeyWhenCompile();
4845 : if (isSupport) {
4846 : *val = RT_DEV_CAP_SUPPORT;
4847 : }
4848 :
4849 : RT_LOG(RT_LOG_INFO, "chipType = %u, *val=%d", static_cast<uint32_t>(chipType), *val);
4850 : return RT_ERROR_NONE;
4851 : }
4852 :
4853 : rtError_t ApiErrorDecorator::GetDeviceCapability(
4854 : const int32_t deviceId, const int32_t moduleType, const int32_t featureType, int32_t* const val)
4855 : {
4856 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(val, RT_ERROR_INVALID_VALUE, "Querying features supported by the device");
4857 :
4858 : if ((featureType == static_cast<int32_t>(FEATURE_TYPE_MODEL_TASK_UPDATE)) &&
4859 : (moduleType == static_cast<int32_t>(RT_MODULE_TYPE_TSCPU)) && (deviceId == STUB_DEVICE_ID)) {
4860 : // adapt to stub device,only consider Chip type
4861 : return GetModTaskUpIsSupport(val);
4862 : }
4863 : int32_t realDeviceId;
4864 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
4865 : static_cast<uint32_t>(deviceId), RtPtrToPtr<uint32_t*>(&realDeviceId));
4866 : COND_RETURN_ERROR(
4867 : error != RT_ERROR_NONE, RT_ERROR_DEVICE_ID, "Failed to convert the user device ID %d to driver device ID.",
4868 : deviceId);
4869 : error = CheckDeviceIdIsValid(realDeviceId);
4870 : COND_RETURN_ERROR_MSG_INNER(
4871 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%d, retCode=%#x", realDeviceId,
4872 : static_cast<uint32_t>(error));
4873 :
4874 : error = impl_->GetDeviceCapability(realDeviceId, moduleType, featureType, val);
4875 : ERROR_RETURN(
4876 : error, "Get device capability failed, deviceId=%d, moduleType=%d, featureType=%d.", deviceId, moduleType,
4877 : featureType);
4878 : return error;
4879 : }
4880 :
4881 : rtError_t ApiErrorDecorator::GetFaultEvent(
4882 : const int32_t deviceId, rtDmsEventFilter* filter, rtDmsFaultEvent* dmsEvent, uint32_t len, uint32_t* eventCount)
4883 : {
4884 : COND_RETURN_ERROR((filter == nullptr), RT_ERROR_INVALID_VALUE, "input filter is null");
4885 : Runtime* const rtInstance = Runtime::Instance();
4886 : COND_RETURN_ERROR_MSG_INNER(rtInstance == nullptr, RT_ERROR_INSTANCE_NULL, "Runtime instance is null");
4887 : const rtChipType_t chipType = rtInstance->GetChipType();
4888 : if (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_DRIVER_GET_FAULT_EVENT)) {
4889 : return RT_ERROR_FEATURE_NOT_SUPPORT;
4890 : }
4891 : int32_t realDeviceId = 0;
4892 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
4893 : static_cast<uint32_t>(deviceId), RtPtrToPtr<uint32_t*>(&realDeviceId));
4894 : COND_RETURN_ERROR(
4895 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", deviceId);
4896 : error = CheckDeviceIdIsValid(realDeviceId);
4897 : COND_RETURN_ERROR_MSG_INNER(
4898 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%d, retCode=%#x", realDeviceId,
4899 : static_cast<uint32_t>(error));
4900 : return impl_->GetFaultEvent(realDeviceId, filter, dmsEvent, len, eventCount);
4901 : }
4902 :
4903 : rtError_t ApiErrorDecorator::GetMemUceInfo(const uint32_t deviceId, rtMemUceInfo* memUceInfo)
4904 : {
4905 : COND_RETURN_ERROR((memUceInfo == nullptr), RT_ERROR_INVALID_VALUE, "input memUceInfo is null.");
4906 : Runtime* const rtInstance = Runtime::Instance();
4907 : COND_RETURN_ERROR_MSG_INNER(rtInstance == nullptr, RT_ERROR_INSTANCE_NULL, "Runtime instance is null.");
4908 : const rtChipType_t chipType = rtInstance->GetChipType();
4909 : if (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_DFX_FAST_RECOVER)) {
4910 : return RT_ERROR_FEATURE_NOT_SUPPORT;
4911 : }
4912 :
4913 : int32_t deviceCnt = 0;
4914 : int32_t realDeviceId = 0;
4915 : rtError_t error =
4916 : rtInstance->ChgUserDevIdToDeviceId(static_cast<uint32_t>(deviceId), RtPtrToPtr<uint32_t*>(&realDeviceId));
4917 : COND_RETURN_ERROR(
4918 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", deviceId);
4919 :
4920 : const driverType_t rawDrvType = rtInstance->GetDriverType();
4921 : Driver* const rawDrv = rtInstance->driverFactory_.GetDriver(rawDrvType);
4922 : error = rawDrv->GetDeviceCount(&deviceCnt);
4923 : ERROR_RETURN_MSG_CALL(ERR_MODULE_DRV, error, "Get device cnt failed, retCode=%#x", static_cast<uint32_t>(error));
4924 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
4925 : ((realDeviceId < 0) || (realDeviceId >= deviceCnt)), RT_ERROR_DEVICE_ID, realDeviceId,
4926 : "[0, " + std::to_string(deviceCnt) + ")");
4927 :
4928 : error = impl_->GetMemUceInfo(static_cast<uint32_t>(realDeviceId), memUceInfo);
4929 : ERROR_RETURN(error, "GetMemUceInfo failed");
4930 : const uint32_t drvDeviceId = memUceInfo->devid;
4931 : error = Runtime::Instance()->GetUserDevIdByDeviceId(drvDeviceId, &memUceInfo->devid);
4932 : ERROR_RETURN_MSG_INNER(
4933 : error, "Failed to convert the driver device ID %u to user device ID, retCode=%#x", drvDeviceId,
4934 : static_cast<uint32_t>(error));
4935 : return RT_ERROR_NONE;
4936 : }
4937 :
4938 : rtError_t ApiErrorDecorator::MemUceRepair(const uint32_t deviceId, rtMemUceInfo* memUceInfo)
4939 : {
4940 : COND_RETURN_ERROR((memUceInfo == nullptr), RT_ERROR_INVALID_VALUE, "input memUceInfo is null");
4941 : Runtime* const rtInstance = Runtime::Instance();
4942 : COND_RETURN_ERROR_MSG_INNER(rtInstance == nullptr, RT_ERROR_INSTANCE_NULL, "Runtime instance is null");
4943 : const rtChipType_t chipType = rtInstance->GetChipType();
4944 : if (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_DFX_FAST_RECOVER)) {
4945 : return RT_ERROR_FEATURE_NOT_SUPPORT;
4946 : }
4947 : int32_t deviceCnt = 0;
4948 : int32_t realDeviceId = 0;
4949 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
4950 : static_cast<uint32_t>(deviceId), RtPtrToPtr<uint32_t*>(&realDeviceId));
4951 : COND_RETURN_ERROR(
4952 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", deviceId);
4953 :
4954 : const driverType_t rawDrvType = rtInstance->GetDriverType();
4955 : Driver* const rawDrv = rtInstance->driverFactory_.GetDriver(rawDrvType);
4956 : error = rawDrv->GetDeviceCount(&deviceCnt);
4957 : ERROR_RETURN_MSG_CALL(ERR_MODULE_DRV, error, "Get device cnt failed, retCode=%#x", static_cast<uint32_t>(error));
4958 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
4959 : ((realDeviceId < 0) || (realDeviceId >= deviceCnt)), RT_ERROR_DEVICE_ID, realDeviceId,
4960 : "[0, " + std::to_string(deviceCnt) + ")");
4961 :
4962 : const uint32_t userDeviceId = memUceInfo->devid;
4963 : error = Runtime::Instance()->ChgUserDevIdToDeviceId(userDeviceId, &memUceInfo->devid);
4964 : COND_RETURN_ERROR(
4965 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", userDeviceId);
4966 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
4967 : memUceInfo->devid >= static_cast<uint32_t>(deviceCnt), RT_ERROR_DEVICE_ID, memUceInfo->devid,
4968 : "[0," + std::to_string(deviceCnt) + ")");
4969 : return impl_->MemUceRepair(realDeviceId, memUceInfo);
4970 : }
4971 :
4972 : rtError_t ApiErrorDecorator::SetOpWaitTimeOut(const uint32_t timeout)
4973 : {
4974 : const rtError_t error = impl_->SetOpWaitTimeOut(timeout);
4975 : COND_RETURN_ERROR(
4976 : (error != RT_ERROR_NONE) && (error != RT_ERROR_FEATURE_NOT_SUPPORT), error,
4977 : "Set op event wait timeout failed, timeout=%us", timeout);
4978 : return error;
4979 : }
4980 :
4981 : rtError_t ApiErrorDecorator::SetOpExecuteTimeOut(const uint32_t timeout, const RtTaskTimeUnitType timeUnitType)
4982 : {
4983 : const rtError_t error = impl_->SetOpExecuteTimeOut(timeout, timeUnitType);
4984 : ERROR_RETURN(error, "Set op execute timeout failed, timeout=%us.", timeout);
4985 : return error;
4986 : }
4987 :
4988 : rtError_t ApiErrorDecorator::GetOpExecuteTimeOut(uint32_t* const timeout)
4989 : {
4990 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
4991 : timeout, RT_ERROR_INVALID_VALUE, "Obtaining the timeout interval of AI Core operator execution");
4992 : const rtError_t error = impl_->GetOpExecuteTimeOut(timeout);
4993 : ERROR_RETURN(error, "Get op execute timeout failed, timeout=%us.", *timeout);
4994 : return error;
4995 : }
4996 :
4997 : rtError_t ApiErrorDecorator::GetOpExecuteTimeoutV2(uint32_t* const timeout)
4998 : {
4999 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5000 : timeout, RT_ERROR_INVALID_VALUE, "Obtaining the timeout interval of AI Core operator execution");
5001 : const rtError_t error = impl_->GetOpExecuteTimeoutV2(timeout);
5002 : ERROR_RETURN(error, "Get op execute timeout failed.");
5003 : return error;
5004 : }
5005 :
5006 : rtError_t ApiErrorDecorator::CheckArchCompatibility(
5007 : const char_t* socVersion, const char_t* omSocVersion, int32_t* canCompatible)
5008 : {
5009 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5010 : omSocVersion, RT_ERROR_INVALID_VALUE, "Checking operator instruction compatibility based on the SoC version");
5011 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5012 : canCompatible, RT_ERROR_INVALID_VALUE, "Checking operator instruction compatibility based on the SoC version");
5013 : if (omSocVersion != nullptr && omSocVersion[0U] == '\0') {
5014 : RT_LOG(RT_LOG_ERROR, "Input omSocVersion is null, please check.");
5015 : return RT_ERROR_INVALID_VALUE;
5016 : }
5017 : const rtError_t error = impl_->CheckArchCompatibility(socVersion, omSocVersion, canCompatible);
5018 : ERROR_RETURN(error, "Check ArchType Compatibility failed, omSocVersion=%s.", omSocVersion);
5019 : return error;
5020 : }
5021 :
5022 : rtError_t ApiErrorDecorator::GetOpTimeOutInterval(uint64_t* interval)
5023 : {
5024 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5025 : interval, RT_ERROR_INVALID_VALUE,
5026 : "Obtaining the minimum interval supported by the hardware for operator timeout configuration");
5027 : return impl_->GetOpTimeOutInterval(interval);
5028 : }
5029 :
5030 : rtError_t ApiErrorDecorator::SetOpExecuteTimeOutV2(uint64_t timeout, uint64_t* actualTimeout)
5031 : {
5032 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5033 : actualTimeout, RT_ERROR_INVALID_VALUE, "Setting the timeout interval for operator execution");
5034 : return impl_->SetOpExecuteTimeOutV2(timeout, actualTimeout);
5035 : }
5036 :
5037 : rtError_t ApiErrorDecorator::SetGroup(const int32_t groupId) { return impl_->SetGroup(groupId); }
5038 :
5039 : rtError_t ApiErrorDecorator::GetGroupCount(uint32_t* const cnt)
5040 : {
5041 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5042 : cnt, RT_ERROR_INVALID_VALUE, "Obtaining the number of available computing power groups");
5043 :
5044 : return impl_->GetGroupCount(cnt);
5045 : }
5046 :
5047 : rtError_t ApiErrorDecorator::GetGroupInfo(const int32_t groupId, rtGroupInfo_t* const groupInfo, const uint32_t cnt)
5048 : {
5049 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5050 : groupInfo, RT_ERROR_INVALID_VALUE, "Querying the computing power information of a specified group");
5051 :
5052 : return impl_->GetGroupInfo(groupId, groupInfo, cnt);
5053 : }
5054 :
5055 : rtError_t ApiErrorDecorator::StarsTaskLaunch(
5056 : const void* const sqe, const uint32_t sqeLen, Stream* const stm, const uint32_t flag)
5057 : {
5058 : /* 1910b tiny not support dvpp accelerator */
5059 : if (!stm->Device_()->GetDevProperties().isSupportDvppAccelerator) {
5060 : return RT_ERROR_FEATURE_NOT_SUPPORT;
5061 : }
5062 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5063 : sqe, RT_ERROR_INVALID_VALUE, "Delivering a Stars task to the device for execution");
5064 : // StarsTaskLaunch only support RT_KERNEL_DEFAULT \ RT_KERNEL_DUMPFLAG \ RT_KERNEL_CMDLIST_NOT_FREE
5065 : constexpr uint32_t permitFlag = (RT_KERNEL_DEFAULT | RT_KERNEL_DUMPFLAG | RT_KERNEL_CMDLIST_NOT_FREE);
5066 : if ((flag & (~permitFlag)) != 0U) {
5067 : RT_LOG(RT_LOG_ERROR, "unsupported flag : %u", flag);
5068 : return RT_ERROR_FEATURE_NOT_SUPPORT;
5069 : }
5070 :
5071 : const rtError_t error = impl_->StarsTaskLaunch(sqe, sqeLen, stm, flag);
5072 : return error;
5073 : }
5074 :
5075 : rtError_t ApiErrorDecorator::GetC2cCtrlAddr(uint64_t* const addr, uint32_t* const len)
5076 : {
5077 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5078 : addr, RT_ERROR_INVALID_VALUE, "Obtaining the address and length of the C2C Ctrl register");
5079 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5080 : len, RT_ERROR_INVALID_VALUE, "Obtaining the address and length of the C2C Ctrl register");
5081 :
5082 : const rtError_t error = impl_->GetC2cCtrlAddr(addr, len);
5083 : ERROR_RETURN(error, "get c2c ctrl addr.");
5084 : return error;
5085 : }
5086 :
5087 : rtError_t ApiErrorDecorator::NpuGetFloatStatus(
5088 : void* const outputAddrPtr, const uint64_t outputSize, const uint32_t checkMode, Stream* const stm)
5089 : {
5090 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5091 : outputAddrPtr, RT_ERROR_INVALID_VALUE, "Obtaining the Float exception status of the NPU");
5092 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5093 : outputSize != OVERFLOW_OUTPUT_SIZE, RT_ERROR_INVALID_VALUE, "Obtaining the Float exception status of the NPU",
5094 : outputSize, std::to_string(OVERFLOW_OUTPUT_SIZE));
5095 : COND_RETURN_AND_MSG_OUTER(
5096 : (stm != nullptr) && (stm->IsCapturing()), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016,
5097 : "Obtaining the Float exception status of the NPU",
5098 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stm->Id_()));
5099 :
5100 : return impl_->NpuGetFloatStatus(outputAddrPtr, outputSize, checkMode, stm);
5101 : }
5102 :
5103 : rtError_t ApiErrorDecorator::NpuClearFloatStatus(const uint32_t checkMode, Stream* const stm)
5104 : {
5105 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
5106 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5107 : curStm, RT_ERROR_INVALID_VALUE, "Clearing the Float exception status flag of the NPU");
5108 : COND_RETURN_AND_MSG_OUTER(
5109 : curStm->IsCapturing(), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016,
5110 : "Clearing the Float exception status flag of the NPU",
5111 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", curStm->Id_()));
5112 : return impl_->NpuClearFloatStatus(checkMode, curStm);
5113 : }
5114 :
5115 : rtError_t ApiErrorDecorator::NpuGetFloatDebugStatus(
5116 : void* const outputAddrPtr, const uint64_t outputSize, const uint32_t checkMode, Stream* const stm)
5117 : {
5118 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
5119 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5120 : outputAddrPtr, RT_ERROR_INVALID_VALUE, "Obtaining the Float exception debugging status of the NPU");
5121 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5122 : curStm, RT_ERROR_INVALID_VALUE, "Obtaining the Float exception debugging status of the NPU");
5123 :
5124 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5125 : outputSize != OVERFLOW_OUTPUT_SIZE, RT_ERROR_INVALID_VALUE,
5126 : "Obtaining the Float exception debugging status of the NPU", outputSize, std::to_string(OVERFLOW_OUTPUT_SIZE));
5127 : COND_RETURN_AND_MSG_OUTER(
5128 : curStm->IsCapturing(), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016,
5129 : "Obtaining the Float exception debugging status of the NPU",
5130 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", curStm->Id_()));
5131 :
5132 : return impl_->NpuGetFloatDebugStatus(outputAddrPtr, outputSize, checkMode, curStm);
5133 : }
5134 :
5135 : rtError_t ApiErrorDecorator::NpuClearFloatDebugStatus(const uint32_t checkMode, Stream* const stm)
5136 : {
5137 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
5138 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5139 : curStm, RT_ERROR_INVALID_VALUE, "Clearing the Float debugging status flag of the NPU");
5140 : COND_RETURN_AND_MSG_OUTER(
5141 : curStm->IsCapturing(), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016,
5142 : "Clearing the Float debugging status flag of the NPU",
5143 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", curStm->Id_()));
5144 : return impl_->NpuClearFloatDebugStatus(checkMode, curStm);
5145 : }
5146 :
5147 : rtError_t ApiErrorDecorator::GetDevMsg(const rtGetDevMsgType_t getMsgType, const rtGetMsgCallback callback)
5148 : {
5149 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(callback, RT_ERROR_INVALID_VALUE, "Obtaining device-related messages");
5150 : const rtError_t error = impl_->GetDevMsg(getMsgType, callback);
5151 : ERROR_RETURN(error, "GetDeviceMsg failed, getMsgType=%d.", static_cast<int32_t>(getMsgType));
5152 : return error;
5153 : }
5154 :
5155 : rtError_t ApiErrorDecorator::ContextSetINFMode(const bool infMode) { return impl_->ContextSetINFMode(infMode); }
5156 :
5157 : rtError_t ApiErrorDecorator::MemQueueInitQS(const int32_t devId, const char_t* const grpName)
5158 : {
5159 : int32_t realDeviceId;
5160 : const rtError_t error =
5161 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5162 : COND_RETURN_ERROR(
5163 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5164 : return impl_->MemQueueInitQS(realDeviceId, grpName);
5165 : }
5166 :
5167 : rtError_t ApiErrorDecorator::MemQueueInitFlowGw(const int32_t devId, const rtInitFlowGwInfo_t* const initInfo)
5168 : {
5169 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5170 : initInfo, RT_ERROR_INVALID_VALUE, "Initializing the FlowGw of a memory queue");
5171 : int32_t realDeviceId;
5172 : const rtError_t error =
5173 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5174 : COND_RETURN_ERROR(
5175 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5176 : return impl_->MemQueueInitFlowGw(realDeviceId, initInfo);
5177 : }
5178 :
5179 : static inline bool IsHostCpuDevId(const int32_t devId) { return (devId == DEFAULT_HOSTCPU_USER_DEVICE_ID); }
5180 :
5181 : rtError_t ApiErrorDecorator::MemQueueCreate(
5182 : const int32_t devId, const rtMemQueueAttr_t* const queAttr, uint32_t* const qid)
5183 : {
5184 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(queAttr, RT_ERROR_INVALID_VALUE, "Memory queue creation");
5185 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(qid, RT_ERROR_INVALID_VALUE, "Memory queue creation");
5186 : int32_t realDeviceId = 0;
5187 : if (IsHostCpuDevId(devId)) {
5188 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5189 : } else {
5190 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5191 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5192 : COND_RETURN_ERROR(
5193 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5194 : }
5195 : return impl_->MemQueueCreate(realDeviceId, queAttr, qid);
5196 : }
5197 :
5198 : rtError_t ApiErrorDecorator::MemQueueExport(
5199 : const int32_t devId, const uint32_t qid, const int32_t peerDevId, const char* const shareName)
5200 : {
5201 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(shareName, RT_ERROR_INVALID_VALUE, "Memory queue export");
5202 : const auto len = strnlen(shareName, SHARE_QUEUE_NAME_LEN);
5203 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5204 : len >= SHARE_QUEUE_NAME_LEN, RT_ERROR_INVALID_VALUE, "Memory queue export", len,
5205 : "less than " + std::to_string(SHARE_QUEUE_NAME_LEN));
5206 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5207 : IsHostCpuDevId(devId), RT_ERROR_INVALID_VALUE, "Memory queue export", devId,
5208 : "not equal to " + std::to_string(DEFAULT_HOSTCPU_USER_DEVICE_ID));
5209 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5210 : IsHostCpuDevId(peerDevId), RT_ERROR_INVALID_VALUE, "Memory queue export", peerDevId,
5211 : "not equal to " + std::to_string(DEFAULT_HOSTCPU_USER_DEVICE_ID));
5212 : COND_RETURN_AND_MSG_OUTER(
5213 : devId == peerDevId, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Memory queue export", "devId or peerDevId",
5214 : RtFmtMsg("Parameter devId %d should not be equal to parameter peerDevId %d", devId, peerDevId));
5215 : int32_t realDeviceId = 0;
5216 : int32_t realPeerDeviceId = 0;
5217 : rtError_t error =
5218 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5219 : COND_RETURN_ERROR(
5220 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5221 : error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5222 : static_cast<uint32_t>(peerDevId), RtPtrToPtr<uint32_t*>(&realPeerDeviceId));
5223 : COND_RETURN_ERROR(
5224 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", peerDevId);
5225 : return impl_->MemQueueExport(realDeviceId, qid, realPeerDeviceId, shareName);
5226 : }
5227 :
5228 : rtError_t ApiErrorDecorator::MemQueueUnExport(
5229 : const int32_t devId, const uint32_t qid, const int32_t peerDevId, const char* const shareName)
5230 : {
5231 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5232 : shareName, RT_ERROR_INVALID_VALUE, "Canceling the export of a specified memory queue");
5233 : const auto len = strnlen(shareName, SHARE_QUEUE_NAME_LEN);
5234 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5235 : len >= SHARE_QUEUE_NAME_LEN, RT_ERROR_INVALID_VALUE, "Canceling the export of a specified memory queue", len,
5236 : "less than " + std::to_string(SHARE_QUEUE_NAME_LEN));
5237 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5238 : IsHostCpuDevId(devId), RT_ERROR_INVALID_VALUE, "Canceling the export of a specified memory queue", devId,
5239 : "not equal to " + std::to_string(DEFAULT_HOSTCPU_USER_DEVICE_ID));
5240 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5241 : IsHostCpuDevId(peerDevId), RT_ERROR_INVALID_VALUE, "Canceling the export of a specified memory queue",
5242 : peerDevId, "not equal to " + std::to_string(DEFAULT_HOSTCPU_USER_DEVICE_ID));
5243 : COND_RETURN_AND_MSG_OUTER(
5244 : devId == peerDevId, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
5245 : "Canceling the export of a specified memory queue", "devId or peerDevId",
5246 : RtFmtMsg("Parameter devId %d should not be equal to parameter peerDevId %d", devId, peerDevId));
5247 : int32_t realDeviceId = 0;
5248 : int32_t realPeerDeviceId = 0;
5249 : rtError_t error =
5250 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5251 : COND_RETURN_ERROR(
5252 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5253 : error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5254 : static_cast<uint32_t>(peerDevId), RtPtrToPtr<uint32_t*>(&realPeerDeviceId));
5255 : COND_RETURN_ERROR(
5256 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", peerDevId);
5257 : return impl_->MemQueueUnExport(realDeviceId, qid, realPeerDeviceId, shareName);
5258 : }
5259 :
5260 : rtError_t ApiErrorDecorator::MemQueueImport(
5261 : const int32_t devId, const int32_t peerDevId, const char* const shareName, uint32_t* const qid)
5262 : {
5263 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(shareName, RT_ERROR_INVALID_VALUE, "Importing a memory queue");
5264 : const auto len = strnlen(shareName, SHARE_QUEUE_NAME_LEN);
5265 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5266 : len >= SHARE_QUEUE_NAME_LEN, RT_ERROR_INVALID_VALUE, "Importing a memory queue", len,
5267 : "less than " + std::to_string(SHARE_QUEUE_NAME_LEN));
5268 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(qid, RT_ERROR_INVALID_VALUE, "Importing a memory queue");
5269 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5270 : IsHostCpuDevId(devId), RT_ERROR_INVALID_VALUE, "Importing a memory queue", devId,
5271 : "not equal to " + std::to_string(DEFAULT_HOSTCPU_USER_DEVICE_ID));
5272 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5273 : IsHostCpuDevId(peerDevId), RT_ERROR_INVALID_VALUE, "Importing a memory queue", peerDevId,
5274 : "not equal to " + std::to_string(DEFAULT_HOSTCPU_USER_DEVICE_ID));
5275 : COND_RETURN_AND_MSG_OUTER(
5276 : devId == peerDevId, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Importing a memory queue", "devId or peerDevId",
5277 : RtFmtMsg("Parameter devId %d should not be equal to parameter peerDevId %d", devId, peerDevId));
5278 : int32_t realDeviceId = 0;
5279 : int32_t realPeerDeviceId = 0;
5280 : rtError_t error =
5281 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5282 : COND_RETURN_ERROR(
5283 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5284 : error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5285 : static_cast<uint32_t>(peerDevId), RtPtrToPtr<uint32_t*>(&realPeerDeviceId));
5286 : COND_RETURN_ERROR(
5287 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", peerDevId);
5288 : return impl_->MemQueueImport(realDeviceId, realPeerDeviceId, shareName, qid);
5289 : }
5290 :
5291 : rtError_t ApiErrorDecorator::MemQueueUnImport(
5292 : const int32_t devId, const uint32_t qid, const int32_t peerDevId, const char* const shareName)
5293 : {
5294 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5295 : shareName, RT_ERROR_INVALID_VALUE, "Canceling the import of a specified memory queue");
5296 : const auto len = strnlen(shareName, SHARE_QUEUE_NAME_LEN);
5297 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5298 : len >= SHARE_QUEUE_NAME_LEN, RT_ERROR_INVALID_VALUE, "Canceling the import of a specified memory queue", len,
5299 : "less than " + std::to_string(SHARE_QUEUE_NAME_LEN));
5300 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5301 : IsHostCpuDevId(devId), RT_ERROR_INVALID_VALUE, "Canceling the import of a specified memory queue", devId,
5302 : "not equal to " + std::to_string(DEFAULT_HOSTCPU_USER_DEVICE_ID));
5303 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5304 : IsHostCpuDevId(peerDevId), RT_ERROR_INVALID_VALUE, "Canceling the import of a specified memory queue",
5305 : peerDevId, "not equal to " + std::to_string(DEFAULT_HOSTCPU_USER_DEVICE_ID));
5306 : COND_RETURN_AND_MSG_OUTER(
5307 : devId == peerDevId, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
5308 : "Canceling the import of a specified memory queue", "devId or peerDevId",
5309 : RtFmtMsg("Parameter devId %d should not be equal to parameter peerDevId %d", devId, peerDevId));
5310 : int32_t realDeviceId = 0;
5311 : int32_t realPeerDeviceId = 0;
5312 : rtError_t error =
5313 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5314 : COND_RETURN_ERROR(
5315 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5316 : error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5317 : static_cast<uint32_t>(peerDevId), RtPtrToPtr<uint32_t*>(&realPeerDeviceId));
5318 : COND_RETURN_ERROR(
5319 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", peerDevId);
5320 : return impl_->MemQueueUnImport(realDeviceId, qid, realPeerDeviceId, shareName);
5321 : }
5322 :
5323 : rtError_t ApiErrorDecorator::MemQueueSet(
5324 : const int32_t devId, const rtMemQueueSetCmdType cmd, const rtMemQueueSetInputPara* const input)
5325 : {
5326 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(input, RT_ERROR_INVALID_VALUE, "Memory queue setting");
5327 : int32_t realDeviceId = 0;
5328 : if (IsHostCpuDevId(devId)) {
5329 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5330 : } else {
5331 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5332 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5333 : COND_RETURN_ERROR(
5334 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5335 : }
5336 : return impl_->MemQueueSet(realDeviceId, cmd, input);
5337 : }
5338 :
5339 : rtError_t ApiErrorDecorator::MemQueueDestroy(const int32_t devId, const uint32_t qid)
5340 : {
5341 : int32_t realDeviceId = 0;
5342 : if (IsHostCpuDevId(devId)) {
5343 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5344 : } else {
5345 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5346 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5347 : COND_RETURN_ERROR(
5348 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5349 : }
5350 : return impl_->MemQueueDestroy(realDeviceId, qid);
5351 : }
5352 :
5353 : rtError_t ApiErrorDecorator::MemQueueInit(const int32_t devId)
5354 : {
5355 : int32_t realDeviceId = 0;
5356 : if (IsHostCpuDevId(devId)) {
5357 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5358 : } else {
5359 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5360 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5361 : COND_RETURN_ERROR(
5362 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5363 : }
5364 : return impl_->MemQueueInit(realDeviceId);
5365 : }
5366 :
5367 : rtError_t ApiErrorDecorator::MemQueueReset(const int32_t devId, const uint32_t qid)
5368 : {
5369 : int32_t realDeviceId = 0;
5370 : if (IsHostCpuDevId(devId)) {
5371 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5372 : } else {
5373 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5374 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5375 : COND_RETURN_ERROR(
5376 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5377 : }
5378 : return impl_->MemQueueReset(realDeviceId, qid);
5379 : }
5380 :
5381 : rtError_t ApiErrorDecorator::MemQueueEnQueue(const int32_t devId, const uint32_t qid, void* const enQBuf)
5382 : {
5383 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(enQBuf, RT_ERROR_INVALID_VALUE, "Memory queue enqueuing");
5384 : int32_t realDeviceId = 0;
5385 : if (IsHostCpuDevId(devId)) {
5386 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5387 : } else {
5388 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5389 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5390 : COND_RETURN_ERROR(
5391 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5392 : }
5393 : return impl_->MemQueueEnQueue(realDeviceId, qid, enQBuf);
5394 : }
5395 :
5396 : rtError_t ApiErrorDecorator::MemQueueDeQueue(const int32_t devId, const uint32_t qid, void** const deQBuf)
5397 : {
5398 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(deQBuf, RT_ERROR_INVALID_VALUE, "Memory queue dequeuing");
5399 : int32_t realDeviceId = 0;
5400 : if (IsHostCpuDevId(devId)) {
5401 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5402 : } else {
5403 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5404 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5405 : COND_RETURN_ERROR(
5406 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5407 : }
5408 : return impl_->MemQueueDeQueue(realDeviceId, qid, deQBuf);
5409 : }
5410 :
5411 : rtError_t ApiErrorDecorator::MemQueuePeek(
5412 : const int32_t devId, const uint32_t qid, size_t* const bufLen, const int32_t timeout)
5413 : {
5414 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(bufLen, RT_ERROR_INVALID_VALUE, "Peeking the memory queue");
5415 : int32_t realDeviceId = 0;
5416 : if (IsHostCpuDevId(devId)) {
5417 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5418 : } else {
5419 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5420 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5421 : COND_RETURN_ERROR(
5422 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5423 : }
5424 : return impl_->MemQueuePeek(realDeviceId, qid, bufLen, timeout);
5425 : }
5426 :
5427 : rtError_t ApiErrorDecorator::MemQueueQueryInfo(
5428 : const int32_t devId, const uint32_t qid, rtMemQueueInfo_t* const queryQueueInfo)
5429 : {
5430 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5431 : queryQueueInfo, RT_ERROR_INVALID_VALUE, "Querying memory queue information");
5432 : int32_t realDeviceId = 0;
5433 : if (IsHostCpuDevId(devId)) {
5434 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5435 : } else {
5436 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5437 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5438 : COND_RETURN_ERROR(
5439 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5440 : }
5441 : return impl_->MemQueueQueryInfo(realDeviceId, qid, queryQueueInfo);
5442 : }
5443 :
5444 : rtError_t ApiErrorDecorator::MemQueueQuery(
5445 : const int32_t devId, const rtMemQueueQueryCmd_t cmd, const void* const inBuff, const uint32_t inLen,
5446 : void* const outBuff, uint32_t* const outLen)
5447 : {
5448 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5449 : inBuff, RT_ERROR_INVALID_VALUE,
5450 : "Querying the access permission of the current process on a specified memory queue");
5451 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5452 : outBuff, RT_ERROR_INVALID_VALUE,
5453 : "Querying the access permission of the current process on a specified memory queue");
5454 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5455 : outLen, RT_ERROR_INVALID_VALUE,
5456 : "Querying the access permission of the current process on a specified memory queue");
5457 : int32_t realDeviceId = 0;
5458 : if (IsHostCpuDevId(devId)) {
5459 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5460 : } else {
5461 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5462 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5463 : COND_RETURN_ERROR(
5464 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5465 : }
5466 : return impl_->MemQueueQuery(realDeviceId, cmd, inBuff, inLen, outBuff, outLen);
5467 : }
5468 :
5469 : rtError_t ApiErrorDecorator::MemQueueGrant(
5470 : const int32_t devId, const uint32_t qid, const int32_t pid, rtMemQueueShareAttr_t* const attr)
5471 : {
5472 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5473 : attr, RT_ERROR_INVALID_VALUE, "Authorizing a specified process to access a memory queue");
5474 : int32_t realDeviceId = 0;
5475 : if (IsHostCpuDevId(devId)) {
5476 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5477 : } else {
5478 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5479 : static_cast<uint32_t>(devId), reinterpret_cast<uint32_t*>(&realDeviceId));
5480 : COND_RETURN_ERROR(
5481 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5482 : }
5483 : return impl_->MemQueueGrant(realDeviceId, qid, pid, attr);
5484 : }
5485 :
5486 : rtError_t ApiErrorDecorator::MemQueueAttach(const int32_t devId, const uint32_t qid, const int32_t timeOut)
5487 : {
5488 : int32_t realDeviceId = 0;
5489 : if (IsHostCpuDevId(devId)) {
5490 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5491 : } else {
5492 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5493 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5494 : COND_RETURN_ERROR(
5495 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5496 : }
5497 : return impl_->MemQueueAttach(realDeviceId, qid, timeOut);
5498 : }
5499 :
5500 : rtError_t ApiErrorDecorator::EschedSubmitEventSync(
5501 : const int32_t devId, rtEschedEventSummary_t* const evt, rtEschedEventReply_t* const ack)
5502 : {
5503 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Synchronous event submission");
5504 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(ack, RT_ERROR_INVALID_VALUE, "Synchronous event submission");
5505 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5506 : ((evt->eventId != RT_MQ_SCHED_EVENT_QS_MSG) && (evt->eventId != RT_MQ_SCHED_EVENT_DRV_CUSTOM_MSG)),
5507 : RT_ERROR_FEATURE_NOT_SUPPORT, "Synchronous event submission", evt->eventId,
5508 : std::to_string(RT_MQ_SCHED_EVENT_QS_MSG) + " or " + std::to_string(RT_MQ_SCHED_EVENT_DRV_CUSTOM_MSG));
5509 : int32_t realDeviceId = 0;
5510 : if (IsHostCpuDevId(devId)) {
5511 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5512 : } else {
5513 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5514 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5515 : COND_RETURN_ERROR(
5516 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5517 : }
5518 : return impl_->EschedSubmitEventSync(realDeviceId, evt, ack);
5519 : }
5520 :
5521 : rtError_t ApiErrorDecorator::MemQueueEnQueueBuff(
5522 : const int32_t devId, const uint32_t qid, rtMemQueueBuff_t* const inBuf, const int32_t timeout)
5523 : {
5524 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(inBuf, RT_ERROR_INVALID_VALUE, "Memory queue enqueuing");
5525 : COND_RETURN_AND_MSG_OUTER(
5526 : (inBuf->buffCount > 0U) && (inBuf->buffInfo == nullptr), RT_ERROR_INVALID_VALUE, ErrorCode::EE1011,
5527 : "Memory queue enqueuing", "nullptr", "inBuf->buffInfo",
5528 : RtFmtMsg(
5529 : "When inBuf->buffCount is greater than 0, inBuf->buffInfo cannot be a null pointer."
5530 : " Parameter inBuf->buffCount is %u, devId is %u, and qid is %u",
5531 : inBuf->buffCount, devId, qid));
5532 : int32_t realDeviceId = 0;
5533 : if (IsHostCpuDevId(devId)) {
5534 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5535 : } else {
5536 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5537 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5538 : COND_RETURN_ERROR(
5539 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5540 : }
5541 : return impl_->MemQueueEnQueueBuff(realDeviceId, qid, inBuf, timeout);
5542 : }
5543 :
5544 : rtError_t ApiErrorDecorator::MemQueueDeQueueBuff(
5545 : const int32_t devId, const uint32_t qid, rtMemQueueBuff_t* const outBuf, const int32_t timeout)
5546 : {
5547 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(outBuf, RT_ERROR_INVALID_VALUE, "Memory queue dequeuing");
5548 : COND_RETURN_AND_MSG_OUTER(
5549 : (outBuf->buffCount > 0U) && (outBuf->buffInfo == nullptr), RT_ERROR_INVALID_VALUE, ErrorCode::EE1011,
5550 : "Memory queue dequeuing", "nullptr", "outBuf->buffInfo",
5551 : RtFmtMsg(
5552 : "When outBuf->buffCount is greater than 0, outBuf->buffInfo cannot be a null pointer."
5553 : " Parameter outBuf->buffCount is %u, devId is %u, and qid is %u",
5554 : outBuf->buffCount, devId, qid));
5555 : int32_t realDeviceId = 0;
5556 : if (IsHostCpuDevId(devId)) {
5557 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5558 : } else {
5559 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5560 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5561 : COND_RETURN_ERROR(
5562 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5563 : }
5564 : return impl_->MemQueueDeQueueBuff(realDeviceId, qid, outBuf, timeout);
5565 : }
5566 :
5567 : rtError_t ApiErrorDecorator::QueueSubF2NFEvent(const int32_t devId, const uint32_t qId, const uint32_t groupId)
5568 : {
5569 : int32_t realDeviceId = devId;
5570 : if (IsHostCpuDevId(devId)) {
5571 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5572 : } else {
5573 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5574 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5575 : COND_RETURN_ERROR(
5576 : error != RT_ERROR_NONE, RT_ERROR_DEVICE_ID, "Failed to convert the user device ID %d to driver device ID.",
5577 : devId);
5578 : error = CheckDeviceIdIsValid(realDeviceId);
5579 : COND_RETURN_ERROR_MSG_INNER(
5580 : error != RT_ERROR_NONE, error, "Device id is invalid, deviceId=%d, retCode=%#x", devId,
5581 : static_cast<uint32_t>(error));
5582 : }
5583 : return impl_->QueueSubF2NFEvent(realDeviceId, qId, groupId);
5584 : }
5585 :
5586 : rtError_t ApiErrorDecorator::QueueSubscribe(
5587 : const int32_t devId, const uint32_t qId, const uint32_t groupId, const int32_t type)
5588 : {
5589 : int32_t realDeviceId = devId;
5590 : if (IsHostCpuDevId(devId)) {
5591 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5592 : } else {
5593 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5594 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5595 : COND_RETURN_ERROR(
5596 : error != RT_ERROR_NONE, RT_ERROR_DEVICE_ID, "Failed to convert the user device ID %d to driver device ID.",
5597 : devId);
5598 : error = CheckDeviceIdIsValid(realDeviceId);
5599 : COND_RETURN_ERROR_MSG_INNER(
5600 : error != RT_ERROR_NONE, error, "Device id is invalid, deviceId=%d, retCode=%#x", devId,
5601 : static_cast<uint32_t>(error));
5602 : }
5603 :
5604 : return impl_->QueueSubscribe(realDeviceId, qId, groupId, type);
5605 : }
5606 :
5607 : rtError_t ApiErrorDecorator::BufEventTrigger(const char_t* const name)
5608 : {
5609 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5610 : name, RT_ERROR_INVALID_VALUE, "Triggering and reporting buffer-related events");
5611 : return impl_->BufEventTrigger(name);
5612 : }
5613 :
5614 : rtError_t ApiErrorDecorator::QueryDevPid(rtBindHostpidInfo_t* const info, int32_t* const devPid)
5615 : {
5616 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(info, RT_ERROR_INVALID_VALUE, "Querying the PID on the device");
5617 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(devPid, RT_ERROR_INVALID_VALUE, "Querying the PID on the device");
5618 :
5619 : uint32_t realDeviceId = 0U;
5620 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(info->chipId, &realDeviceId);
5621 : COND_RETURN_ERROR(
5622 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", info->chipId);
5623 : info->chipId = realDeviceId;
5624 : return impl_->QueryDevPid(info, devPid);
5625 : }
5626 :
5627 : rtError_t ApiErrorDecorator::BuffAlloc(const uint64_t size, void** buff)
5628 : {
5629 : ZERO_RETURN_AND_MSG_OUTER(size);
5630 : return impl_->BuffAlloc(size, buff);
5631 : }
5632 :
5633 : rtError_t ApiErrorDecorator::BuffConfirm(void* const buff, const uint64_t size)
5634 : {
5635 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5636 : buff, RT_ERROR_INVALID_VALUE, "Checking whether the specified buffer is valid shared memory");
5637 : return impl_->BuffConfirm(buff, size);
5638 : }
5639 :
5640 : rtError_t ApiErrorDecorator::BuffFree(void* const buff)
5641 : {
5642 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(buff, RT_ERROR_INVALID_VALUE, "Shared buffer release");
5643 : return impl_->BuffFree(buff);
5644 : }
5645 :
5646 : rtError_t ApiErrorDecorator::MemGrpCreate(const char_t* const name, const rtMemGrpConfig_t* const cfg)
5647 : {
5648 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(name, RT_ERROR_INVALID_VALUE, "Memory group creation");
5649 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(cfg, RT_ERROR_INVALID_VALUE, "Memory group creation");
5650 : return impl_->MemGrpCreate(name, cfg);
5651 : }
5652 :
5653 : rtError_t ApiErrorDecorator::BuffGetInfo(
5654 : const rtBuffGetCmdType type, const void* const inBuff, const uint32_t inLen, void* const outBuff,
5655 : uint32_t* const outLen)
5656 : {
5657 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(inBuff, RT_ERROR_INVALID_VALUE, "Buffer information obtaining");
5658 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(outBuff, RT_ERROR_INVALID_VALUE, "Buffer information obtaining");
5659 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(outLen, RT_ERROR_INVALID_VALUE, "Buffer information obtaining");
5660 : return impl_->BuffGetInfo(type, inBuff, inLen, outBuff, outLen);
5661 : }
5662 :
5663 : rtError_t ApiErrorDecorator::MemGrpCacheAlloc(
5664 : const char_t* const name, const int32_t devId, const rtMemGrpCacheAllocPara* const para)
5665 : {
5666 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(name, RT_ERROR_INVALID_VALUE, "Memory group cache allocation");
5667 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(para, RT_ERROR_INVALID_VALUE, "Memory group cache allocation");
5668 : int32_t realDeviceId;
5669 : if (IsHostCpuDevId(devId)) {
5670 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5671 : } else {
5672 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5673 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5674 : COND_RETURN_ERROR(
5675 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5676 : }
5677 : return impl_->MemGrpCacheAlloc(name, realDeviceId, para);
5678 : }
5679 :
5680 : rtError_t ApiErrorDecorator::MemGrpAddProc(
5681 : const char_t* const name, const int32_t pid, const rtMemGrpShareAttr_t* const attr)
5682 : {
5683 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(name, RT_ERROR_INVALID_VALUE, "Adding the process to a memory group");
5684 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(attr, RT_ERROR_INVALID_VALUE, "Adding the process to a memory group");
5685 : return impl_->MemGrpAddProc(name, pid, attr);
5686 : }
5687 :
5688 : rtError_t ApiErrorDecorator::MemGrpAttach(const char_t* const name, const int32_t timeout)
5689 : {
5690 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5691 : name, RT_ERROR_INVALID_VALUE, "Attaching the current process to the memory group with the specified name");
5692 : return impl_->MemGrpAttach(name, timeout);
5693 : }
5694 :
5695 : rtError_t ApiErrorDecorator::MemGrpQuery(rtMemGrpQueryInput_t* const input, rtMemGrpQueryOutput_t* const output)
5696 : {
5697 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(input, RT_ERROR_INVALID_VALUE, "Memory group information query");
5698 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(output, RT_ERROR_INVALID_VALUE, "Memory group information query");
5699 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5700 : ((input->cmd <= RT_MEM_GRP_QUERY_GROUP) || (input->cmd >= RT_MEM_GRP_QUERY_CMD_MAX)),
5701 : RT_ERROR_FEATURE_NOT_SUPPORT, "Memory group information query", input->cmd,
5702 : "(" + std::to_string(RT_MEM_GRP_QUERY_GROUP) + ", " + std::to_string(RT_MEM_GRP_QUERY_CMD_MAX) + ")");
5703 : if (input->cmd == GRP_QUERY_GROUP_ADDR_INFO) {
5704 : uint32_t realDeviceId = 0U;
5705 : const uint32_t userDeviceId = input->grpQueryGroupAddrPara.devId;
5706 : if (IsHostCpuDevId(static_cast<int32_t>(userDeviceId))) {
5707 : realDeviceId = static_cast<uint32_t>(DEFAULT_HOSTCPU_LOGIC_DEVICE_ID);
5708 : } else {
5709 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(userDeviceId, &realDeviceId);
5710 : COND_RETURN_ERROR(
5711 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.",
5712 : userDeviceId);
5713 : error = CheckDeviceIdIsValid(static_cast<int32_t>(realDeviceId));
5714 : COND_RETURN_ERROR_MSG_INNER(
5715 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%u, retCode=%#x", realDeviceId,
5716 : static_cast<uint32_t>(error));
5717 : }
5718 : input->grpQueryGroupAddrPara.devId = realDeviceId;
5719 : }
5720 : return impl_->MemGrpQuery(input, output);
5721 : }
5722 :
5723 : rtError_t ApiErrorDecorator::MemQueueGetQidByName(const int32_t devId, const char_t* const name, uint32_t* const qId)
5724 : {
5725 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5726 : name, RT_ERROR_INVALID_VALUE, "Obtaining the ID of a memory queue by name");
5727 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(qId, RT_ERROR_INVALID_VALUE, "Obtaining the ID of a memory queue by name");
5728 : int32_t realDeviceId = 0;
5729 : if (IsHostCpuDevId(devId)) {
5730 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5731 : } else {
5732 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5733 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5734 : COND_RETURN_ERROR(
5735 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5736 : }
5737 : return impl_->MemQueueGetQidByName(realDeviceId, name, qId);
5738 : }
5739 :
5740 : rtError_t ApiErrorDecorator::EschedAttachDevice(const uint32_t devId)
5741 : {
5742 : uint32_t realDeviceId = 0U;
5743 : /* HostCPU场景下, 底软三件套(Mbuff/队列调度/事件调度)接口无需对DeviceID做转换 */
5744 : if (IsHostCpuDevId(static_cast<int32_t>(devId))) {
5745 : realDeviceId = static_cast<uint32_t>(DEFAULT_HOSTCPU_LOGIC_DEVICE_ID);
5746 : } else {
5747 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(devId, &realDeviceId);
5748 : COND_RETURN_ERROR(
5749 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", devId);
5750 : }
5751 : return impl_->EschedAttachDevice(realDeviceId);
5752 : }
5753 :
5754 : rtError_t ApiErrorDecorator::EschedDettachDevice(const uint32_t devId)
5755 : {
5756 : uint32_t realDeviceId = 0U;
5757 : if (IsHostCpuDevId(static_cast<int32_t>(devId))) {
5758 : realDeviceId = static_cast<uint32_t>(DEFAULT_HOSTCPU_LOGIC_DEVICE_ID);
5759 : } else {
5760 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(devId, &realDeviceId);
5761 : COND_RETURN_ERROR(
5762 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", devId);
5763 : }
5764 : return impl_->EschedDettachDevice(realDeviceId);
5765 : }
5766 :
5767 : rtError_t ApiErrorDecorator::EschedWaitEvent(
5768 : const int32_t devId, const uint32_t grpId, const uint32_t threadId, const int32_t timeout,
5769 : rtEschedEventSummary_t* const evt)
5770 : {
5771 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Waiting for an event");
5772 : int32_t realDeviceId = 0;
5773 : if (IsHostCpuDevId(devId)) {
5774 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5775 : } else {
5776 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5777 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5778 : COND_RETURN_ERROR(
5779 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5780 : }
5781 : return impl_->EschedWaitEvent(realDeviceId, grpId, threadId, timeout, evt);
5782 : }
5783 :
5784 : rtError_t ApiErrorDecorator::EschedCreateGrp(const int32_t devId, const uint32_t grpId, const rtGroupType_t type)
5785 : {
5786 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
5787 : (type < RT_GRP_TYPE_BIND_DP_CPU) || (type > RT_GRP_TYPE_BIND_DP_CPU_EXCLUSIVE), RT_ERROR_INVALID_VALUE, type,
5788 : "[" + std::to_string(RT_GRP_TYPE_BIND_DP_CPU) + ", " + std::to_string(RT_GRP_TYPE_BIND_DP_CPU_EXCLUSIVE) + "]");
5789 :
5790 : int32_t realDeviceId = 0;
5791 : if (IsHostCpuDevId(devId)) {
5792 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5793 : } else {
5794 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5795 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5796 : COND_RETURN_ERROR(
5797 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5798 : }
5799 : return impl_->EschedCreateGrp(realDeviceId, grpId, type);
5800 : }
5801 :
5802 : rtError_t ApiErrorDecorator::EschedSubmitEvent(const int32_t devId, rtEschedEventSummary_t* const evt)
5803 : {
5804 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(evt, RT_ERROR_INVALID_VALUE, "Event submission");
5805 : int32_t realDeviceId = 0;
5806 : if (IsHostCpuDevId(devId)) {
5807 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5808 : } else {
5809 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5810 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5811 : COND_RETURN_ERROR(
5812 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5813 : }
5814 : return impl_->EschedSubmitEvent(realDeviceId, evt);
5815 : }
5816 :
5817 : rtError_t ApiErrorDecorator::EschedSubscribeEvent(
5818 : const int32_t devId, const uint32_t grpId, const uint32_t threadId, const uint64_t eventBitmap)
5819 : {
5820 : int32_t realDeviceId = 0;
5821 : if (IsHostCpuDevId(devId)) {
5822 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5823 : } else {
5824 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5825 : static_cast<uint32_t>(devId), reinterpret_cast<uint32_t*>(&realDeviceId));
5826 : COND_RETURN_ERROR(
5827 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5828 : }
5829 : return impl_->EschedSubscribeEvent(realDeviceId, grpId, threadId, eventBitmap);
5830 : }
5831 :
5832 : rtError_t ApiErrorDecorator::EschedAckEvent(
5833 : const int32_t devId, const rtEventIdType_t evtId, const uint32_t subeventId, char_t* const msg, const uint32_t len)
5834 : {
5835 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(msg, RT_ERROR_INVALID_VALUE, "Event confirmation");
5836 : int32_t realDeviceId = 0;
5837 : if (IsHostCpuDevId(devId)) {
5838 : realDeviceId = DEFAULT_HOSTCPU_LOGIC_DEVICE_ID;
5839 : } else {
5840 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
5841 : static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
5842 : COND_RETURN_ERROR(
5843 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
5844 : }
5845 : return impl_->EschedAckEvent(realDeviceId, evtId, subeventId, msg, len);
5846 : }
5847 :
5848 : rtError_t ApiErrorDecorator::CheckDeviceIdIsValid(const int32_t devId) const
5849 : {
5850 : int32_t devCnt;
5851 : Runtime* const rt = Runtime::Instance();
5852 : Driver* const npuDrv = rt->driverFactory_.GetDriver(NPU_DRIVER);
5853 : NULL_PTR_RETURN_MSG(npuDrv, RT_ERROR_DRV_NULL);
5854 : const rtError_t error = npuDrv->GetDeviceCount(&devCnt);
5855 : COND_RETURN_ERROR_MSG_INNER(
5856 : error != RT_ERROR_NONE, error, "Get device cnt failed, retCode=%#x", static_cast<uint32_t>(error));
5857 : COND_RETURN_ERROR_MSG_INNER(
5858 : devCnt < 0, RT_ERROR_INVALID_VALUE, "The device count %d obtained from the driver is invalid.", devCnt);
5859 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
5860 : (devId < 0) || ((devId >= devCnt) && (devCnt != 0)), RT_ERROR_DEVICE_ID, devId,
5861 : "[0, " + std::to_string(devCnt) + ")");
5862 : return RT_ERROR_NONE;
5863 : }
5864 :
5865 : rtError_t ApiErrorDecorator::CmoTaskLaunch(
5866 : const rtCmoTaskInfo_t* const taskInfo, Stream* const stm, const uint32_t flag)
5867 : {
5868 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5869 : taskInfo, RT_ERROR_INVALID_VALUE, "Operating the cache memory on the device");
5870 : const rtChipType_t chipType = Runtime::Instance()->GetChipType();
5871 : const rtCmoOpCode_t opCode = static_cast<rtCmoOpCode_t>(taskInfo->opCode);
5872 : if (IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_TASK_CMO)) {
5873 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5874 : (opCode < RT_CMO_PREFETCH) || (opCode >= RT_CMO_RESERVED), RT_ERROR_INVALID_VALUE,
5875 : "Operating the cache memory on the device", taskInfo->opCode,
5876 : "[" + std::to_string(RT_CMO_PREFETCH) + ", " + std::to_string(RT_CMO_RESERVED) + ")");
5877 : }
5878 : const rtError_t error = impl_->CmoTaskLaunch(taskInfo, stm, flag);
5879 : COND_RETURN_ERROR(
5880 : ((error != RT_ERROR_NONE) && (error != RT_ERROR_FEATURE_NOT_SUPPORT)), error, "Cmo Task launch failed.");
5881 : return error;
5882 : }
5883 :
5884 : rtError_t ApiErrorDecorator::CmoAddrTaskLaunch(
5885 : void* cmoAddrInfo, const uint64_t destMax, const rtCmoOpCode_t cmoOpCode, Stream* const stm, const uint32_t flag)
5886 : {
5887 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5888 : cmoAddrInfo, RT_ERROR_INVALID_VALUE, "Using the memory descriptor to operate the cache memory on the device");
5889 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_DESC(
5890 : ((cmoOpCode < RT_CMO_PREFETCH) || (cmoOpCode >= RT_CMO_RESERVED)), RT_ERROR_INVALID_VALUE,
5891 : "Using the memory descriptor to operate the cache memory on the device", CmoOpCodeToString(cmoOpCode),
5892 : "cmoOpCode", "[" + std::to_string(RT_CMO_PREFETCH) + ", " + std::to_string(RT_CMO_RESERVED) + ")");
5893 : rtChipType_t chipType = Runtime::Instance()->GetChipType();
5894 : DevProperties devProperty{};
5895 : rtError_t error = GET_DEV_PROPERTIES(chipType, devProperty);
5896 : COND_RETURN_ERROR_MSG_INNER(
5897 : error != RT_ERROR_NONE, RT_ERROR_DRV_INVALID_DEVICE, "Failed to get dev properties, chipType = %u", chipType);
5898 : const uint64_t sizeMax = (devProperty.cmoAddrInfoType == CmoAddrInfoType::CMO_ADDR_INFO_TYPE_DAVID) ?
5899 : sizeof(rtDavidCmoAddrInfo) :
5900 : sizeof(rtCmoAddrInfo);
5901 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5902 : ((destMax == 0) || (destMax > sizeMax)), RT_ERROR_INVALID_VALUE,
5903 : "Using the memory descriptor to operate the cache memory on the device", destMax,
5904 : "(0, " + std::to_string(sizeMax) + "]");
5905 :
5906 : error = impl_->CmoAddrTaskLaunch(cmoAddrInfo, destMax, cmoOpCode, stm, flag);
5907 : ERROR_RETURN(error, "CmoAddr Task launch failed.");
5908 : return error;
5909 : }
5910 :
5911 : rtError_t ApiErrorDecorator::BarrierTaskLaunch(
5912 : const rtBarrierTaskInfo_t* const taskInfo, Stream* const stm, const uint32_t flag)
5913 : {
5914 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(taskInfo, RT_ERROR_INVALID_VALUE, "Barrier task delivery");
5915 : ZERO_RETURN_AND_MSG_OUTER(taskInfo->logicIdNum);
5916 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5917 : taskInfo->logicIdNum > RT_CMO_MAX_BARRIER_NUM, RT_ERROR_INVALID_VALUE, "Barrier task delivery",
5918 : taskInfo->logicIdNum, "[1, " + std::to_string(RT_CMO_MAX_BARRIER_NUM) + "]");
5919 :
5920 : const rtError_t error = impl_->BarrierTaskLaunch(taskInfo, stm, flag);
5921 : ERROR_RETURN(error, "Barrier Task failed.");
5922 : return error;
5923 : }
5924 :
5925 : rtError_t ApiErrorDecorator::MemcpyHostTask(
5926 : void* const dst, const uint64_t destMax, const void* const src, const uint64_t cnt, const rtMemcpyKind_t kind,
5927 : Stream* const stm)
5928 : {
5929 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(dst, RT_ERROR_INVALID_VALUE, "Delivering a memory copy task on the host");
5930 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(src, RT_ERROR_INVALID_VALUE, "Delivering a memory copy task on the host");
5931 : ZERO_RETURN_AND_MSG_OUTER(cnt);
5932 :
5933 : Context* curCtx = nullptr;
5934 : rtError_t error = RT_ERROR_NONE;
5935 : error = impl_->ContextGetCurrent(&curCtx);
5936 : COND_RETURN_WITH_NOLOG((error != RT_ERROR_NONE), error);
5937 : CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL);
5938 : const uint32_t devRunMode = curCtx->Device_()->Driver_()->GetRunMode();
5939 : if ((devRunMode != RT_RUN_MODE_ONLINE) ||
5940 : ((kind != RT_MEMCPY_HOST_TO_DEVICE) && (kind != RT_MEMCPY_DEVICE_TO_HOST))) {
5941 : RT_LOG(
5942 : RT_LOG_INFO, "unsupported MemcpyHostTask feature, kind=%s, run mode=%u", MemcpyKindToStr(kind), devRunMode);
5943 : return RT_ERROR_FEATURE_NOT_SUPPORT;
5944 : }
5945 : return impl_->MemcpyHostTask(dst, destMax, src, cnt, kind, stm);
5946 : }
5947 :
5948 : rtError_t ApiErrorDecorator::SetDeviceSatMode(const rtFloatOverflowMode_t floatOverflowMode)
5949 : {
5950 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME(
5951 : (floatOverflowMode >= RT_OVERFLOW_MODE_UNDEF) || (floatOverflowMode < RT_OVERFLOW_MODE_SATURATION),
5952 : RT_ERROR_INVALID_VALUE, FloatOverflowModeToString(floatOverflowMode), "floatOverflowMode", "[0, 2)");
5953 : return impl_->SetDeviceSatMode(floatOverflowMode);
5954 : }
5955 :
5956 : rtError_t ApiErrorDecorator::GetDeviceSatMode(rtFloatOverflowMode_t* const floatOverflowMode)
5957 : {
5958 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5959 : floatOverflowMode, RT_ERROR_INVALID_VALUE,
5960 : "Querying the output mode of the floating-point computation result of the current device");
5961 : return impl_->GetDeviceSatMode(floatOverflowMode);
5962 : }
5963 :
5964 : rtError_t ApiErrorDecorator::GetDeviceSatModeForStream(
5965 : Stream* const stm, rtFloatOverflowMode_t* const floatOverflowMode)
5966 : {
5967 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5968 : floatOverflowMode, RT_ERROR_INVALID_VALUE,
5969 : "Querying the output mode of the floating-point computation result of a specified stream");
5970 : return impl_->GetDeviceSatModeForStream(stm, floatOverflowMode);
5971 : }
5972 :
5973 : rtError_t ApiErrorDecorator::SetStreamOverflowSwitch(Stream* const stm, const uint32_t flags)
5974 : {
5975 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
5976 : flags >= static_cast<uint32_t>(RT_OVERFLOW_MODE_UNDEF), RT_ERROR_INVALID_VALUE,
5977 : "Setting the stream overflow/underflow detection switch", flags,
5978 : "[" + std::to_string(RT_OVERFLOW_MODE_SATURATION) + ", " + std::to_string(RT_OVERFLOW_MODE_UNDEF) + ")");
5979 : COND_RETURN_AND_MSG_OUTER(
5980 : (stm != nullptr) && (stm->IsCapturing()), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016,
5981 : "Setting the stream overflow/underflow detection switch",
5982 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stm->Id_()));
5983 : return impl_->SetStreamOverflowSwitch(stm, flags);
5984 : }
5985 : rtError_t ApiErrorDecorator::GetStreamOverflowSwitch(Stream* const stm, uint32_t* const flags)
5986 : {
5987 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
5988 : flags, RT_ERROR_INVALID_VALUE, "Obtaining the overflow/underflow detection flag of a specified stream");
5989 : return impl_->GetStreamOverflowSwitch(stm, flags);
5990 : }
5991 :
5992 : rtError_t ApiErrorDecorator::SetStreamPriorityValue(Stream* const stm, const uint32_t streamPriority)
5993 : {
5994 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(stm, RT_ERROR_INVALID_VALUE, "Setting the stream priority");
5995 : COND_RETURN_ERROR(
5996 : (stm->Flags() & RT_STREAM_FORBIDDEN_DEFAULT) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT,
5997 : "The stream with flag %u does not support priority setting.", stm->Flags());
5998 : COND_RETURN_AND_MSG_OUTER(
5999 : (stm->Flags() & RT_STREAM_AICPU) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT, ErrorCode::EE1006,
6000 : "Setting the stream priority", "Parameter stm->Flags() value " + std::to_string(stm->Flags()),
6001 : "The current stream is used to carry AI CPU scheduling tasks and does not support priority setting");
6002 : const int32_t validPriority = static_cast<int32_t>(streamPriority);
6003 : uint32_t priority = streamPriority;
6004 : if (validPriority < RT_STREAM_GREATEST_PRIORITY) {
6005 : priority = RT_STREAM_GREATEST_PRIORITY;
6006 : } else if (validPriority > RT_STREAM_LEAST_PRIORITY) {
6007 : priority = RT_STREAM_LEAST_PRIORITY;
6008 : } else {
6009 : // no operation
6010 : }
6011 : if (priority != streamPriority) {
6012 : RT_LOG(
6013 : RT_LOG_INFO, "Input priority=%d is out of range [%u, %u], adjusted to %u", validPriority,
6014 : RT_STREAM_GREATEST_PRIORITY, RT_STREAM_LEAST_PRIORITY, priority);
6015 : }
6016 : return impl_->SetStreamPriorityValue(stm, priority);
6017 : }
6018 :
6019 : rtError_t ApiErrorDecorator::GetStreamPriorityValue(Stream* const stm, uint32_t* const streamPriority)
6020 : {
6021 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(streamPriority, RT_ERROR_INVALID_VALUE, "Obtaining the stream priority");
6022 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(stm, RT_ERROR_INVALID_VALUE, "Obtaining the stream priority");
6023 : COND_RETURN_ERROR(
6024 : (stm->Flags() & RT_STREAM_FORBIDDEN_DEFAULT) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT,
6025 : "The stream with flag %u does not support priority setting.", stm->Flags());
6026 : COND_RETURN_AND_MSG_OUTER(
6027 : (stm->Flags() & RT_STREAM_AICPU) != 0U, RT_ERROR_FEATURE_NOT_SUPPORT, ErrorCode::EE1006,
6028 : "Obtaining the stream priority", "Parameter stm->Flags() value " + std::to_string(stm->Flags()),
6029 : "The current stream is used to carry AI CPU scheduling tasks and does not support priority getting");
6030 : return impl_->GetStreamPriorityValue(stm, streamPriority);
6031 : }
6032 :
6033 : rtError_t ApiErrorDecorator::DvppGroupCreate(DvppGrp** grp, const uint32_t flags)
6034 : {
6035 : /* 1910b tiny not support dvpp accelerator */
6036 : Runtime* const rtInstance = Runtime::Instance();
6037 : const rtChipType_t chipType = rtInstance->GetChipType();
6038 : if (!IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_STREAM_DVPP_GROUP)) {
6039 : return RT_ERROR_FEATURE_NOT_SUPPORT;
6040 : }
6041 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(grp, RT_ERROR_INVALID_VALUE, "DVPP group creation");
6042 : const rtError_t error = impl_->DvppGroupCreate(grp, flags);
6043 : ERROR_RETURN(error, "Dvpp grp create failed.");
6044 : return error;
6045 : }
6046 :
6047 : rtError_t ApiErrorDecorator::DvppGroupDestory(DvppGrp* grp)
6048 : {
6049 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(grp, RT_ERROR_INVALID_VALUE, "DVPP group destruction");
6050 : const rtError_t error = impl_->DvppGroupDestory(grp);
6051 : ERROR_RETURN(error, "dvpp grp destroy failed.");
6052 : return error;
6053 : }
6054 :
6055 : rtError_t ApiErrorDecorator::DvppWaitGroupReport(
6056 : DvppGrp* const grp, const rtDvppGrpCallback callBackFunc, const int32_t timeout)
6057 : {
6058 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6059 : grp, RT_ERROR_INVALID_VALUE, "Waiting for reporting of the DVPP group task");
6060 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6061 : callBackFunc, RT_ERROR_INVALID_VALUE, "Waiting for reporting of the DVPP group task");
6062 :
6063 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
6064 : timeout < -1, RT_ERROR_INVALID_VALUE, "Waiting for reporting of the DVPP group task", timeout,
6065 : "[0, " + std::to_string(MAX_INT32_NUM) + "] or -1");
6066 : const rtError_t err = impl_->DvppWaitGroupReport(grp, callBackFunc, timeout);
6067 : if (err != RT_ERROR_NONE) {
6068 : RT_LOG(RT_LOG_DEBUG, "dvpp wait grp report timeout=%dms, ret=%u", timeout, err);
6069 : }
6070 :
6071 : return err;
6072 : }
6073 :
6074 : rtError_t ApiErrorDecorator::SetStreamTag(Stream* const stm, const uint32_t geOpTag)
6075 : {
6076 : COND_RETURN_AND_MSG_OUTER(
6077 : (stm != nullptr) && (stm->IsCapturing()), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016, "Setting the stream tag",
6078 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stm->Id_()));
6079 : const rtError_t error = impl_->SetStreamTag(stm, geOpTag);
6080 : ERROR_RETURN(error, "set stream geOpTag failed.");
6081 : return error;
6082 : }
6083 :
6084 : rtError_t ApiErrorDecorator::GetStreamTag(Stream* const stm, uint32_t* const geOpTag)
6085 : {
6086 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(geOpTag, RT_ERROR_INVALID_VALUE, "Obtaining the stream label");
6087 : const rtError_t error = impl_->GetStreamTag(stm, geOpTag);
6088 : ERROR_RETURN(error, "get stream geOpTag failed.");
6089 : return error;
6090 : }
6091 :
6092 : rtError_t ApiErrorDecorator::GetVisibleDeviceIdByLogicDeviceId(
6093 : const int32_t logicDeviceId, int32_t* const visibleDeviceId)
6094 : {
6095 : Runtime* const rt = Runtime::Instance();
6096 : Driver* const npuDrv = rt->driverFactory_.GetDriver(NPU_DRIVER);
6097 : NULL_PTR_RETURN_MSG(npuDrv, RT_ERROR_DRV_NULL);
6098 : int32_t deviceCnt;
6099 :
6100 : const rtError_t error = npuDrv->GetDeviceCount(&deviceCnt);
6101 : ERROR_RETURN_MSG_CALL(ERR_MODULE_DRV, error, "Get device cnt failed, retCode=%#x", static_cast<uint32_t>(error));
6102 : if ((logicDeviceId >= deviceCnt) || (logicDeviceId < 0)) {
6103 : RT_LOG_OUTER_MSG_INVALID_PARAM_WITH_DESC(
6104 : "Obtaining the visible device ID based on the user device ID", logicDeviceId,
6105 : "[0, " + std::to_string(deviceCnt) + ')');
6106 : return RT_ERROR_DEVICE_ID;
6107 : }
6108 :
6109 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6110 : visibleDeviceId, RT_ERROR_INVALID_VALUE, "Obtaining the visible device ID based on the user device ID");
6111 : return impl_->GetVisibleDeviceIdByLogicDeviceId(logicDeviceId, visibleDeviceId);
6112 : }
6113 :
6114 : rtError_t ApiErrorDecorator::CtxSetSysParamOpt(const rtSysParamOpt configOpt, const int64_t configVal)
6115 : {
6116 : constexpr int64_t SYS_OPT_DETERMINISTIC_LEVEL_MAX = 4;
6117 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME(
6118 : (configOpt >= SYS_OPT_RESERVED) || (configOpt < 0), RT_ERROR_INVALID_VALUE, SysParamOptToString(configOpt),
6119 : "configOpt", RtFmtMsg("[0, %d)", static_cast<int32_t>(SYS_OPT_RESERVED)));
6120 : const int64_t maxVal =
6121 : (configOpt == SYS_OPT_DETERMINISTIC) ? SYS_OPT_DETERMINISTIC_LEVEL_MAX : static_cast<int64_t>(SYS_OPT_MAX);
6122 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
6123 : (configVal >= maxVal) || (configVal < 0), RT_ERROR_INVALID_VALUE, configVal,
6124 : RtFmtMsg("[0, %" PRId64 ")", maxVal));
6125 : return impl_->CtxSetSysParamOpt(configOpt, configVal);
6126 : }
6127 :
6128 : rtError_t ApiErrorDecorator::CtxGetSysParamOpt(const rtSysParamOpt configOpt, int64_t* const configVal)
6129 : {
6130 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_DESC(
6131 : (configOpt >= SYS_OPT_RESERVED) || (configOpt < 0), RT_ERROR_INVALID_VALUE,
6132 : "Obtaining the system parameter value in the current context", SysParamOptToString(configOpt), "configOpt",
6133 : "[0, " + std::to_string(SYS_OPT_RESERVED) + ")");
6134 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6135 : configVal, RT_ERROR_INVALID_VALUE, "Obtaining the system parameter value in the current context");
6136 : return impl_->CtxGetSysParamOpt(configOpt, configVal);
6137 : }
6138 :
6139 : rtError_t ApiErrorDecorator::CtxGetOverflowAddr(void** const overflowAddr)
6140 : {
6141 : COND_RETURN_ERROR(
6142 : overflowAddr == nullptr, RT_ERROR_INVALID_VALUE, "Check param failed, overflowAddr can not be null.");
6143 : return impl_->CtxGetOverflowAddr(overflowAddr);
6144 : }
6145 :
6146 : rtError_t ApiErrorDecorator::GetDeviceSatStatus(void* const outputAddrPtr, const uint64_t outputSize, Stream* const stm)
6147 : {
6148 : COND_RETURN_ERROR(
6149 : outputAddrPtr == nullptr, RT_ERROR_INVALID_VALUE, "Check param failed, outputAddrPtr can not be null.");
6150 : COND_RETURN_ERROR(
6151 : outputSize != OVERFLOW_OUTPUT_SIZE, RT_ERROR_INVALID_VALUE,
6152 : "Output size %lu is invalid. Only %lu bytes are supported", outputSize, OVERFLOW_OUTPUT_SIZE);
6153 : COND_RETURN_AND_MSG_OUTER(
6154 : (stm != nullptr) && (stm->IsCapturing()), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016,
6155 : "Obtaining the overflow status of tasks in all streams on the current device",
6156 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stm->Id_()));
6157 : return impl_->GetDeviceSatStatus(outputAddrPtr, outputSize, stm);
6158 : }
6159 :
6160 : rtError_t ApiErrorDecorator::CleanDeviceSatStatus(Stream* const stm)
6161 : {
6162 : COND_RETURN_AND_MSG_OUTER(
6163 : (stm != nullptr) && (stm->IsCapturing()), RT_ERROR_STREAM_CAPTURED, ErrorCode::EE1016,
6164 : "Clearing the overflow status of tasks in all streams on the current device",
6165 : RtFmtMsg("Stream (stream_id=%d) during the capture stage is not supported", stm->Id_()));
6166 : return impl_->CleanDeviceSatStatus(stm);
6167 : }
6168 :
6169 : rtError_t ApiErrorDecorator::GetAllUtilizations(const int32_t devId, const rtTypeUtil_t kind, uint8_t* const util)
6170 : {
6171 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
6172 : (kind >= RT_UTIL_TYPE_MAX) || (kind < 0), RT_ERROR_INVALID_VALUE,
6173 : "Querying the usage of Cube, Vector, and AI CPU on the device", kind,
6174 : "[0, " + std::to_string(RT_UTIL_TYPE_MAX) + ")");
6175 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6176 : util, RT_ERROR_INVALID_VALUE, "Querying the usage of Cube, Vector, and AI CPU on the device");
6177 : int32_t realDeviceId;
6178 : const rtError_t error =
6179 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
6180 : COND_RETURN_ERROR(
6181 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
6182 :
6183 : return impl_->GetAllUtilizations(realDeviceId, kind, util);
6184 : }
6185 :
6186 : rtError_t ApiErrorDecorator::GetTaskBufferLen(const rtTaskBuffType_t type, uint32_t* const bufferLen)
6187 : {
6188 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(bufferLen, RT_ERROR_INVALID_VALUE, "Obtaining the task buffer length");
6189 :
6190 : return impl_->GetTaskBufferLen(type, bufferLen);
6191 : }
6192 :
6193 : rtError_t ApiErrorDecorator::TaskSqeBuild(const rtTaskInput_t* const taskInput, uint32_t* const taskLen)
6194 : {
6195 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6196 : taskInput, RT_ERROR_INVALID_VALUE, "Creating Submission Queue Entry (SQE) for a task");
6197 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6198 : taskLen, RT_ERROR_INVALID_VALUE, "Creating Submission Queue Entry (SQE) for a task");
6199 :
6200 : return impl_->TaskSqeBuild(taskInput, taskLen);
6201 : }
6202 :
6203 : rtError_t ApiErrorDecorator::GetKernelBin(const char_t* const binFileName, char_t** const buffer, uint32_t* length)
6204 : {
6205 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6206 : binFileName, RT_ERROR_INVALID_VALUE, "Obtaining the binary file content of an operator");
6207 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6208 : buffer, RT_ERROR_INVALID_VALUE, "Obtaining the binary file content of an operator");
6209 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6210 : length, RT_ERROR_INVALID_VALUE, "Obtaining the binary file content of an operator");
6211 :
6212 : return impl_->GetKernelBin(binFileName, buffer, length);
6213 : }
6214 :
6215 : rtError_t ApiErrorDecorator::GetBinBuffer(
6216 : const rtBinHandle binHandle, const rtBinBufferType_t type, void** bin, uint32_t* binSize)
6217 : {
6218 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(binHandle, RT_ERROR_INVALID_VALUE, "Obtaining the binHandle address");
6219 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(bin, RT_ERROR_INVALID_VALUE, "Obtaining the binHandle address");
6220 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(binSize, RT_ERROR_INVALID_VALUE, "Obtaining the binHandle address");
6221 : return impl_->GetBinBuffer(binHandle, type, bin, binSize);
6222 : }
6223 :
6224 : rtError_t ApiErrorDecorator::GetStackBuffer(
6225 : const rtBinHandle binHandle, uint32_t deviceId, const uint32_t stackType, const uint32_t coreType,
6226 : const uint32_t coreId, const void** stack, uint32_t* stackSize)
6227 : {
6228 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(binHandle, RT_ERROR_INVALID_VALUE, "Obtaining the stack buffer");
6229 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(stack, RT_ERROR_INVALID_VALUE, "Obtaining the stack buffer");
6230 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(stackSize, RT_ERROR_INVALID_VALUE, "Obtaining the stack buffer");
6231 : return impl_->GetStackBuffer(binHandle, deviceId, stackType, coreType, coreId, stack, stackSize);
6232 : }
6233 :
6234 : rtError_t ApiErrorDecorator::BinaryGetGlobal(
6235 : const Program* const binHandle, const char* name, void** dptr, size_t* size)
6236 : {
6237 : if (binHandle->GetKernelRegType() == RT_KERNEL_REG_TYPE_CPU) {
6238 : return RT_ERROR_FEATURE_NOT_SUPPORT;
6239 : }
6240 : return impl_->BinaryGetGlobal(binHandle, name, dptr, size);
6241 : }
6242 :
6243 : rtError_t ApiErrorDecorator::FreeKernelBin(char_t* const buffer)
6244 : {
6245 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6246 : buffer, RT_ERROR_INVALID_VALUE, "Releasing memory allocated to the kernel binary file");
6247 :
6248 : return impl_->FreeKernelBin(buffer);
6249 : }
6250 :
6251 : rtError_t ApiErrorDecorator::EschedQueryInfo(
6252 : const uint32_t devId, const rtEschedQueryType type, rtEschedInputInfo* inPut, rtEschedOutputInfo* outPut)
6253 : {
6254 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(inPut, RT_ERROR_INVALID_VALUE, "Information query");
6255 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(outPut, RT_ERROR_INVALID_VALUE, "Information query");
6256 : uint32_t realDeviceId = 0U;
6257 : if (IsHostCpuDevId(static_cast<int32_t>(devId))) {
6258 : realDeviceId = static_cast<uint32_t>(DEFAULT_HOSTCPU_LOGIC_DEVICE_ID);
6259 : } else {
6260 : const rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(devId, &realDeviceId);
6261 : COND_RETURN_ERROR(
6262 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", devId);
6263 : }
6264 : return impl_->EschedQueryInfo(realDeviceId, type, inPut, outPut);
6265 : }
6266 :
6267 : rtError_t ApiErrorDecorator::ModelCheckArchVersion(const char_t* omsocVersion)
6268 : {
6269 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6270 : omsocVersion, RT_ERROR_INVALID_VALUE,
6271 : "Checking the compatibility between the model SoC version and the device SoC version");
6272 : if (omsocVersion[0U] == '\0') {
6273 : RT_LOG(RT_LOG_ERROR, "input omsocVersion is null, please check.");
6274 : return RT_ERROR_INVALID_VALUE;
6275 : }
6276 : return impl_->ModelCheckArchVersion(omsocVersion);
6277 : }
6278 :
6279 : rtError_t ApiErrorDecorator::ReserveMemAddress(
6280 : void** devPtr, size_t size, size_t alignment, void* devAddr, uint64_t flags)
6281 : {
6282 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(devPtr, RT_ERROR_INVALID_VALUE, "Virtual memory allocation");
6283 : return impl_->ReserveMemAddress(devPtr, size, alignment, devAddr, flags);
6284 : }
6285 :
6286 : rtError_t ApiErrorDecorator::ReleaseMemAddress(void* devPtr) { return impl_->ReleaseMemAddress(devPtr); }
6287 :
6288 : rtError_t ApiErrorDecorator::MallocPhysical(rtDrvMemHandle* handle, size_t size, rtDrvMemProp_t* prop, uint64_t flags)
6289 : {
6290 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(prop, RT_ERROR_INVALID_VALUE, "Physical memory allocation");
6291 : rtError_t error = RT_ERROR_NONE;
6292 : // only device id need covert
6293 : if (prop->side == DEVICE_TYPE) {
6294 : const uint32_t userDeviceId = prop->devid;
6295 : error = Runtime::Instance()->ChgUserDevIdToDeviceId(userDeviceId, &prop->devid);
6296 : COND_RETURN_ERROR(
6297 : error != RT_ERROR_NONE, RT_ERROR_DEVICE_ID, "Failed to convert the user device ID %u to driver device ID.",
6298 : userDeviceId);
6299 : error = CheckDeviceIdIsValid(static_cast<int32_t>(prop->devid));
6300 : COND_RETURN_ERROR_MSG_INNER(
6301 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%u, retCode=%#x", prop->devid,
6302 : static_cast<uint32_t>(error));
6303 : }
6304 : // check feature is support
6305 : if (prop->side == NUMA_TYPE) {
6306 : Context* curCtx = Runtime::Instance()->CurrentContext();
6307 : CHECK_CONTEXT_VALID_WITH_RETURN(curCtx, RT_ERROR_CONTEXT_NULL);
6308 : NULL_PTR_RETURN_MSG(curCtx->Device_(), RT_ERROR_DEVICE_NULL);
6309 : COND_RETURN_WARN(
6310 : (!(NpuDriver::CheckIsSupportFeature(curCtx->Device_()->Id_(), FEATURE_SVM_VMM_NORMAL_GRANULARITY))),
6311 : RT_ERROR_DRV_NOT_SUPPORT, "[drv api] driver does not support the alloc mem via numa id feature.");
6312 : // rt location type covert drv location type
6313 : prop->side = DRV_MEM_HOST_NUMA_SIDE;
6314 : }
6315 : if (prop->pg_type == HUGE1G_PAGE) {
6316 : error = NpuDriver::CheckIfSupport1GHugePage();
6317 : COND_RETURN_ERROR_MSG_INNER(
6318 : error != RT_ERROR_NONE, error, "pageType does not support, pageType[%u], retCode=%#x", prop->pg_type,
6319 : static_cast<uint32_t>(error));
6320 : }
6321 : return impl_->MallocPhysical(handle, size, prop, flags);
6322 : }
6323 :
6324 : rtError_t ApiErrorDecorator::FreePhysical(rtDrvMemHandle handle)
6325 : {
6326 : /* handle在上下文中作为一个整体使用, 内部的devid不用进行转换 */
6327 : return impl_->FreePhysical(handle);
6328 : }
6329 :
6330 : rtError_t ApiErrorDecorator::MapMem(void* devPtr, size_t size, size_t offset, rtDrvMemHandle handle, uint64_t flags)
6331 : {
6332 : /* handle在上下文中作为一个整体使用, 内部的devid不用进行转换 */
6333 : return impl_->MapMem(devPtr, size, offset, handle, flags);
6334 : }
6335 :
6336 : rtError_t ApiErrorDecorator::UnmapMem(void* devPtr) { return impl_->UnmapMem(devPtr); }
6337 :
6338 : rtError_t ApiErrorDecorator::MemMapNoAccess(
6339 : void* virPtr, size_t size, size_t offset, rtDrvMemHandle handle, uint64_t flags)
6340 : {
6341 : return impl_->MemMapNoAccess(virPtr, size, offset, handle, flags);
6342 : }
6343 :
6344 : rtError_t ApiErrorDecorator::MemSetAccess(void* virPtr, size_t size, rtMemAccessDesc* desc, size_t count)
6345 : {
6346 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(virPtr, RT_ERROR_INVALID_VALUE, "Setting the memory access permission");
6347 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(desc, RT_ERROR_INVALID_VALUE, "Setting the memory access permission");
6348 : return impl_->MemSetAccess(virPtr, size, desc, count);
6349 : }
6350 :
6351 : rtError_t ApiErrorDecorator::MemGetAccess(void* virPtr, rtMemLocation* location, uint64_t* flags)
6352 : {
6353 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(virPtr, RT_ERROR_INVALID_VALUE, "Obtaining the memory access permission");
6354 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6355 : location, RT_ERROR_INVALID_VALUE, "Obtaining the memory access permission");
6356 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(flags, RT_ERROR_INVALID_VALUE, "Obtaining the memory access permission");
6357 : return impl_->MemGetAccess(virPtr, location, flags);
6358 : }
6359 :
6360 : rtError_t ApiErrorDecorator::ExportToShareableHandle(
6361 : rtDrvMemHandle handle, rtDrvMemHandleType handleType, uint64_t flags, uint64_t* shareableHandle)
6362 : {
6363 : constexpr uint64_t maxFlag = RT_VMM_EXPORT_FLAG_DISABLE_PID_VALIDATION;
6364 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
6365 : (flags > maxFlag), RT_ERROR_INVALID_VALUE, flags, "[0, " + std::to_string(maxFlag) + "]");
6366 : /* handle在上下文中作为一个整体使用, 内部的devid不用进行转换 */
6367 : return impl_->ExportToShareableHandle(handle, handleType, flags, shareableHandle);
6368 : }
6369 :
6370 : rtError_t ApiErrorDecorator::ExportToShareableHandleV2(
6371 : rtDrvMemHandle handle, rtMemSharedHandleType handleType, uint64_t flags, void* shareableHandle)
6372 : {
6373 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6374 : shareableHandle, RT_ERROR_INVALID_VALUE, "Exporting the shared handle of the AI server");
6375 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_DESC(
6376 : (handleType != RT_MEM_SHARE_HANDLE_TYPE_DEFAULT && handleType != RT_MEM_SHARE_HANDLE_TYPE_FABRIC),
6377 : RT_ERROR_INVALID_VALUE, "Exporting the shared handle of the AI server",
6378 : RtFmtMsg("UNKNOWN(%d)", static_cast<int32_t>(handleType)), "handleType", MEM_SHARED_HANDLE_TYPE_EXPECT_DESC);
6379 : constexpr uint64_t maxFlag = RT_VMM_EXPORT_FLAG_DISABLE_PID_VALIDATION;
6380 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
6381 : (flags > maxFlag), RT_ERROR_INVALID_VALUE, "Exporting the shared handle of the AI server", flags,
6382 : "[0, " + std::to_string(maxFlag) + "]");
6383 : /* handle在上下文中作为一个整体使用, 内部的devid不用进行转换 */
6384 : return impl_->ExportToShareableHandleV2(handle, handleType, flags, shareableHandle);
6385 : }
6386 :
6387 : rtError_t ApiErrorDecorator::ImportFromShareableHandle(uint64_t shareableHandle, int32_t devId, rtDrvMemHandle* handle)
6388 : {
6389 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6390 : handle, RT_ERROR_INVALID_VALUE,
6391 : "Obtaining shareableHandle information and returning the handle in the current process");
6392 : int32_t realDeviceId = 0;
6393 : rtError_t error =
6394 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
6395 : COND_RETURN_ERROR(
6396 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
6397 : error = CheckDeviceIdIsValid(realDeviceId);
6398 : COND_RETURN_ERROR_MSG_INNER(
6399 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%d, retCode=%#x", realDeviceId,
6400 : static_cast<uint32_t>(error));
6401 : return impl_->ImportFromShareableHandle(shareableHandle, realDeviceId, handle);
6402 : }
6403 :
6404 : rtError_t ApiErrorDecorator::ImportFromShareableHandleV2(
6405 : const void* shareableHandle, rtMemSharedHandleType handleType, uint64_t flags, int32_t devId,
6406 : rtDrvMemHandle* handle)
6407 : {
6408 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6409 : shareableHandle, RT_ERROR_INVALID_VALUE,
6410 : "Obtaining shareableHandle information and returning the handle in the current process");
6411 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6412 : handle, RT_ERROR_INVALID_VALUE,
6413 : "Obtaining shareableHandle information and returning the handle in the current process");
6414 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_DESC(
6415 : (handleType != RT_MEM_SHARE_HANDLE_TYPE_DEFAULT && handleType != RT_MEM_SHARE_HANDLE_TYPE_FABRIC),
6416 : RT_ERROR_INVALID_VALUE, "Obtaining shareableHandle information and returning the handle in the current process",
6417 : RtFmtMsg("UNKNOWN(%d)", static_cast<int32_t>(handleType)), "handleType", MEM_SHARED_HANDLE_TYPE_EXPECT_DESC);
6418 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
6419 : (flags != 0U), RT_ERROR_INVALID_VALUE,
6420 : "Obtaining shareableHandle information and returning the handle in the current process", flags, "0");
6421 : int32_t realDeviceId = 0;
6422 : rtError_t error =
6423 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
6424 : COND_RETURN_ERROR(
6425 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
6426 : error = CheckDeviceIdIsValid(realDeviceId);
6427 : COND_RETURN_ERROR_MSG_INNER(
6428 : error != RT_ERROR_NONE, error, "Device id is invalid, drv deviceId=%d, retCode=%#x", realDeviceId,
6429 : static_cast<uint32_t>(error));
6430 : return impl_->ImportFromShareableHandleV2(shareableHandle, handleType, flags, realDeviceId, handle);
6431 : }
6432 :
6433 : rtError_t ApiErrorDecorator::SetPidToShareableHandle(uint64_t shareableHandle, int32_t pid[], uint32_t pidNum)
6434 : {
6435 : return impl_->SetPidToShareableHandle(shareableHandle, pid, pidNum);
6436 : }
6437 :
6438 : rtError_t ApiErrorDecorator::SetPidToShareableHandleV2(
6439 : const void* shareableHandle, rtMemSharedHandleType handleType, int32_t pid[], uint32_t pidNum)
6440 : {
6441 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6442 : shareableHandle, RT_ERROR_INVALID_VALUE, "Setting the trustlist of processes that can share memory");
6443 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_DESC(
6444 : (handleType != RT_MEM_SHARE_HANDLE_TYPE_DEFAULT && handleType != RT_MEM_SHARE_HANDLE_TYPE_FABRIC),
6445 : RT_ERROR_INVALID_VALUE, "Setting the trustlist of processes that can share memory",
6446 : RtFmtMsg("UNKNOWN(%d)", static_cast<int32_t>(handleType)), "handleType", MEM_SHARED_HANDLE_TYPE_EXPECT_DESC);
6447 : return impl_->SetPidToShareableHandleV2(shareableHandle, handleType, pid, pidNum);
6448 : }
6449 :
6450 : rtError_t ApiErrorDecorator::GetAllocationGranularity(
6451 : rtDrvMemProp_t* prop, rtDrvMemGranularityOptions option, size_t* granularity)
6452 : {
6453 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6454 : prop, RT_ERROR_INVALID_VALUE, "Querying the memory allocation granularity");
6455 : if (prop->side == DEVICE_TYPE) {
6456 : const uint32_t userDeviceId = prop->devid;
6457 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(userDeviceId, &prop->devid);
6458 : COND_RETURN_ERROR(
6459 : error != RT_ERROR_NONE, RT_ERROR_DEVICE_ID, "Failed to convert the user device ID %u to driver device ID.",
6460 : userDeviceId);
6461 : error = CheckDeviceIdIsValid(static_cast<int32_t>(prop->devid));
6462 : COND_RETURN_ERROR_MSG_INNER(
6463 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%u, retCode=%#x", prop->devid,
6464 : static_cast<uint32_t>(error));
6465 : }
6466 : if (prop->side == NUMA_TYPE) {
6467 : // rt location type covert drv location type
6468 : prop->side = DRV_MEM_HOST_NUMA_SIDE;
6469 : }
6470 : return impl_->GetAllocationGranularity(prop, option, granularity);
6471 : }
6472 :
6473 : rtError_t ApiErrorDecorator::DeviceStatusQuery(const uint32_t devId, rtDeviceStatus* deviceStatus)
6474 : {
6475 : uint32_t realDeviceId = 0U;
6476 : const Runtime* const rtInstance = Runtime::Instance();
6477 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6478 : deviceStatus, RT_ERROR_INVALID_VALUE, "Querying the device running status");
6479 : rtError_t error =
6480 : rtInstance->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
6481 : COND_RETURN_ERROR(
6482 : error != RT_ERROR_NONE, RT_ERROR_DEVICE_ID, "Failed to convert the user device ID %u to driver device ID.",
6483 : devId);
6484 : error = CheckDeviceIdIsValid(realDeviceId);
6485 : COND_RETURN_ERROR_MSG_INNER(
6486 : error != RT_ERROR_NONE, error, "drv devId is invalid, devId=%u, drv devId=%u, retCode=%#x", devId, realDeviceId,
6487 : static_cast<uint32_t>(error));
6488 : return impl_->DeviceStatusQuery(realDeviceId, deviceStatus);
6489 : }
6490 :
6491 : rtError_t ApiErrorDecorator::BindHostPid(rtBindHostpidInfo info) { return impl_->BindHostPid(info); }
6492 :
6493 : rtError_t ApiErrorDecorator::UnbindHostPid(rtBindHostpidInfo info) { return impl_->UnbindHostPid(info); }
6494 :
6495 : rtError_t ApiErrorDecorator::QueryProcessHostPid(
6496 : int32_t pid, uint32_t* chipId, uint32_t* vfId, uint32_t* hostPid, uint32_t* cpType)
6497 : {
6498 : rtError_t error = impl_->QueryProcessHostPid(pid, chipId, vfId, hostPid, cpType);
6499 : ERROR_RETURN(error, "QueryProcessHostPid failed");
6500 : if (chipId != nullptr) {
6501 : const uint32_t drvDeviceId = *chipId;
6502 : error = Runtime::Instance()->GetUserDevIdByDeviceId(drvDeviceId, chipId);
6503 : ERROR_RETURN_MSG_INNER(
6504 : error, "Failed to convert the driver device ID %u to user device ID, retCode=%#x", drvDeviceId,
6505 : static_cast<uint32_t>(error));
6506 : }
6507 : return RT_ERROR_NONE;
6508 : }
6509 :
6510 : rtError_t ApiErrorDecorator::SetStreamSqLockUnlock(Stream* const stm, bool isLock)
6511 : {
6512 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
6513 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6514 : curStm, RT_ERROR_INVALID_VALUE, "Locking or unlocking the send queue of a stream");
6515 : return impl_->SetStreamSqLockUnlock(curStm, isLock);
6516 : }
6517 :
6518 : rtError_t ApiErrorDecorator::ShrIdSetPodPid(const char* name, uint32_t sdid, int32_t pid)
6519 : {
6520 : return impl_->ShrIdSetPodPid(name, sdid, pid);
6521 : }
6522 :
6523 : rtError_t ApiErrorDecorator::ShmemSetPodPid(const char* name, uint32_t sdid, int32_t pid[], int32_t num)
6524 : {
6525 : return impl_->ShmemSetPodPid(name, sdid, pid, num);
6526 : }
6527 :
6528 : rtError_t ApiErrorDecorator::DevVA2PA(uint64_t devAddr, uint64_t len, Stream* stm, bool isAsync)
6529 : {
6530 : return impl_->DevVA2PA(devAddr, len, stm, isAsync);
6531 : }
6532 :
6533 : rtError_t ApiErrorDecorator::StreamClear(Stream* const stm, rtClearStep_t step)
6534 : {
6535 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
6536 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(curStm, RT_ERROR_INVALID_VALUE, "Clearing tasks in a stream");
6537 : COND_RETURN_ERROR(
6538 : (step > RT_STREAM_CLEAR) || (step < RT_STREAM_STOP), RT_ERROR_INVALID_VALUE,
6539 : "Invalid clearStop, current step=%d, valid range is [%d, %d].", step, RT_STREAM_STOP, RT_STREAM_CLEAR);
6540 : const rtError_t ret = impl_->StreamClear(curStm, step);
6541 : RT_LOG(RT_LOG_EVENT, "Clear stream_id=%d, step=%u, ret = %u", curStm->Id_(), step, static_cast<uint32_t>(ret));
6542 : return ret;
6543 : }
6544 :
6545 : rtError_t ApiErrorDecorator::StreamStop(Stream* const stm)
6546 : {
6547 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(stm, RT_ERROR_INVALID_VALUE, "Stopping the running tasks in a stream");
6548 : const rtError_t ret = impl_->StreamStop(stm);
6549 : return ret;
6550 : }
6551 :
6552 : rtError_t ApiErrorDecorator::StreamAbort(Stream* const stm)
6553 : {
6554 : Stream* curStm = Runtime::Instance()->GetCurStream(stm);
6555 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(curStm, RT_ERROR_INVALID_VALUE, "Aborting tasks in a stream");
6556 : const rtError_t ret = impl_->StreamAbort(curStm);
6557 : RT_LOG(RT_LOG_EVENT, "Abort stream_id=%d,ret = %u", curStm->Id_(), ret);
6558 : return ret;
6559 : }
6560 :
6561 : rtError_t ApiErrorDecorator::DebugSetDumpMode(const uint64_t mode) { return impl_->DebugSetDumpMode(mode); }
6562 :
6563 : rtError_t ApiErrorDecorator::DebugGetStalledCore(rtDbgCoreInfo_t* const coreInfo)
6564 : {
6565 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6566 : coreInfo, RT_ERROR_INVALID_VALUE, "Obtaining the physical ID of the stalled AI Core in the current process");
6567 : return impl_->DebugGetStalledCore(coreInfo);
6568 : }
6569 :
6570 : rtError_t ApiErrorDecorator::DebugReadAICore(rtDebugMemoryParam_t* const param)
6571 : {
6572 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6573 : param, RT_ERROR_INVALID_VALUE, "Reading the register or buffer information of the AI Core");
6574 : return impl_->DebugReadAICore(param);
6575 : }
6576 :
6577 : rtError_t ApiErrorDecorator::GetExceptionRegInfo(
6578 : const rtExceptionInfo_t* const exceptionInfo, rtExceptionErrRegInfo_t** exceptionErrRegInfo, uint32_t* num)
6579 : {
6580 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6581 : exceptionInfo, RT_ERROR_INVALID_VALUE, "Obtaining details about the register related to the exception");
6582 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6583 : exceptionErrRegInfo, RT_ERROR_INVALID_VALUE, "Obtaining details about the register related to the exception");
6584 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6585 : num, RT_ERROR_INVALID_VALUE, "Obtaining details about the register related to the exception");
6586 : return impl_->GetExceptionRegInfo(exceptionInfo, exceptionErrRegInfo, num);
6587 : }
6588 :
6589 : rtError_t ApiErrorDecorator::GetServerIDBySDID(uint32_t sdid, uint32_t* srvId)
6590 : {
6591 : return impl_->GetServerIDBySDID(sdid, srvId);
6592 : }
6593 :
6594 : rtError_t ApiErrorDecorator::ModelNameSet(Model* const mdl, const char_t* const name)
6595 : {
6596 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6597 : mdl, RT_ERROR_INVALID_VALUE, "Setting the name of a model running instance");
6598 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6599 : name, RT_ERROR_INVALID_VALUE, "Setting the name of a model running instance");
6600 : const rtError_t error = impl_->ModelNameSet(mdl, name);
6601 : ERROR_RETURN(error, "set model name failed");
6602 : return error;
6603 : }
6604 :
6605 : rtError_t ApiErrorDecorator::SetDefaultDeviceId(const int32_t deviceId)
6606 : {
6607 : Runtime* rtInstance = Runtime::Instance();
6608 : NULL_PTR_RETURN_MSG(rtInstance, RT_ERROR_INSTANCE_NULL);
6609 : if (deviceId == DEFAULT_DEVICE_ID) {
6610 : rtInstance->SetDefaultDeviceId(deviceId);
6611 : return RT_ERROR_NONE;
6612 : }
6613 :
6614 : int32_t realDeviceId;
6615 : rtError_t error =
6616 : rtInstance->ChgUserDevIdToDeviceId(static_cast<uint32_t>(deviceId), RtPtrToPtr<uint32_t*>(&realDeviceId), true);
6617 : COND_RETURN_ERROR(
6618 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", deviceId);
6619 :
6620 : error = CheckDeviceIdIsValid(realDeviceId);
6621 : COND_RETURN_ERROR_MSG_INNER(
6622 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%d, retCode=%#x", realDeviceId, error);
6623 : return impl_->SetDefaultDeviceId(realDeviceId);
6624 : }
6625 :
6626 : rtError_t ApiErrorDecorator::CtxGetCurrentDefaultStream(Stream** const stm)
6627 : {
6628 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6629 : stm, RT_ERROR_INVALID_VALUE, "Obtaining the default stream of the current context");
6630 : return impl_->CtxGetCurrentDefaultStream(stm);
6631 : }
6632 :
6633 : rtError_t ApiErrorDecorator::GetPrimaryCtxState(const int32_t devId, uint32_t* flags, int32_t* active)
6634 : {
6635 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6636 : flags, RT_ERROR_INVALID_VALUE, "Obtaining the status of the default context");
6637 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6638 : active, RT_ERROR_INVALID_VALUE, "Obtaining the status of the default context");
6639 : int32_t realDeviceId;
6640 : Runtime* rtInstance = Runtime::Instance();
6641 :
6642 : driverType_t const rawDrvType = rtInstance->GetDriverType();
6643 : Driver* const rawDrv = rtInstance->driverFactory_.GetDriver(rawDrvType);
6644 : NULL_PTR_RETURN_MSG(rawDrv, RT_ERROR_DRV_NULL);
6645 :
6646 : int32_t deviceCnt = 0;
6647 : rtError_t error = rawDrv->GetDeviceCount(&deviceCnt);
6648 : ERROR_RETURN_MSG_CALL(ERR_MODULE_DRV, error, "Get device cnt failed, retCode=%#x", static_cast<uint32_t>(error));
6649 :
6650 : error =
6651 : rtInstance->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId), true);
6652 : COND_RETURN_ERROR(error != RT_ERROR_NONE, error, "input error deviceId:%d is err:%#x", devId, error);
6653 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
6654 : ((realDeviceId < 0) || (realDeviceId >= deviceCnt)), RT_ERROR_DEVICE_ID,
6655 : "Obtaining the status of the default context", realDeviceId, "[0, " + std::to_string(deviceCnt) + ")");
6656 :
6657 : return impl_->GetPrimaryCtxState(realDeviceId, flags, active);
6658 : }
6659 : rtError_t ApiErrorDecorator::RegStreamStateCallback(
6660 : const char_t* regName, void* callback, void* args, StreamStateCallback type)
6661 : {
6662 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6663 : regName, RT_ERROR_INVALID_VALUE, "Registering the stream status callback function");
6664 : return impl_->RegStreamStateCallback(regName, callback, args, type);
6665 : }
6666 :
6667 : rtError_t ApiErrorDecorator::DeviceResetForce(const int32_t devId)
6668 : {
6669 : int32_t realDeviceId;
6670 : rtError_t error =
6671 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
6672 : COND_RETURN_ERROR(
6673 : error != RT_ERROR_NONE, RT_ERROR_DEVICE_ID, "Failed to convert the user device ID %d to driver device ID.",
6674 : devId);
6675 : error = CheckDeviceIdIsValid(realDeviceId);
6676 : COND_RETURN_ERROR_MSG_INNER(
6677 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%d, retCode=%#x", realDeviceId,
6678 : static_cast<uint32_t>(error));
6679 :
6680 : return impl_->DeviceResetForce(realDeviceId);
6681 : }
6682 :
6683 : rtError_t ApiErrorDecorator::GetDeviceStatus(const int32_t devId, rtDevStatus_t* const status)
6684 : {
6685 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
6686 : (devId < 0), RT_ERROR_DEVICE_ID, "Obtaining device status", devId, "greater than or equal to 0");
6687 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(status, RT_ERROR_INVALID_VALUE, "Obtaining device status");
6688 : rtError_t error;
6689 : int32_t realDeviceId;
6690 : error =
6691 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
6692 : COND_RETURN_ERROR(
6693 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
6694 : error = CheckDeviceIdIsValid(realDeviceId);
6695 : COND_RETURN_ERROR_MSG_INNER(
6696 : error != RT_ERROR_NONE, error, "Device ID is invalid, drv devId=%d, retCode=%#x", realDeviceId,
6697 : static_cast<uint32_t>(error));
6698 : return impl_->GetDeviceStatus(realDeviceId, status);
6699 : }
6700 :
6701 : rtError_t ApiErrorDecorator::SetDeviceResLimit(const uint32_t devId, const rtDevResLimitType_t type, uint32_t value)
6702 : {
6703 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_DESC(
6704 : static_cast<uint32_t>(type) >= RT_DEV_RES_TYPE_MAX, RT_ERROR_INVALID_VALUE, "Setting the device resource limit",
6705 : DevResLimitTypeToString(type), "type", "[0, 2)");
6706 : uint32_t drvDevId = 0;
6707 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(devId, &drvDevId);
6708 : COND_RETURN_ERROR(
6709 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", devId);
6710 : error = CheckDeviceIdIsValid(static_cast<uint32_t>(drvDevId));
6711 : COND_RETURN_ERROR_MSG_INNER(
6712 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%u, retCode=%#x", drvDevId,
6713 : static_cast<uint32_t>(error));
6714 : return impl_->SetDeviceResLimit(drvDevId, type, value);
6715 : }
6716 :
6717 : rtError_t ApiErrorDecorator::ResetDeviceResLimit(const uint32_t devId)
6718 : {
6719 : uint32_t drvDevId = 0;
6720 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(devId, &drvDevId);
6721 : COND_RETURN_ERROR(
6722 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", devId);
6723 : error = CheckDeviceIdIsValid(static_cast<uint32_t>(drvDevId));
6724 : COND_RETURN_ERROR_MSG_INNER(
6725 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%u, retCode=%#x", drvDevId,
6726 : static_cast<uint32_t>(error));
6727 : return impl_->ResetDeviceResLimit(drvDevId);
6728 : }
6729 :
6730 : rtError_t ApiErrorDecorator::GetDeviceResLimit(const uint32_t devId, const rtDevResLimitType_t type, uint32_t* value)
6731 : {
6732 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_DESC(
6733 : static_cast<uint32_t>(type) >= RT_DEV_RES_TYPE_MAX, RT_ERROR_INVALID_VALUE,
6734 : "Obtaining the device resource limits of the current process", DevResLimitTypeToString(type), "type", "[0, 2)");
6735 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6736 : value, RT_ERROR_INVALID_VALUE, "Obtaining the device resource limits of the current process");
6737 : uint32_t drvDevId = 0;
6738 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(devId, &drvDevId);
6739 : COND_RETURN_ERROR(
6740 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", devId);
6741 : error = CheckDeviceIdIsValid(static_cast<uint32_t>(drvDevId));
6742 : COND_RETURN_ERROR_MSG_INNER(
6743 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%u, retCode=%#x", drvDevId,
6744 : static_cast<uint32_t>(error));
6745 : return impl_->GetDeviceResLimit(drvDevId, type, value);
6746 : }
6747 :
6748 : rtError_t ApiErrorDecorator::SetStreamResLimit(Stream* const stm, const rtDevResLimitType_t type, const uint32_t value)
6749 : {
6750 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME(
6751 : static_cast<uint32_t>(type) >= RT_DEV_RES_TYPE_MAX, RT_ERROR_INVALID_VALUE, DevResLimitTypeToString(type),
6752 : "type", "[0, 2)");
6753 : return impl_->SetStreamResLimit(stm, type, value);
6754 : }
6755 :
6756 : rtError_t ApiErrorDecorator::ResetStreamResLimit(Stream* const stm) { return impl_->ResetStreamResLimit(stm); }
6757 :
6758 : rtError_t ApiErrorDecorator::GetStreamResLimit(
6759 : const Stream* const stm, const rtDevResLimitType_t type, uint32_t* const value)
6760 : {
6761 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_DESC(
6762 : static_cast<uint32_t>(type) >= RT_DEV_RES_TYPE_MAX, RT_ERROR_INVALID_VALUE,
6763 : "Obtaining the device resource limits of a specified stream", DevResLimitTypeToString(type), "type", "[0, 2)");
6764 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6765 : value, RT_ERROR_INVALID_VALUE, "Obtaining the device resource limits of a specified stream");
6766 : return impl_->GetStreamResLimit(stm, type, value);
6767 : }
6768 :
6769 : rtError_t ApiErrorDecorator::UseStreamResInCurrentThread(const Stream* const stm)
6770 : {
6771 : return impl_->UseStreamResInCurrentThread(stm);
6772 : }
6773 :
6774 : rtError_t ApiErrorDecorator::NotUseStreamResInCurrentThread(const Stream* const stm)
6775 : {
6776 : return impl_->NotUseStreamResInCurrentThread(stm);
6777 : }
6778 :
6779 : rtError_t ApiErrorDecorator::GetResInCurrentThread(const rtDevResLimitType_t type, uint32_t* const value)
6780 : {
6781 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_DESC(
6782 : static_cast<uint32_t>(type) >= RT_DEV_RES_TYPE_MAX, RT_ERROR_INVALID_VALUE,
6783 : "Obtaining the device resources that can be used by the current thread", DevResLimitTypeToString(type), "type",
6784 : "[0, 2)");
6785 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6786 : value, RT_ERROR_INVALID_VALUE, "Obtaining the device resources that can be used by the current thread");
6787 : return impl_->GetResInCurrentThread(type, value);
6788 : }
6789 :
6790 : rtError_t ApiErrorDecorator::HdcServerCreate(
6791 : const int32_t devId, const rtHdcServiceType_t type, rtHdcServer_t* const server)
6792 : {
6793 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
6794 : (devId < 0), RT_ERROR_DEVICE_ID, "HDC server creation", devId, "greater than or equal to 0");
6795 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(server, RT_ERROR_INVALID_VALUE, "HDC server creation");
6796 : rtError_t error;
6797 : int32_t realDeviceId;
6798 : error =
6799 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&realDeviceId));
6800 : COND_RETURN_ERROR(
6801 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
6802 : error = CheckDeviceIdIsValid(realDeviceId);
6803 : COND_RETURN_ERROR_MSG_INNER(
6804 : error != RT_ERROR_NONE, error, "Device ID is invalid, drv devId=%d, retCode=%#x", realDeviceId,
6805 : static_cast<uint32_t>(error));
6806 : return impl_->HdcServerCreate(realDeviceId, type, server);
6807 : }
6808 :
6809 : rtError_t ApiErrorDecorator::HdcServerDestroy(rtHdcServer_t const server)
6810 : {
6811 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(server, RT_ERROR_INVALID_VALUE, "HDC server destruction");
6812 : return impl_->HdcServerDestroy(server);
6813 : }
6814 :
6815 : rtError_t ApiErrorDecorator::HdcSessionConnect(
6816 : const int32_t peerNode, const int32_t peerDevId, rtHdcClient_t const client, rtHdcSession_t* const session)
6817 : {
6818 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
6819 : (peerDevId < 0), RT_ERROR_DEVICE_ID, "HDC session connection", peerDevId, "greater than or equal to 0");
6820 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(client, RT_ERROR_INVALID_VALUE, "HDC session connection");
6821 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(session, RT_ERROR_INVALID_VALUE, "HDC session connection");
6822 : rtError_t error;
6823 : int32_t realDeviceId;
6824 : error = Runtime::Instance()->ChgUserDevIdToDeviceId(
6825 : static_cast<uint32_t>(peerDevId), RtPtrToPtr<uint32_t*>(&realDeviceId));
6826 : COND_RETURN_ERROR(
6827 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", peerDevId);
6828 : error = CheckDeviceIdIsValid(realDeviceId);
6829 : COND_RETURN_ERROR_MSG_INNER(
6830 : error != RT_ERROR_NONE, error, "Device ID is invalid, drv devId=%d, retCode=%#x", realDeviceId,
6831 : static_cast<uint32_t>(error));
6832 : return impl_->HdcSessionConnect(peerNode, realDeviceId, client, session);
6833 : }
6834 :
6835 : rtError_t ApiErrorDecorator::HdcSessionClose(rtHdcSession_t const session)
6836 : {
6837 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(session, RT_ERROR_INVALID_VALUE, "HDC session close");
6838 : return impl_->HdcSessionClose(session);
6839 : }
6840 :
6841 : rtError_t ApiErrorDecorator::GetHostCpuDevId(int32_t* const devId)
6842 : {
6843 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6844 : devId, RT_ERROR_INVALID_VALUE, "Obtaining the device ID allocated to the host CPU");
6845 : return impl_->GetHostCpuDevId(devId);
6846 : }
6847 :
6848 : rtError_t ApiErrorDecorator::GetLogicDevIdByUserDevId(const int32_t userDevId, int32_t* const logicDevId)
6849 : {
6850 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
6851 : (userDevId < 0), RT_ERROR_DEVICE_ID, "Obtaining the logical device ID based on the user device ID", userDevId,
6852 : "greater than or equal to 0");
6853 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6854 : logicDevId, RT_ERROR_INVALID_VALUE, "Obtaining the logical device ID based on the user device ID");
6855 : int32_t realDeviceId = 0;
6856 : rtError_t error = impl_->GetLogicDevIdByUserDevId(userDevId, &realDeviceId);
6857 : COND_RETURN_ERROR_MSG_INNER(error != RT_ERROR_NONE, error, "Get logicDevId failed.");
6858 : error = CheckDeviceIdIsValid(realDeviceId);
6859 : COND_RETURN_ERROR_MSG_INNER(
6860 : error != RT_ERROR_NONE, error, "logicDevId is invalid, devId=%d, retCode=%#x", realDeviceId,
6861 : static_cast<uint32_t>(error));
6862 : *logicDevId = realDeviceId;
6863 : return RT_ERROR_NONE;
6864 : }
6865 :
6866 : rtError_t ApiErrorDecorator::GetUserDevIdByLogicDevId(const int32_t logicDevId, int32_t* const userDevId)
6867 : {
6868 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
6869 : (logicDevId < 0), RT_ERROR_DEVICE_ID, "Obtaining the user device ID based on the logical device ID", logicDevId,
6870 : "greater than or equal to 0");
6871 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6872 : userDevId, RT_ERROR_INVALID_VALUE, "Obtaining the user device ID based on the logical device ID");
6873 : const rtError_t error = CheckDeviceIdIsValid(logicDevId);
6874 : COND_RETURN_ERROR_MSG_INNER(
6875 : error != RT_ERROR_NONE, error, "logicDevId is invalid, devId=%d, retCode=%#x", logicDevId,
6876 : static_cast<uint32_t>(error));
6877 : return impl_->GetUserDevIdByLogicDevId(logicDevId, userDevId);
6878 : }
6879 :
6880 : rtError_t ApiErrorDecorator::GetDeviceUuid(const int32_t devId, rtUuid_t* uuid)
6881 : {
6882 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
6883 : (devId < 0), RT_ERROR_DEVICE_ID, "Obtaining the device UUID", devId, "greater than or equal to 0");
6884 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(uuid, RT_ERROR_INVALID_VALUE, "Obtaining the device UUID");
6885 :
6886 : int32_t drvDeviceId;
6887 : rtError_t error =
6888 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&drvDeviceId));
6889 : COND_RETURN_ERROR(
6890 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
6891 :
6892 : error = CheckDeviceIdIsValid(drvDeviceId);
6893 : COND_RETURN_ERROR_MSG_INNER(
6894 : error != RT_ERROR_NONE, error, "drvDeviceId is invalid, drvDeviceId=%d, ErrorCode=%#x", drvDeviceId,
6895 : static_cast<uint32_t>(error));
6896 :
6897 : return impl_->GetDeviceUuid(drvDeviceId, uuid);
6898 : }
6899 :
6900 : rtError_t ApiErrorDecorator::GetDevicePCIBusId(const int32_t devId, char* pciBusId, const int32_t len)
6901 : {
6902 : // Parameter validation: devId >= 0, pciBusId non-null, buffer length > min BDF length (12 chars + '\0' = 13).
6903 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
6904 : (devId < 0), RT_ERROR_DEVICE_ID, "Obtaining the device PCI bus id", devId, "greater than or equal to 0");
6905 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(pciBusId, RT_ERROR_INVALID_VALUE, "Obtaining the device PCI bus id");
6906 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
6907 : (len < static_cast<int32_t>(RT_PCI_BUS_ID_MIN_LEN)), RT_ERROR_INVALID_VALUE, "Obtaining the device PCI bus id",
6908 : len, "greater than or equal to %u", RT_PCI_BUS_ID_MIN_LEN);
6909 :
6910 : // Convert user device ID to driver device ID (affected by ASCEND_RT_VISIBLE_DEVICES).
6911 : int32_t drvDeviceId;
6912 : rtError_t error =
6913 : Runtime::Instance()->ChgUserDevIdToDeviceId(static_cast<uint32_t>(devId), RtPtrToPtr<uint32_t*>(&drvDeviceId));
6914 : COND_RETURN_ERROR(
6915 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %d to driver device ID.", devId);
6916 :
6917 : // Validate driver device ID.
6918 : error = CheckDeviceIdIsValid(drvDeviceId);
6919 : COND_RETURN_ERROR_MSG_INNER(
6920 : error != RT_ERROR_NONE, error, "drvDeviceId is invalid, drvDeviceId=%d, ErrorCode=%#x", drvDeviceId,
6921 : static_cast<uint32_t>(error));
6922 :
6923 : return impl_->GetDevicePCIBusId(drvDeviceId, pciBusId, len);
6924 : }
6925 :
6926 : rtError_t ApiErrorDecorator::GetDeviceByPCIBusId(const char* pciBusId, int32_t* devId)
6927 : {
6928 : // Parameter validation: pciBusId and devId must not be null.
6929 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(pciBusId, RT_ERROR_INVALID_VALUE, "Obtaining the device by PCI bus id");
6930 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(devId, RT_ERROR_INVALID_VALUE, "Obtaining the device by PCI bus id");
6931 :
6932 : return impl_->GetDeviceByPCIBusId(pciBusId, devId);
6933 : }
6934 :
6935 : rtError_t ApiErrorDecorator::SetStreamCacheOpInfoSwitch(const Stream* const stm, uint32_t cacheOpInfoSwitch)
6936 : {
6937 : Stream* curStm = Runtime::Instance()->GetCurStream(const_cast<Stream*>(stm));
6938 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6939 : curStm, RT_ERROR_INVALID_VALUE, "Setting the switch for caching operator information in a stream");
6940 : if (cacheOpInfoSwitch != 0U && cacheOpInfoSwitch != 1U) {
6941 : return RT_ERROR_INVALID_VALUE;
6942 : }
6943 :
6944 : return impl_->SetStreamCacheOpInfoSwitch(curStm, cacheOpInfoSwitch);
6945 : }
6946 :
6947 : rtError_t ApiErrorDecorator::GetStreamCacheOpInfoSwitch(const Stream* const stm, uint32_t* const cacheOpInfoSwitch)
6948 : {
6949 : Stream* curStm = Runtime::Instance()->GetCurStream(const_cast<Stream*>(stm));
6950 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6951 : curStm, RT_ERROR_INVALID_VALUE, "Querying whether the operator information is cached");
6952 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6953 : cacheOpInfoSwitch, RT_ERROR_INVALID_VALUE, "Querying whether the operator information is cached");
6954 :
6955 : return impl_->GetStreamCacheOpInfoSwitch(curStm, cacheOpInfoSwitch);
6956 : }
6957 :
6958 : rtError_t ApiErrorDecorator::ModelUpdate(Model* mdl)
6959 : {
6960 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(mdl, RT_ERROR_INVALID_VALUE, "Model update");
6961 : COND_RETURN_AND_MSG_OUTER(
6962 : mdl->GetModelType() != RT_MODEL_CAPTURE_MODEL, RT_ERROR_FEATURE_NOT_SUPPORT, ErrorCode::EE1016, "Model update",
6963 : "Non ACL Graph mode is not supported");
6964 : CaptureModel* captureModel = dynamic_cast<CaptureModel*>(mdl);
6965 : COND_RETURN_WARN(
6966 : ((captureModel != nullptr) && captureModel->IsSubCaptureModel()), RT_ERROR_FEATURE_NOT_SUPPORT,
6967 : "sub ACL Graph does not support updating model");
6968 : return impl_->ModelUpdate(mdl);
6969 : }
6970 :
6971 : rtError_t ApiErrorDecorator::ModelDestroyRegisterCallback(Model* const mdl, const rtCallback_t fn, void* ptr)
6972 : {
6973 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6974 : mdl, RT_ERROR_INVALID_VALUE, "Registering the callback function for model destruction");
6975 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6976 : fn, RT_ERROR_INVALID_VALUE, "Registering the callback function for model destruction");
6977 : if (mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL) {
6978 : CaptureModel* captureModel = dynamic_cast<CaptureModel*>(mdl);
6979 : COND_RETURN_WARN(
6980 : ((captureModel != nullptr) && captureModel->IsSubCaptureModel()), RT_ERROR_FEATURE_NOT_SUPPORT,
6981 : "sub ACL Graph does not support registering destroy callback");
6982 : }
6983 : return impl_->ModelDestroyRegisterCallback(mdl, fn, ptr);
6984 : }
6985 :
6986 : rtError_t ApiErrorDecorator::ModelDestroyUnregisterCallback(Model* const mdl, rtCallback_t const fn)
6987 : {
6988 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6989 : mdl, RT_ERROR_INVALID_VALUE, "Deregistering the callback function for model destruction");
6990 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
6991 : fn, RT_ERROR_INVALID_VALUE, "Deregistering the callback function for model destruction");
6992 : if (mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL) {
6993 : CaptureModel* captureModel = dynamic_cast<CaptureModel*>(mdl);
6994 : COND_RETURN_WARN(
6995 : ((captureModel != nullptr) && captureModel->IsSubCaptureModel()), RT_ERROR_FEATURE_NOT_SUPPORT,
6996 : "sub ACL Graph does not support unregistering destroy callback");
6997 : }
6998 : return impl_->ModelDestroyUnregisterCallback(mdl, fn);
6999 : }
7000 :
7001 : rtError_t ApiErrorDecorator::DevMalloc(
7002 : void** const devPtr, const uint64_t size, rtMallocPolicy policy, rtMallocAdvise advise,
7003 : const rtMallocConfig_t* const cfg)
7004 : {
7005 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(devPtr, RT_ERROR_INVALID_VALUE, "Allocating device memory");
7006 : Runtime* rtInstance = Runtime::Instance();
7007 : NULL_PTR_RETURN_MSG(rtInstance, RT_ERROR_INSTANCE_NULL);
7008 :
7009 : if (cfg != nullptr) {
7010 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(cfg->attrs, RT_ERROR_INVALID_VALUE, "Allocating device memory");
7011 : }
7012 : const rtError_t error = impl_->DevMalloc(devPtr, size, policy, advise, cfg);
7013 : RT_LOG(
7014 : RT_LOG_INFO, "device malloc, size=%" PRIu64 "(bytes), start ptr=0x%llx, end ptr=0x%llx", size,
7015 : RtPtrToValue(*devPtr), (RtPtrToValue(*devPtr) + size));
7016 : return error;
7017 : }
7018 :
7019 : rtError_t ApiErrorDecorator::MemReserveAddress(
7020 : void** virPtr, size_t size, rtMallocPolicy policy, void* expectAddr, rtMallocConfig_t* cfg)
7021 : {
7022 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(virPtr, RT_ERROR_INVALID_VALUE, "Reserving the virtual address space");
7023 : ZERO_RETURN_AND_MSG_OUTER(size);
7024 : COND_RETURN_AND_MSG_RESERVED_PARAM(
7025 : (expectAddr != nullptr), RT_ERROR_INVALID_VALUE, "expectAddr",
7026 : "expectAddr is reserved parameter and must be null");
7027 : COND_RETURN_AND_MSG_RESERVED_PARAM(
7028 : (cfg != nullptr), RT_ERROR_INVALID_VALUE, "cfg", "cfg is reserved parameter and must be null");
7029 : return impl_->MemReserveAddress(virPtr, size, policy, expectAddr, cfg);
7030 : }
7031 :
7032 : rtError_t ApiErrorDecorator::MemMallocPhysical(
7033 : rtMemHandle* handle, size_t size, rtMallocPolicy policy, rtMallocConfig_t* cfg)
7034 : {
7035 : ZERO_RETURN_AND_MSG_OUTER(size);
7036 :
7037 : if ((cfg != nullptr) && (cfg->attrs == nullptr)) {
7038 : RT_LOG(RT_LOG_ERROR, "cfg is not nullptr, but attrs is nullptr");
7039 : return RT_ERROR_INVALID_VALUE;
7040 : }
7041 :
7042 : return impl_->MemMallocPhysical(handle, size, policy, cfg);
7043 : }
7044 :
7045 : rtError_t ApiErrorDecorator::GetThreadLastTaskId(uint32_t* const taskId)
7046 : {
7047 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7048 : taskId, RT_ERROR_INVALID_VALUE, "Obtaining the ID of the last task delivered by the current thread");
7049 :
7050 : return impl_->GetThreadLastTaskId(taskId);
7051 : }
7052 :
7053 : rtError_t ApiErrorDecorator::LaunchDvppTask(
7054 : const void* const sqe, const uint32_t sqeLen, Stream* const stm, rtDvppCfg_t* cfg)
7055 : {
7056 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(sqe, RT_ERROR_INVALID_VALUE, "DVPP task delivery");
7057 : const rtError_t error = impl_->LaunchDvppTask(sqe, sqeLen, stm, cfg);
7058 : ERROR_RETURN(error, "Stars launch dvpp task failed.");
7059 :
7060 : return error;
7061 : }
7062 :
7063 : rtError_t ApiErrorDecorator::LaunchRandomNumTask(
7064 : const rtRandomNumTaskInfo_t* taskInfo, Stream* const stm, void* reserve)
7065 : {
7066 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7067 : taskInfo, RT_ERROR_INVALID_VALUE, "Starting the random number generation task");
7068 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7069 : reserve != nullptr, RT_ERROR_INVALID_VALUE, "Starting the random number generation task", reserve, "nullptr");
7070 :
7071 : const rtError_t error = impl_->LaunchRandomNumTask(taskInfo, stm, reserve);
7072 : ERROR_RETURN(error, "Stars launch dsa task failed.");
7073 :
7074 : return error;
7075 : }
7076 :
7077 : rtError_t ApiErrorDecorator::KernelArgsInit(Kernel* const funcHandle, RtArgsHandle** argsHandle)
7078 : {
7079 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7080 : funcHandle, RT_ERROR_INVALID_VALUE, "Initializing the parameter list based on the kernel function handle");
7081 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7082 : argsHandle, RT_ERROR_INVALID_VALUE, "Initializing the parameter list based on the kernel function handle");
7083 :
7084 : const rtError_t error = impl_->KernelArgsInit(funcHandle, argsHandle);
7085 : ERROR_RETURN(error, "kernel args init failed.");
7086 :
7087 : return error;
7088 : }
7089 :
7090 : rtError_t ApiErrorDecorator::KernelArgsAppendPlaceHolder(RtArgsHandle* argsHandle, ParaDetail** paraHandle)
7091 : {
7092 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7093 : argsHandle, RT_ERROR_INVALID_VALUE, "Adding placeholder parameters to the kernel parameter handle");
7094 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7095 : argsHandle->funcHandle, RT_ERROR_INVALID_VALUE, "Adding placeholder parameters to the kernel parameter handle");
7096 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7097 : paraHandle, RT_ERROR_INVALID_VALUE, "Adding placeholder parameters to the kernel parameter handle");
7098 :
7099 : const rtError_t error = impl_->KernelArgsAppendPlaceHolder(argsHandle, paraHandle);
7100 : ERROR_RETURN(error, "kernel args append ph failed.");
7101 :
7102 : return error;
7103 : }
7104 :
7105 : rtError_t ApiErrorDecorator::KernelArgsGetPlaceHolderBuffer(
7106 : RtArgsHandle* argsHandle, ParaDetail* paraHandle, size_t dataSize, void** bufferAddr)
7107 : {
7108 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7109 : argsHandle, RT_ERROR_INVALID_VALUE, "Obtaining the memory address pointed to by the paramHandle placeholder");
7110 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7111 : argsHandle->funcHandle, RT_ERROR_INVALID_VALUE,
7112 : "Obtaining the memory address pointed to by the paramHandle placeholder");
7113 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7114 : paraHandle, RT_ERROR_INVALID_VALUE, "Obtaining the memory address pointed to by the paramHandle placeholder");
7115 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7116 : bufferAddr, RT_ERROR_INVALID_VALUE, "Obtaining the memory address pointed to by the paramHandle placeholder");
7117 : ZERO_RETURN_AND_MSG_OUTER(dataSize);
7118 :
7119 : const rtError_t error = impl_->KernelArgsGetPlaceHolderBuffer(argsHandle, paraHandle, dataSize, bufferAddr);
7120 : ERROR_RETURN(error, "kernel args get ph buffer failed.");
7121 :
7122 : return error;
7123 : }
7124 :
7125 : rtError_t ApiErrorDecorator::KernelArgsGetHandleMemSize(Kernel* const funcHandle, size_t* memSize)
7126 : {
7127 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7128 : funcHandle, RT_ERROR_INVALID_VALUE, "Obtaining the memory size occupied by the parameter list handle");
7129 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7130 : memSize, RT_ERROR_INVALID_VALUE, "Obtaining the memory size occupied by the parameter list handle");
7131 :
7132 : const rtError_t error = impl_->KernelArgsGetHandleMemSize(funcHandle, memSize);
7133 : ERROR_RETURN(error, "kernel args get handle mem size failed.");
7134 :
7135 : return error;
7136 : }
7137 :
7138 : rtError_t ApiErrorDecorator::KernelArgsFinalize(RtArgsHandle* argsHandle)
7139 : {
7140 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7141 : argsHandle, RT_ERROR_INVALID_VALUE, "Marking the completion of kernel parameter assembly");
7142 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7143 : argsHandle->funcHandle, RT_ERROR_INVALID_VALUE, "Marking the completion of kernel parameter assembly");
7144 :
7145 : const rtError_t error = impl_->KernelArgsFinalize(argsHandle);
7146 : ERROR_RETURN(error, "kernel args finalize failed.");
7147 :
7148 : return error;
7149 : }
7150 :
7151 : rtError_t ApiErrorDecorator::KernelArgsInitByUserMem(
7152 : Kernel* const funcHandle, RtArgsHandle* argsHandle, void* userHostMem, size_t actualArgsSize)
7153 : {
7154 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7155 : funcHandle, RT_ERROR_INVALID_VALUE, "Initializing the parameter list based on the kernel function handle");
7156 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7157 : argsHandle, RT_ERROR_INVALID_VALUE, "Initializing the parameter list based on the kernel function handle");
7158 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7159 : userHostMem, RT_ERROR_INVALID_VALUE, "Initializing the parameter list based on the kernel function handle");
7160 : ZERO_RETURN_AND_MSG_OUTER(actualArgsSize);
7161 :
7162 : const rtError_t error = impl_->KernelArgsInitByUserMem(funcHandle, argsHandle, userHostMem, actualArgsSize);
7163 : ERROR_RETURN(error, "kernel args init by user mem failed.");
7164 :
7165 : return error;
7166 : }
7167 :
7168 : rtError_t ApiErrorDecorator::KernelArgsGetMemSize(Kernel* const funcHandle, size_t userArgsSize, size_t* actualArgsSize)
7169 : {
7170 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7171 : funcHandle, RT_ERROR_INVALID_VALUE,
7172 : "Obtaining the memory size required by the parameter list during kernel launch");
7173 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7174 : actualArgsSize, RT_ERROR_INVALID_VALUE,
7175 : "Obtaining the memory size required by the parameter list during kernel launch");
7176 :
7177 : const rtError_t error = impl_->KernelArgsGetMemSize(funcHandle, userArgsSize, actualArgsSize);
7178 : ERROR_RETURN(error, "kernel args get mem size failed.");
7179 : return error;
7180 : }
7181 :
7182 : rtError_t ApiErrorDecorator::KernelArgsAppend(
7183 : RtArgsHandle* argsHandle, void* para, size_t paraSize, ParaDetail** paraHandle)
7184 : {
7185 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7186 : argsHandle, RT_ERROR_INVALID_VALUE, "Adding parameters to the kernel parameter handle");
7187 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7188 : para, RT_ERROR_INVALID_VALUE, "Adding parameters to the kernel parameter handle");
7189 : ZERO_RETURN_AND_MSG_OUTER(paraSize);
7190 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7191 : paraHandle, RT_ERROR_INVALID_VALUE, "Adding parameters to the kernel parameter handle");
7192 :
7193 : const rtError_t error = impl_->KernelArgsAppend(argsHandle, para, paraSize, paraHandle);
7194 : ERROR_RETURN(error, "kernel args append failed.");
7195 : return error;
7196 : }
7197 :
7198 : rtError_t ApiErrorDecorator::MemWriteValue(
7199 : const void* const devAddr, const uint64_t value, const uint32_t flag, Stream* const stm)
7200 : {
7201 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(devAddr, RT_ERROR_INVALID_VALUE, "Writing data to the specified memory");
7202 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7203 : (flag != 0U), RT_ERROR_INVALID_VALUE, "Writing data to the specified memory", flag, "0");
7204 :
7205 : rtError_t error = RT_ERROR_NONE;
7206 : rtPtrAttributes_t attributes;
7207 : error = impl_->PtrGetAttributes(devAddr, &attributes);
7208 : COND_RETURN_ERROR_MSG_CALL(
7209 : ERR_MODULE_GE, error != RT_ERROR_NONE, error,
7210 : "mem write value failed, get devAddr attributes failed, retCode=%#x", static_cast<uint32_t>(error));
7211 :
7212 9 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_DESC(
7213 : (attributes.location.type != RT_MEMORY_LOC_DEVICE), RT_ERROR_INVALID_VALUE,
7214 : "Writing data to the specified memory", MemLocationTypeToString(attributes.location.type),
7215 : "attributes.location.type", MemLocationTypeToString(RT_MEMORY_LOC_DEVICE));
7216 :
7217 : return impl_->MemWriteValue(devAddr, value, flag, stm);
7218 : }
7219 :
7220 : rtError_t ApiErrorDecorator::MemWaitValue(
7221 : const void* const devAddr, const uint64_t value, const uint32_t flag, Stream* const stm)
7222 : {
7223 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7224 : devAddr, RT_ERROR_INVALID_VALUE,
7225 : "Unblocking the data in the specified memory when the data meets certain conditions");
7226 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7227 : (flag >= static_cast<uint32_t>(MEM_WAIT_VALUE_TYPE_MAX)), RT_ERROR_INVALID_VALUE,
7228 : "Unblocking the data in the specified memory when the data meets certain conditions", flag,
7229 : "[0, " + std::to_string(static_cast<uint32_t>(MEM_WAIT_VALUE_TYPE_MAX)) + ")");
7230 :
7231 : rtError_t error = RT_ERROR_NONE;
7232 : rtPtrAttributes_t attributes;
7233 : error = impl_->PtrGetAttributes(devAddr, &attributes);
7234 : COND_RETURN_ERROR_MSG_CALL(
7235 : ERR_MODULE_GE, error != RT_ERROR_NONE, error,
7236 : "mem wait value failed, get devAddr attributes failed, retCode=%#x", static_cast<uint32_t>(error));
7237 :
7238 9 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_NAME_DESC(
7239 : (attributes.location.type != RT_MEMORY_LOC_DEVICE), RT_ERROR_INVALID_VALUE,
7240 : "Unblocking the data in the specified memory when the data meets certain conditions",
7241 : MemLocationTypeToString(attributes.location.type), "attributes.location.type",
7242 : MemLocationTypeToString(RT_MEMORY_LOC_DEVICE));
7243 :
7244 : return impl_->MemWaitValue(devAddr, value, flag, stm);
7245 : }
7246 :
7247 : rtError_t ApiErrorDecorator::MemcpyBatch(
7248 : void** dsts, void** srcs, size_t* sizes, size_t count, rtMemcpyBatchAttr* attrs, size_t* attrsIdxs, size_t numAttrs,
7249 : size_t* failIdx)
7250 : {
7251 : SetFailIndex(failIdx, SIZE_MAX);
7252 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(dsts, RT_ERROR_INVALID_VALUE, "Batch synchronous memory copy");
7253 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(srcs, RT_ERROR_INVALID_VALUE, "Batch synchronous memory copy");
7254 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(sizes, RT_ERROR_INVALID_VALUE, "Batch synchronous memory copy");
7255 : ZERO_RETURN_AND_MSG_OUTER(count);
7256 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(attrs, RT_ERROR_INVALID_VALUE, "Batch synchronous memory copy");
7257 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(attrsIdxs, RT_ERROR_INVALID_VALUE, "Batch synchronous memory copy");
7258 : ZERO_RETURN_AND_MSG_OUTER(numAttrs);
7259 : COND_RETURN_AND_MSG_OUTER(
7260 : (numAttrs > count), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Batch synchronous memory copy",
7261 : "numAttrs or count",
7262 : RtFmtMsg("Parameter numAttrs %zu should be less than or equal to parameter count %zu", numAttrs, count));
7263 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7264 : (count > static_cast<size_t>(DEVMM_MEMCPY_BATCH_MAX_COUNT)), RT_ERROR_INVALID_VALUE,
7265 : "Batch synchronous memory copy", count,
7266 : "less than or equal to " + std::to_string(static_cast<size_t>(DEVMM_MEMCPY_BATCH_MAX_COUNT)));
7267 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7268 : (attrsIdxs[0] != 0U), RT_ERROR_INVALID_VALUE, "Batch synchronous memory copy", attrsIdxs[0], "0");
7269 : for (size_t i = 1U; i < numAttrs; i++) {
7270 : COND_RETURN_AND_MSG_OUTER(
7271 : (attrsIdxs[i] <= attrsIdxs[i - 1U]), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
7272 : "Batch synchronous memory copy", RtFmtMsg("attrsIdxs[%zu] or attrsIdxs[%zu]", i, i - 1U),
7273 : RtFmtMsg(
7274 : "Each entry in attrsIdxs must be greater than the previous entry. Parameter attrsIdxs[%zu] is %zu, and "
7275 : "attrsIdxs[%zu] is %zu",
7276 : i, attrsIdxs[i], i - 1U, attrsIdxs[i - 1U]));
7277 : COND_RETURN_AND_MSG_OUTER(
7278 : (attrsIdxs[i] >= count), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Batch synchronous memory copy",
7279 : RtFmtMsg("attrsIdxs[%zu] or count", i),
7280 : RtFmtMsg(
7281 : "Each entry in attrsIdxs must be less than the parameter count. Parameter attrsIdxs[%zu] is %zu, and "
7282 : "count is %zu",
7283 : i, attrsIdxs[i], count));
7284 : }
7285 :
7286 : const rtError_t error = impl_->MemcpyBatch(dsts, srcs, sizes, count, attrs, attrsIdxs, numAttrs, failIdx);
7287 : COND_RETURN_ERROR(
7288 : (error != RT_ERROR_NONE) && (error != RT_ERROR_DRV_NOT_SUPPORT), error, "MemcpyBatch failed, retCode=%#x",
7289 : error);
7290 : return error;
7291 : }
7292 :
7293 : rtError_t ApiErrorDecorator::MemcpyBatchAsync(
7294 : void** const dsts, const size_t* const destMaxs, void** const srcs, const size_t* const sizes, const size_t count,
7295 : const rtMemcpyBatchAttr* const attrs, const size_t* const attrsIdxs, const size_t numAttrs, size_t* const failIdx,
7296 : Stream* const stm)
7297 : {
7298 : SetFailIndex(failIdx, SIZE_MAX);
7299 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(dsts, RT_ERROR_INVALID_VALUE, "Batch asynchronous memory copy");
7300 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(destMaxs, RT_ERROR_INVALID_VALUE, "Batch asynchronous memory copy");
7301 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(srcs, RT_ERROR_INVALID_VALUE, "Batch asynchronous memory copy");
7302 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(sizes, RT_ERROR_INVALID_VALUE, "Batch asynchronous memory copy");
7303 : ZERO_RETURN_AND_MSG_OUTER(count);
7304 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(attrs, RT_ERROR_INVALID_VALUE, "Batch asynchronous memory copy");
7305 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(attrsIdxs, RT_ERROR_INVALID_VALUE, "Batch asynchronous memory copy");
7306 : ZERO_RETURN_AND_MSG_OUTER(numAttrs);
7307 :
7308 : COND_RETURN_AND_MSG_OUTER(
7309 : (numAttrs > count), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Batch asynchronous memory copy",
7310 : "numAttrs or count",
7311 : RtFmtMsg("Parameter numAttrs %zu should be less than or equal to parameter count %zu", numAttrs, count));
7312 :
7313 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7314 : (attrsIdxs[0] != 0U), RT_ERROR_INVALID_VALUE, "Batch asynchronous memory copy", attrsIdxs[0], "0");
7315 : for (size_t i = 1U; i < numAttrs; i++) {
7316 : COND_RETURN_AND_MSG_OUTER(
7317 : (attrsIdxs[i] <= attrsIdxs[i - 1U]), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
7318 : "Batch asynchronous memory copy", RtFmtMsg("attrsIdxs[%zu] or attrsIdxs[%zu]", i, i - 1U),
7319 : RtFmtMsg(
7320 : "Each entry in attrsIdxs must be greater than the previous entry. Parameter attrsIdxs[%zu] is %zu,"
7321 : " and attrsIdxs[%zu] is %zu",
7322 : i, attrsIdxs[i], i - 1U, attrsIdxs[i - 1U]));
7323 : COND_RETURN_AND_MSG_OUTER(
7324 : (attrsIdxs[i] >= count), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017, "Batch asynchronous memory copy",
7325 : RtFmtMsg("attrsIdxs[%zu] or count", i),
7326 : RtFmtMsg(
7327 : "Each entry in attrsIdxs must be less than the parameter count. Parameter attrsIdxs[%zu] is %zu, and "
7328 : "count is %zu",
7329 : i, attrsIdxs[i], count));
7330 : }
7331 : COND_RETURN_WARN(
7332 : (Runtime::Instance()->GetConnectUbFlag()) && IsStreamBindWithSubModel(stm), RT_ERROR_FEATURE_NOT_SUPPORT,
7333 : "stream belongs to sub ACL Graph, does not support asynchronous memory copy.");
7334 : return impl_->MemcpyBatchAsync(dsts, destMaxs, srcs, sizes, count, attrs, attrsIdxs, numAttrs, failIdx, stm);
7335 : }
7336 :
7337 : rtError_t ApiErrorDecorator::GetCmoDescSize(size_t* size)
7338 : {
7339 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7340 : size, RT_ERROR_INVALID_VALUE,
7341 : "Obtaining the memory size used by the cache memory descriptor of the current device");
7342 :
7343 : return impl_->GetCmoDescSize(size);
7344 : }
7345 :
7346 : rtError_t ApiErrorDecorator::SetCmoDesc(rtCmoDesc_t cmoDesc, void* srcAddr, size_t srcLen)
7347 : {
7348 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(cmoDesc, RT_ERROR_INVALID_VALUE, "Setting the cache memory descriptor");
7349 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(srcAddr, RT_ERROR_INVALID_VALUE, "Setting the cache memory descriptor");
7350 : ZERO_RETURN_AND_MSG_OUTER(srcLen);
7351 :
7352 : return impl_->SetCmoDesc(cmoDesc, srcAddr, srcLen);
7353 : }
7354 :
7355 : rtError_t ApiErrorDecorator::ModelGetName(Model* const mdl, const uint32_t maxLen, char_t* const mdlName)
7356 : {
7357 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7358 : mdl, RT_ERROR_INVALID_VALUE, "Obtaining the name of a model running instance");
7359 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7360 : mdlName, RT_ERROR_INVALID_VALUE, "Obtaining the name of a model running instance");
7361 : ZERO_RETURN_AND_MSG_OUTER(maxLen);
7362 : const rtError_t error = impl_->ModelGetName(mdl, maxLen, mdlName);
7363 : ERROR_RETURN(error, "get model name failed");
7364 : return error;
7365 : }
7366 :
7367 : rtError_t ApiErrorDecorator::FuncGetName(const Kernel* const kernel, const uint32_t maxLen, char_t* const name)
7368 : {
7369 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(kernel, RT_ERROR_INVALID_VALUE, "Obtaining the kernel function name");
7370 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(name, RT_ERROR_INVALID_VALUE, "Obtaining the kernel function name");
7371 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7372 : maxLen < (kernel->Name_().length() + 1U), RT_ERROR_INVALID_VALUE, "Obtaining the kernel function name", maxLen,
7373 : "greater than or equal to " + std::to_string(kernel->Name_().length() + 1U));
7374 : const rtError_t error = impl_->FuncGetName(kernel, maxLen, name);
7375 : ERROR_RETURN(error, "get func name failed");
7376 : return error;
7377 : }
7378 :
7379 : rtError_t ApiErrorDecorator::GetErrorVerbose(const uint32_t deviceId, rtErrorInfo* const errorInfo)
7380 : {
7381 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(errorInfo, RT_ERROR_INVALID_VALUE, "Obtaining detailed error information");
7382 : const Runtime* const rtInstance = Runtime::Instance();
7383 : uint32_t realDeviceId = 0U;
7384 : rtError_t error = rtInstance->ChgUserDevIdToDeviceId(deviceId, &realDeviceId);
7385 : COND_RETURN_ERROR(
7386 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", deviceId);
7387 :
7388 : int32_t deviceCnt = 0;
7389 : const driverType_t rawDrvType = rtInstance->GetDriverType();
7390 : Driver* const rawDrv = Runtime::Instance()->driverFactory_.GetDriver(rawDrvType);
7391 : error = rawDrv->GetDeviceCount(&deviceCnt);
7392 : ERROR_RETURN_MSG_CALL(ERR_MODULE_DRV, error, "Get device cnt failed, retCode=%#x", static_cast<uint32_t>(error));
7393 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7394 : realDeviceId >= static_cast<uint32_t>(deviceCnt), RT_ERROR_DEVICE_ID, "Obtaining detailed error information",
7395 : realDeviceId, "[0," + std::to_string(deviceCnt) + ")");
7396 :
7397 : return impl_->GetErrorVerbose(realDeviceId, errorInfo);
7398 : }
7399 :
7400 : rtError_t ApiErrorDecorator::RepairError(const uint32_t deviceId, const rtErrorInfo* const errorInfo)
7401 : {
7402 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(errorInfo, RT_ERROR_INVALID_VALUE, "Rectifying the device faults");
7403 : if (errorInfo->tryRepair == 0U) {
7404 : RT_LOG(RT_LOG_ERROR, "Repair flag is invalid [%u], should be 1.", errorInfo->tryRepair);
7405 : return RT_ERROR_INVALID_VALUE;
7406 : }
7407 : const Runtime* const rtInstance = Runtime::Instance();
7408 : uint32_t realDeviceId = 0U;
7409 : rtError_t error = rtInstance->ChgUserDevIdToDeviceId(deviceId, &realDeviceId);
7410 : COND_RETURN_ERROR(
7411 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", deviceId);
7412 :
7413 : int32_t deviceCnt = 0;
7414 : const driverType_t rawDrvType = rtInstance->GetDriverType();
7415 : Driver* const rawDrv = Runtime::Instance()->driverFactory_.GetDriver(rawDrvType);
7416 : error = rawDrv->GetDeviceCount(&deviceCnt);
7417 : ERROR_RETURN_MSG_CALL(ERR_MODULE_DRV, error, "Get device cnt failed, retCode=%#x", static_cast<uint32_t>(error));
7418 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7419 : realDeviceId >= static_cast<uint32_t>(deviceCnt), RT_ERROR_DEVICE_ID, "Rectifying the device faults",
7420 : realDeviceId, "[0," + std::to_string(deviceCnt) + ")");
7421 :
7422 : return impl_->RepairError(realDeviceId, errorInfo);
7423 : }
7424 :
7425 : rtError_t ApiErrorDecorator::CheckMemType(
7426 : void** addrs, uint32_t size, uint32_t memType, uint32_t* checkResult, uint32_t reserve)
7427 : {
7428 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(checkResult, RT_ERROR_INVALID_VALUE, "Device memory type check");
7429 : *checkResult = 0U;
7430 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(addrs, RT_ERROR_INVALID_VALUE, "Device memory type check");
7431 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7432 : reserve != 0U, RT_ERROR_INVALID_VALUE, "Device memory type check", reserve, "0");
7433 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7434 : size <= 0U, RT_ERROR_INVALID_VALUE, "Device memory type check", size, "greater than 0");
7435 : constexpr uint32_t tmpMemType = RT_MEM_MASK_DEV_TYPE | RT_MEM_MASK_RSVD_TYPE | RT_MEM_MASK_DVPP_TYPE;
7436 : COND_RETURN_AND_MSG_OUTER(
7437 : (memType & ~tmpMemType) != 0U, RT_ERROR_INVALID_VALUE, ErrorCode::EE1006, "Device memory type check",
7438 : RtFmtMsg("Parameter memType value %u", memType),
7439 : "Parameter memType only supports OR combinations of one or more of "
7440 : "RT_MEM_MASK_DEV_TYPE(0x2U), RT_MEM_MASK_RSVD_TYPE(0x20U), and RT_MEM_MASK_DVPP_TYPE(0x8U)");
7441 : return impl_->CheckMemType(addrs, size, memType, checkResult, reserve);
7442 : }
7443 :
7444 : rtError_t ApiErrorDecorator::GetMemUsageInfo(
7445 : const uint32_t deviceId, rtMemUsageInfo_t* const memUsageInfo, const size_t inputNum, size_t* const outputNum)
7446 : {
7447 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7448 : outputNum, RT_ERROR_INVALID_VALUE, "Querying the memory usage of a component");
7449 : *outputNum = 0U;
7450 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7451 : memUsageInfo, RT_ERROR_INVALID_VALUE, "Querying the memory usage of a component");
7452 : ZERO_RETURN_AND_MSG_OUTER(inputNum);
7453 : rtError_t error;
7454 : uint32_t realDeviceId = 0U;
7455 : error = Runtime::Instance()->ChgUserDevIdToDeviceId(deviceId, &realDeviceId);
7456 : COND_RETURN_ERROR(
7457 : error != RT_ERROR_NONE, error, "Failed to convert the user device ID %u to driver device ID.", deviceId);
7458 : error = CheckDeviceIdIsValid(realDeviceId);
7459 : COND_RETURN_ERROR_MSG_INNER(
7460 : error != RT_ERROR_NONE, error, "Device ID is invalid, drv devId=%u, retCode=%#x", realDeviceId,
7461 : static_cast<uint32_t>(error));
7462 : return impl_->GetMemUsageInfo(realDeviceId, memUsageInfo, inputNum, outputNum);
7463 : }
7464 :
7465 : rtError_t ApiErrorDecorator::LaunchHostFunc(Stream* const stm, const rtCallback_t callBackFunc, void* const fnData)
7466 : {
7467 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7468 : callBackFunc, RT_ERROR_INVALID_VALUE, "Adding a host callback function to the stream task queue");
7469 : COND_RETURN_AND_MSG_OUTER(
7470 : (stm != nullptr) && (stm->GetSubscribeFlag() == StreamSubscribeFlag::SUBSCRIBE_USER), RT_ERROR_SUBSCRIBE_STREAM,
7471 : ErrorCode::EE1016, "Adding a host callback function to the stream task queue",
7472 : RtFmtMsg(
7473 : "The stream (stream_id=%d) is in the host callback process and cannot call rtsLaunchHostFunc", stm->Id_()));
7474 : return impl_->LaunchHostFunc(stm, callBackFunc, fnData);
7475 : }
7476 :
7477 : rtError_t ApiErrorDecorator::LaunchHostFuncV2(Stream* const stm, const rtHostCpuFunc callBackFunc, void* const fnData)
7478 : {
7479 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7480 : callBackFunc, RT_ERROR_INVALID_VALUE, "Adding a host callback function to the stream task queue");
7481 : COND_RETURN_AND_MSG_OUTER(
7482 : (stm != nullptr) && (stm->GetSubscribeFlag() == StreamSubscribeFlag::SUBSCRIBE_USER), RT_ERROR_SUBSCRIBE_STREAM,
7483 : ErrorCode::EE1016, "Adding a host callback function to the stream task queue",
7484 : RtFmtMsg(
7485 : "The stream (stream_id=%d) is in the host callback process and cannot call LaunchHostFuncV2", stm->Id_()));
7486 : return impl_->LaunchHostFuncV2(stm, callBackFunc, fnData);
7487 : }
7488 :
7489 : rtError_t ApiErrorDecorator::CacheLastTaskOpInfo(const void* const infoPtr, const size_t infoSize)
7490 : {
7491 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7492 : infoPtr, RT_ERROR_INVALID_VALUE, "Caching the operator information of the latest task");
7493 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7494 : (infoSize == 0U || infoSize > MAX_SHAPE_INFO_SIZE), RT_ERROR_INVALID_VALUE,
7495 : "Caching the operator information of the latest task", infoSize,
7496 : "(0, " + std::to_string(MAX_SHAPE_INFO_SIZE) + "]");
7497 : return impl_->CacheLastTaskOpInfo(infoPtr, infoSize);
7498 : }
7499 :
7500 : rtError_t ApiErrorDecorator::CacheLastTaskExtendInfo(const char* const extendInfoPtr, const size_t infoSize)
7501 : {
7502 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7503 : extendInfoPtr, RT_ERROR_INVALID_VALUE, "Caching the extended information of the latest task");
7504 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7505 : (infoSize == 0U), RT_ERROR_INVALID_VALUE, "Caching the extended information of the latest task", infoSize,
7506 : "not equal to 0");
7507 : constexpr size_t maxExtendInfoSize = 4096U;
7508 : if (infoSize > maxExtendInfoSize) {
7509 : RT_LOG(
7510 : RT_LOG_WARNING, "extend info size=%zu exceeds max size=%zu, only the first %zu bytes will be cached.",
7511 : infoSize, maxExtendInfoSize, maxExtendInfoSize);
7512 : }
7513 : const size_t validSize = (infoSize > maxExtendInfoSize) ? maxExtendInfoSize : infoSize;
7514 : return impl_->CacheLastTaskExtendInfo(extendInfoPtr, validSize);
7515 : }
7516 :
7517 : rtError_t ApiErrorDecorator::FunctionGetAttribute(rtFuncHandle funcHandle, rtFuncAttribute attrType, int64_t* attrValue)
7518 : {
7519 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7520 : funcHandle, RT_ERROR_INVALID_VALUE, "Obtaining kernel function attributes");
7521 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(attrValue, RT_ERROR_INVALID_VALUE, "Obtaining kernel function attributes");
7522 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7523 : ((static_cast<uint32_t>(attrType) < RT_FUNCTION_ATTR_KERNEL_TYPE) ||
7524 : (static_cast<uint32_t>(attrType) >= RT_FUNCTION_ATTR_MAX)),
7525 : RT_ERROR_INVALID_VALUE, "Obtaining kernel function attributes", attrType,
7526 : "[" + std::to_string(RT_FUNCTION_ATTR_KERNEL_TYPE) + ", " + std::to_string(RT_FUNCTION_ATTR_MAX) + ")");
7527 :
7528 : if (attrType == RT_FUNCTION_ATTR_KERNEL_RATIO) {
7529 : const Runtime* const rtInstance = Runtime::Instance();
7530 : NULL_PTR_RETURN_MSG(rtInstance, RT_ERROR_INSTANCE_NULL);
7531 : const rtChipType_t chipType = rtInstance->GetChipType();
7532 : COND_RETURN_WARN(
7533 : !IS_SUPPORT_CHIP_FEATURE(chipType, RtOptionalFeatureType::RT_FEATURE_MODEL_ACL_GRAPH),
7534 : ACL_ERROR_RT_FEATURE_NOT_SUPPORT, "chip type(%d) does not support rtFunctionGetAttribute api, return.",
7535 : static_cast<int32_t>(chipType));
7536 : const Kernel* const kernel = RtPtrToPtr<Kernel*>(funcHandle);
7537 : const KernelRegisterType kernelRegType = kernel->GetKernelRegisterType();
7538 : COND_RETURN_AND_MSG_OUTER(
7539 : kernelRegType != RT_KERNEL_REG_TYPE_NON_CPU, RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
7540 : "Obtaining kernel function attributes", "funcHandle",
7541 : "The funcHandle obtained after registering the AI CPU operator is not supported");
7542 : }
7543 : return impl_->FunctionGetAttribute(funcHandle, attrType, attrValue);
7544 : }
7545 :
7546 : rtError_t ApiErrorDecorator::FunctionGetBinary(const Kernel* const funcHandle, Program** const binHandle)
7547 : {
7548 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7549 : funcHandle, RT_ERROR_INVALID_VALUE, "Obtaining the binary handle of an operator");
7550 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7551 : binHandle, RT_ERROR_INVALID_VALUE, "Obtaining the binary handle of an operator");
7552 : return impl_->FunctionGetBinary(funcHandle, binHandle);
7553 : }
7554 :
7555 : rtError_t ApiErrorDecorator::FunctionGetParamCount(const Kernel* funcHandle, size_t* paramCount)
7556 : {
7557 : COND_RETURN_WARN(
7558 : funcHandle->GetKernelRegisterType() == RT_KERNEL_REG_TYPE_CPU, RT_ERROR_FEATURE_NOT_SUPPORT,
7559 : "AI CPU kernels are not supported.");
7560 : COND_RETURN_AND_MSG_OUTER(
7561 : !funcHandle->HasParamSummary(), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
7562 : "Obtaining the number of parameters from the kernel function handle", "funcHandle",
7563 : "Kernel does not have parameter information");
7564 :
7565 : return impl_->FunctionGetParamCount(funcHandle, paramCount);
7566 : }
7567 :
7568 : rtError_t ApiErrorDecorator::FunctionGetParamInfo(
7569 : const Kernel* funcHandle, size_t paramIndex, size_t* paramOffset, size_t* paramSize)
7570 : {
7571 : COND_RETURN_WARN(
7572 : funcHandle->GetKernelRegisterType() == RT_KERNEL_REG_TYPE_CPU, RT_ERROR_FEATURE_NOT_SUPPORT,
7573 : "AI CPU kernels are not supported.");
7574 : COND_RETURN_AND_MSG_OUTER(
7575 : !funcHandle->HasParamSummary(), RT_ERROR_INVALID_VALUE, ErrorCode::EE1017,
7576 : "Obtaining parameter information from the kernel function handle", "funcHandle",
7577 : "Kernel does not have parameter information");
7578 : if (paramIndex >= funcHandle->GetParamCount()) {
7579 : RT_LOG_OUTER_MSG_WITH_FUNC_DESC(
7580 : ErrorCode::EE1003, "Obtaining parameter information from the kernel function handle", paramIndex,
7581 : "paramIndex", "[0, " + std::to_string(funcHandle->GetParamCount()) + ")");
7582 : return RT_ERROR_INVALID_VALUE;
7583 : }
7584 : return impl_->FunctionGetParamInfo(funcHandle, paramIndex, paramOffset, paramSize);
7585 : }
7586 :
7587 : rtError_t ApiErrorDecorator::FunctionGetAvailDynUbufPerBlock(
7588 : Kernel* funcHandle, uint32_t flags, size_t* dynamicUbufSize)
7589 : {
7590 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7591 : funcHandle, RT_ERROR_INVALID_VALUE,
7592 : "Querying the maximum size of the dynamic UB buffer that can be set for a kernel function");
7593 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7594 : dynamicUbufSize, RT_ERROR_INVALID_VALUE,
7595 : "Querying the maximum size of the dynamic UB buffer that can be set for a kernel function");
7596 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7597 : (flags != 0U), RT_ERROR_INVALID_VALUE,
7598 : "Querying the maximum size of the dynamic UB buffer that can be set for a kernel function", flags, "0");
7599 :
7600 : Program* const prog = funcHandle->Program_();
7601 : NULL_PTR_RETURN_MSG(prog, RT_ERROR_PROGRAM_NULL);
7602 :
7603 : return impl_->FunctionGetAvailDynUbufPerBlock(funcHandle, flags, dynamicUbufSize);
7604 : }
7605 :
7606 : rtError_t ApiErrorDecorator::MemRetainAllocationHandle(void* virPtr, rtDrvMemHandle* handle)
7607 : {
7608 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7609 : virPtr, RT_ERROR_INVALID_VALUE,
7610 : "Obtaining the handle of the physical memory based on the virtual memory address");
7611 : return impl_->MemRetainAllocationHandle(virPtr, handle);
7612 : }
7613 :
7614 : rtError_t ApiErrorDecorator::MemGetAllocationPropertiesFromHandle(rtDrvMemHandle handle, rtDrvMemProp_t* prop)
7615 : {
7616 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7617 : handle, RT_ERROR_INVALID_VALUE,
7618 : "Querying the memory attribute information based on the handle of the physical memory information");
7619 : return impl_->MemGetAllocationPropertiesFromHandle(handle, prop);
7620 : }
7621 :
7622 : rtError_t ApiErrorDecorator::MemGetAddressRange(void* ptr, void** pbase, size_t* psize)
7623 : {
7624 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7625 : ptr, RT_ERROR_INVALID_VALUE,
7626 : "Obtaining the start address and size of the memory block to which the address to be queried belongs");
7627 : COND_RETURN_AND_MSG_OUTER(
7628 : (pbase == nullptr) && (psize == nullptr), RT_ERROR_INVALID_VALUE, ErrorCode::EE1022,
7629 : "Obtaining the start address and size of the memory block to which the address to be queried belongs",
7630 : "nullptr and nullptr", "pbase and psize", "Parameters pbase and psize cannot both be nullptr");
7631 : return impl_->MemGetAddressRange(ptr, pbase, psize);
7632 : }
7633 :
7634 : rtError_t ApiErrorDecorator::MemMapSelectedLink(void* virPtrDst, size_t size, void* virPtrSrc, uint32_t linkIdx)
7635 : {
7636 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7637 : virPtrDst, RT_ERROR_INVALID_VALUE,
7638 : "Mapping the target virtual address to the physical address corresponding to the source virtual address");
7639 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7640 : virPtrSrc, RT_ERROR_INVALID_VALUE,
7641 : "Mapping the target virtual address to the physical address corresponding to the source virtual address");
7642 : ZERO_RETURN_AND_MSG_OUTER(size);
7643 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7644 : linkIdx > RT_MEM_LINK_IDX_1, RT_ERROR_INVALID_VALUE,
7645 : "Mapping the target virtual address to the physical address corresponding to the source virtual address",
7646 : linkIdx, "[" + std::to_string(RT_MEM_LINK_IDX_0) + ", " + std::to_string(RT_MEM_LINK_IDX_1) + "]");
7647 : return impl_->MemMapSelectedLink(virPtrDst, size, virPtrSrc, linkIdx);
7648 : }
7649 :
7650 : rtError_t ApiErrorDecorator::MemMapSetLink(rtDrvMemHandle handle, rtMemLinkType adviceLink)
7651 : {
7652 : NULL_PTR_RETURN_MSG_OUTER(handle, RT_ERROR_INVALID_VALUE);
7653 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM(
7654 : adviceLink > RT_MEM_ACCESS_UB_MULTI_PORT_PATH, RT_ERROR_INVALID_VALUE, adviceLink,
7655 : "[" + std::to_string(RT_MEM_ACCESS_LINK_SIO) + ", " + std::to_string(RT_MEM_ACCESS_UB_MULTI_PORT_PATH) + "]");
7656 : return impl_->MemMapSetLink(handle, adviceLink);
7657 : }
7658 :
7659 : rtError_t ApiErrorDecorator::BinarySetExceptionCallback(Program* binHandle, void* callback, void* userData)
7660 : {
7661 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7662 : binHandle, RT_ERROR_INVALID_VALUE, "Registering a callback function for an operator execution exception");
7663 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7664 : callback, RT_ERROR_INVALID_VALUE, "Registering a callback function for an operator execution exception");
7665 : /* userData为预留字段, 当前不进行非空校验 */
7666 : return impl_->BinarySetExceptionCallback(binHandle, callback, userData);
7667 : }
7668 :
7669 : rtError_t ApiErrorDecorator::GetFuncHandleFromExceptionInfo(const rtExceptionInfo_t* info, Kernel** const funcHandle)
7670 : {
7671 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7672 : info, RT_ERROR_INVALID_VALUE, "Obtaining the kernel function handle from the exception information");
7673 : return impl_->GetFuncHandleFromExceptionInfo(info, funcHandle);
7674 : }
7675 :
7676 : rtError_t ApiErrorDecorator::TaskGetParams(rtTask_t task, rtTaskParams* const params)
7677 : {
7678 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(task, RT_ERROR_INVALID_VALUE, "Obtaining task parameter information");
7679 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(params, RT_ERROR_INVALID_VALUE, "Obtaining task parameter information");
7680 : return impl_->TaskGetParams(task, params);
7681 : }
7682 :
7683 : rtError_t ApiErrorDecorator::TaskSetParams(rtTask_t task, rtTaskParams* const params)
7684 : {
7685 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(task, RT_ERROR_INVALID_VALUE, "Setting task parameters");
7686 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(params, RT_ERROR_INVALID_VALUE, "Setting task parameters");
7687 : return impl_->TaskSetParams(task, params);
7688 : }
7689 :
7690 : rtError_t ApiErrorDecorator::KernelTaskGetAttribute(
7691 : rtTask_t task, rtLaunchKernelAttrId attrId, rtLaunchKernelAttrVal_t* attrValue)
7692 : {
7693 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7694 : task, RT_ERROR_INVALID_VALUE, "Obtaining the launch configuration attributes of a kernel task");
7695 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7696 : attrValue, RT_ERROR_INVALID_VALUE, "Obtaining the launch configuration attributes of a kernel task");
7697 : return impl_->KernelTaskGetAttribute(task, attrId, attrValue);
7698 : }
7699 :
7700 : rtError_t ApiErrorDecorator::SetKernelDfxInfoCallback(rtKernelDfxInfoType type, rtKernelDfxInfoProFunc func)
7701 : {
7702 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7703 : (type < RT_KERNEL_DFX_INFO_DEFAULT || type > RT_KERNEL_DFX_INFO_BLOCK_INFO), RT_ERROR_INVALID_VALUE,
7704 : "Registering the dump callback function", type,
7705 : "[" + std::to_string(RT_KERNEL_DFX_INFO_DEFAULT) + ", " + std::to_string(RT_KERNEL_DFX_INFO_BLOCK_INFO) + "]");
7706 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(func, RT_ERROR_INVALID_VALUE, "Registering the dump callback function");
7707 : return impl_->SetKernelDfxInfoCallback(type, func);
7708 : }
7709 :
7710 : rtError_t ApiErrorDecorator::ModelGetStreams(const Model* const mdl, Stream** streams, uint32_t* numStreams)
7711 : {
7712 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7713 : mdl, RT_ERROR_INVALID_VALUE, "Obtaining the stream associated with a model running instance");
7714 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7715 : numStreams, RT_ERROR_INVALID_VALUE, "Obtaining the stream associated with a model running instance");
7716 : if (mdl->GetModelType() == RT_MODEL_CAPTURE_MODEL) {
7717 : const CaptureModel* captureModel = dynamic_cast<const CaptureModel*>(mdl);
7718 : if (captureModel == nullptr) {
7719 : RT_LOG(
7720 : RT_LOG_ERROR, "dynamic_cast to CaptureModel failed, model_type=%d, model_id=%u.", mdl->GetModelType(),
7721 : mdl->Id_());
7722 : return RT_ERROR_MODEL_NULL;
7723 : }
7724 : COND_RETURN_WARN(
7725 : captureModel->IsSubCaptureModel(), RT_ERROR_FEATURE_NOT_SUPPORT,
7726 : "sub ACL Graph does not support getting streams");
7727 : }
7728 : return impl_->ModelGetStreams(mdl, streams, numStreams);
7729 : }
7730 :
7731 : rtError_t ApiErrorDecorator::StreamGetTasks(Stream* const stm, void** tasks, uint32_t* numTasks)
7732 : {
7733 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(stm, RT_ERROR_INVALID_VALUE, "Obtaining all tasks in a stream");
7734 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(numTasks, RT_ERROR_INVALID_VALUE, "Obtaining all tasks in a stream");
7735 : return impl_->StreamGetTasks(stm, tasks, numTasks);
7736 : }
7737 :
7738 : rtError_t ApiErrorDecorator::TaskGetType(rtTask_t task, rtTaskType* type)
7739 : {
7740 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(task, RT_ERROR_INVALID_VALUE, "Obtaining the task type");
7741 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(type, RT_ERROR_INVALID_VALUE, "Obtaining the task type");
7742 : return impl_->TaskGetType(task, type);
7743 : }
7744 :
7745 : rtError_t ApiErrorDecorator::TaskGetSeqId(rtTask_t task, uint32_t* id)
7746 : {
7747 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7748 : task, RT_ERROR_INVALID_VALUE, "Obtaining the Submission Queue Entry (SQE) ID of a task");
7749 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7750 : id, RT_ERROR_INVALID_VALUE, "Obtaining the Submission Queue Entry (SQE) ID of a task");
7751 : return impl_->TaskGetSeqId(task, id);
7752 : }
7753 :
7754 : rtError_t ApiErrorDecorator::ModelTaskDisable(rtTask_t task)
7755 : {
7756 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7757 : task, RT_ERROR_INVALID_VALUE, "Setting the status of a specified task to disabled");
7758 : return impl_->ModelTaskDisable(task);
7759 : }
7760 :
7761 : static rtError_t ValidateAtomicOperations(const rtAtomicOperation* operations, uint32_t count)
7762 : {
7763 : for (uint32_t i = 0U; i < count; ++i) {
7764 : COND_RETURN_AND_MSG_OUTER(
7765 : (operations[i] < RT_ATOMIC_OPERATION_INTEGER_ADD || operations[i] > RT_ATOMIC_OPERATION_SIMD_SCALAR_EXCH),
7766 : RT_ERROR_INVALID_VALUE, ErrorCode::EE1011, "Validating atomic operations",
7767 : "UNKNOWN(" + std::to_string(static_cast<int32_t>(operations[i])) + ")",
7768 : "operations[" + std::to_string(i) + "]",
7769 : "the operation must be in [" + std::to_string(RT_ATOMIC_OPERATION_INTEGER_ADD) + ", " +
7770 : std::to_string(RT_ATOMIC_OPERATION_SIMD_SCALAR_EXCH) + "]");
7771 : }
7772 : return RT_ERROR_NONE;
7773 : }
7774 :
7775 : rtError_t ApiErrorDecorator::GetHostAtomicCapabilities(
7776 : uint32_t* capabilities, const rtAtomicOperation* operations, const uint32_t count, int32_t deviceId)
7777 : {
7778 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7779 : capabilities, RT_ERROR_INVALID_VALUE,
7780 : "Querying details about the atomic operations supported between a specified device and the host");
7781 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7782 : operations, RT_ERROR_INVALID_VALUE,
7783 : "Querying details about the atomic operations supported between a specified device and the host");
7784 : ZERO_RETURN_AND_MSG_OUTER(count);
7785 :
7786 : int32_t realDeviceId;
7787 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
7788 : static_cast<uint32_t>(deviceId), RtPtrToPtr<uint32_t*>(&realDeviceId), true);
7789 : COND_RETURN_ERROR(
7790 : error != RT_ERROR_NONE, RT_ERROR_DEVICE_ID, "Failed to convert the user device ID %d to driver device ID.",
7791 : deviceId);
7792 :
7793 : error = CheckDeviceIdIsValid(realDeviceId);
7794 : COND_RETURN_ERROR_MSG_INNER(
7795 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%d, retCode=%#x", realDeviceId,
7796 : static_cast<uint32_t>(error));
7797 :
7798 : error = ValidateAtomicOperations(operations, count);
7799 : COND_RETURN_ERROR_MSG_INNER(
7800 : error != RT_ERROR_NONE, error, "validate atomic operations failed, retCode=%#x", static_cast<uint32_t>(error));
7801 :
7802 : return impl_->GetHostAtomicCapabilities(capabilities, operations, count, realDeviceId);
7803 : }
7804 :
7805 : rtError_t ApiErrorDecorator::GetP2PAtomicCapabilities(
7806 : uint32_t* capabilities, const rtAtomicOperation* operations, const uint32_t count, int32_t srcDeviceId,
7807 : int32_t dstDeviceId)
7808 : {
7809 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7810 : capabilities, RT_ERROR_INVALID_VALUE, "Querying details about the atomic operations supported between devices");
7811 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7812 : operations, RT_ERROR_INVALID_VALUE, "Querying details about the atomic operations supported between devices");
7813 : ZERO_RETURN_AND_MSG_OUTER(count);
7814 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7815 : (srcDeviceId == dstDeviceId), RT_ERROR_DEVICE_ID,
7816 : "Querying details about the atomic operations supported between devices", srcDeviceId,
7817 : "srcDeviceId must be different from dstDeviceId");
7818 :
7819 : int32_t realSrcDeviceId;
7820 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(
7821 : static_cast<uint32_t>(srcDeviceId), RtPtrToPtr<uint32_t*>(&realSrcDeviceId), true);
7822 : COND_RETURN_ERROR(
7823 : error != RT_ERROR_NONE, RT_ERROR_DEVICE_ID, "Failed to convert the user device ID %d to driver device ID.",
7824 : srcDeviceId);
7825 : error = CheckDeviceIdIsValid(realSrcDeviceId);
7826 : COND_RETURN_ERROR_MSG_INNER(
7827 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%d, retCode=%#x", realSrcDeviceId,
7828 : static_cast<uint32_t>(error));
7829 :
7830 : int32_t realDstDeviceId;
7831 : error = Runtime::Instance()->ChgUserDevIdToDeviceId(
7832 : static_cast<uint32_t>(dstDeviceId), RtPtrToPtr<uint32_t*>(&realDstDeviceId), true);
7833 : COND_RETURN_ERROR(
7834 : error != RT_ERROR_NONE, RT_ERROR_DEVICE_ID, "Failed to convert the user device ID %d to driver device ID.",
7835 : dstDeviceId);
7836 : error = CheckDeviceIdIsValid(realDstDeviceId);
7837 : COND_RETURN_ERROR_MSG_INNER(
7838 : error != RT_ERROR_NONE, error, "drv devId is invalid, drv devId=%d, retCode=%#x", realDstDeviceId,
7839 : static_cast<uint32_t>(error));
7840 :
7841 : error = ValidateAtomicOperations(operations, count);
7842 : COND_RETURN_ERROR_MSG_INNER(
7843 : error != RT_ERROR_NONE, error, "validate atomic operations failed, retCode=%#x", static_cast<uint32_t>(error));
7844 :
7845 : return impl_->GetP2PAtomicCapabilities(capabilities, operations, count, realSrcDeviceId, realDstDeviceId);
7846 : }
7847 :
7848 : rtError_t ApiErrorDecorator::GetDeviceInfoByAttr(uint32_t deviceId, rtDevAttr attr, int64_t* val)
7849 : {
7850 : NULL_PTR_RETURN_MSG_OUTER_WITH_FUNC_DESC(
7851 : val, RT_ERROR_INVALID_VALUE, "Querying device information based on the specified attribute");
7852 : uint32_t realDeviceId;
7853 : rtError_t error = Runtime::Instance()->ChgUserDevIdToDeviceId(deviceId, &realDeviceId);
7854 : COND_RETURN_ERROR(
7855 : error != RT_ERROR_NONE, RT_ERROR_INVALID_VALUE, "Failed to convert the user device ID %u to driver device ID.",
7856 : deviceId);
7857 : const auto npuDrv = Runtime::Instance()->driverFactory_.GetDriver(NPU_DRIVER);
7858 : NULL_PTR_RETURN_MSG(npuDrv, RT_ERROR_DRV_NULL);
7859 : int32_t cnt = 1;
7860 : error = npuDrv->GetDeviceCount(&cnt);
7861 : COND_RETURN_ERROR_MSG_CALL(
7862 : ERR_MODULE_DRV, error != RT_ERROR_NONE, error, "Get device info failed, get device count failed, retCode=%#x",
7863 : static_cast<uint32_t>(error));
7864 : COND_RETURN_AND_MSG_OUTER_WITH_PARAM_DESC(
7865 : realDeviceId >= static_cast<uint32_t>(cnt), RT_ERROR_INVALID_VALUE,
7866 : "Querying device information based on the specified attribute", realDeviceId,
7867 : "[0, " + std::to_string(cnt) + ")");
7868 :
7869 : return impl_->GetDeviceInfoByAttr(realDeviceId, attr, val);
7870 : }
7871 :
7872 : } // namespace runtime
7873 : } // namespace cce
|