Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "acl_rt_impl.h"
12 : #include "acl_rt_impl_base.h"
13 : #include "runtime/dev.h"
14 : #include "runtime/kernel.h"
15 : #include "runtime/config.h"
16 : #include "runtime/rts/rts_device.h"
17 : #include "runtime/rts/rts_stream.h"
18 : #include "common/log_inner.h"
19 : #include "common/error_codes_inner.h"
20 : #include "common/prof_reporter.h"
21 : #include "common/resource_statistics.h"
22 :
23 : namespace {
24 : constexpr int32_t DEVICE_UTILIZATION_NOT_SUPPORT = -1;
25 :
26 6 : int32_t GetAllUtilizations(const int32_t deviceId, const rtTypeUtil_t utilType)
27 : {
28 6 : uint8_t utilRate = 0U;
29 6 : const rtError_t rtErr = rtGetAllUtilizations(deviceId, utilType, &utilRate);
30 6 : if (rtErr == ACL_ERROR_RT_FEATURE_NOT_SUPPORT) {
31 1 : ACL_LOG_WARN("rtGetAllUtilizations not to support this query, utilType = %d, runtime result = %d.",
32 : static_cast<int32_t>(utilType), static_cast<int32_t>(rtErr));
33 1 : return DEVICE_UTILIZATION_NOT_SUPPORT;
34 : }
35 5 : if (rtErr != RT_ERROR_NONE) {
36 1 : ACL_LOG_CALL_ERROR("rtGetAllUtilizations failed, utilType = %d, runtime result = %d.",
37 : static_cast<int32_t>(utilType), static_cast<int32_t>(rtErr));
38 1 : return DEVICE_UTILIZATION_NOT_SUPPORT;
39 : }
40 4 : ACL_LOG_INFO("successfully execute rtGetAllUtilizations, utilType = %d, utilRate = %u.",
41 : static_cast<int32_t>(utilType), utilRate);
42 4 : return static_cast<int32_t>(utilRate);
43 : }
44 : }
45 :
46 13 : aclError aclrtSetDeviceImpl(int32_t deviceId)
47 : {
48 26 : ACL_PROFILING_REG(acl::AclProfType::AclrtSetDevice);
49 13 : ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
50 13 : ACL_LOG_INFO("start to execute aclrtSetDevice, deviceId = %d.", deviceId);
51 13 : const rtError_t rtErr = rtSetDevice(deviceId);
52 13 : if (rtErr != RT_ERROR_NONE) {
53 2 : ACL_LOG_CALL_ERROR("open device %d failed, runtime result = %d.", deviceId, static_cast<int32_t>(rtErr));
54 2 : return ACL_GET_ERRCODE_RTS(rtErr);
55 : }
56 11 : ACL_LOG_INFO("successfully execute aclrtSetDevice, deviceId = %d", deviceId);
57 11 : ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
58 : // update platform info
59 11 : const auto err = acl::UpdatePlatformInfoWithDevice(deviceId);
60 11 : if (err != ACL_SUCCESS) {
61 7 : ACL_LOG_WARN("update platform info with device failed, error code is [%d], deviceId is [%d]", err, deviceId);
62 : }
63 11 : return ACL_SUCCESS;
64 : }
65 :
66 4 : aclError aclrtSetDeviceWithoutTsdVXXImpl(int32_t deviceId)
67 : {
68 8 : ACL_PROFILING_REG(acl::AclProfType::AclrtSetDeviceWithoutTsdVXX);
69 4 : ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
70 4 : ACL_LOG_INFO("start to execute aclrtSetDeviceWithoutTsdVXX, deviceId = %d.", deviceId);
71 4 : const std::string &socVersion = acl::GetSocVersion();
72 4 : if (strncmp(socVersion.c_str(), "Ascend910", (sizeof("Ascend910") - 1UL)) != 0) {
73 0 : ACL_LOG_INFO("The soc version is not Ascend910, not support");
74 0 : return ACL_ERROR_API_NOT_SUPPORT;
75 : }
76 4 : const rtError_t rtErr = rtSetDeviceWithoutTsd(deviceId);
77 4 : if (rtErr != RT_ERROR_NONE) {
78 2 : ACL_LOG_CALL_ERROR("open device %d failed, runtime result = %d.", deviceId, static_cast<int32_t>(rtErr));
79 2 : return ACL_GET_ERRCODE_RTS(rtErr);
80 : }
81 2 : ACL_LOG_INFO("open device %d successfully.", deviceId);
82 2 : ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
83 2 : return ACL_SUCCESS;
84 : }
85 :
86 5 : aclError aclrtResetDeviceImpl(int32_t deviceId)
87 : {
88 10 : ACL_PROFILING_REG(acl::AclProfType::AclrtResetDevice);
89 5 : ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
90 5 : ACL_LOG_INFO("start to execute aclrtResetDevice, deviceId = %d.", deviceId);
91 5 : const rtError_t rtErr = rtDeviceReset(deviceId);
92 5 : if (rtErr != RT_ERROR_NONE) {
93 3 : ACL_LOG_CALL_ERROR("reset device %d failed, runtime result = %d.", deviceId, static_cast<int32_t>(rtErr));
94 3 : return ACL_GET_ERRCODE_RTS(rtErr);
95 : }
96 2 : ACL_LOG_INFO("successfully execute aclrtResetDevice, reset device %d.", deviceId);
97 2 : ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
98 2 : return ACL_SUCCESS;
99 : }
100 :
101 5 : aclError aclrtResetDeviceForceImpl(int32_t deviceId)
102 : {
103 10 : ACL_PROFILING_REG(acl::AclProfType::AclrtResetDeviceForce);
104 5 : ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
105 5 : ACL_LOG_INFO("start to execute aclrtResetDeviceForce, deviceId = %d.", deviceId);
106 5 : const rtError_t rtErr = rtDeviceResetForce(deviceId);
107 5 : if (rtErr != RT_ERROR_NONE) {
108 2 : ACL_LOG_CALL_ERROR("force reset device %d failed, runtime result = %d.", deviceId, static_cast<int32_t>(rtErr));
109 2 : return ACL_GET_ERRCODE_RTS(rtErr);
110 : }
111 3 : ACL_LOG_INFO("successfully execute aclrtResetDeviceForce, reset device %d.", deviceId);
112 3 : ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
113 3 : return ACL_SUCCESS;
114 : }
115 :
116 4 : aclError aclrtResetDeviceWithoutTsdVXXImpl(int32_t deviceId)
117 : {
118 8 : ACL_PROFILING_REG(acl::AclProfType::AclrtResetDeviceWithoutTsdVXX);
119 4 : ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
120 4 : ACL_LOG_INFO("start to execute aclrtResetDeviceWithoutTsdVXX, deviceId = %d.", deviceId);
121 4 : const std::string &socVersion = acl::GetSocVersion();
122 4 : if (strncmp(socVersion.c_str(), "Ascend910", (sizeof("Ascend910") - 1UL)) != 0) {
123 0 : ACL_LOG_INNER_ERROR("The soc version is not Ascend910, not support");
124 0 : return ACL_ERROR_API_NOT_SUPPORT;
125 : }
126 4 : const rtError_t rtErr = rtDeviceResetWithoutTsd(deviceId);
127 4 : if (rtErr != RT_ERROR_NONE) {
128 2 : ACL_LOG_CALL_ERROR("reset device %d failed, runtime result = %d.", deviceId, static_cast<int32_t>(rtErr));
129 2 : return ACL_GET_ERRCODE_RTS(rtErr);
130 : }
131 2 : ACL_LOG_INFO("successfully execute aclrtResetDeviceWithoutTsdVXX, reset device %d", deviceId);
132 2 : ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
133 2 : return ACL_SUCCESS;
134 : }
135 :
136 6 : aclError aclrtGetDeviceImpl(int32_t *deviceId)
137 : {
138 6 : ACL_LOG_INFO("start to execute aclrtGetDevice");
139 6 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(deviceId);
140 4 : const rtError_t rtErr = rtGetDevice(deviceId);
141 4 : if (rtErr != RT_ERROR_NONE) {
142 2 : ACL_LOG_INFO("can not get device id, runtime result = %d.", static_cast<int32_t>(rtErr));
143 2 : return ACL_GET_ERRCODE_RTS(rtErr);
144 : }
145 2 : ACL_LOG_DEBUG("successfully execute aclrtGetDevice, get device id is %d.", *deviceId);
146 2 : return ACL_SUCCESS;
147 : }
148 :
149 20 : aclError aclrtGetRunModeImpl(aclrtRunMode *runMode)
150 : {
151 20 : ACL_LOG_INFO("start to execute aclrtGetRunMode");
152 20 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(runMode);
153 20 : rtRunMode rtMode;
154 20 : const rtError_t rtErr = rtGetRunMode(&rtMode);
155 20 : if (rtErr != RT_ERROR_NONE) {
156 3 : ACL_LOG_CALL_ERROR("get runMode failed, runtime result = %d.", static_cast<int32_t>(rtErr));
157 3 : return ACL_GET_ERRCODE_RTS(rtErr);
158 : }
159 17 : if (rtMode == RT_RUN_MODE_OFFLINE) {
160 2 : *runMode = ACL_DEVICE;
161 2 : return ACL_SUCCESS;
162 : }
163 15 : *runMode = ACL_HOST;
164 15 : ACL_LOG_INFO("successfully execute aclrtGetRunMode, current runMode is %d.", static_cast<int32_t>(*runMode));
165 15 : return ACL_SUCCESS;
166 : }
167 :
168 4 : aclError aclrtSynchronizeDeviceImpl()
169 : {
170 8 : ACL_PROFILING_REG(acl::AclProfType::AclrtSynchronizeDevice);
171 4 : ACL_LOG_INFO("start to execute aclrtSynchronizeDevice");
172 4 : const rtError_t rtErr = rtDeviceSynchronize();
173 4 : if (rtErr != RT_ERROR_NONE) {
174 2 : ACL_LOG_CALL_ERROR("wait for compute device to finish failed, runtime result = %d.",
175 : static_cast<int32_t>(rtErr));
176 2 : return ACL_GET_ERRCODE_RTS(rtErr);
177 : }
178 2 : ACL_LOG_INFO("device synchronize successfully.");
179 2 : return ACL_SUCCESS;
180 : }
181 :
182 4 : aclError aclrtSynchronizeDeviceWithTimeoutImpl(int32_t timeout)
183 : {
184 8 : ACL_PROFILING_REG(acl::AclProfType::AclrtSynchronizeDeviceWithTimeout);
185 4 : ACL_LOG_INFO("start to execute aclrtSynchronizeDeviceWithTimeout, timeout %dms", timeout);
186 4 : constexpr int32_t defaultTimeout = -1;
187 4 : if (timeout < defaultTimeout) {
188 1 : ACL_LOG_CALL_ERROR("the timeout of synchronize device is invalid, timeout is %d", timeout);
189 1 : return ACL_ERROR_RT_PARAM_INVALID;
190 : }
191 :
192 3 : const rtError_t rtErr = rtDeviceSynchronizeWithTimeout(timeout);
193 3 : if (rtErr == ACL_ERROR_RT_STREAM_SYNC_TIMEOUT) {
194 1 : ACL_LOG_CALL_ERROR("synchronize device timeout, timeout = %dms", timeout);
195 1 : return ACL_ERROR_RT_STREAM_SYNC_TIMEOUT;
196 2 : } else if (rtErr != RT_ERROR_NONE) {
197 1 : ACL_LOG_CALL_ERROR("wait for compute device to finish failed, runtime result = %d.",
198 : static_cast<int32_t>(rtErr));
199 1 : return ACL_GET_ERRCODE_RTS(rtErr);
200 : }
201 1 : ACL_LOG_INFO("device synchronize with timeout %dms successfully.", timeout);
202 1 : return ACL_SUCCESS;
203 : }
204 :
205 6 : aclError aclrtSetTsDeviceImpl(aclrtTsId tsId)
206 : {
207 12 : ACL_PROFILING_REG(acl::AclProfType::AclrtSetTsDevice);
208 6 : ACL_LOG_INFO("start to execute aclrtSetTsDevice, tsId = %d.", static_cast<int32_t>(tsId));
209 6 : if ((tsId != ACL_TS_ID_AICORE) && (tsId != ACL_TS_ID_AIVECTOR)) {
210 2 : ACL_LOG_INNER_ERROR("invalid tsId, tsID is %d.", static_cast<int32_t>(tsId));
211 2 : return ACL_ERROR_INVALID_PARAM;
212 : }
213 4 : const rtError_t rtErr = rtSetTSDevice(static_cast<uint32_t>(tsId));
214 4 : if (rtErr != RT_ERROR_NONE) {
215 2 : ACL_LOG_CALL_ERROR("set device ts %d failed, runtime result = %d.", static_cast<int32_t>(tsId), rtErr);
216 2 : return ACL_GET_ERRCODE_RTS(rtErr);
217 : }
218 2 : ACL_LOG_INFO("successfully execute aclrtSetTsDevice, set device ts %d", static_cast<int32_t>(tsId));
219 2 : return ACL_SUCCESS;
220 : }
221 :
222 3 : aclError aclrtGetDeviceUtilizationRateImpl(int32_t deviceId, aclrtUtilizationInfo *utilizationInfo)
223 : {
224 3 : ACL_LOG_INFO("start to execute aclrtGetDeviceUtilizationRate, device is %d.", deviceId);
225 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(utilizationInfo);
226 3 : aclrtUtilizationExtendInfo *utilizationExtend = utilizationInfo->utilizationExtend;
227 3 : if (utilizationExtend != nullptr) {
228 1 : ACL_LOG_ERROR("utilizationExtend is reserved parameter, current version needs to be null!");
229 1 : return ACL_ERROR_INVALID_PARAM;
230 : }
231 2 : utilizationInfo->cubeUtilization = GetAllUtilizations(deviceId, RT_UTIL_TYPE_AICORE);
232 2 : utilizationInfo->vectorUtilization = GetAllUtilizations(deviceId, RT_UTIL_TYPE_AIVECTOR);
233 2 : utilizationInfo->aicpuUtilization = GetAllUtilizations(deviceId, RT_UTIL_TYPE_AICPU);
234 : // Currently, memory is not supported
235 2 : utilizationInfo->memoryUtilization = DEVICE_UTILIZATION_NOT_SUPPORT;
236 2 : ACL_LOG_INFO("successfully execute aclrtGetDeviceUtilizationRate, device is %d.", deviceId);
237 2 : return ACL_SUCCESS;
238 : };
239 :
240 6 : aclError aclrtGetDeviceCountImpl(uint32_t *count)
241 : {
242 12 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetDeviceCount);
243 6 : ACL_LOG_INFO("start to execute aclrtGetDeviceCount");
244 6 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(count);
245 :
246 4 : const rtError_t rtErr = rtGetDeviceCount(reinterpret_cast<int32_t *>(count));
247 4 : if (rtErr != RT_ERROR_NONE) {
248 2 : ACL_LOG_CALL_ERROR("get device count failed, runtime result = %d.", static_cast<int32_t>(rtErr));
249 2 : return ACL_GET_ERRCODE_RTS(rtErr);
250 : }
251 2 : ACL_LOG_INFO("successfully execute aclrtGetDeviceCount, get device count is %u.", *count);
252 2 : return ACL_SUCCESS;
253 : }
254 :
255 2 : aclError aclrtGetDeviceSatModeImpl(aclrtFloatOverflowMode *mode)
256 : {
257 2 : ACL_LOG_INFO("start to execute aclrtGetDeviceSatMode");
258 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(mode);
259 2 : rtFloatOverflowMode_t rtMode = RT_OVERFLOW_MODE_UNDEF;
260 2 : const rtError_t rtErr = rtGetDeviceSatMode(&rtMode);
261 2 : if (rtErr != RT_ERROR_NONE) {
262 1 : ACL_LOG_CALL_ERROR("rtGetDeviceSatMode failed, runtime result = %d.", static_cast<int32_t>(rtErr));
263 1 : return ACL_GET_ERRCODE_RTS(rtErr);
264 : }
265 1 : *mode = static_cast<aclrtFloatOverflowMode>(rtMode);
266 1 : ACL_LOG_INFO("successfully execute aclrtGetDeviceSatMode, mode is %d.", *mode);
267 1 : return ACL_SUCCESS;
268 : }
269 :
270 2 : aclError aclrtSetDeviceSatModeImpl(aclrtFloatOverflowMode mode)
271 : {
272 2 : ACL_LOG_INFO("start to execute aclrtSetDeviceSatMode, mode is %d", mode);
273 2 : const rtError_t rtErr = rtSetDeviceSatMode(static_cast<rtFloatOverflowMode_t>(mode));
274 2 : if (rtErr != RT_ERROR_NONE) {
275 1 : ACL_LOG_CALL_ERROR("rtSetDeviceSatMode failed, runtime result = %d.", static_cast<int32_t>(rtErr));
276 1 : return ACL_GET_ERRCODE_RTS(rtErr);
277 : }
278 1 : ACL_LOG_INFO("successfully execute aclrtSetDeviceSatMode, mode is %d", mode);
279 1 : return ACL_SUCCESS;
280 : }
281 :
282 3 : aclError aclrtGetOverflowStatusImpl(void *outputAddr, size_t outputSize, aclrtStream stream)
283 : {
284 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetOverflowStatus);
285 3 : ACL_LOG_INFO("start to execute aclrtGetOverflowStatus, outputSize = %lu", outputSize);
286 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(outputAddr);
287 2 : const rtError_t rtErr = rtGetDeviceSatStatus(outputAddr, outputSize, static_cast<rtStream_t>(stream));
288 2 : if (rtErr != RT_ERROR_NONE) {
289 1 : ACL_LOG_CALL_ERROR("rtGetDeviceSatStatus failed, runtime result = %d.", static_cast<int32_t>(rtErr));
290 1 : return ACL_GET_ERRCODE_RTS(rtErr);
291 : }
292 1 : ACL_LOG_INFO("successfully execute aclrtGetOverflowStatus");
293 1 : return ACL_SUCCESS;
294 : }
295 :
296 2 : aclError aclrtResetOverflowStatusImpl(aclrtStream stream)
297 : {
298 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtResetOverflowStatus);
299 2 : ACL_LOG_INFO("start to execute aclrtResetOverflowStatus");
300 2 : const rtError_t rtErr = rtCleanDeviceSatStatus(static_cast<rtStream_t>(stream));
301 2 : if (rtErr != RT_ERROR_NONE) {
302 1 : ACL_LOG_CALL_ERROR("rtCleanDeviceSatStatus failed, runtime result = %d.", static_cast<int32_t>(rtErr));
303 1 : return ACL_GET_ERRCODE_RTS(rtErr);
304 : }
305 1 : ACL_LOG_INFO("successfully execute aclrtResetOverflowStatus");
306 1 : return ACL_SUCCESS;
307 : }
308 :
309 3 : aclError aclrtQueryDeviceStatusImpl(int32_t deviceId, aclrtDeviceStatus *deviceStatus)
310 : {
311 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtQueryDeviceStatus);
312 3 : ACL_LOG_INFO("start to execute aclrtQueryDeviceStatus with device id:%d", deviceId);
313 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(deviceStatus);
314 2 : rtDeviceStatus rtDevStatus = RT_DEVICE_STATUS_END;
315 2 : const rtError_t rtErr = rtDeviceStatusQuery(static_cast<uint32_t>(deviceId), &rtDevStatus);
316 2 : if (rtErr != RT_ERROR_NONE) {
317 1 : ACL_LOG_WARN("rtDeviceStatusQuery failed, runtime result = %d.", static_cast<int32_t>(rtErr));
318 1 : return ACL_GET_ERRCODE_RTS(rtErr);
319 : }
320 1 : *deviceStatus = static_cast<aclrtDeviceStatus>(rtDevStatus);
321 1 : ACL_LOG_INFO("successfully execute aclrtQueryDeviceStatus");
322 1 : return ACL_SUCCESS;
323 : }
324 :
325 2 : aclError aclrtDeviceTaskAbortImpl(int32_t deviceId, uint32_t timeout)
326 : {
327 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceTaskAbort);
328 2 : ACL_LOG_INFO("start to execute aclrtDeviceTaskAbort on device %d, timeout %ums", deviceId, timeout);
329 2 : const rtError_t rtErr = rtDeviceTaskAbort(deviceId, timeout);
330 2 : if (rtErr != RT_ERROR_NONE) {
331 1 : ACL_LOG_ERROR("rtDeviceTaskAbort for device %d, failed, runtime result = %d.",
332 : deviceId, static_cast<int32_t>(rtErr));
333 1 : return ACL_GET_ERRCODE_RTS(rtErr);
334 : }
335 1 : return ACL_SUCCESS;
336 : }
337 :
338 3 : aclError aclrtGetDeviceInfoImpl(uint32_t deviceId, aclrtDevAttr attr, int64_t *value)
339 : {
340 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetDeviceInfo);
341 3 : ACL_LOG_INFO("start to execute aclrtGetDeviceInfo");
342 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
343 :
344 2 : const rtError_t rtErr = rtsDeviceGetInfo(deviceId, static_cast<rtDevAttr>(attr), value);
345 2 : if (rtErr != RT_ERROR_NONE) {
346 1 : ACL_LOG_CALL_ERROR("call rtsDeviceGetInfo failed, runtime result = %d.", static_cast<int32_t>(rtErr));
347 1 : return ACL_GET_ERRCODE_RTS(rtErr);
348 : }
349 :
350 1 : ACL_LOG_INFO("successfully execute aclrtGetDeviceInfo");
351 1 : return ACL_SUCCESS;
352 : }
353 :
354 4 : aclError aclrtDeviceGetStreamPriorityRangeImpl(int32_t *leastPriority, int32_t *greatestPriority)
355 : {
356 8 : ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceGetStreamPriorityRange);
357 4 : ACL_LOG_INFO("start to execute aclrtDeviceGetStreamPriorityRange");
358 :
359 4 : const rtError_t rtErr = rtsDeviceGetStreamPriorityRange(leastPriority, greatestPriority);
360 4 : if (rtErr != RT_ERROR_NONE) {
361 0 : ACL_LOG_CALL_ERROR("call rtsDeviceGetStreamPriorityRange failed, runtime result = %d.",
362 : static_cast<int32_t>(rtErr));
363 0 : return ACL_GET_ERRCODE_RTS(rtErr);
364 : }
365 :
366 4 : ACL_LOG_INFO("successfully execute aclrtDeviceGetStreamPriorityRange");
367 4 : return ACL_SUCCESS;
368 : }
369 :
370 3 : aclError aclrtGetDeviceCapabilityImpl(int32_t deviceId, aclrtDevFeatureType devFeatureType, int32_t *value)
371 : {
372 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetDeviceCapability);
373 3 : ACL_LOG_INFO("start to execute aclrtGetDeviceCapability");
374 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
375 :
376 2 : const rtError_t rtErr = rtsDeviceGetCapability(deviceId, devFeatureType, value);
377 2 : if (rtErr != RT_ERROR_NONE) {
378 1 : ACL_LOG_CALL_ERROR("call rtsDeviceGetCapability failed, runtime result = %d.", static_cast<int32_t>(rtErr));
379 1 : return ACL_GET_ERRCODE_RTS(rtErr);
380 : }
381 :
382 1 : ACL_LOG_INFO("successfully execute aclrtGetDeviceCapability");
383 1 : return ACL_SUCCESS;
384 : }
385 :
386 3 : aclError aclrtDeviceGetUuidImpl(int32_t deviceId, aclrtUuid *uuid)
387 : {
388 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceGetUuid);
389 3 : ACL_LOG_INFO("start to execute aclrtGetDeviceUuid, deviceId is [%d]", deviceId);
390 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(uuid);
391 :
392 2 : const rtError_t rtErr = rtGetDeviceUuid(deviceId, reinterpret_cast<rtUuid_t*>(uuid));
393 2 : if (rtErr != RT_ERROR_NONE) {
394 1 : ACL_LOG_CALL_ERROR("get device uuid failed, deviceId = %d, runtime result = %d",
395 : deviceId, static_cast<int32_t>(rtErr));
396 1 : return ACL_GET_ERRCODE_RTS(rtErr);
397 : }
398 :
399 1 : ACL_LOG_INFO("successfully execute aclrtGetDeviceUuid");
400 1 : return ACL_SUCCESS;
401 : }
402 :
403 3 : aclError aclrtGetDeviceResLimitImpl(int32_t deviceId, aclrtDevResLimitType type, uint32_t *value)
404 : {
405 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetDeviceResLimit);
406 3 : ACL_LOG_INFO("start to execute aclrtGetDeviceResLimit, deviceId is [%d], type is [%u]", deviceId,
407 : static_cast<uint32_t>(type));
408 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
409 :
410 2 : const rtError_t rtErr = rtsGetDeviceResLimit(deviceId, static_cast<rtDevResLimitType_t>(type), value);
411 2 : if (rtErr != RT_ERROR_NONE) {
412 1 : ACL_LOG_CALL_ERROR("call rtsGetDeviceResLimit failed, runtime result = %d.", static_cast<int32_t>(rtErr));
413 1 : return ACL_GET_ERRCODE_RTS(rtErr);
414 : }
415 :
416 1 : ACL_LOG_INFO("successfully execute aclrtGetDeviceResLimit");
417 1 : return ACL_SUCCESS;
418 : }
419 :
420 2 : aclError aclrtSetDeviceResLimitImpl(int32_t deviceId, aclrtDevResLimitType type, uint32_t value)
421 : {
422 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtSetDeviceResLimit);
423 2 : ACL_LOG_INFO("start to execute aclrtSetDeviceResLimit, deviceId is [%d], type is [%u], value is [%u]", deviceId,
424 : static_cast<uint32_t>(type), value);
425 :
426 2 : const rtError_t rtErr = rtsSetDeviceResLimit(deviceId, static_cast<rtDevResLimitType_t>(type), value);
427 2 : if (rtErr != RT_ERROR_NONE) {
428 1 : ACL_LOG_CALL_ERROR("call rtsSetDeviceResLimit failed, runtime result = %d.", static_cast<int32_t>(rtErr));
429 1 : return ACL_GET_ERRCODE_RTS(rtErr);
430 : }
431 :
432 1 : ACL_LOG_INFO("successfully execute aclrtSetDeviceResLimit");
433 1 : return ACL_SUCCESS;
434 : }
435 :
436 2 : aclError aclrtResetDeviceResLimitImpl(int32_t deviceId)
437 : {
438 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtResetDeviceResLimit);
439 2 : ACL_LOG_INFO("start to execute aclrtResetDeviceResLimit, deviceId is [%d]", deviceId);
440 :
441 2 : const rtError_t rtErr = rtsResetDeviceResLimit(deviceId);
442 2 : if (rtErr != RT_ERROR_NONE) {
443 1 : ACL_LOG_CALL_ERROR("call rtsResetDeviceResLimit failed, runtime result = %d.", static_cast<int32_t>(rtErr));
444 1 : return ACL_GET_ERRCODE_RTS(rtErr);
445 : }
446 :
447 1 : ACL_LOG_INFO("successfully execute aclrtResetDeviceResLimit");
448 1 : return ACL_SUCCESS;
449 : }
450 :
451 4 : aclError aclrtGetStreamResLimitImpl(aclrtStream stream, aclrtDevResLimitType type, uint32_t *value)
452 : {
453 8 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetStreamResLimit);
454 4 : ACL_LOG_INFO("start to execute aclrtGetStreamResLimit, type is [%u]", static_cast<uint32_t>(type));
455 4 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
456 3 : const rtError_t rtErr = rtsGetStreamResLimit(static_cast<rtStream_t>(stream), static_cast<rtDevResLimitType_t>(type), value);
457 3 : if (rtErr != RT_ERROR_NONE) {
458 2 : ACL_LOG_CALL_ERROR("call rtsGetStreamResLimit failed, runtime result = %d.", static_cast<int32_t>(rtErr));
459 2 : return ACL_GET_ERRCODE_RTS(rtErr);
460 : }
461 :
462 1 : ACL_LOG_INFO("successfully execute aclrtGetStreamResLimit, value is [%u]", *value);
463 1 : return ACL_SUCCESS;
464 : }
465 :
466 3 : aclError aclrtSetStreamResLimitImpl(aclrtStream stream, aclrtDevResLimitType type, uint32_t value)
467 : {
468 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtSetStreamResLimit);
469 3 : ACL_LOG_INFO("start to execute aclrtSetStreamResLimit, type is [%u], value is [%u]", static_cast<uint32_t>(type), value);
470 3 : const rtError_t rtErr = rtsSetStreamResLimit(static_cast<rtStream_t>(stream), static_cast<rtDevResLimitType_t>(type), value);
471 3 : if (rtErr != RT_ERROR_NONE) {
472 2 : ACL_LOG_CALL_ERROR("call rtsSetStreamResLimit failed, runtime result = %d.", static_cast<int32_t>(rtErr));
473 2 : return ACL_GET_ERRCODE_RTS(rtErr);
474 : }
475 :
476 1 : ACL_LOG_INFO("successfully execute aclrtSetStreamResLimit");
477 1 : return ACL_SUCCESS;
478 : }
479 :
480 3 : aclError aclrtResetStreamResLimitImpl(aclrtStream stream)
481 : {
482 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtResetStreamResLimit);
483 3 : ACL_LOG_INFO("start to execute aclrtResetStreamResLimit");
484 3 : const rtError_t rtErr = rtsResetStreamResLimit(static_cast<rtStream_t>(stream));
485 3 : if (rtErr != RT_ERROR_NONE) {
486 2 : ACL_LOG_CALL_ERROR("call rtsResetStreamResLimit failed, runtime result = %d.", static_cast<int32_t>(rtErr));
487 2 : return ACL_GET_ERRCODE_RTS(rtErr);
488 : }
489 :
490 1 : ACL_LOG_INFO("successfully execute aclrtResetStreamResLimit");
491 1 : return ACL_SUCCESS;
492 : }
493 :
494 3 : aclError aclrtUseStreamResInCurrentThreadImpl(aclrtStream stream)
495 : {
496 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtUseStreamResInCurrentThread);
497 3 : ACL_LOG_INFO("start to execute aclrtUseStreamResInCurrentThread");
498 3 : const rtError_t rtErr = rtsUseStreamResInCurrentThread(static_cast<rtStream_t>(stream));
499 3 : if (rtErr != RT_ERROR_NONE) {
500 2 : ACL_LOG_CALL_ERROR("call rtsUseStreamResInCurrentThread failed, runtime result = %d.", static_cast<int32_t>(rtErr));
501 2 : return ACL_GET_ERRCODE_RTS(rtErr);
502 : }
503 :
504 1 : ACL_LOG_INFO("successfully execute aclrtUseStreamResInCurrentThread");
505 1 : return ACL_SUCCESS;
506 : }
507 :
508 3 : aclError aclrtUnuseStreamResInCurrentThreadImpl(aclrtStream stream)
509 : {
510 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtUnuseStreamResInCurrentThread);
511 3 : ACL_LOG_INFO("start to execute aclrtUnuseStreamResInCurrentThread");
512 3 : const rtError_t rtErr = rtsNotUseStreamResInCurrentThread(static_cast<rtStream_t>(stream));
513 3 : if (rtErr != RT_ERROR_NONE) {
514 2 : ACL_LOG_CALL_ERROR("call rtsNotUseStreamResInCurrentThread failed, runtime result = %d.", static_cast<int32_t>(rtErr));
515 2 : return ACL_GET_ERRCODE_RTS(rtErr);
516 : }
517 :
518 1 : ACL_LOG_INFO("successfully execute aclrtUnuseStreamResInCurrentThread");
519 1 : return ACL_SUCCESS;
520 : }
521 :
522 3 : aclError aclrtGetResInCurrentThreadImpl(aclrtDevResLimitType type, uint32_t *value)
523 : {
524 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetResInCurrentThread);
525 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
526 2 : const rtError_t rtErr = rtsGetResInCurrentThread(static_cast<rtDevResLimitType_t>(type), value);
527 2 : if (rtErr != RT_ERROR_NONE) {
528 1 : ACL_LOG_CALL_ERROR("call rtsGetResInCurrentThread failed, runtime result = %d.", static_cast<int32_t>(rtErr));
529 1 : return ACL_GET_ERRCODE_RTS(rtErr);
530 : }
531 :
532 1 : return ACL_SUCCESS;
533 : }
534 :
535 3 : aclError aclrtGetDevicesTopoImpl(uint32_t deviceId, uint32_t otherDeviceId, uint64_t *value)
536 : {
537 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetDevicesTopo);
538 3 : ACL_LOG_INFO("start to execute aclrtGetDevicesTopo, deviceId is [%u], otherDeviceId is [%u]",
539 : deviceId, otherDeviceId);
540 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
541 :
542 2 : const rtError_t rtErr = rtsGetPairDevicesInfo(deviceId, otherDeviceId,
543 : static_cast<int32_t>(RT_DEVS_INFO_TYPE_TOPOLOGY), value);
544 2 : if (rtErr != RT_ERROR_NONE) {
545 1 : ACL_LOG_CALL_ERROR("call rtsGetPairDevicesInfo failed, runtime result = %d.", static_cast<int32_t>(rtErr));
546 1 : return ACL_GET_ERRCODE_RTS(rtErr);
547 : }
548 :
549 1 : ACL_LOG_INFO("successfully execute aclrtGetDevicesTopo");
550 1 : return ACL_SUCCESS;
551 : }
552 :
553 2 : aclError aclrtGetLogicDevIdByUserDevIdImpl(const int32_t userDevid, int32_t *const logicDevId)
554 : {
555 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetLogicDevIdByUserDevId);
556 2 : ACL_LOG_INFO("start to execute aclrtGetLogicDevIdByUserDevId, userDevid is [%d]", userDevid);
557 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(logicDevId);
558 2 : const rtError_t rtErr = rtsGetLogicDevIdByUserDevId(userDevid, logicDevId);
559 2 : if (rtErr != RT_ERROR_NONE) {
560 1 : ACL_LOG_CALL_ERROR("call rtsGetGetLogicDevIdByUserDevId failed, runtime result = %d.", static_cast<int32_t>(rtErr));
561 1 : return ACL_GET_ERRCODE_RTS(rtErr);
562 : }
563 :
564 1 : ACL_LOG_INFO("successfully execute aclrtGetLogicDevIdByUserDevId");
565 1 : return ACL_SUCCESS;
566 : }
567 :
568 2 : aclError aclrtGetUserDevIdByLogicDevIdImpl(const int32_t logicDevId, int32_t *const userDevid)
569 : {
570 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetUserDevIdByLogicDevId);
571 2 : ACL_LOG_INFO("start to execute aclrtGetUserDevIdByLogicDevId, logicDevId is [%d]", logicDevId);
572 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(userDevid);
573 2 : const rtError_t rtErr = rtsGetUserDevIdByLogicDevId(logicDevId, userDevid);
574 2 : if (rtErr != RT_ERROR_NONE) {
575 1 : ACL_LOG_CALL_ERROR("call rtsGetUserDevIdByLogicDevId failed, runtime result = %d.", static_cast<int32_t>(rtErr));
576 1 : return ACL_GET_ERRCODE_RTS(rtErr);
577 : }
578 :
579 1 : ACL_LOG_INFO("successfully execute aclrtGetUserDevIdByLogicDevId");
580 1 : return ACL_SUCCESS;
581 : }
582 :
583 2 : aclError aclrtGetLogicDevIdByPhyDevIdImpl(int32_t phyDevId, int32_t *const logicDevId)
584 : {
585 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetLogicDevIdByPhyDevId);
586 2 : ACL_LOG_INFO("start to execute aclrtGetLogicDevIdByPhyDevId, phyDevId is [%d]", phyDevId);
587 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(logicDevId);
588 2 : const rtError_t rtErr = rtsGetLogicDevIdByPhyDevId(phyDevId, logicDevId);
589 2 : if (rtErr != RT_ERROR_NONE) {
590 1 : ACL_LOG_CALL_ERROR("call rtsGetLogicDevIdByPhyDevId failed, runtime result = %d.", static_cast<int32_t>(rtErr));
591 1 : return ACL_GET_ERRCODE_RTS(rtErr);
592 : }
593 :
594 1 : ACL_LOG_INFO("successfully execute aclrtGetLogicDevIdByPhyDevId");
595 1 : return ACL_SUCCESS;
596 : }
597 :
598 2 : aclError aclrtGetPhyDevIdByLogicDevIdImpl(int32_t logicDevId, int32_t *const phyDevId)
599 : {
600 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetPhyDevIdByLogicDevId);
601 2 : ACL_LOG_INFO("start to execute aclrtGetPhyDevIdByLogicDevId, logicDevId is [%d]", logicDevId);
602 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(phyDevId);
603 2 : const rtError_t rtErr = rtsGetPhyDevIdByLogicDevId(logicDevId, phyDevId);
604 2 : if (rtErr != RT_ERROR_NONE) {
605 1 : ACL_LOG_CALL_ERROR("call rtsGetPhyDevIdByLogicDevId failed, runtime result = %d.", static_cast<int32_t>(rtErr));
606 1 : return ACL_GET_ERRCODE_RTS(rtErr);
607 : }
608 :
609 1 : ACL_LOG_INFO("successfully execute aclrtGetPhyDevIdByLogicDevId");
610 1 : return ACL_SUCCESS;
611 : }
612 :
613 3 : aclError aclrtGetOpExecuteTimeoutImpl(uint32_t *const timeoutMs)
614 : {
615 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetOpExecuteTimeout);
616 3 : ACL_LOG_INFO("start to execute aclrtGetOpExecuteTimeout");
617 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(timeoutMs);
618 2 : const rtError_t rtErr = rtGetOpExecuteTimeoutV2(timeoutMs);
619 2 : if (rtErr != RT_ERROR_NONE) {
620 1 : ACL_LOG_CALL_ERROR("call rtGetOpExecuteTimeoutV2 failed, runtime result = %d.", static_cast<int32_t>(rtErr));
621 1 : return ACL_GET_ERRCODE_RTS(rtErr);
622 : }
623 1 : ACL_LOG_INFO("successfully execute aclrtGetOpExecuteTimeout");
624 1 : return ACL_SUCCESS;
625 : }
626 :
627 2 : aclError aclrtCheckArchCompatibilityImpl(const char *socVersion, int32_t *canCompatible)
628 : {
629 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtCheckArchCompatibility);
630 2 : ACL_LOG_INFO("start to execute aclrtCheckArchCompatibility");
631 2 : const rtError_t rtErr = rtCheckArchCompatibility(socVersion, canCompatible);
632 2 : if (rtErr != RT_ERROR_NONE) {
633 1 : ACL_LOG_CALL_ERROR(
634 : "call aclrtCheckArchCompatibility failed, runtime result = %d.", static_cast<int32_t>(rtErr));
635 1 : return ACL_GET_ERRCODE_RTS(rtErr);
636 : }
637 1 : ACL_LOG_INFO("successfully execute aclrtCheckArchCompatibility");
638 1 : return ACL_SUCCESS;
639 : }
|