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 : #include "runtime/rt_inner_device.h"
23 : #include "utils/data_type_utils.h"
24 :
25 : namespace {
26 : constexpr int32_t DEVICE_UTILIZATION_NOT_SUPPORT = -1;
27 :
28 6 : int32_t GetAllUtilizations(const int32_t deviceId, const rtTypeUtil_t utilType)
29 : {
30 6 : uint8_t utilRate = 0U;
31 6 : const rtError_t rtErr = rtGetAllUtilizations(deviceId, utilType, &utilRate);
32 6 : if (rtErr == ACL_ERROR_RT_FEATURE_NOT_SUPPORT) {
33 1 : ACL_LOG_WARN(
34 : "rtGetAllUtilizations not to support this query, utilType = %d, runtime result = %d.",
35 : static_cast<int32_t>(utilType), static_cast<int32_t>(rtErr));
36 1 : return DEVICE_UTILIZATION_NOT_SUPPORT;
37 : }
38 5 : if (rtErr != RT_ERROR_NONE) {
39 1 : ACL_LOG_CALL_ERROR(
40 : "rtGetAllUtilizations failed, utilType = %d, runtime result = %d.", static_cast<int32_t>(utilType),
41 : static_cast<int32_t>(rtErr));
42 1 : return DEVICE_UTILIZATION_NOT_SUPPORT;
43 : }
44 4 : ACL_LOG_INFO(
45 : "successfully execute rtGetAllUtilizations, utilType = %d, utilRate = %u.", static_cast<int32_t>(utilType),
46 : utilRate);
47 4 : return static_cast<int32_t>(utilRate);
48 : }
49 : } // namespace
50 :
51 : #ifdef __cplusplus
52 : extern "C" {
53 : #endif
54 :
55 13 : aclError aclrtSetDeviceImpl(int32_t deviceId)
56 : {
57 13 : ACL_PROFILING_REG(acl::AclProfType::AclrtSetDevice);
58 13 : ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
59 13 : ACL_LOG_INFO("start to execute aclrtSetDevice, deviceId = %d.", deviceId);
60 13 : ACL_REQUIRES_RTS_OK(rtSetDevice(deviceId));
61 11 : ACL_LOG_INFO("successfully execute aclrtSetDevice, deviceId = %d", deviceId);
62 11 : ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
63 : // update platform info
64 11 : const auto err = acl::UpdatePlatformInfoWithDevice(deviceId);
65 11 : if (err != ACL_SUCCESS) {
66 7 : ACL_LOG_WARN("update platform info with device failed, error code is [%d], deviceId is [%d]", err, deviceId);
67 : }
68 11 : return ACL_SUCCESS;
69 13 : }
70 :
71 4 : aclError aclrtSetDeviceWithoutTsdVXXImpl(int32_t deviceId)
72 : {
73 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtSetDeviceWithoutTsdVXX);
74 4 : ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
75 4 : ACL_LOG_INFO("start to execute aclrtSetDeviceWithoutTsdVXX, deviceId = %d.", deviceId);
76 4 : const std::string& socVersion = acl::GetSocVersion();
77 4 : if (strncmp(socVersion.c_str(), "Ascend910", (sizeof("Ascend910") - 1UL)) != 0) {
78 0 : ACL_LOG_INFO("The soc version is not Ascend910, which is not supported");
79 0 : acl::AclErrorLogManager::ReportInputError(
80 : acl::UNSUPPORTED_SYSTEM_MSG, {"func"},
81 : {"aclrtSetDeviceWithoutTsdVXX, only Ascend 910 chips are supported"});
82 0 : return ACL_ERROR_API_NOT_SUPPORT;
83 : }
84 4 : ACL_REQUIRES_RTS_OK(rtSetDeviceWithoutTsd(deviceId));
85 2 : ACL_LOG_INFO("open device %d successfully.", deviceId);
86 2 : ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
87 2 : return ACL_SUCCESS;
88 4 : }
89 :
90 5 : aclError aclrtResetDeviceImpl(int32_t deviceId)
91 : {
92 5 : ACL_PROFILING_REG(acl::AclProfType::AclrtResetDevice);
93 5 : ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
94 5 : ACL_LOG_INFO("start to execute aclrtResetDevice, deviceId = %d.", deviceId);
95 5 : ACL_REQUIRES_RTS_OK(rtDeviceReset(deviceId));
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 5 : }
100 :
101 5 : aclError aclrtResetDeviceForceImpl(int32_t deviceId)
102 : {
103 5 : 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 : ACL_REQUIRES_RTS_OK(rtDeviceResetForce(deviceId));
107 3 : ACL_LOG_INFO("successfully execute aclrtResetDeviceForce, reset device %d.", deviceId);
108 3 : ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
109 3 : return ACL_SUCCESS;
110 5 : }
111 :
112 4 : aclError aclrtResetDeviceWithoutTsdVXXImpl(int32_t deviceId)
113 : {
114 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtResetDeviceWithoutTsdVXX);
115 4 : ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
116 4 : ACL_LOG_INFO("start to execute aclrtResetDeviceWithoutTsdVXX, deviceId = %d.", deviceId);
117 4 : const std::string& socVersion = acl::GetSocVersion();
118 4 : if (strncmp(socVersion.c_str(), "Ascend910", (sizeof("Ascend910") - 1UL)) != 0) {
119 0 : ACL_LOG_ERROR("The soc version is not Ascend910, which is not supported");
120 0 : acl::AclErrorLogManager::ReportInputError(
121 : acl::UNSUPPORTED_SYSTEM_MSG, {"func"},
122 : {"aclrtResetDeviceWithoutTsdVXX, only Ascend 910 chips are supported"});
123 0 : return ACL_ERROR_API_NOT_SUPPORT;
124 : }
125 4 : ACL_REQUIRES_RTS_OK(rtDeviceResetWithoutTsd(deviceId));
126 2 : ACL_LOG_INFO("successfully execute aclrtResetDeviceWithoutTsdVXX, reset device %d", deviceId);
127 2 : ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
128 2 : return ACL_SUCCESS;
129 4 : }
130 :
131 6 : aclError aclrtGetDeviceImpl(int32_t* deviceId)
132 : {
133 6 : ACL_LOG_INFO("start to execute aclrtGetDevice");
134 6 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(deviceId);
135 4 : const rtError_t rtErr = rtGetDevice(deviceId);
136 4 : if (rtErr != RT_ERROR_NONE) {
137 2 : ACL_LOG_INFO("Cannot get device id, runtime result = %d.", static_cast<int32_t>(rtErr));
138 2 : return ACL_GET_ERRCODE_RTS(rtErr);
139 : }
140 2 : ACL_LOG_DEBUG("successfully execute aclrtGetDevice, get device id is %d.", *deviceId);
141 2 : return ACL_SUCCESS;
142 : }
143 :
144 20 : aclError aclrtGetRunModeImpl(aclrtRunMode* runMode)
145 : {
146 20 : ACL_LOG_INFO("start to execute aclrtGetRunMode");
147 20 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(runMode);
148 : rtRunMode rtMode;
149 20 : ACL_REQUIRES_RTS_OK(rtGetRunMode(&rtMode));
150 17 : if (rtMode == RT_RUN_MODE_OFFLINE) {
151 15 : *runMode = ACL_DEVICE;
152 15 : return ACL_SUCCESS;
153 : }
154 2 : *runMode = ACL_HOST;
155 2 : ACL_LOG_INFO("successfully execute aclrtGetRunMode, current runMode is %s.", acl::GetRunModeDesc(*runMode));
156 2 : return ACL_SUCCESS;
157 : }
158 :
159 4 : aclError aclrtSynchronizeDeviceImpl()
160 : {
161 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtSynchronizeDevice);
162 4 : ACL_LOG_INFO("start to execute aclrtSynchronizeDevice");
163 4 : ACL_REQUIRES_RTS_OK(rtDeviceSynchronize());
164 2 : ACL_LOG_INFO("device synchronize successfully.");
165 2 : return ACL_SUCCESS;
166 4 : }
167 :
168 7 : aclError aclrtSynchronizeDeviceWithTimeoutImpl(int32_t timeout)
169 : {
170 7 : ACL_PROFILING_REG(acl::AclProfType::AclrtSynchronizeDeviceWithTimeout);
171 7 : ACL_LOG_INFO("start to execute aclrtSynchronizeDeviceWithTimeout, timeout %dms", timeout);
172 7 : constexpr int32_t defaultTimeout = -1;
173 13 : ACL_CHECK_INVALID_VALUE_WITH_EXPECT_RET(
174 : timeout >= defaultTimeout, timeout, "[-1, INT_MAX]", ACL_ERROR_RT_PARAM_INVALID);
175 :
176 5 : const rtError_t rtErr = rtDeviceSynchronizeWithTimeout(timeout);
177 5 : if (rtErr == ACL_ERROR_RT_STREAM_SYNC_TIMEOUT) {
178 1 : return ACL_ERROR_RT_STREAM_SYNC_TIMEOUT;
179 4 : } else if (rtErr != RT_ERROR_NONE) {
180 1 : return ACL_GET_ERRCODE_RTS(rtErr);
181 : }
182 3 : ACL_LOG_INFO("device synchronize with timeout %dms successfully.", timeout);
183 3 : return ACL_SUCCESS;
184 7 : }
185 :
186 6 : aclError aclrtSetTsDeviceImpl(aclrtTsId tsId)
187 : {
188 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtSetTsDevice);
189 6 : ACL_LOG_INFO("start to execute aclrtSetTsDevice, tsId = %s.", acl::GetTsIdDesc(tsId));
190 6 : if ((tsId != ACL_TS_ID_AICORE) && (tsId != ACL_TS_ID_AIVECTOR)) {
191 2 : std::string funcName = acl::AclErrorLogManager::GetFuncNameWithoutImplSuffix(__func__);
192 2 : acl::AclErrorLogManager::ReportInputError(
193 4 : acl::INVALID_VALUE_MSG, std::vector<const char*>({"func", "value", "param", "expect"}),
194 2 : std::vector<const char*>(
195 4 : {funcName.c_str(), acl::GetTsIdDesc(tsId), "tsId", "ACL_TS_ID_AICORE or ACL_TS_ID_AIVECTOR"}));
196 2 : return ACL_ERROR_INVALID_PARAM;
197 2 : }
198 4 : ACL_REQUIRES_RTS_OK(rtSetTSDevice(static_cast<uint32_t>(tsId)));
199 2 : ACL_LOG_INFO("successfully execute aclrtSetTsDevice, set device ts %s", acl::GetTsIdDesc(tsId));
200 2 : return ACL_SUCCESS;
201 6 : }
202 :
203 3 : aclError aclrtGetDeviceUtilizationRateImpl(int32_t deviceId, aclrtUtilizationInfo* utilizationInfo)
204 : {
205 3 : ACL_LOG_INFO("start to execute aclrtGetDeviceUtilizationRate, device is %d.", deviceId);
206 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(utilizationInfo);
207 3 : aclrtUtilizationExtendInfo* utilizationExtend = utilizationInfo->utilizationExtend;
208 :
209 3 : ACL_CHECK_INVALID_PARAM_NO_VALUE(
210 : utilizationExtend == nullptr, "utilizationInfo->utilizationExtend",
211 : "utilizationExtend is a reserved parameter and must be nullptr");
212 2 : utilizationInfo->cubeUtilization = GetAllUtilizations(deviceId, RT_UTIL_TYPE_AICORE);
213 2 : utilizationInfo->vectorUtilization = GetAllUtilizations(deviceId, RT_UTIL_TYPE_AIVECTOR);
214 2 : utilizationInfo->aicpuUtilization = GetAllUtilizations(deviceId, RT_UTIL_TYPE_AICPU);
215 : // Currently, memory is not supported
216 2 : utilizationInfo->memoryUtilization = DEVICE_UTILIZATION_NOT_SUPPORT;
217 2 : ACL_LOG_INFO("successfully execute aclrtGetDeviceUtilizationRate, device is %d.", deviceId);
218 2 : return ACL_SUCCESS;
219 : };
220 :
221 6 : aclError aclrtGetDeviceCountImpl(uint32_t* count)
222 : {
223 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetDeviceCount);
224 6 : ACL_LOG_INFO("start to execute aclrtGetDeviceCount");
225 6 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(count);
226 :
227 4 : ACL_REQUIRES_RTS_OK(rtGetDeviceCount(reinterpret_cast<int32_t*>(count)));
228 2 : ACL_LOG_INFO("successfully execute aclrtGetDeviceCount, get device count is %u.", *count);
229 2 : return ACL_SUCCESS;
230 6 : }
231 :
232 2 : aclError aclrtGetDeviceSatModeImpl(aclrtFloatOverflowMode* mode)
233 : {
234 2 : ACL_LOG_INFO("start to execute aclrtGetDeviceSatMode");
235 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(mode);
236 2 : rtFloatOverflowMode_t rtMode = RT_OVERFLOW_MODE_UNDEF;
237 2 : ACL_REQUIRES_RTS_OK(rtGetDeviceSatMode(&rtMode));
238 1 : *mode = static_cast<aclrtFloatOverflowMode>(rtMode);
239 1 : ACL_LOG_INFO("successfully execute aclrtGetDeviceSatMode, mode is %s.", acl::GetFloatOverflowModeDesc(*mode));
240 1 : return ACL_SUCCESS;
241 : }
242 :
243 2 : aclError aclrtSetDeviceSatModeImpl(aclrtFloatOverflowMode mode)
244 : {
245 2 : ACL_LOG_INFO("start to execute aclrtSetDeviceSatMode, mode is %s", acl::GetFloatOverflowModeDesc(mode));
246 2 : ACL_REQUIRES_RTS_OK(rtSetDeviceSatMode(static_cast<rtFloatOverflowMode_t>(mode)));
247 1 : ACL_LOG_INFO("successfully execute aclrtSetDeviceSatMode, mode is %s", acl::GetFloatOverflowModeDesc(mode));
248 1 : return ACL_SUCCESS;
249 : }
250 :
251 3 : aclError aclrtGetOverflowStatusImpl(void* outputAddr, size_t outputSize, aclrtStream stream)
252 : {
253 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetOverflowStatus);
254 3 : ACL_LOG_INFO("start to execute aclrtGetOverflowStatus, outputSize = %lu", outputSize);
255 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(outputAddr);
256 2 : ACL_REQUIRES_RTS_OK(rtGetDeviceSatStatus(outputAddr, outputSize, static_cast<rtStream_t>(stream)));
257 1 : ACL_LOG_INFO("successfully execute aclrtGetOverflowStatus");
258 1 : return ACL_SUCCESS;
259 3 : }
260 :
261 2 : aclError aclrtResetOverflowStatusImpl(aclrtStream stream)
262 : {
263 2 : ACL_PROFILING_REG(acl::AclProfType::AclrtResetOverflowStatus);
264 2 : ACL_LOG_INFO("start to execute aclrtResetOverflowStatus");
265 2 : ACL_REQUIRES_RTS_OK(rtCleanDeviceSatStatus(static_cast<rtStream_t>(stream)));
266 1 : ACL_LOG_INFO("successfully execute aclrtResetOverflowStatus");
267 1 : return ACL_SUCCESS;
268 2 : }
269 :
270 3 : aclError aclrtQueryDeviceStatusImpl(int32_t deviceId, aclrtDeviceStatus* deviceStatus)
271 : {
272 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtQueryDeviceStatus);
273 3 : ACL_LOG_INFO("start to execute aclrtQueryDeviceStatus with device id:%d", deviceId);
274 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(deviceStatus);
275 2 : rtDeviceStatus rtDevStatus = RT_DEVICE_STATUS_END;
276 2 : const rtError_t rtErr = rtDeviceStatusQuery(static_cast<uint32_t>(deviceId), &rtDevStatus);
277 2 : if (rtErr != RT_ERROR_NONE) {
278 1 : ACL_LOG_WARN("rtDeviceStatusQuery failed, runtime result = %d.", static_cast<int32_t>(rtErr));
279 1 : return ACL_GET_ERRCODE_RTS(rtErr);
280 : }
281 1 : *deviceStatus = static_cast<aclrtDeviceStatus>(rtDevStatus);
282 1 : ACL_LOG_INFO("successfully execute aclrtQueryDeviceStatus");
283 1 : return ACL_SUCCESS;
284 3 : }
285 :
286 2 : aclError aclrtDeviceTaskAbortImpl(int32_t deviceId, uint32_t timeout)
287 : {
288 2 : ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceTaskAbort);
289 2 : ACL_LOG_INFO("start to execute aclrtDeviceTaskAbort on device %d, timeout %ums", deviceId, timeout);
290 2 : const rtError_t rtErr = rtDeviceTaskAbort(deviceId, timeout);
291 2 : if (rtErr != RT_ERROR_NONE) {
292 1 : ACL_LOG_ERROR(
293 : "rtDeviceTaskAbort for device %d, failed, runtime result = %d.", deviceId, static_cast<int32_t>(rtErr));
294 1 : return ACL_GET_ERRCODE_RTS(rtErr);
295 : }
296 1 : return ACL_SUCCESS;
297 2 : }
298 :
299 8 : aclError aclrtGetDeviceInfoImpl(uint32_t deviceId, aclrtDevAttr attr, int64_t* value)
300 : {
301 8 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetDeviceInfo);
302 8 : ACL_LOG_INFO("start to execute aclrtGetDeviceInfo");
303 8 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
304 :
305 5 : ACL_REQUIRES_RTS_OK(rtsDeviceGetInfo(deviceId, static_cast<rtDevAttr>(attr), value));
306 :
307 3 : ACL_LOG_INFO("successfully execute aclrtGetDeviceInfo");
308 3 : return ACL_SUCCESS;
309 8 : }
310 :
311 4 : aclError aclrtDeviceGetStreamPriorityRangeImpl(int32_t* leastPriority, int32_t* greatestPriority)
312 : {
313 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceGetStreamPriorityRange);
314 4 : ACL_LOG_INFO("start to execute aclrtDeviceGetStreamPriorityRange");
315 :
316 4 : ACL_REQUIRES_RTS_OK(rtsDeviceGetStreamPriorityRange(leastPriority, greatestPriority));
317 :
318 4 : ACL_LOG_INFO("successfully execute aclrtDeviceGetStreamPriorityRange");
319 4 : return ACL_SUCCESS;
320 4 : }
321 :
322 3 : aclError aclrtGetDeviceCapabilityImpl(int32_t deviceId, aclrtDevFeatureType devFeatureType, int32_t* value)
323 : {
324 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetDeviceCapability);
325 3 : ACL_LOG_INFO("start to execute aclrtGetDeviceCapability");
326 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
327 :
328 2 : ACL_REQUIRES_RTS_OK(rtsDeviceGetCapability(deviceId, devFeatureType, value));
329 :
330 1 : ACL_LOG_INFO("successfully execute aclrtGetDeviceCapability");
331 1 : return ACL_SUCCESS;
332 3 : }
333 :
334 3 : aclError aclrtDeviceGetHostAtomicCapabilitiesImpl(
335 : uint32_t* capabilities, const aclrtAtomicOperation* operations, const uint32_t count, int32_t deviceId)
336 : {
337 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceGetHostAtomicCapabilities);
338 3 : ACL_LOG_INFO(
339 : "start to execute aclrtDeviceGetHostAtomicCapabilities, deviceId is [%u], count is [%u]", deviceId, count);
340 :
341 3 : ACL_REQUIRES_RTS_OK(rtDeviceGetHostAtomicCapabilities(
342 : capabilities, reinterpret_cast<const rtAtomicOperation*>(operations), count, deviceId));
343 :
344 1 : ACL_LOG_INFO("successfully execute aclrtDeviceGetHostAtomicCapabilities");
345 1 : return ACL_SUCCESS;
346 3 : }
347 :
348 3 : aclError aclrtDeviceGetP2PAtomicCapabilitiesImpl(
349 : uint32_t* capabilities, const aclrtAtomicOperation* operations, const uint32_t count, int32_t srcDeviceId,
350 : int32_t dstDeviceId)
351 : {
352 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceGetP2PAtomicCapabilities);
353 3 : ACL_LOG_INFO(
354 : "start to execute aclrtDeviceGetP2PAtomicCapabilities, srcDeviceId is [%u], dstDeviceId is [%u], "
355 : "count is [%u]",
356 : srcDeviceId, dstDeviceId, count);
357 :
358 3 : ACL_REQUIRES_RTS_OK(rtDeviceGetP2PAtomicCapabilities(
359 : capabilities, reinterpret_cast<const rtAtomicOperation*>(operations), count, srcDeviceId, dstDeviceId));
360 :
361 1 : ACL_LOG_INFO("successfully execute aclrtDeviceGetP2PAtomicCapabilities");
362 1 : return ACL_SUCCESS;
363 3 : }
364 :
365 4 : aclError aclrtDeviceGetUuidImpl(int32_t deviceId, aclrtUuid* uuid)
366 : {
367 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceGetUuid);
368 4 : ACL_LOG_INFO("start to execute aclrtGetDeviceUuid, deviceId is [%d]", deviceId);
369 4 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(uuid);
370 3 : ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtGetDeviceUuid(deviceId, reinterpret_cast<rtUuid_t*>(uuid)), rtGetDeviceUuid);
371 :
372 1 : ACL_LOG_INFO("successfully execute aclrtGetDeviceUuid");
373 1 : return ACL_SUCCESS;
374 4 : }
375 :
376 3 : aclError aclrtDeviceGetPCIBusIdImpl(int32_t deviceId, char* pciBusId, int32_t len)
377 : {
378 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceGetPCIBusId);
379 3 : ACL_LOG_INFO("start to execute aclrtDeviceGetPCIBusId, deviceId is [%d]", deviceId);
380 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(pciBusId);
381 2 : ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtDeviceGetPCIBusId(deviceId, pciBusId, len), rtDeviceGetPCIBusId);
382 :
383 1 : ACL_LOG_INFO("successfully execute aclrtDeviceGetPCIBusId");
384 1 : return ACL_SUCCESS;
385 3 : }
386 :
387 4 : aclError aclrtDeviceGetByPCIBusIdImpl(const char* pciBusId, int32_t* deviceId)
388 : {
389 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceGetByPCIBusId);
390 4 : ACL_LOG_INFO("start to execute aclrtDeviceGetByPCIBusId");
391 4 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(pciBusId);
392 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(deviceId);
393 2 : ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtDeviceGetByPCIBusId(pciBusId, deviceId), rtDeviceGetByPCIBusId);
394 :
395 1 : ACL_LOG_INFO("successfully execute aclrtDeviceGetByPCIBusId");
396 1 : return ACL_SUCCESS;
397 4 : }
398 :
399 3 : aclError aclrtGetDeviceResLimitImpl(int32_t deviceId, aclrtDevResLimitType type, uint32_t* value)
400 : {
401 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetDeviceResLimit);
402 3 : ACL_LOG_INFO(
403 : "start to execute aclrtGetDeviceResLimit, deviceId is [%d], type is [%s]", deviceId,
404 : acl::GetDevResLimitTypeDesc(type));
405 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
406 :
407 2 : ACL_REQUIRES_RTS_OK(rtsGetDeviceResLimit(deviceId, static_cast<rtDevResLimitType_t>(type), value));
408 :
409 1 : ACL_LOG_INFO("successfully execute aclrtGetDeviceResLimit");
410 1 : return ACL_SUCCESS;
411 3 : }
412 :
413 2 : aclError aclrtSetDeviceResLimitImpl(int32_t deviceId, aclrtDevResLimitType type, uint32_t value)
414 : {
415 2 : ACL_PROFILING_REG(acl::AclProfType::AclrtSetDeviceResLimit);
416 2 : ACL_LOG_INFO(
417 : "start to execute aclrtSetDeviceResLimit, deviceId is [%d], type is [%s], value is [%u]", deviceId,
418 : acl::GetDevResLimitTypeDesc(type), value);
419 :
420 2 : ACL_REQUIRES_RTS_OK(rtsSetDeviceResLimit(deviceId, static_cast<rtDevResLimitType_t>(type), value));
421 :
422 1 : ACL_LOG_INFO("successfully execute aclrtSetDeviceResLimit");
423 1 : return ACL_SUCCESS;
424 2 : }
425 :
426 2 : aclError aclrtResetDeviceResLimitImpl(int32_t deviceId)
427 : {
428 2 : ACL_PROFILING_REG(acl::AclProfType::AclrtResetDeviceResLimit);
429 2 : ACL_LOG_INFO("start to execute aclrtResetDeviceResLimit, deviceId is [%d]", deviceId);
430 :
431 2 : ACL_REQUIRES_RTS_OK(rtsResetDeviceResLimit(deviceId));
432 :
433 1 : ACL_LOG_INFO("successfully execute aclrtResetDeviceResLimit");
434 1 : return ACL_SUCCESS;
435 2 : }
436 :
437 4 : aclError aclrtGetStreamResLimitImpl(aclrtStream stream, aclrtDevResLimitType type, uint32_t* value)
438 : {
439 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetStreamResLimit);
440 4 : ACL_LOG_INFO("start to execute aclrtGetStreamResLimit, type is [%s]", acl::GetDevResLimitTypeDesc(type));
441 4 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
442 3 : ACL_REQUIRES_RTS_OK(
443 : rtsGetStreamResLimit(static_cast<rtStream_t>(stream), static_cast<rtDevResLimitType_t>(type), value));
444 :
445 1 : ACL_LOG_INFO("successfully execute aclrtGetStreamResLimit, value is [%u]", *value);
446 1 : return ACL_SUCCESS;
447 4 : }
448 :
449 3 : aclError aclrtSetStreamResLimitImpl(aclrtStream stream, aclrtDevResLimitType type, uint32_t value)
450 : {
451 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtSetStreamResLimit);
452 3 : ACL_LOG_INFO(
453 : "start to execute aclrtSetStreamResLimit, type is [%s], value is [%u]", acl::GetDevResLimitTypeDesc(type),
454 : value);
455 3 : ACL_REQUIRES_RTS_OK(
456 : rtsSetStreamResLimit(static_cast<rtStream_t>(stream), static_cast<rtDevResLimitType_t>(type), value));
457 :
458 1 : ACL_LOG_INFO("successfully execute aclrtSetStreamResLimit");
459 1 : return ACL_SUCCESS;
460 3 : }
461 :
462 3 : aclError aclrtResetStreamResLimitImpl(aclrtStream stream)
463 : {
464 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtResetStreamResLimit);
465 3 : ACL_LOG_INFO("start to execute aclrtResetStreamResLimit");
466 3 : ACL_REQUIRES_RTS_OK(rtsResetStreamResLimit(static_cast<rtStream_t>(stream)));
467 :
468 1 : ACL_LOG_INFO("successfully execute aclrtResetStreamResLimit");
469 1 : return ACL_SUCCESS;
470 3 : }
471 :
472 3 : aclError aclrtUseStreamResInCurrentThreadImpl(aclrtStream stream)
473 : {
474 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtUseStreamResInCurrentThread);
475 3 : ACL_LOG_INFO("start to execute aclrtUseStreamResInCurrentThread");
476 3 : ACL_REQUIRES_RTS_OK(rtsUseStreamResInCurrentThread(static_cast<rtStream_t>(stream)));
477 :
478 1 : ACL_LOG_INFO("successfully execute aclrtUseStreamResInCurrentThread");
479 1 : return ACL_SUCCESS;
480 3 : }
481 :
482 3 : aclError aclrtUnuseStreamResInCurrentThreadImpl(aclrtStream stream)
483 : {
484 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtUnuseStreamResInCurrentThread);
485 3 : ACL_LOG_INFO("start to execute aclrtUnuseStreamResInCurrentThread");
486 3 : ACL_REQUIRES_RTS_OK(rtsNotUseStreamResInCurrentThread(static_cast<rtStream_t>(stream)));
487 :
488 1 : ACL_LOG_INFO("successfully execute aclrtUnuseStreamResInCurrentThread");
489 1 : return ACL_SUCCESS;
490 3 : }
491 :
492 3 : aclError aclrtGetResInCurrentThreadImpl(aclrtDevResLimitType type, uint32_t* value)
493 : {
494 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetResInCurrentThread);
495 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
496 2 : ACL_REQUIRES_RTS_OK(rtsGetResInCurrentThread(static_cast<rtDevResLimitType_t>(type), value));
497 :
498 1 : return ACL_SUCCESS;
499 3 : }
500 :
501 3 : aclError aclrtGetDevicesTopoImpl(uint32_t deviceId, uint32_t otherDeviceId, uint64_t* value)
502 : {
503 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetDevicesTopo);
504 3 : ACL_LOG_INFO(
505 : "start to execute aclrtGetDevicesTopo, deviceId is [%u], otherDeviceId is [%u]", deviceId, otherDeviceId);
506 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
507 :
508 2 : ACL_REQUIRES_RTS_OK(
509 : rtsGetPairDevicesInfo(deviceId, otherDeviceId, static_cast<int32_t>(RT_DEVS_INFO_TYPE_TOPOLOGY), value));
510 :
511 1 : ACL_LOG_INFO("successfully execute aclrtGetDevicesTopo");
512 1 : return ACL_SUCCESS;
513 3 : }
514 :
515 2 : aclError aclrtGetLogicDevIdByUserDevIdImpl(const int32_t userDevid, int32_t* const logicDevId)
516 : {
517 2 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetLogicDevIdByUserDevId);
518 2 : ACL_LOG_INFO("start to execute aclrtGetLogicDevIdByUserDevId, userDevid is [%d]", userDevid);
519 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(logicDevId);
520 2 : ACL_REQUIRES_RTS_OK(rtsGetLogicDevIdByUserDevId(userDevid, logicDevId));
521 :
522 1 : ACL_LOG_INFO("successfully execute aclrtGetLogicDevIdByUserDevId");
523 1 : return ACL_SUCCESS;
524 2 : }
525 :
526 2 : aclError aclrtGetUserDevIdByLogicDevIdImpl(const int32_t logicDevId, int32_t* const userDevid)
527 : {
528 2 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetUserDevIdByLogicDevId);
529 2 : ACL_LOG_INFO("start to execute aclrtGetUserDevIdByLogicDevId, logicDevId is [%d]", logicDevId);
530 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(userDevid);
531 2 : ACL_REQUIRES_RTS_OK(rtsGetUserDevIdByLogicDevId(logicDevId, userDevid));
532 :
533 1 : ACL_LOG_INFO("successfully execute aclrtGetUserDevIdByLogicDevId");
534 1 : return ACL_SUCCESS;
535 2 : }
536 :
537 2 : aclError aclrtGetLogicDevIdByPhyDevIdImpl(int32_t phyDevId, int32_t* const logicDevId)
538 : {
539 2 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetLogicDevIdByPhyDevId);
540 2 : ACL_LOG_INFO("start to execute aclrtGetLogicDevIdByPhyDevId, phyDevId is [%d]", phyDevId);
541 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(logicDevId);
542 2 : ACL_REQUIRES_RTS_OK(rtsGetLogicDevIdByPhyDevId(phyDevId, logicDevId));
543 :
544 1 : ACL_LOG_INFO("successfully execute aclrtGetLogicDevIdByPhyDevId");
545 1 : return ACL_SUCCESS;
546 2 : }
547 :
548 2 : aclError aclrtGetPhyDevIdByLogicDevIdImpl(int32_t logicDevId, int32_t* const phyDevId)
549 : {
550 2 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetPhyDevIdByLogicDevId);
551 2 : ACL_LOG_INFO("start to execute aclrtGetPhyDevIdByLogicDevId, logicDevId is [%d]", logicDevId);
552 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(phyDevId);
553 2 : ACL_REQUIRES_RTS_OK(rtsGetPhyDevIdByLogicDevId(logicDevId, phyDevId));
554 :
555 1 : ACL_LOG_INFO("successfully execute aclrtGetPhyDevIdByLogicDevId");
556 1 : return ACL_SUCCESS;
557 2 : }
558 :
559 4 : aclError aclrtGetUserDevIdByPhyDevIdImpl(const int32_t phyDevId, int32_t* const userDevId)
560 : {
561 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetUserDevIdByPhyDevId);
562 4 : ACL_LOG_INFO("start to execute aclrtGetUserDevIdByPhyDevId, phyDevId is [%d]", phyDevId);
563 4 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(userDevId);
564 3 : ACL_REQUIRES_RTS_OK(rtsGetLogicDevIdByPhyDevId(phyDevId, userDevId));
565 :
566 2 : ACL_LOG_INFO("successfully execute aclrtGetUserDevIdByPhyDevId");
567 2 : return ACL_SUCCESS;
568 4 : }
569 :
570 4 : aclError aclrtGetPhyDevIdByUserDevIdImpl(const int32_t userDevId, int32_t* const phyDevId)
571 : {
572 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetPhyDevIdByUserDevId);
573 4 : ACL_LOG_INFO("start to execute aclrtGetPhyDevIdByUserDevId, userDevId is [%d]", userDevId);
574 4 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(phyDevId);
575 3 : ACL_REQUIRES_RTS_OK(rtsGetPhyDevIdByLogicDevId(userDevId, phyDevId));
576 :
577 2 : ACL_LOG_INFO("successfully execute aclrtGetPhyDevIdByUserDevId");
578 2 : return ACL_SUCCESS;
579 4 : }
580 :
581 3 : aclError aclrtGetOpExecuteTimeoutImpl(uint32_t* const timeoutMs)
582 : {
583 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetOpExecuteTimeout);
584 3 : ACL_LOG_INFO("start to execute aclrtGetOpExecuteTimeout");
585 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(timeoutMs);
586 2 : ACL_REQUIRES_RTS_OK(rtGetOpExecuteTimeoutV2(timeoutMs));
587 1 : ACL_LOG_INFO("successfully execute aclrtGetOpExecuteTimeout");
588 1 : return ACL_SUCCESS;
589 3 : }
590 :
591 2 : aclError aclrtCheckArchCompatibilityImpl(const char* socVersion, int32_t* canCompatible)
592 : {
593 2 : ACL_PROFILING_REG(acl::AclProfType::AclrtCheckArchCompatibility);
594 2 : ACL_LOG_INFO("start to execute aclrtCheckArchCompatibility");
595 2 : ACL_REQUIRES_RTS_OK(rtCheckArchCompatibility(socVersion, canCompatible));
596 1 : ACL_LOG_INFO("successfully execute aclrtCheckArchCompatibility");
597 1 : return ACL_SUCCESS;
598 2 : }
599 :
600 : static constexpr rtLimitType_t ACL_TO_RT_LIMIT_TABLE[] = {
601 : RT_LIMIT_TYPE_SIMT_STACK_SIZE,
602 : RT_LIMIT_TYPE_SIMT_DVG_WARP_STACK_SIZE,
603 : RT_LIMIT_TYPE_STACK_SIZE,
604 : RT_LIMIT_TYPE_SIMD_PRINTF_FIFO_SIZE_PER_CORE,
605 : RT_LIMIT_TYPE_SIMT_PRINTF_FIFO_SIZE,
606 : };
607 : static constexpr size_t ACL_TO_RT_LIMIT_TABLE_SIZE = sizeof(ACL_TO_RT_LIMIT_TABLE) / sizeof(ACL_TO_RT_LIMIT_TABLE[0]);
608 :
609 28 : static rtLimitType_t AclLimitToRtLimit(aclrtDeviceLimit limit)
610 : {
611 28 : const auto idx = static_cast<size_t>(limit);
612 28 : if (idx >= ACL_TO_RT_LIMIT_TABLE_SIZE) {
613 2 : return RT_LIMIT_TYPE_RESERVED;
614 : }
615 26 : return ACL_TO_RT_LIMIT_TABLE[idx];
616 : }
617 :
618 17 : aclError aclrtDeviceSetLimitImpl(aclrtDeviceLimit limit, size_t value)
619 : {
620 17 : ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceSetLimit);
621 17 : ACL_LOG_INFO(
622 : "start to execute aclrtDeviceSetLimit, limit is [%s], value is [%zu]", acl::GetDeviceLimitDesc(limit), value);
623 17 : const auto rtType = AclLimitToRtLimit(limit);
624 17 : if (rtType == RT_LIMIT_TYPE_RESERVED) {
625 1 : std::string funcName = acl::AclErrorLogManager::GetFuncNameWithoutImplSuffix(__func__);
626 1 : const char_t* const limitStr = acl::GetDeviceLimitDesc(limit);
627 1 : acl::AclErrorLogManager::ReportInputError(
628 2 : acl::INVALID_VALUE_MSG, std::vector<const char*>({"func", "value", "param", "expect"}),
629 2 : std::vector<const char*>({funcName.c_str(), limitStr, "limit", "[0, 4]"}));
630 1 : return ACL_ERROR_INVALID_PARAM;
631 1 : }
632 16 : if (value > static_cast<size_t>(UINT32_MAX)) {
633 1 : std::string funcName = acl::AclErrorLogManager::GetFuncNameWithoutImplSuffix(__func__);
634 1 : std::string valueStr = std::to_string(value);
635 1 : acl::AclErrorLogManager::ReportInputError(
636 2 : acl::INVALID_VALUE_MSG, std::vector<const char*>({"func", "value", "param", "expect"}),
637 2 : std::vector<const char*>({funcName.c_str(), valueStr.c_str(), "value", "[0, UINT32_MAX]"}));
638 1 : return ACL_ERROR_INVALID_PARAM;
639 1 : }
640 15 : const rtError_t rtSetErr = rtDeviceSetLimit(0, rtType, static_cast<uint32_t>(value));
641 15 : if (rtSetErr != RT_ERROR_NONE) {
642 1 : if (rtSetErr == ACL_ERROR_RT_FEATURE_NOT_SUPPORT) {
643 0 : ACL_LOG_WARN(
644 : "aclrtDeviceSetLimit not supported, limit is [%s], value is [%zu].", acl::GetDeviceLimitDesc(limit),
645 : value);
646 0 : return rtSetErr;
647 : }
648 1 : ACL_LOG_CALL_ERROR("rtDeviceSetLimit failed, runtime result = %d.", static_cast<int32_t>(rtSetErr));
649 1 : return ACL_GET_ERRCODE_RTS(rtSetErr);
650 : }
651 14 : ACL_LOG_INFO(
652 : "successfully execute aclrtDeviceSetLimit, limit is [%s], value is [%zu]", acl::GetDeviceLimitDesc(limit),
653 : value);
654 14 : return ACL_SUCCESS;
655 17 : }
656 :
657 12 : aclError aclrtDeviceGetLimitImpl(aclrtDeviceLimit limit, size_t* value)
658 : {
659 12 : ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceGetLimit);
660 12 : ACL_LOG_INFO("start to execute aclrtDeviceGetLimit, limit is [%s]", acl::GetDeviceLimitDesc(limit));
661 12 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
662 11 : const auto rtType = AclLimitToRtLimit(limit);
663 11 : if (rtType == RT_LIMIT_TYPE_RESERVED) {
664 1 : std::string funcName = acl::AclErrorLogManager::GetFuncNameWithoutImplSuffix(__func__);
665 1 : const char_t* const limitStr = acl::GetDeviceLimitDesc(limit);
666 1 : acl::AclErrorLogManager::ReportInputError(
667 2 : acl::INVALID_VALUE_MSG, std::vector<const char*>({"func", "value", "param", "expect"}),
668 2 : std::vector<const char*>({funcName.c_str(), limitStr, "limit", "[0, 4]"}));
669 1 : return ACL_ERROR_INVALID_PARAM;
670 1 : }
671 10 : uint32_t rtValue = 0U;
672 10 : const rtError_t rtGetErr = rtDeviceGetLimit(rtType, &rtValue);
673 10 : if (rtGetErr != RT_ERROR_NONE) {
674 1 : if (rtGetErr == ACL_ERROR_RT_FEATURE_NOT_SUPPORT) {
675 1 : ACL_LOG_WARN("aclrtDeviceGetLimit not supported, limit is [%s].", acl::GetDeviceLimitDesc(limit));
676 1 : return rtGetErr;
677 : }
678 0 : ACL_LOG_CALL_ERROR("rtDeviceGetLimit failed, runtime result = %d.", static_cast<int32_t>(rtGetErr));
679 0 : return ACL_GET_ERRCODE_RTS(rtGetErr);
680 : }
681 9 : *value = static_cast<size_t>(rtValue);
682 9 : ACL_LOG_INFO(
683 : "successfully execute aclrtDeviceGetLimit, limit is [%s], value is [%zu]", acl::GetDeviceLimitDesc(limit),
684 : *value);
685 9 : return ACL_SUCCESS;
686 12 : }
687 :
688 3 : aclError aclrtDeviceL2CacheFlushImpl(void* rsv)
689 : {
690 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceL2CacheFlush);
691 3 : ACL_LOG_INFO("start to execute aclrtDeviceL2CacheFlush");
692 3 : ACL_CHECK_INVALID_PARAM_NO_VALUE(rsv == nullptr, "rsv", "rsv must be nullptr");
693 :
694 2 : ACL_REQUIRES_RTS_OK(rtDeviceL2CacheFlush(rsv));
695 :
696 1 : return ACL_SUCCESS;
697 3 : }
698 : #ifdef __cplusplus
699 : }
700 : #endif
|