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 "runtime/event.h"
13 : #include "runtime/config.h"
14 : #include "runtime/rt_ras.h"
15 : #include "runtime/rts/rts_event.h"
16 : #include "runtime/rts/rts_device.h"
17 : #include "common/log_inner.h"
18 : #include "common/error_codes_inner.h"
19 : #include "common/prof_reporter.h"
20 : #include "common/resource_statistics.h"
21 :
22 : #ifdef __cplusplus
23 : extern "C" {
24 : #endif
25 :
26 6 : aclError aclrtCreateEventImpl(aclrtEvent *event)
27 : {
28 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtCreateEvent);
29 6 : ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_EVENT);
30 6 : ACL_LOG_INFO("start to execute aclrtCreateEvent");
31 6 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(event);
32 :
33 4 : rtEvent_t rtEvent = nullptr;
34 4 : ACL_REQUIRES_RTS_OK(rtEventCreate(&rtEvent));
35 :
36 2 : *event = static_cast<aclrtEvent>(rtEvent);
37 2 : ACL_LOG_INFO("successfully execute aclrtCreateEvent");
38 2 : ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_EVENT);
39 2 : return ACL_SUCCESS;
40 6 : }
41 :
42 6 : aclError aclrtCreateEventWithFlagImpl(aclrtEvent *event, uint32_t flag)
43 : {
44 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtCreateEventWithFlag);
45 6 : ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_EVENT);
46 6 : ACL_LOG_INFO("start to execute aclrtCreateEventWithFlag.");
47 6 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(event);
48 4 : rtEvent_t rtEvent = nullptr;
49 4 : ACL_REQUIRES_RTS_OK(rtEventCreateWithFlag(&rtEvent, flag));
50 2 : *event = static_cast<aclrtEvent>(rtEvent);
51 2 : ACL_LOG_INFO("successfully execute aclrtCreateEventWithFlag.");
52 2 : ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_EVENT);
53 2 : return ACL_SUCCESS;
54 6 : }
55 :
56 5 : aclError aclrtCreateEventExWithFlagImpl(aclrtEvent *event, uint32_t flag)
57 : {
58 5 : ACL_PROFILING_REG(acl::AclProfType::AclrtCreateEventExWithFlag);
59 5 : ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_EVENT);
60 5 : ACL_LOG_INFO("start to execute aclrtCreateEventExWithFlag.");
61 5 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(event);
62 4 : rtEvent_t rtEvent = nullptr;
63 4 : ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtEventCreateExWithFlag(&rtEvent, flag), rtEventCreateExWithFlag);
64 2 : *event = static_cast<aclrtEvent>(rtEvent);
65 2 : ACL_LOG_INFO("successfully execute aclrtCreateEventExWithFlag.");
66 2 : ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_EVENT);
67 2 : return ACL_SUCCESS;
68 5 : }
69 :
70 6 : aclError aclrtDestroyEventImpl(aclrtEvent event)
71 : {
72 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtDestroyEvent);
73 6 : ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_EVENT);
74 6 : ACL_LOG_INFO("start to execute aclrtDestroyEvent");
75 6 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(event);
76 :
77 4 : ACL_REQUIRES_RTS_OK(rtEventDestroy(static_cast<rtEvent_t>(event)));
78 2 : ACL_LOG_INFO("successfully execute aclrtDestroyEvent");
79 2 : ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_EVENT);
80 2 : return ACL_SUCCESS;
81 6 : }
82 :
83 6 : aclError aclrtRecordEventImpl(aclrtEvent event, aclrtStream stream)
84 : {
85 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtRecordEvent);
86 6 : ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_RECORD_RESET_EVENT);
87 6 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(event);
88 :
89 4 : ACL_REQUIRES_RTS_OK(rtEventRecord(static_cast<rtEvent_t>(event), static_cast<rtStream_t>(stream)));
90 2 : ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_RECORD_RESET_EVENT);
91 2 : return ACL_SUCCESS;
92 6 : }
93 :
94 10 : aclError aclrtResetEventImpl(aclrtEvent event, aclrtStream stream)
95 : {
96 10 : ACL_PROFILING_REG(acl::AclProfType::AclrtResetEvent);
97 10 : ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_RECORD_RESET_EVENT);
98 10 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(event);
99 :
100 6 : ACL_REQUIRES_RTS_OK(rtEventReset(static_cast<rtEvent_t>(event), static_cast<rtStream_t>(stream)));
101 2 : ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_RECORD_RESET_EVENT);
102 2 : return ACL_SUCCESS;
103 10 : }
104 :
105 6 : aclError aclrtQueryEventImpl(aclrtEvent event, aclrtEventStatus *status)
106 : {
107 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtQueryEvent);
108 6 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(event);
109 6 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(status);
110 :
111 6 : const rtError_t rtErr = rtEventQuery(static_cast<rtEvent_t>(event));
112 6 : if (rtErr == RT_ERROR_NONE) {
113 2 : *status = ACL_EVENT_STATUS_COMPLETE;
114 4 : } else if (rtErr == ACL_ERROR_RT_EVENT_NOT_COMPLETE) {
115 2 : *status = ACL_EVENT_STATUS_NOT_READY;
116 : } else {
117 2 : return ACL_GET_ERRCODE_RTS(rtErr);
118 : }
119 4 : return ACL_SUCCESS;
120 6 : }
121 :
122 5 : aclError aclrtQueryEventStatusImpl(aclrtEvent event, aclrtEventRecordedStatus *status)
123 : {
124 5 : ACL_PROFILING_REG(acl::AclProfType::AclrtQueryEventStatus);
125 5 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(event);
126 4 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(status);
127 :
128 3 : rtEventStatus_t rtStatus = RT_EVENT_INIT;
129 3 : ACL_REQUIRES_RTS_OK(rtEventQueryStatus(static_cast<rtEvent_t>(event), &rtStatus));
130 2 : if (rtStatus == RT_EVENT_RECORDED) {
131 1 : *status = ACL_EVENT_RECORDED_STATUS_COMPLETE;
132 : } else {
133 1 : *status = ACL_EVENT_RECORDED_STATUS_NOT_READY;
134 : }
135 2 : return ACL_SUCCESS;
136 5 : }
137 :
138 5 : aclError aclrtQueryEventWaitStatusImpl(aclrtEvent event, aclrtEventWaitStatus *status)
139 : {
140 5 : ACL_PROFILING_REG(acl::AclProfType::AclrtQueryEventWaitStatus);
141 5 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(event);
142 4 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(status);
143 :
144 3 : rtEventWaitStatus_t rtWaitStatus = EVENT_STATUS_NOT_READY;
145 3 : ACL_REQUIRES_RTS_OK(rtEventQueryWaitStatus(static_cast<rtEvent_t>(event), &rtWaitStatus));
146 2 : if (rtWaitStatus == EVENT_STATUS_COMPLETE) {
147 1 : *status = ACL_EVENT_WAIT_STATUS_COMPLETE;
148 : } else {
149 1 : *status = ACL_EVENT_WAIT_STATUS_NOT_READY;
150 : }
151 2 : return ACL_SUCCESS;
152 5 : }
153 :
154 6 : aclError aclrtSynchronizeEventImpl(aclrtEvent event)
155 : {
156 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtSynchronizeEvent);
157 6 : ACL_LOG_INFO("start to execute aclrtSynchronizeEvent");
158 6 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(event);
159 :
160 4 : ACL_REQUIRES_RTS_OK(rtEventSynchronize(static_cast<rtEvent_t>(event)));
161 2 : ACL_LOG_INFO("successfully execute aclrtSynchronizeEvent");
162 2 : return ACL_SUCCESS;
163 6 : }
164 :
165 5 : aclError aclrtSynchronizeEventWithTimeoutImpl(aclrtEvent event, int32_t timeout)
166 : {
167 5 : ACL_LOG_INFO("start to execute aclrtSynchronizeEventWithTimeout, timeout = %dms", timeout);
168 5 : constexpr int32_t defaultTimeout = -1;
169 8 : ACL_CHECK_INVALID_VALUE_WITH_EXPECT_RET(timeout >= defaultTimeout, timeout, "[-1, INT_MAX]", ACL_ERROR_RT_PARAM_INVALID);
170 4 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(event);
171 :
172 3 : const rtError_t rtErr = rtEventSynchronizeWithTimeout(static_cast<rtEvent_t>(event), timeout);
173 3 : if (rtErr == ACL_ERROR_RT_EVENT_SYNC_TIMEOUT) {
174 1 : return ACL_ERROR_RT_EVENT_SYNC_TIMEOUT;
175 2 : } else if (rtErr != RT_ERROR_NONE) {
176 0 : return ACL_GET_ERRCODE_RTS(rtErr);
177 : }
178 2 : ACL_LOG_INFO("successfully execute aclrtSynchronizeEventWithTimeout");
179 2 : return ACL_SUCCESS;
180 : }
181 :
182 10 : aclError aclrtEventElapsedTimeImpl(float *ms, aclrtEvent startEvent, aclrtEvent endEvent)
183 : {
184 10 : ACL_LOG_INFO("start to execute aclrtEventElapsedTime");
185 10 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(ms);
186 8 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(startEvent);
187 6 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(endEvent);
188 :
189 4 : ACL_REQUIRES_RTS_OK(rtEventElapsedTime(ms, startEvent, endEvent));
190 2 : ACL_LOG_INFO("successfully execute aclrtEventElapsedTime");
191 2 : return ACL_SUCCESS;
192 : }
193 :
194 3 : aclError aclrtEventGetTimestampImpl(aclrtEvent event, uint64_t *timestamp)
195 : {
196 3 : ACL_LOG_INFO("start to execute aclrtEventGetTimestamp");
197 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(timestamp);
198 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(event);
199 :
200 1 : ACL_REQUIRES_RTS_OK(rtEventGetTimeStamp(timestamp, event));
201 :
202 1 : ACL_LOG_INFO("successfully execute aclrtEventGetTimestamp");
203 1 : return ACL_SUCCESS;
204 : }
205 :
206 4 : aclError aclrtSetOpWaitTimeoutImpl(uint32_t timeout)
207 : {
208 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtSetOpWaitTimeout);
209 4 : ACL_LOG_INFO("start to execute aclrtSetOpWaitTimeout, timeout = %us", timeout);
210 4 : ACL_REQUIRES_RTS_OK(rtSetOpWaitTimeOut(timeout));
211 2 : ACL_LOG_INFO("successfully execute aclrtSetOpWaitTimeout, timeout = %us", timeout);
212 2 : return ACL_SUCCESS;
213 4 : }
214 :
215 2 : aclError aclrtSetOpExecuteTimeOutImpl(uint32_t timeout)
216 : {
217 2 : ACL_PROFILING_REG(acl::AclProfType::AclrtSetOpExecuteTimeOut);
218 2 : ACL_LOG_INFO("start to execute aclrtSetOpExecuteTimeOut, timeout = %us", timeout);
219 :
220 2 : ACL_REQUIRES_RTS_OK(rtSetOpExecuteTimeOut(timeout));
221 :
222 1 : ACL_LOG_INFO("successfully execute aclrtSetOpExecuteTimeOut, timeout = %us", timeout);
223 1 : return ACL_SUCCESS;
224 2 : }
225 :
226 2 : aclError aclrtSetOpExecuteTimeOutWithMsImpl(uint32_t timeout)
227 : {
228 2 : ACL_PROFILING_REG(acl::AclProfType::AclrtSetOpExecuteTimeOutWithMs);
229 2 : ACL_LOG_INFO("start to execute aclrtSetOpExecuteTimeOutWithMs, timeout = %ums", timeout);
230 :
231 2 : ACL_REQUIRES_RTS_OK(rtSetOpExecuteTimeOutWithMs(timeout));
232 :
233 1 : ACL_LOG_INFO("successfully execute aclrtSetOpExecuteTimeOutWithMs, timeout = %ums", timeout);
234 1 : return ACL_SUCCESS;
235 2 : }
236 :
237 2 : aclError aclrtSetOpExecuteTimeOutV2Impl(uint64_t timeout, uint64_t *actualTimeout)
238 : {
239 2 : ACL_PROFILING_REG(acl::AclProfType::AclrtSetOpExecuteTimeOutV2);
240 2 : ACL_LOG_INFO("start to execute aclrtSetOpExecuteTimeOutV2, timeout = %zu us", timeout);
241 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(actualTimeout);
242 2 : ACL_REQUIRES_RTS_OK(rtSetOpExecuteTimeOutV2(timeout, actualTimeout));
243 1 : ACL_LOG_INFO("successfully execute aclrtSetOpExecuteTimeOutV2, timeout = %zu us, actual timeout = %zu us", timeout,
244 : *actualTimeout);
245 1 : return ACL_SUCCESS;
246 2 : }
247 :
248 2 : aclError aclrtGetOpTimeOutIntervalImpl(uint64_t *interval)
249 : {
250 2 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetOpTimeOutInterval);
251 2 : ACL_LOG_INFO("start to execute aclrtGetOpTimeOutIntervalImpl");
252 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(interval);
253 2 : ACL_REQUIRES_RTS_OK(rtGetOpTimeOutInterval(interval));
254 1 : ACL_LOG_INFO("successfully execute aclrtGetOpTimeOutIntervalImpl, interval = %zu us", *interval);
255 1 : return ACL_SUCCESS;
256 2 : }
257 :
258 6 : aclError aclrtGetMemUceInfoImpl(int32_t deviceId, aclrtMemUceInfo *memUceInfoArray,
259 : size_t arraySize, size_t *retSize)
260 : {
261 6 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetMemUceInfo);
262 6 : ACL_LOG_INFO("start to execute aclrtGetMemUceInfo on device %d, arraySize %zu", deviceId, arraySize);
263 6 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(memUceInfoArray);
264 5 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(retSize);
265 :
266 4 : rtMemUceInfo rtUceInfo = {};
267 4 : ACL_REQUIRES_RTS_OK(rtGetMemUceInfo(deviceId, &rtUceInfo));
268 3 : if (arraySize < rtUceInfo.count) {
269 1 : ACL_LOG_ERROR("Failed to execute aclrtGetMemUceInfo, because arraySize %zu is less than the required size %u.",
270 : arraySize, rtUceInfo.count);
271 1 : const std::string arraySizeVal = std::to_string(arraySize);
272 : std::string reason = acl::AclErrorLogManager::FormatStr(
273 1 : "arraySize must be greater than or equal to %u", rtUceInfo.count);
274 1 : std::string funcName = acl::AclErrorLogManager::GetFuncNameWithoutImplSuffix(__func__);
275 1 : acl::AclErrorLogManager::ReportInputError(acl::INVALID_PARAM_REASON_MSG,
276 2 : std::vector<const char *>({"func", "value", "param", "reason"}),
277 2 : std::vector<const char *>({funcName.c_str(), arraySizeVal.c_str(), "arraySize", reason.c_str()}));
278 1 : return ACL_ERROR_INVALID_PARAM;
279 1 : }
280 :
281 2 : size_t realSize = std::min(rtUceInfo.count, RT_MAX_RECORD_PA_NUM_PER_DEV);
282 22 : for (size_t i = 0; i < realSize; ++i) {
283 20 : memUceInfoArray[i].addr = reinterpret_cast<void *>(rtUceInfo.repairAddr[i].ptr);
284 20 : memUceInfoArray[i].len = rtUceInfo.repairAddr[i].len;
285 20 : (void)memset_s(memUceInfoArray[i].reserved, sizeof(memUceInfoArray[i].reserved),
286 : 0, sizeof(memUceInfoArray[i].reserved));
287 : }
288 2 : *retSize = realSize;
289 :
290 2 : ACL_LOG_INFO("successfully execute aclrtGetMemUceInfo on device %d, arraySize %zu, retSize %zu,",
291 : deviceId, arraySize, *retSize);
292 2 : return ACL_SUCCESS;
293 6 : }
294 :
295 5 : aclError aclrtMemUceRepairImpl(int32_t deviceId, aclrtMemUceInfo *memUceInfoArray, size_t arraySize)
296 : {
297 5 : ACL_PROFILING_REG(acl::AclProfType::AclrtMemUceRepair);
298 5 : ACL_LOG_INFO("start to execute aclrtMemUceRepair on device %d, arraySize %zu", deviceId, arraySize);
299 5 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(memUceInfoArray);
300 :
301 7 : ACL_CHECK_INVALID_PARAM_WITH_REASON_RET(arraySize > RT_MAX_RECORD_PA_NUM_PER_DEV, arraySize,
302 : "must be less than or equal to 128", ACL_ERROR_INVALID_PARAM);
303 :
304 : //reserved value check, should be fill with zero
305 3 : size_t reservedZeroValue[UCE_INFO_RESERVED_SIZE] = {0};
306 19 : for (size_t i = 0; i < arraySize; ++i) {
307 17 : if (memcmp(memUceInfoArray[i].reserved, reservedZeroValue, UCE_INFO_RESERVED_SIZE)) {
308 1 : ACL_LOG_ERROR("Failed to execute aclrtMemUceRepair with mismatched version, "
309 : "pls set valid value only for ptr and len.");
310 1 : const char_t *argList[] = {"func", "param", "reason"};
311 1 : std::string funcName = acl::AclErrorLogManager::GetFuncNameWithoutImplSuffix(__func__);
312 1 : const char_t *argVal[] = {funcName.c_str(), "memUceInfoArray.reserved", "memUceInfoArray.reserved is a reserved parameter and must be 0"};
313 1 : acl::AclErrorLogManager::ReportInputErrorWithChar(acl::INVALID_PARAM_NO_VALUE_MSG, argList, argVal, 3U);
314 1 : return ACL_ERROR_INVALID_PARAM;
315 1 : }
316 : }
317 :
318 2 : rtMemUceInfo rtUceInfo = {};
319 2 : rtUceInfo.devid = deviceId;
320 2 : rtUceInfo.count = arraySize;
321 18 : for (size_t i = 0; i < arraySize; ++i) {
322 16 : rtUceInfo.repairAddr[i].ptr = reinterpret_cast<uint64_t>(memUceInfoArray[i].addr);
323 16 : rtUceInfo.repairAddr[i].len = memUceInfoArray[i].len;
324 : }
325 :
326 2 : ACL_REQUIRES_RTS_OK(rtMemUceRepair(deviceId, &rtUceInfo));
327 1 : return ACL_SUCCESS;
328 5 : }
329 :
330 4 : aclError aclrtGetEventIdImpl(aclrtEvent event, uint32_t *eventId)
331 : {
332 4 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetEventId);
333 4 : ACL_LOG_INFO("start to execute aclrtGetEventId");
334 4 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(event);
335 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(eventId);
336 :
337 2 : ACL_REQUIRES_RTS_OK(rtsEventGetId(static_cast<rtEvent_t>(event), eventId));
338 :
339 1 : ACL_LOG_INFO("successfully execute aclrtGetEventId");
340 1 : return ACL_SUCCESS;
341 4 : }
342 :
343 3 : aclError aclrtGetEventAvailNumImpl(uint32_t *eventCount)
344 : {
345 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetEventAvailNum);
346 3 : ACL_LOG_INFO("start to execute aclrtGetEventAvailNum");
347 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(eventCount);
348 :
349 2 : ACL_REQUIRES_RTS_OK(rtsEventGetAvailNum(eventCount));
350 :
351 1 : ACL_LOG_INFO("successfully execute aclrtGetEventAvailNum");
352 1 : return ACL_SUCCESS;
353 3 : }
354 :
355 : // Implementation of querying detailed information of NPU faults
356 2 : aclError aclrtGetErrorVerboseImpl(int32_t deviceId, aclrtErrorInfo *errorInfo)
357 : {
358 2 : ACL_PROFILING_REG(acl::AclProfType::AclrtGetErrorVerbose);
359 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(errorInfo);
360 :
361 2 : ACL_LOG_INFO("start to execute aclrtGetErrorVerbose with deviceId %d", deviceId);
362 :
363 : // Type conversion adaptation
364 2 : uint32_t rtsDeviceId = static_cast<uint32_t>(deviceId);
365 2 : rtErrorInfo rtsErrorInfo = {};
366 : // Call RTS interface
367 2 : ACL_REQUIRES_RTS_OK(rtsGetErrorVerbose(rtsDeviceId, &rtsErrorInfo));
368 2 : aclrtMemUceInfoArray *uceInfo = &(errorInfo->detail.uceInfo);
369 2 : errorInfo->tryRepair = rtsErrorInfo.tryRepair;
370 2 : errorInfo->hasDetail = rtsErrorInfo.hasDetail;
371 2 : errorInfo->errorType = static_cast<aclrtErrorType>(rtsErrorInfo.errorType);
372 2 : errorInfo->detail.aicoreErrType = static_cast<aclrtAicoreErrorType>(rtsErrorInfo.detail.aicoreErrType);
373 2 : if ((rtsErrorInfo.hasDetail == 1U) && (rtsErrorInfo.errorType == RT_ERROR_MEMORY)) {
374 1 : uceInfo->arraySize = rtsErrorInfo.detail.uceInfo.arraySize;
375 1 : size_t realSize = std::min(rtsErrorInfo.detail.uceInfo.arraySize, static_cast<size_t>(ACL_RT_MEM_UCE_INFO_MAX_NUM));
376 3 : for (size_t i = 0U; i < realSize; ++i) {
377 2 : uceInfo->memUceInfoArray[i].addr = reinterpret_cast<void *>(rtsErrorInfo.detail.uceInfo.repairAddrArray[i].ptr);
378 2 : uceInfo->memUceInfoArray[i].len = rtsErrorInfo.detail.uceInfo.repairAddrArray[i].len;
379 : }
380 : }
381 2 : ACL_LOG_INFO("successfully execute aclrtGetErrorVerbose");
382 2 : return ACL_SUCCESS;
383 2 : }
384 :
385 : // Repair NPU malfunction implementation
386 2 : aclError aclrtRepairErrorImpl(int32_t deviceId, const aclrtErrorInfo *errorInfo)
387 : {
388 2 : ACL_PROFILING_REG(acl::AclProfType::AclrtRepairError);
389 2 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(errorInfo);
390 2 : ACL_LOG_INFO("start to execute aclrtRepairError with deviceId %d and errorType %d", deviceId, errorInfo->errorType);
391 :
392 : // Type conversion adaptation
393 2 : uint32_t rtsDeviceId = static_cast<uint32_t>(deviceId);
394 2 : rtErrorInfo rtsErrorInfo = {};
395 2 : rtsErrorInfo.tryRepair = errorInfo->tryRepair;
396 2 : rtsErrorInfo.hasDetail = errorInfo->hasDetail;
397 2 : rtsErrorInfo.errorType = static_cast<rtErrType>(errorInfo->errorType);
398 2 : rtsErrorInfo.detail.aicoreErrType = static_cast<rtAicoreErrorType>(errorInfo->detail.aicoreErrType);
399 2 : if ((rtsErrorInfo.hasDetail == 1U) && (rtsErrorInfo.errorType == RT_ERROR_MEMORY)) {
400 1 : rtsErrorInfo.detail.uceInfo.arraySize = errorInfo->detail.uceInfo.arraySize;
401 1 : size_t realSize = std::min(rtsErrorInfo.detail.uceInfo.arraySize, static_cast<size_t>(RT_MAX_RECORD_PA_NUM_PER_DEV));
402 3 : for (size_t i = 0U; i < realSize; ++i) {
403 2 : rtsErrorInfo.detail.uceInfo.repairAddrArray[i].ptr = reinterpret_cast<uint64_t>(errorInfo->detail.uceInfo.memUceInfoArray[i].addr);
404 2 : rtsErrorInfo.detail.uceInfo.repairAddrArray[i].len = errorInfo->detail.uceInfo.memUceInfoArray[i].len;
405 : }
406 : }
407 : // Call RTS interface
408 2 : ACL_REQUIRES_RTS_OK(rtsRepairError(rtsDeviceId, &rtsErrorInfo));
409 2 : ACL_LOG_INFO("successfully execute aclrtRepairError");
410 2 : return ACL_SUCCESS;
411 2 : }
412 :
413 5 : aclError aclrtStreamWaitEventWithTimeoutImpl(aclrtStream stream, aclrtEvent event, int32_t timeout)
414 : {
415 5 : ACL_PROFILING_REG(acl::AclProfType::AclrtStreamWaitEventWithTimeout);
416 5 : ACL_LOG_INFO("start to execute aclrtStreamWaitEventWithTimeout, timeout is %d", timeout);
417 8 : ACL_CHECK_INVALID_VALUE_WITH_EXPECT_RET(timeout >= 0, timeout, "[0, INT_MAX]", ACL_ERROR_RT_PARAM_INVALID);
418 :
419 4 : ACL_REQUIRES_RTS_OK(rtsEventWait(static_cast<rtStream_t>(stream), static_cast<rtEvent_t>(event), timeout));
420 3 : ACL_LOG_INFO("successfully execute aclrtStreamWaitEventWithTimeout");
421 3 : return ACL_SUCCESS;
422 5 : }
423 :
424 3 : aclError aclrtIpcGetEventHandleImpl(aclrtEvent event, aclrtIpcEventHandle *handle)
425 : {
426 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtIpcGetEventHandle);
427 3 : ACL_LOG_INFO("start to execute aclrtIpcGetEventHandle.");
428 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(handle);
429 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(event);
430 3 : ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtIpcGetEventHandle(static_cast<rtEvent_t>(event), reinterpret_cast<rtIpcEventHandle_t*>(handle)), rtIpcGetEventHandle);
431 1 : ACL_LOG_INFO("successfully execute aclrtIpcGetEventHandle.");
432 1 : return ACL_SUCCESS;
433 3 : }
434 :
435 3 : aclError aclrtIpcOpenEventHandleImpl(aclrtIpcEventHandle handle, aclrtEvent *event)
436 : {
437 3 : ACL_PROFILING_REG(acl::AclProfType::AclrtIpcOpenEventHandle);
438 3 : ACL_LOG_INFO("start to execute aclrtIpcOpenEventHandle.");
439 3 : ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(event);
440 3 : rtEvent_t rtEvent = nullptr;
441 3 : ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtIpcOpenEventHandle(*(rtIpcEventHandle_t*)&handle, &rtEvent), rtIpcOpenEventHandle);
442 1 : *event = static_cast<aclrtEvent>(rtEvent);
443 1 : ACL_LOG_INFO("successfully execute aclrtIpcOpenEventHandle.");
444 1 : return ACL_SUCCESS;
445 3 : }
446 : #ifdef __cplusplus
447 : }
448 : #endif
|