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