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