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 : #include <unordered_map>
11 : #include <dlog_pub.h>
12 : #include <securec.h>
13 :
14 : #include "driver/ascend_hal.h"
15 : #include "externalinput_pub.h"
16 : #include "log.h"
17 : #include "sal_pub.h"
18 : #include "dlrts_function.h"
19 : #include "adapter_error_manager.h"
20 : #include "adapter_hal.h"
21 : #include "device_capacity.h"
22 : #include "config_plf_log.h"
23 : #include "adapter_rts.h"
24 :
25 : using namespace hccl;
26 : using namespace std;
27 :
28 : #define CHK_RT_RET(call) \
29 : do { \
30 : s32 ret = call; \
31 : if (ret != 0) { \
32 : HCCL_ERROR("call trace: ret -> %d", ret); \
33 : return HCCL_E_RUNTIME; \
34 : } \
35 : } while (0)
36 :
37 : #define REPLACE_NOTIFY_WITH_EVENT(notify, event) \
38 : do { \
39 : s32 result = 0; \
40 : if (result != 0) { \
41 : CHK_RT_RET(event); \
42 : } else { \
43 : CHK_RT_RET(notify); \
44 : } \
45 : } while (0)
46 :
47 6817 : inline s32 GetDeviceLogicalId()
48 : {
49 6817 : s32 deviceId = 0;
50 6817 : if (hrtGetDevice(&deviceId) != HCCL_SUCCESS) {
51 0 : deviceId = -1;
52 : }
53 6817 : return deviceId;
54 : }
55 :
56 : constexpr char RTS_SO_NAME[] = "libruntime.so";
57 : constexpr u32 H2D_COPY_FLAG = 0; // hccl中都需要runtime做args copy默认都设置为0
58 : DlRtsFunction<RTS_SO_NAME> g_dlRts;
59 :
60 : constexpr char ACL_SO_NAME[] = "libascendcl.so";
61 : DlRtsFunction<ACL_SO_NAME> g_dlAcl;
62 :
63 : constexpr char ACL_RT_SO_NAME[] = "libacl_rt.so";
64 : DlRtsFunction<ACL_RT_SO_NAME> g_dlAclrt;
65 :
66 : namespace {
67 : constexpr char RT_MEMCPY[] = "rtMemcpy";
68 : constexpr char RT_POINTER_GET_ATTR[] = "rtPointerGetAttributes";
69 : constexpr char RT_IPC_CLOSE_MEM[] = "rtIpcCloseMemory";
70 : constexpr char ACL_RT_DESTORY_MEM_NAME[] = "aclrtIpcMemClose";
71 : constexpr char ACL_RT_GET_LOGICID_BY_PHYID[] = "rtsGetLogicDevIdByPhyDevId";
72 : constexpr char RT_RDMA_DB_SEND[] = "rtRDMADBSend";
73 : constexpr char ACL_RT_MALLOC_WITH_CFG[] = "aclrtMallocWithCfg";
74 : constexpr char ACL_GET_SOC_NAME[] = "aclrtGetSocName";
75 : constexpr char RT_GET_PAIR_PHY_DEVICES_INFO[] = "rtGetPairPhyDevicesInfo";
76 : constexpr char ACL_RT_CREATE_CONTEXT[] = "aclrtCreateContext";
77 : constexpr char ACL_RT_DESTROY_CONTEXT[] = "aclrtDestroyContext";
78 : constexpr char ACL_RT_GET_CURRENT_CONTEXT[] = "aclrtGetCurrentContext";
79 : constexpr char ACL_RT_SET_CURRENT_CONTEXT[] = "aclrtSetCurrentContext";
80 : constexpr char ACL_RT_SET_DEVICE[] = "aclrtSetDevice";
81 : constexpr char ACL_RT_RESET_DEVICE[] = "aclrtResetDevice";
82 : constexpr char ACL_RT_FREE[] = "aclrtFree";
83 : constexpr char ACL_RT_FREE_HOST[] = "aclrtFreeHost";
84 : constexpr char ACL_RT_MALLOC_HOST_WITH_CFG[] = "aclrtMallocHostWithCfg";
85 : constexpr char ACL_RT_IPC_MEM_SET_IMPORT_PID[] = "aclrtIpcMemSetImportPid";
86 : constexpr char ACL_RT_IPC_MEM_IMPORT_BY_KEY[] = "aclrtIpcMemImportByKey";
87 : constexpr char ACL_RT_IPC_MEM_GET_EXPORT_KEY[] = "aclrtIpcMemGetExportKey";
88 : constexpr char ACL_RT_MEMCPY[] = "aclrtMemcpy";
89 : constexpr char ACL_RT_POINTER_GET_ATTRIBUTES[] = "aclrtPointerGetAttributes";
90 : constexpr char ACL_RT_CACHE_LAST_TASK_EXTEND_INFO[] = "aclrtCacheLastTaskExtendInfo";
91 : }
92 : u32 g_stubDeviceId = 0;
93 : static std::unordered_map<s32, s64> g_deviceChipIdMap; // 记录 devLogID 和 chipID 的关系,避免重复查询
94 : bool g_workModeAicpu = false; // AI场景下aicpu工作模式
95 : DevType g_localDeviceType = DevType::DEV_TYPE_COUNT;
96 : s32 g_localDeviceLogicId = INVALID_INT;
97 : aclrtFloatOverflowMode g_deviceSatMode = ACL_RT_OVERFLOW_MODE_UNDEF;
98 : namespace {
99 : static thread_local s32 g_deviceLogicId = INVALID_INT;
100 : static thread_local u32 g_devicePhyId = INVALID_UINT;
101 : static thread_local DevType g_deviceType = DevType::DEV_TYPE_COUNT;
102 : }
103 :
104 : // 根据soc name判断是否支持 hccl v2流程,使用全局变量减少重复调用aclrt接口
105 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
106 : enum class HcclV2SupportStatus {
107 : UNKNOWN, // 获取soc name失败
108 : SUPPORTED, // 支持v2
109 : NOT_SUPPORTED // 不支持v2
110 : };
111 :
112 : static thread_local HcclV2SupportStatus g_socV2SupportStatus = HcclV2SupportStatus::UNKNOWN;
113 : #endif
114 :
115 2949 : HcclResult hrtGetHcclV2Support(bool *isSupport)
116 : {
117 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
118 2949 : CHK_PTR_NULL(isSupport);
119 2949 : if (LIKELY(g_socV2SupportStatus != HcclV2SupportStatus::UNKNOWN)) {
120 2900 : *isSupport = g_socV2SupportStatus == HcclV2SupportStatus::SUPPORTED;
121 2900 : return HcclResult::HCCL_SUCCESS;
122 : }
123 :
124 49 : const char *socNamePtr = aclrtGetSocName();
125 49 : CHK_PTR_NULL(socNamePtr);
126 49 : if (strstr(socNamePtr, "Ascend950") != nullptr) {
127 2 : g_socV2SupportStatus = HcclV2SupportStatus::SUPPORTED;
128 2 : *isSupport = true;
129 2 : return HcclResult::HCCL_SUCCESS;
130 : }
131 47 : if (strstr(socNamePtr, "Ascend910_96") != nullptr) {
132 0 : g_socV2SupportStatus = HcclV2SupportStatus::SUPPORTED;
133 0 : *isSupport = true;
134 0 : return HcclResult::HCCL_SUCCESS;
135 : }
136 47 : if (strstr(socNamePtr, "Ascend960") != nullptr || strstr(socNamePtr, "ascend960") != nullptr) {
137 0 : g_socV2SupportStatus = HcclV2SupportStatus::SUPPORTED;
138 0 : *isSupport = true;
139 0 : return HcclResult::HCCL_SUCCESS;
140 : }
141 :
142 47 : g_socV2SupportStatus = HcclV2SupportStatus::NOT_SUPPORTED;
143 47 : *isSupport = false;
144 47 : return HcclResult::HCCL_SUCCESS;
145 :
146 : #endif
147 : HCCL_WARNING("[%s] Does does not support this interface.", __func__);
148 : return HCCL_E_NOT_SUPPORT;
149 : }
150 :
151 : #if T_DESC("Device管理", true)
152 : HcclResult hrtThreadExchangeCaptureMode(aclmdlRICaptureMode *mode);
153 :
154 341 : HcclResult hrtGetDeviceCount(u32 *count)
155 : {
156 : #ifndef HCCD
157 : // 参数有效性检查
158 341 : CHK_PTR_NULL(count);
159 :
160 341 : aclError ret = aclrtGetDeviceCount(count);
161 :
162 341 : HCCL_DEBUG("Call rtGetDeviceCount, return value[%d], para: count[%u].", ret, *count);
163 341 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[hrtGetDeviceCount]errNo[0x%016llx] aclGet device count fail, "\
164 : "return[%d], para:count[%u]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, *count), HCCL_E_RUNTIME);
165 :
166 341 : if (*count == 0) {
167 0 : return HCCL_SUCCESS;
168 : }
169 :
170 : DevType deviceType;
171 341 : CHK_RET(hrtGetDeviceType(deviceType));
172 341 : if (deviceType == DevType::DEV_TYPE_NOSOC) {
173 0 : *count = 0;
174 0 : return HCCL_SUCCESS;
175 : }
176 :
177 341 : return HCCL_SUCCESS;
178 : #else
179 : HCCL_ERROR("[hrtGetDeviceCount]Does not support this interface.");
180 : return HCCL_E_NOT_SUPPORT;
181 : #endif
182 : };
183 :
184 : /* 设定当前线程操作的目标设备编号 */
185 811 : HcclResult hrtSetDevice(s32 deviceLogicId)
186 : {
187 : #ifndef HCCD
188 811 : aclError ret = aclrtSetDevice(deviceLogicId);
189 811 : HCCL_DEBUG("Call aclrtSetDevice, return value[%d], para: device_id[%d], g_deviceLogicId = %d.",
190 : ret, deviceLogicId, g_deviceLogicId);
191 811 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Set][Device]errNo[0x%016llx] rtSet device fail, return[%d], "\
192 : "para:deviceLogicId[%d]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, deviceLogicId), HCCL_E_RUNTIME);
193 811 : g_deviceLogicId = INVALID_INT;
194 811 : return HCCL_SUCCESS;
195 : #else
196 : static auto funcPtr = (aclError(*)(int32_t))g_dlAcl.Handle<ACL_RT_SET_DEVICE>();
197 : CHK_PTR_NULL(funcPtr);
198 : aclError ret = funcPtr(deviceLogicId);
199 : HCCL_DEBUG("Call aclrtSetDevice, return value[%d], para: device_id[%d], g_deviceLogicId = %d.",
200 : ret, deviceLogicId, g_deviceLogicId);
201 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Set][Device]errNo[0x%016llx] rtSet device fail, return[%d], "\
202 : "para:deviceLogicId[%d]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, deviceLogicId), HCCL_E_RUNTIME);
203 : return HCCL_SUCCESS;
204 : #endif
205 : }
206 :
207 : /* 释放当前线程操作的目标设备编号,释放前必须先释放设备资源 */
208 211 : HcclResult hrtResetDevice(s32 deviceLogicId)
209 : {
210 : #ifndef HCCD
211 211 : aclError ret = aclrtResetDevice(deviceLogicId);
212 :
213 211 : HCCL_DEBUG("Call aclrtResetDevice, return value[%d], para: device_id[%d].", ret, deviceLogicId);
214 211 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Reset][Device]errNo[0x%016llx] rtReset device fail, return[%d], "\
215 : "para: deviceLogicId[%d]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, deviceLogicId), HCCL_E_RUNTIME);
216 :
217 211 : return HCCL_SUCCESS;
218 : #else
219 : static auto funcPtr = (aclError(*)(int32_t))g_dlAcl.Handle<ACL_RT_RESET_DEVICE>();
220 : CHK_PTR_NULL(funcPtr);
221 : aclError ret = funcPtr(deviceLogicId);
222 :
223 : HCCL_DEBUG("Call aclrtResetDevice, return value[%d], para: device_id[%d].", ret, deviceLogicId);
224 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Reset][Device]errNo[0x%016llx] rtReset device fail, return[%d], "\
225 : "para: deviceLogicId[%d]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, deviceLogicId), HCCL_E_RUNTIME);
226 : return HCCL_SUCCESS;
227 : #endif
228 : }
229 :
230 0 : HcclResult stubSetDevice(u32 deviceLogicId)
231 : {
232 0 : g_stubDeviceId = deviceLogicId;
233 0 : return HCCL_SUCCESS;
234 : }
235 :
236 3550 : HcclResult hrtGetDeviceRefresh(s32 *deviceLogicId)
237 : {
238 : #ifndef HCCD
239 : // 参数有效性检查
240 3550 : CHK_PTR_NULL(deviceLogicId);
241 :
242 3550 : aclError ret = 0;
243 3550 : ret = aclrtGetDevice(deviceLogicId);
244 3550 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Get][DeviceRefresh]errNo[0x%016llx] rtGet device fail, "\
245 : "please make sure that device is set. return[%d], para:deviceLogicId[%d]",
246 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, *deviceLogicId), HCCL_E_RUNTIME);
247 3546 : g_deviceLogicId = *deviceLogicId;
248 3546 : HCCL_INFO("[hrtGetDeviceRefresh]deviceLogicId[%d]", *deviceLogicId);
249 3546 : return HCCL_SUCCESS;
250 : #else
251 : HCCL_WARNING("[hrtGetDeviceRefresh]Does not support this interface.");
252 : return HCCL_E_NOT_SUPPORT;
253 : #endif
254 : }
255 :
256 11 : HcclResult hrtSetlocalDevice(s32 deviceLogicId)
257 : {
258 : #ifdef HCCD
259 : g_localDeviceLogicId = deviceLogicId;
260 : #endif
261 11 : return HCCL_SUCCESS;
262 : }
263 :
264 : /* 查询当前线程目前操作的目标设备编号 */
265 : #ifdef __cplusplus
266 : extern "C" {
267 : #endif
268 23 : HcclResult __hrtGetDevice(s32 *deviceLogicId)
269 : {
270 : // 参数有效性检查
271 23 : CHK_PTR_NULL(deviceLogicId);
272 : #ifndef HCCD
273 :
274 23 : if (LIKELY(g_deviceLogicId != INVALID_INT)) {
275 22 : *deviceLogicId = g_deviceLogicId;
276 22 : return HCCL_SUCCESS;
277 : }
278 1 : aclError ret = 0;
279 1 : ret = aclrtGetDevice(deviceLogicId);
280 1 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_WARNING("[Get][Device]errNo[0x%016llx] rtGet device fail, "\
281 : "please make sure that device is set. return[%d], para:deviceLogicId[%d]",
282 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, *deviceLogicId), HCCL_E_RUNTIME);
283 1 : g_deviceLogicId = *deviceLogicId;
284 1 : HCCL_INFO("[hrtGetDevice]deviceLogicId[%d]", *deviceLogicId);
285 1 : return HCCL_SUCCESS;
286 : #else
287 : if (g_workModeAicpu) {
288 : HCCL_DEBUG("[hrtGetDevice]Device logicId = %d.", g_localDeviceLogicId);
289 : *deviceLogicId = g_localDeviceLogicId;
290 : return HCCL_SUCCESS;
291 : }
292 : *deviceLogicId = 0;
293 : HCCL_WARNING("[hrtGetDevice]Does does not support this interface.");
294 : return HCCL_E_NOT_SUPPORT;
295 : #endif
296 : }
297 : weak_alias(__hrtGetDevice, hrtGetDevice);
298 : #ifdef __cplusplus
299 : } // extern "C"
300 : #endif
301 :
302 :
303 0 : HcclResult hrtCtxCreate(aclrtContext *createCtx, uint32_t flags, int32_t devId)
304 : {
305 0 : CHK_PTR_NULL(createCtx);
306 : #ifndef HCCD
307 :
308 : // acl 接口的 flag 默认是 rtCtxMode_t::RT_CTX_NORMAL_MODE
309 0 : aclError ret = aclrtCreateContext(createCtx, devId);
310 : #else
311 : static auto funcPtr = (aclError(*)(aclrtContext *, int32_t))g_dlAcl.Handle<ACL_RT_CREATE_CONTEXT>();
312 : CHK_PTR_NULL(funcPtr);
313 : aclError ret = funcPtr(createCtx, devId);
314 : #endif
315 0 : CHK_PRT_RET(ret != ACL_SUCCESS && ret != ACL_ERROR_RT_CONTEXT_NULL, HCCL_ERROR(
316 : "[Get][Device]errNo[0x%016llx] aclrtCreateContext fail, return[%d], para:flags[%u], devId[%d]",
317 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, flags, devId), HCCL_E_RUNTIME);
318 0 : HCCL_INFO("[hrtCtxCreate]deviceLogicId[%d]", devId);
319 0 : return HCCL_SUCCESS;
320 : }
321 :
322 0 : HcclResult hrtCtxDestroy(aclrtContext destroyCtx)
323 : {
324 0 : CHK_PTR_NULL(destroyCtx);
325 : #ifndef HCCD
326 0 : aclError ret = aclrtDestroyContext(destroyCtx);
327 : #else
328 : static auto funcPtr = (aclError(*)(aclrtContext))g_dlAcl.Handle<ACL_RT_DESTROY_CONTEXT>();
329 : CHK_PTR_NULL(funcPtr);
330 : aclError ret = funcPtr(destroyCtx);
331 : #endif
332 0 : CHK_PRT_RET(ret != ACL_SUCCESS && ret != ACL_ERROR_RT_CONTEXT_NULL, HCCL_ERROR(
333 : "[Get][Device]errNo[0x%016llx] aclrtDestroyContext fail, return[%d]",
334 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret), HCCL_E_RUNTIME);
335 :
336 0 : return HCCL_SUCCESS;
337 : }
338 :
339 2970 : HcclResult hrtCtxGetCurrent(HcclRtContext *ctx)
340 : {
341 2970 : CHK_PTR_NULL(ctx);
342 : #ifndef HCCD
343 2970 : aclError ret = aclrtGetCurrentContext(ctx);
344 : #else
345 : static auto funcPtr = (aclError(*)(aclrtContext*))g_dlAcl.Handle<ACL_RT_GET_CURRENT_CONTEXT>();
346 : CHK_PTR_NULL(funcPtr);
347 : aclError ret = funcPtr(ctx);
348 : #endif
349 2971 : CHK_PRT_RET(ret != ACL_SUCCESS && ret != ACL_ERROR_RT_CONTEXT_NULL, HCCL_ERROR(
350 : "[Get][Device]errNo[0x%016llx] aclrtGetCurrentContext fail, "\
351 : "please make sure that DIE is set. return[%d]",
352 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret), HCCL_E_RUNTIME);
353 2971 : if (ret == ACL_ERROR_RT_CONTEXT_NULL) {
354 0 : HCCL_INFO("[Get][Device] curCtx is nullptr!");
355 0 : *ctx = nullptr;
356 : }
357 2971 : return HCCL_SUCCESS;
358 : }
359 :
360 1252 : HcclResult hrtCtxSetCurrent(HcclRtContext ctx)
361 : {
362 1252 : CHK_PTR_NULL(ctx);
363 : #ifndef HCCD
364 1252 : aclError ret = aclrtSetCurrentContext(ctx);
365 : #else
366 : static auto funcPtr = (aclError(*)(aclrtContext))g_dlAcl.Handle<ACL_RT_SET_CURRENT_CONTEXT>();
367 : CHK_PTR_NULL(funcPtr);
368 : aclError ret = funcPtr(ctx);
369 : #endif
370 1252 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Set][Device]errNo[0x%016llx] aclrtSetCurrentContext fail, "\
371 : "please make sure that DIE is set. return[%d]",
372 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret), HCCL_E_RUNTIME);
373 1252 : HCCL_INFO("[hrtCtxSetCurrent] success");
374 1252 : return HCCL_SUCCESS;
375 : }
376 :
377 : #ifdef __cplusplus
378 : extern "C" {
379 : #endif
380 7 : HcclResult __hrtGetDevicePhyIdByIndex(u32 deviceLogicId, u32 &devicePhyId, bool isRefresh)
381 : {
382 : #ifndef HCCD
383 7 : if (LIKELY(g_devicePhyId != INVALID_UINT) && (!isRefresh)) {
384 6 : devicePhyId = g_devicePhyId;
385 6 : return HCCL_SUCCESS;
386 : }
387 :
388 : DevType deviceType;
389 1 : CHK_RET(hrtGetDeviceType(deviceType));
390 1 : if (deviceType == DevType::DEV_TYPE_NOSOC) {
391 0 : devicePhyId = 0;
392 0 : g_devicePhyId = 0;
393 0 : return HCCL_SUCCESS;
394 : }
395 :
396 1 : s32 logicDevId = static_cast<s32>(deviceLogicId);
397 : s32 phyDevId;
398 1 : aclError ret = aclrtGetPhyDevIdByLogicDevId(logicDevId, &phyDevId);
399 1 : if (ret != ACL_SUCCESS) {
400 0 : HCCL_ERROR("[Get][DevicePhyId]errNo[0x%016llx] rtGet device PhyId by index failed, return[%d], "\
401 : "para: devIndex[%d], phyId[%d]", HCCL_ERROR_CODE(HCCL_E_DRV), ret, logicDevId, phyDevId);
402 0 : return HCCL_E_RUNTIME;
403 : }
404 1 : devicePhyId = static_cast<u32>(phyDevId);
405 1 : g_devicePhyId = devicePhyId;
406 1 : return HCCL_SUCCESS;
407 : #else
408 : HCCL_ERROR("[hrtGetDevicePhyIdByIndex]Does not support this interface.");
409 : return HCCL_E_NOT_SUPPORT;
410 : #endif
411 : }
412 : weak_alias(__hrtGetDevicePhyIdByIndex, hrtGetDevicePhyIdByIndex);
413 : #ifdef __cplusplus
414 : } // extern "C"
415 : #endif
416 :
417 22443 : HcclResult hrtGetDeviceIndexByPhyId(u32 devicePhyId, u32 &deviceLogicId)
418 : {
419 22443 : s32 phyDevId = static_cast<s32>(devicePhyId);
420 : s32 logicDevId;
421 : #ifndef HCCD
422 : DevType deviceType;
423 22443 : CHK_RET(hrtGetDeviceType(deviceType));
424 22441 : if (deviceType == DevType::DEV_TYPE_NOSOC) {
425 0 : deviceLogicId = 0;
426 0 : return HCCL_SUCCESS;
427 : }
428 :
429 22441 : aclError ret = aclrtGetLogicDevIdByPhyDevId(phyDevId, &logicDevId);
430 : #else
431 : static auto funcPtr = (rtError_t(*)(int32_t, int32_t *const))g_dlAclrt.Handle<ACL_RT_GET_LOGICID_BY_PHYID>();
432 : CHK_PTR_NULL(funcPtr);
433 : aclError ret = funcPtr(phyDevId, &logicDevId);
434 : #endif
435 22440 : if (ret != ACL_SUCCESS) {
436 0 : HCCL_ERROR("[Get][DeviceIndex]errNo[0x%016llx] rtGet device logicid by PhyId failed, return[%d], "\
437 : "para: phyId[%d], devIndex[%d]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, phyDevId, logicDevId);
438 0 : return HCCL_E_RUNTIME;
439 : }
440 22440 : deviceLogicId = static_cast<u32>(logicDevId);
441 22440 : return HCCL_SUCCESS;
442 : };
443 :
444 1020 : HcclResult hrtGetLogicDevIdByUserDevId(s32 userDevId, s32 &logicDevId)
445 : {
446 : #ifndef HCCD
447 : DevType deviceType;
448 1020 : CHK_RET(hrtGetDeviceType(deviceType));
449 1020 : if (deviceType == DevType::DEV_TYPE_NOSOC) {
450 0 : logicDevId = 0;
451 0 : return HCCL_SUCCESS;
452 : }
453 :
454 1020 : aclError ret = aclrtGetLogicDevIdByUserDevId(userDevId, &logicDevId);
455 1020 : if (ret != ACL_SUCCESS) {
456 0 : HCCL_ERROR("aclrtGetLogicDevIdByUserDevId failed, return[%d], "\
457 : "para: userDevId[%d], logicDevId[%d]", ret, userDevId, logicDevId);
458 0 : return HCCL_E_RUNTIME;
459 : }
460 : #else
461 : logicDevId = userDevId;
462 : HCCL_WARNING("[aclrtGetLogicDevIdByUserDevId]Does not support this interface.");
463 : #endif
464 1020 : return HCCL_SUCCESS;
465 : };
466 :
467 2039 : HcclResult hrtGetPhyDeviceInfo(u32 devicePhysicId, s32 moduleType, s32 infoType, s64 &value)
468 : {
469 : #ifndef HCCD
470 2039 : rtError_t rtRet = rtGetPhyDeviceInfo(devicePhysicId, moduleType, infoType, reinterpret_cast<int64_t *>(&value));
471 2038 : HCCL_INFO("[hrtGetPhyDeviceInfo] Call rtGetPhyDeviceInfo, ret[%d], para: devicePhysicId[%u], moduleType[%d], "
472 : "infoType[%d], value[%lld]", rtRet, devicePhysicId, moduleType, infoType, value);
473 2040 : CHK_PRT_RET(rtRet != RT_ERROR_NONE, HCCL_ERROR("[Get][DeviceInfo]errNo[0x%016llx] rt get pair devices "\
474 : "info failed, return[%d], para:devicePhysicId[%u], moduleType[%d], infoType[%d], value[%lld].",\
475 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), rtRet, devicePhysicId, moduleType, infoType, value), HCCL_E_RUNTIME);
476 2040 : return HCCL_SUCCESS;
477 : #else
478 : HCCL_ERROR("[hrtGetPhyDeviceInfo]Does not support this interface.");
479 : return HCCL_E_NOT_SUPPORT;
480 : #endif
481 : }
482 :
483 29638 : HcclResult hrtGetSocVer(std::string &socName)
484 : {
485 : #ifndef HCCD
486 29638 : const char *socNamePtr = aclrtGetSocName();
487 29635 : CHK_PRT_RET((socNamePtr == nullptr), HCCL_ERROR("[Get][SocVer]errNo[0x%016llx] aclrtGet socName failed",
488 : HCCL_ERROR_CODE(HCCL_E_RUNTIME)), HCCL_E_RUNTIME);
489 :
490 29635 : socName = socNamePtr;
491 29637 : return HCCL_SUCCESS;
492 : #else
493 : HCCL_ERROR("[hrtGetSocVer]Does not support this interface.");
494 : return HCCL_E_NOT_SUPPORT;
495 : #endif
496 : }
497 :
498 : // 获取芯片类型
499 : #ifdef __cplusplus
500 : extern "C" {
501 : #endif
502 5 : HcclResult hrtGetDeviceTypeBySocVersion(std::string &socVersion, DevType &devType)
503 : {
504 5 : devType = DevType::DEV_TYPE_COUNT;
505 5 : if (socVersion == "Ascend310B1") {
506 0 : HCCL_WARNING("hrtGetDeviceTypeBySocVersion Ascend310B1 not support! please check usage");
507 : }
508 :
509 5 : if (socVersion.find("Ascend950") != std::string::npos) {
510 0 : devType = DevType::DEV_TYPE_950;
511 0 : return HCCL_SUCCESS;
512 : }
513 :
514 5 : if (socVersion.find("Ascend910_96") != std::string::npos
515 5 : || socVersion.find("Ascend960") != std::string::npos
516 10 : || socVersion.find("ascend960") != std::string::npos) {
517 0 : devType = DevType::DEV_TYPE_960;
518 0 : return HCCL_SUCCESS;
519 : }
520 :
521 5 : auto iter = SOC_VER_CONVERT.find(socVersion);
522 5 : if (iter == SOC_VER_CONVERT.end()) {
523 0 : HCCL_ERROR("[Get][DeviceType]errNo[0x%016llx] rtGetSocVersion get illegal chipver, chip_ver[%s].",
524 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), socVersion.c_str());
525 0 : return HCCL_E_RUNTIME;
526 : }
527 5 : devType = iter->second;
528 5 : return HCCL_SUCCESS;
529 : }
530 11 : HcclResult hrtSetWorkModeAicpu(bool workModeAicpu)
531 : {
532 : #ifdef HCCD
533 : g_workModeAicpu = workModeAicpu;
534 : #endif
535 11 : HCCL_INFO("[Set][hrtSetWorkModeAicpu]work mode aicpu[%u]", g_workModeAicpu);
536 11 : return HCCL_SUCCESS;
537 : }
538 :
539 11 : HcclResult hrtSetlocalDeviceType(DevType devType)
540 : {
541 : #ifdef HCCD
542 : g_localDeviceType = devType;
543 : #endif
544 11 : return HCCL_SUCCESS;
545 : }
546 :
547 36590 : HcclResult __hrtGetDeviceType(DevType &devType)
548 : {
549 36590 : if (LIKELY((g_deviceType != DevType::DEV_TYPE_COUNT))) {
550 36375 : devType = g_deviceType;
551 36375 : return HCCL_SUCCESS;
552 : }
553 :
554 215 : std::string socName;
555 : #ifndef HCCD
556 219 : CHK_RET(hrtGetSocVer(socName));
557 : #else
558 : if (g_workModeAicpu) {
559 : devType = g_localDeviceType;
560 : return HCCL_SUCCESS;
561 : }
562 :
563 : static auto funcPtr = (const char *(*)())g_dlAcl.Handle<ACL_GET_SOC_NAME>();
564 : CHK_PTR_NULL(funcPtr);
565 : const char *socNamePtr = funcPtr();
566 : CHK_PRT_RET((socNamePtr == nullptr),
567 : HCCL_ERROR("[hrtGetDeviceType]errNo[0x%016llx] aclrtGet socName failed",
568 : HCCL_ERROR_CODE(HCCL_E_RUNTIME)), HCCL_E_RUNTIME);
569 : socName = socNamePtr;
570 : #endif
571 : // 根据芯片版本号获取芯片类型
572 220 : HCCL_DEBUG("[hrtGetDeviceType]socName = %s.", socName.c_str());
573 219 : if (socName.find("Ascend950") != std::string::npos) {
574 0 : devType = DevType::DEV_TYPE_950;
575 0 : g_deviceType = devType;
576 0 : HCCL_DEBUG("[hrtGetDeviceType]DeviceType = %d.", static_cast<s32>(g_deviceType));
577 0 : return HCCL_SUCCESS;
578 : }
579 :
580 220 : if (socName.find("Ascend910_96") != std::string::npos
581 219 : || socName.find("Ascend960") != std::string::npos
582 439 : || socName.find("ascend960") != std::string::npos) {
583 0 : devType = DevType::DEV_TYPE_960;
584 0 : g_deviceType = devType;
585 0 : HCCL_DEBUG("[hrtGetDeviceType]DeviceType = %d.", static_cast<s32>(g_deviceType));
586 0 : return HCCL_SUCCESS;
587 : }
588 :
589 220 : auto iter = SOC_VER_CONVERT.find(socName);
590 219 : if (iter == SOC_VER_CONVERT.end()) {
591 0 : HCCL_ERROR("[Get][DeviceType]errNo[0x%016llx] rtGetSocVersion get illegal chipver, chip_ver[%s].", \
592 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), socName.c_str());
593 0 : return HCCL_E_RUNTIME;
594 : }
595 219 : devType = iter->second;
596 219 : g_deviceType = devType;
597 219 : return HCCL_SUCCESS;
598 219 : }
599 : weak_alias(__hrtGetDeviceType, hrtGetDeviceType);
600 : #ifdef __cplusplus
601 : } // extern "C"
602 : #endif
603 :
604 : #endif
605 :
606 : #if T_DESC("DeviceMemory管理", true)
607 :
608 0 : HcclResult HrtDevFree(void *devPtr)
609 : {
610 0 : CHK_PTR_NULL(devPtr);
611 0 : s32 deviceId = GetDeviceLogicalId();
612 0 : PLF_CONFIG_DEBUG(PLF_RES, "Free DevMem para: deviceId[%d] devPtr[%p]", deviceId, devPtr);
613 :
614 0 : static auto funcPtr = (aclError(*)(void *))g_dlAcl.Handle<ACL_RT_FREE>();
615 0 : CHK_PTR_NULL(funcPtr);
616 0 : aclError ret = funcPtr(devPtr);
617 :
618 0 : HCCL_DEBUG("Call aclrtFree, ret[%d], devPtr[%p]", ret, devPtr);
619 0 : CHK_PRT_RET((ret != ACL_SUCCESS), HCCL_ERROR("[Free][Mem]errNo[0x%016llx] aclrtFree failed, return[%d]"
620 : ", para: devPtr[%p].", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, devPtr), HCCL_E_RUNTIME);
621 0 : return HCCL_SUCCESS;
622 : }
623 :
624 0 : HcclResult HrtDevMalloc(void **devPtr, u64 size)
625 : {
626 0 : CHK_PTR_NULL(devPtr);
627 :
628 0 : static auto funcPtr = (rtError_t(*)(void **, size_t, aclrtMemMallocPolicy,
629 0 : aclrtMallocConfig *))g_dlAcl.Handle<ACL_RT_MALLOC_WITH_CFG>();
630 0 : CHK_PTR_NULL(funcPtr);
631 :
632 : aclrtMallocAttrValue moduleIdValue;
633 0 : moduleIdValue.moduleId = HCCL;
634 0 : aclrtMallocAttribute attrs{.attr = ACL_RT_MEM_ATTR_MODULE_ID, .value = moduleIdValue};
635 0 : aclrtMallocConfig cfg{.attrs = &attrs, .numAttrs = 1};
636 :
637 0 : aclError ret = funcPtr(devPtr, size, ACL_MEM_TYPE_HIGH_BAND_WIDTH, &cfg);
638 :
639 0 : CHK_PRT_RET((ret != ACL_SUCCESS || *devPtr == nullptr), HCCL_ERROR("[Malloc][Mem]errNo[0x%016llx] "
640 : "aclrtMallocWithCfg failed, return[%d], para: devPtr[%p], size[%llu Byte].", HCCL_ERROR_CODE(HCCL_E_RUNTIME),
641 : ret, *devPtr, size), HCCL_E_RUNTIME);
642 :
643 0 : s32 deviceId = GetDeviceLogicalId();
644 0 : PLF_CONFIG_DEBUG(PLF_RES, "Malloc DevMem para: deviceId[%d] devPtr[%p] size[%llu Byte]",
645 : deviceId, *devPtr, size);
646 0 : return HCCL_SUCCESS;
647 : }
648 :
649 4520 : HcclResult hrtMalloc(void **devPtr, u64 size, bool level2Address)
650 : {
651 : #ifndef HCCD
652 : // 参数有效性检查
653 4520 : CHK_PTR_NULL(devPtr);
654 :
655 : DevType devType;
656 4520 : CHK_RET(hrtGetDeviceType(devType));
657 4521 : s32 deviceId = 0;
658 4521 : CHK_RET(hrtGetDevice(&deviceId));
659 :
660 4522 : aclError ret = ACL_SUCCESS;
661 4522 : s32 policy = 0;
662 4522 : bool isTsMem = false;
663 4522 : if (Is310PDevice()) {
664 0 : if (devType == DevType::DEV_TYPE_310P3 || devType == DevType::DEV_TYPE_310P1) {
665 0 : if (level2Address) { // 310P二级地址刷新时申请内存类型为:RT_MEMORY_TS
666 0 : isTsMem = true;
667 : } else {
668 0 : policy = static_cast<int>(ACL_MEM_TYPE_LOW_BAND_WIDTH);
669 : }
670 : } else {
671 0 : policy = static_cast<int>(ACL_MEM_TYPE_HIGH_BAND_WIDTH);
672 : }
673 : } else {
674 4522 : if (devType == DevType::DEV_TYPE_310P3) {
675 0 : if (level2Address) { // 310P二级地址刷新时申请内存类型为:RT_MEMORY_TS
676 0 : isTsMem = true;
677 : } else {
678 0 : policy = static_cast<int>(ACL_MEM_TYPE_LOW_BAND_WIDTH) |
679 : static_cast<int>(ACL_MEM_MALLOC_NORMAL_ONLY_P2P);
680 : }
681 4522 : } else if (devType == DevType::DEV_TYPE_310P1) {
682 0 : policy = static_cast<int>(ACL_MEM_TYPE_LOW_BAND_WIDTH);
683 : } else {
684 4522 : policy = static_cast<int>(ACL_MEM_TYPE_HIGH_BAND_WIDTH) |
685 : static_cast<int>(ACL_MEM_MALLOC_HUGE_FIRST);
686 : }
687 : }
688 :
689 : aclrtMallocAttrValue moduleIdValue;
690 4522 : moduleIdValue.moduleId = HCCL;
691 4522 : aclrtMallocAttribute attrs{.attr = ACL_RT_MEM_ATTR_MODULE_ID, .value = moduleIdValue};
692 4522 : aclrtMallocConfig cfg{.attrs = &attrs, .numAttrs = 1};
693 :
694 4522 : if (UNLIKELY(isTsMem)) {
695 0 : ret = aclrtMallocForTaskScheduler(devPtr, size, ACL_MEM_MALLOC_HUGE_FIRST, &cfg);
696 : } else {
697 4522 : ret = aclrtMallocWithCfg(devPtr, size, static_cast<aclrtMemMallocPolicy>(policy), &cfg);
698 : }
699 4536 : RPT_ENV_ERR(ret == ACL_ERROR_RT_MEMORY_ALLOCATION, "EI0011",
700 : std::vector<std::string>({"memory_size"}),
701 : std::vector<std::string>({std::to_string(size)}));
702 :
703 4524 : CHK_PRT_RET(ret == ACL_ERROR_RT_MEMORY_ALLOCATION, HCCL_ERROR("[Malloc][Mem] rtMalloc failed, "\
704 : "Reason: out of memory, return[%d], para: devPtrAddr[%p], size[%llu Byte].", ret, *devPtr, size),
705 : HCCL_E_OOM);
706 :
707 4532 : RPT_ENV_ERR((ret != ACL_SUCCESS), "EI0007", std::vector<std::string>({"resource_type", "resource_info"}), \
708 : std::vector<std::string>({"DeviceMemory", std::string("Malloc, size:") + std::to_string(size)+ " bytes"}));
709 :
710 4522 : CHK_PRT_RET((ret != ACL_SUCCESS), HCCL_ERROR("[%s][%s]errNo[0x%016llx] rtMalloc failed, "\
711 : "return[%d], para: devPtrAddr[%p], size[%llu Byte].", LOG_KEYWORDS_INIT_GROUP.c_str(),
712 : LOG_KEYWORDS_RESOURCE.c_str(), HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, *devPtr, size), HCCL_E_RUNTIME);
713 4521 : PLF_CONFIG_INFO(PLF_RES, "Malloc DevMem para: deviceId[%d] devPtr[%p] size[%llu Byte] "\
714 : "level2Address[%u]", deviceId, *devPtr, size, level2Address);
715 4521 : return HCCL_SUCCESS;
716 : #else
717 : // 参数有效性检查
718 : CHK_PTR_NULL(devPtr);
719 :
720 : *devPtr = malloc(size);
721 : CHK_PTR_NULL(*devPtr);
722 : PLF_CONFIG_INFO(PLF_RES, "Malloc para: devPtr[%p] size[%llu Byte]", *devPtr, size);
723 : return HCCL_SUCCESS;
724 : #endif
725 5 : }
726 :
727 803 : HcclResult hrtMemSyncCopy(void *dst, uint64_t destMax, const void *src, uint64_t count, HcclRtMemcpyKind kind)
728 : {
729 : #ifndef HCCD
730 : // 参数有效性检查
731 803 : CHK_PTR_NULL(dst);
732 803 : CHK_PTR_NULL(src);
733 803 : CHK_PRT_RET(count == 0, HCCL_WARNING("[hrtMemSyncCopy] count is zero"), HCCL_SUCCESS);
734 :
735 803 : aclmdlRICaptureMode mode = aclmdlRICaptureMode::ACL_MODEL_RI_CAPTURE_MODE_RELAXED;
736 803 : HcclResult hcclRet = hrtThreadExchangeCaptureMode(&mode);
737 802 : CHK_PRT_CONT(hcclRet != HCCL_SUCCESS && hcclRet != HCCL_E_NOT_SUPPORT,
738 : HCCL_ERROR("[hrtMemSyncCopy] hrtThreadExchangeCaptureMode return [%d]", hcclRet));
739 :
740 : aclrtMemcpyKind rtKind;
741 802 : CHK_RET(MemcpyKindTranslate(kind, &rtKind));
742 803 : aclError ret = aclrtMemcpy(dst, destMax, src, count, rtKind);
743 802 : HCCL_DEBUG("Call aclrtMemcpy, return[%d], para: dstAddr[%p], destMax[%llu], srcAddr[%p], count[%llu], rtKind[%d]",
744 : ret, dst, destMax, src, count, rtKind);
745 802 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[SyncCopy][Mem]errNo[0x%016llx] aclrtMemcpy failed, "\
746 : "return[%d], para: dstAddr[%p], destMax[%llu], srcAddr[%p], count[%llu], rtKind[%d].",\
747 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, dst, destMax, src, count, rtKind), HCCL_E_RUNTIME);
748 :
749 802 : hcclRet = hrtThreadExchangeCaptureMode(&mode);
750 803 : CHK_PRT_CONT(hcclRet != HCCL_SUCCESS && hcclRet != HCCL_E_NOT_SUPPORT,
751 : HCCL_ERROR("[hrtMemSyncCopy] hrtThreadExchangeCaptureMode return [%d]", hcclRet));
752 803 : return HCCL_SUCCESS;
753 : #else
754 : HCCL_ERROR("[hrtMemSyncCopy]Does not support this interface.");
755 : return HCCL_E_NOT_SUPPORT;
756 : #endif
757 : }
758 :
759 1 : HcclResult hrtMemSyncCopyEx(void *dst, uint64_t destMax, const void *src, uint64_t count, HcclRtMemcpyKind kind)
760 : {
761 : #ifndef HCCD
762 : // 参数有效性检查
763 1 : CHK_PTR_NULL(dst);
764 1 : CHK_PTR_NULL(src);
765 1 : CHK_PRT_RET(count == 0, HCCL_WARNING("[hrtMemSyncCopyEx] count is zero"), HCCL_SUCCESS);
766 :
767 : aclrtMemcpyKind rtKind;
768 1 : CHK_RET(MemcpyKindTranslate(kind, &rtKind));
769 1 : aclError ret = aclrtMemcpy(dst, destMax, src, count, rtKind);
770 :
771 1 : HCCL_DEBUG("[hrtMemSyncCopyEx] Call aclrtMemcpy, ret[%d], dstAddr[%p], destMax[%llu], srcAddr[%p], count[%llu], "
772 : "rtKind[%d]", ret, dst, destMax, src, count, rtKind);
773 1 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[SyncCopy][Mem]errNo[0x%016llx] aclrtMemcpy failed, "\
774 : "return[%d], para: dstAddr[%p], destMax[%llu], srcAddr[%p], count[%llu], rtKind[%d].",\
775 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, dst, destMax, src, count, rtKind), HCCL_E_RUNTIME);
776 :
777 1 : return HCCL_SUCCESS;
778 : #else
779 : HCCL_ERROR("[hrtMemSyncCopyEx]Does not support this interface.");
780 : return HCCL_E_NOT_SUPPORT;
781 : #endif
782 : }
783 :
784 4354 : HcclResult hrtFree(void *devPtr)
785 : {
786 : #ifndef HCCD
787 : // 参数有效性检查
788 4354 : CHK_PTR_NULL(devPtr);
789 4354 : s32 deviceId = GetDeviceLogicalId();
790 4355 : PLF_CONFIG_DEBUG(PLF_RES, "Free DevMem para: deviceId[%d] dev_ptr[%p].", deviceId, devPtr);
791 :
792 4360 : aclError ret = aclrtFree(devPtr);
793 4361 : HCCL_DEBUG("Call aclrtFree, return value[%d], para: dev_ptr[%p].", ret, devPtr);
794 4361 : CHK_PRT_RET((ret != ACL_SUCCESS), HCCL_ERROR("[Free][Mem]errNo[0x%016llx] aclrtFree failed, "\
795 : "return[%d], para: devPtrAddr[%p].", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, devPtr), HCCL_E_RUNTIME);
796 :
797 4361 : return HCCL_SUCCESS;
798 : #else
799 : CHK_PTR_NULL(devPtr);
800 : PLF_CONFIG_DEBUG(PLF_RES, "Free DevMem para: dev_ptr[%p].", devPtr);
801 : free(devPtr);
802 :
803 : return HCCL_SUCCESS;
804 : #endif
805 : }
806 :
807 0 : HcclResult hrtMemcpyAddrAsync(void *dst, uint64_t destMax, uint64_t destOffset, const void *src, uint64_t count,
808 : uint64_t srcOffset, rtStream_t stream)
809 : {
810 : #ifndef HCCD
811 : // 参数有效性检查
812 0 : CHK_PTR_NULL(dst);
813 0 : CHK_PTR_NULL(src);
814 0 : CHK_PTR_NULL(stream);
815 :
816 0 : if (count == 0) {
817 0 : HCCL_WARNING("Call hrtMemcpyAddrAsync, count [%d]", count);
818 0 : return HCCL_SUCCESS;
819 : }
820 :
821 0 : aclError ret = aclrtMemcpyAsyncWithOffset(reinterpret_cast<void **>(dst), destMax, destOffset,
822 : reinterpret_cast<const void **>(const_cast<void *>(src)), count, srcOffset, ACL_MEMCPY_INNER_DEVICE_TO_DEVICE,
823 : stream);
824 :
825 0 : HCCL_DEBUG("Call hrtMemcpyAddrAsync, return value[%d], dstAddr[%p], destMax[%llu], destOffset[%llu], "\
826 : "srcAddr[%p], count[%llu], srcOffset[%llu]", ret, dst, destMax, destOffset, src, count, srcOffset);
827 :
828 0 : if (ret == ACL_ERROR_RT_FEATURE_NOT_SUPPORT) {
829 0 : HCCL_WARNING("hrtMemcpyAddrAsync is not supported.", ret);
830 0 : return HCCL_E_NOT_SUPPORT;
831 : }
832 :
833 0 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[AsyncCopy][Mem]errNo[0x%016llx] rt memory async copy failed, "\
834 : "return[%d], para: dstAddr[%p], destMax[%llu], destOffset[%llu], srcAddr[%p], count[%llu], srcOffset[%llu], "\
835 : "stream[%p].",\
836 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, dst, destMax, destOffset, src, count, srcOffset, stream), HCCL_E_RUNTIME);
837 :
838 0 : return HCCL_SUCCESS;
839 : #else
840 : HCCL_ERROR("[hrtMemcpyAddrAsync]Does not support this interface.");
841 : return HCCL_E_NOT_SUPPORT;
842 : #endif
843 : }
844 :
845 842 : HcclResult MemcpyKindTranslate(HcclRtMemcpyKind kind, aclrtMemcpyKind *rtKind)
846 : {
847 842 : switch (kind) {
848 1 : case HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_HOST_TO_HOST: {
849 1 : *rtKind = ACL_MEMCPY_HOST_TO_HOST;
850 1 : return HCCL_SUCCESS;
851 : }
852 :
853 526 : case HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_HOST_TO_DEVICE: {
854 526 : *rtKind = ACL_MEMCPY_HOST_TO_DEVICE;
855 526 : return HCCL_SUCCESS;
856 : }
857 :
858 277 : case HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_HOST: {
859 277 : *rtKind = ACL_MEMCPY_DEVICE_TO_HOST;
860 277 : return HCCL_SUCCESS;
861 : }
862 :
863 38 : case HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_DEVICE: {
864 38 : *rtKind = ACL_MEMCPY_DEVICE_TO_DEVICE;
865 38 : return HCCL_SUCCESS;
866 : }
867 :
868 0 : default: {
869 0 : HCCL_ERROR("[MemcpyKindTranslate]Not support the memory copy type[%d].", kind);
870 0 : return HCCL_E_PARA;
871 : }
872 : }
873 : }
874 :
875 38 : HcclResult hrtMemAsyncCopy(void *dst, uint64_t destMax, const void *src, uint64_t count,
876 : HcclRtMemcpyKind kind, rtStream_t stream)
877 : {
878 : #ifndef HCCD
879 : // 参数有效性检查
880 38 : CHK_PTR_NULL(dst);
881 38 : CHK_PTR_NULL(src);
882 38 : CHK_PTR_NULL(stream);
883 38 : CHK_PRT_RET(count == 0, HCCL_WARNING("[hrtMemAsyncCopy] count is zero"), HCCL_SUCCESS);
884 :
885 : aclrtMemcpyKind rtKind;
886 38 : CHK_RET(MemcpyKindTranslate(kind, &rtKind));
887 :
888 38 : aclError ret = aclrtMemcpyAsync(dst, destMax, src, count, rtKind, stream);
889 38 : HCCL_DEBUG("Call aclrtMemcpyAsync, return value[%d], para: dstAddr[%p], destMax[%llu], "
890 : "srcAddr[%p], count[%llu], rtKind[%d]", ret, dst, destMax, src, count, rtKind);
891 :
892 38 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[AsyncCopy][Mem]errNo[0x%016llx] rt memory async copy failed, "\
893 : "return[%d], para: dstAddr[%p], destMax[%llu], srcAddr[%p], count[%llu], rtKind[%d], stream[%p].",\
894 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, dst, destMax, src, count, rtKind, stream), HCCL_E_RUNTIME);
895 :
896 38 : return HCCL_SUCCESS;
897 : #else
898 : HCCL_ERROR("[hrtMemAsyncCopy]Does not support this interface.");
899 : return HCCL_E_NOT_SUPPORT;
900 : #endif
901 : }
902 :
903 0 : HcclResult hrtMemAsyncCopyWithoutCheckKind(void *dst, uint64_t destMax, const void *src, uint64_t count,
904 : HcclRtMemcpyKind kind, rtStream_t stream)
905 : {
906 : #ifndef HCCD
907 : // 参数有效性检查
908 0 : CHK_PTR_NULL(dst);
909 0 : CHK_PTR_NULL(src);
910 0 : CHK_PTR_NULL(stream);
911 0 : CHK_PRT_RET(count == 0, HCCL_WARNING("[hrtMemAsyncCopyWithoutCheckKind] count is zero"), HCCL_SUCCESS);
912 :
913 : aclrtMemcpyKind rtKind;
914 0 : CHK_RET(MemcpyKindTranslate(kind, &rtKind));
915 0 : aclError ret = aclrtMemcpyAsync(dst, destMax, src, count, rtKind, stream);
916 :
917 0 : HCCL_DEBUG("Call rtsMemcpyAsync, return value[%d], dstAddr[%p], destMax[%llu],"\
918 : "srcAddr[%p], count[%llu]", ret, dst, destMax, src, count);
919 0 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[AsyncCopy][Mem]errNo[0x%016llx] rt memory async copy failed, "\
920 : "return[%d], para: dstAddr[%p], destMax[%llu], srcAddr[%p], count[%llu], rtKind[%d], stream[%p].",\
921 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, dst, destMax, src, count, rtKind, stream), HCCL_E_RUNTIME);
922 :
923 0 : return HCCL_SUCCESS;
924 : #else
925 : HCCL_ERROR("[hrtMemAsyncCopyWithoutCheckKind]Does not support this interface.");
926 : return HCCL_E_NOT_SUPPORT;
927 : #endif
928 : }
929 :
930 10402 : HcclResult hrtGetPairDeviceLinkTypeRaw(u32 phyDevId, u32 otherPhyDevId, s32 infoType, s64 *pValue)
931 : {
932 10402 : static auto funcPtr = (rtGetPairPhyDevicesInfoPtr)g_dlRts.Handle<RT_GET_PAIR_PHY_DEVICES_INFO>();
933 10403 : if (funcPtr != nullptr) {
934 0 : return hrtGetPairPhyDevicesInfo(phyDevId, otherPhyDevId, infoType, pValue, funcPtr);
935 : } else {
936 10403 : return hrtGetPairDevicesInfo(phyDevId, otherPhyDevId, infoType, pValue);
937 : }
938 : }
939 :
940 10401 : HcclResult hrtGetPairDevicesInfo(u32 phyDevId, u32 otherPhyDevId, s32 infoType, s64 *pValue)
941 : {
942 : #ifndef HCCD
943 10401 : CHK_PTR_NULL(pValue);
944 10401 : u32 logicIdLocal = 0;
945 10401 : u32 logicIdDest = 0;
946 10401 : CHK_RET(hrtGetDeviceIndexByPhyId(phyDevId, logicIdLocal));
947 :
948 10398 : CHK_RET(hrtGetDeviceIndexByPhyId(otherPhyDevId, logicIdDest));
949 :
950 10397 : aclError ret = aclrtGetDevicesTopo(logicIdLocal, logicIdDest, reinterpret_cast<uint64_t*>(pValue));
951 10394 : HCCL_DEBUG("aclrt get pair devices info, return[%d], "
952 : "para: phyDevId[%u], otherPhyDevId[%u], logicIdLocal[%u], logicIdDest[%u], value[%lld].",
953 : ret, phyDevId, otherPhyDevId, logicIdLocal, logicIdDest, *pValue);
954 10409 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Get][PairPhyDevicesInfo]errNo[0x%016llx] rt get pair devices info "
955 : "failed, return[%d], para: phyDevId[%u], otherPhyDevId[%u], logicIdLocal[%u], logicIdDest[%u], value[%lld].",
956 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, phyDevId, otherPhyDevId, logicIdLocal, logicIdDest, *pValue),
957 : HCCL_E_RUNTIME);
958 :
959 : // 当前 aclrtGetDevicesTopo 仅支持返回一种链路类型,将来可能会同时按照二进制位排列返回所支持的多种类型
960 : // 按二进制位进行比较
961 10409 : if ((*pValue & ACL_RT_DEVS_TOPOLOGY_HCCS) != 0) {
962 10200 : *pValue = TOPOLOGY_HCCS;
963 209 : } else if ((*pValue & ACL_RT_DEVS_TOPOLOGY_PIX) != 0) {
964 0 : *pValue = TOPOLOGY_PIX;
965 209 : } else if ((*pValue & ACL_RT_DEVS_TOPOLOGY_PIB) != 0) {
966 0 : *pValue = TOPOLOGY_PIB;
967 209 : } else if ((*pValue & ACL_RT_DEVS_TOPOLOGY_PHB) != 0) {
968 0 : *pValue = TOPOLOGY_PHB;
969 209 : } else if ((*pValue & ACL_RT_DEVS_TOPOLOGY_SYS) != 0) {
970 0 : *pValue = TOPOLOGY_SYS;
971 209 : } else if ((*pValue & ACL_RT_DEVS_TOPOLOGY_SIO) != 0) {
972 0 : *pValue = TOPOLOGY_SIO;
973 209 : } else if ((*pValue & ACL_RT_DEVS_TOPOLOGY_HCCS_SW) != 0) {
974 216 : *pValue = TOPOLOGY_HCCS_SW;
975 : } else {
976 0 : HCCL_ERROR("aclrt get pair devices info failed, unknown linkType[%lld], "
977 : "para: phyDevId[%u], otherPhyDevId[%u], logicIdLocal[%u], logicIdDest[%u].",
978 : *pValue, phyDevId, otherPhyDevId, logicIdLocal, logicIdDest);
979 0 : return HCCL_E_RUNTIME;
980 : }
981 10416 : return HCCL_SUCCESS;
982 : #else
983 : HCCL_ERROR("[hrtGetPairDevicesInfo]Does not support this interface.");
984 : return HCCL_E_NOT_SUPPORT;
985 : #endif
986 : }
987 :
988 0 : HcclResult hrtGetPairPhyDevicesInfo(u32 phyDevId, u32 otherPhyDevId, s32 infoType, s64 *pValue,
989 : rtGetPairPhyDevicesInfoPtr funcPtr)
990 : {
991 : #ifndef HCCD
992 0 : CHK_PTR_NULL(pValue);
993 0 : rtError_t ret = funcPtr(phyDevId, otherPhyDevId, infoType, reinterpret_cast<int64_t*>(pValue));
994 0 : HCCL_DEBUG("rt get pair devices info, return[%d], para: phyDevId[%u], otherPhyDevId[%u], infoType[%d], value[%lld]",
995 : ret, phyDevId, otherPhyDevId, infoType, *pValue);
996 0 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[Get][PairPhyDevicesInfo]errNo[0x%016llx] rt get pair devices "
997 : "info failed, return[%d], para: phyDevId[%u], otherPhyDevId[%u], infoType[%d], value[%lld].",
998 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, phyDevId, otherPhyDevId, infoType, *pValue), HCCL_E_RUNTIME);
999 0 : return HCCL_SUCCESS;
1000 : #else
1001 : HCCL_ERROR("[hrtGetPairPhyDevicesInfo]Does not support this interface.");
1002 : return HCCL_E_NOT_SUPPORT;
1003 : #endif
1004 : }
1005 :
1006 10403 : HcclResult hrtGetPairDeviceLinkType(u32 phyDevId, u32 otherPhyDevId, LinkTypeInServer &linkType)
1007 : {
1008 10403 : if (Is310PDevice()) {
1009 0 : linkType = LinkTypeInServer::HCCS_TYPE;
1010 0 : return HCCL_SUCCESS;
1011 : }
1012 :
1013 10401 : s64 linkTypeRaw = 0;
1014 : #ifndef HCCD
1015 10401 : CHK_RET(hrtGetPairDeviceLinkTypeRaw(phyDevId, otherPhyDevId, 0, &linkTypeRaw));
1016 : #else
1017 : HCCL_ERROR("[hrtGetPairDeviceLinkTypeRaw]Does not support this interface.");
1018 : return HCCL_E_NOT_SUPPORT;
1019 : #endif
1020 10414 : HCCL_INFO("[hrtGetPairDeviceLinkTypeRaw]phyDevId[%u] otherPhyDevId[%u] linkTypeRaw[%d]",
1021 : phyDevId, otherPhyDevId, linkTypeRaw);
1022 :
1023 : // 若当前为标卡/虚拟机device间通过HCCS直接互联:HCCS_TYPE,device间通过HCCS交换芯片互联:TOPOLOGY_HCCS_SW
1024 : // Ascend910_93* die间为SIO_TYPE
1025 : // 其他情况为PXI_TYPE
1026 :
1027 10414 : switch (linkTypeRaw) {
1028 10198 : case TOPOLOGY_HCCS:
1029 10198 : linkType = LinkTypeInServer::HCCS_TYPE;
1030 10198 : break;
1031 :
1032 216 : case TOPOLOGY_HCCS_SW:
1033 216 : linkType = LinkTypeInServer::HCCS_SW_TYPE;
1034 216 : break;
1035 :
1036 0 : case TOPOLOGY_SIO:
1037 0 : linkType = LinkTypeInServer::SIO_TYPE;
1038 0 : break;
1039 :
1040 0 : default:
1041 0 : linkType = LinkTypeInServer::PXI_TYPE;
1042 : }
1043 :
1044 10414 : return HCCL_SUCCESS;
1045 : }
1046 :
1047 0 : HcclResult hrtGetPairDevicePhyId(u32 localDevPhyId, u32 &pairDevPhyId)
1048 : {
1049 : #ifndef HCCD
1050 0 : DevType deviceType = DevType::DEV_TYPE_COUNT;
1051 0 : CHK_RET(hrtGetDeviceType(deviceType));
1052 0 : CHK_PRT_RET(deviceType != DevType::DEV_TYPE_910_93,
1053 : HCCL_ERROR("[hrtGetPairDevicePhyId] is not supported on device type[%d]. Please check device type.", deviceType),
1054 : HCCL_E_NOT_SUPPORT);
1055 :
1056 : // 奇数die对应的phyid - 1,偶数die对应的phyid + 1
1057 0 : int offset = static_cast<s32>(localDevPhyId) % 2 == 0 ? 1 : -1;
1058 :
1059 : // 通过本端的phyId获取同一个chip上的另一个die的PhyId
1060 0 : pairDevPhyId = localDevPhyId + offset;
1061 0 : LinkTypeInServer linkType = LinkTypeInServer::RESERVED_LINK_TYPE;
1062 0 : CHK_RET(hrtGetPairDeviceLinkType(localDevPhyId, pairDevPhyId, linkType));
1063 0 : if (linkType != LinkTypeInServer::SIO_TYPE) {
1064 0 : pairDevPhyId = localDevPhyId - offset;
1065 0 : CHK_RET(hrtGetPairDeviceLinkType(localDevPhyId, pairDevPhyId, linkType));
1066 0 : CHK_PRT_RET(linkType != LinkTypeInServer::SIO_TYPE,
1067 : HCCL_ERROR("[hrtGetPairDevicePhyId] neither of the two neighbour device is a pair device of dev[%u].",
1068 : localDevPhyId), HCCL_E_NOT_SUPPORT);
1069 : }
1070 0 : HCCL_DEBUG("[hrtGetPairDevicePhyId]GetPairDevicePhyId success, phyDevId[%u], pairDevPhyId[%u]",
1071 : localDevPhyId, pairDevPhyId);
1072 0 : return HCCL_SUCCESS;
1073 : #else
1074 : HCCL_ERROR("[hrtGetPairDevicePhyId]Does not support this interface.");
1075 : return HCCL_E_NOT_SUPPORT;
1076 : #endif
1077 : }
1078 :
1079 : // 获取指针的属性,主要是页表大小,单位Byte
1080 467 : HcclResult hrtGetPointAttr(HcclRtPointAttr ptrAttr, const void *ptr)
1081 : {
1082 : // 参数有效性检查
1083 467 : CHK_PTR_NULL(ptrAttr);
1084 467 : CHK_PTR_NULL(ptr);
1085 :
1086 : #ifndef HCCD
1087 467 : aclError ret = aclrtPointerGetAttributes(ptr, reinterpret_cast<aclrtPtrAttributes *>(ptrAttr));
1088 : #else
1089 : static auto funcPtr =
1090 : (aclError(*)(const void *ptr, aclrtPtrAttributes *attributes))g_dlAcl.Handle<ACL_RT_POINTER_GET_ATTRIBUTES>();
1091 : CHK_PTR_NULL(funcPtr);
1092 : aclError ret = funcPtr(ptr, reinterpret_cast<aclrtPtrAttributes *>(ptrAttr));
1093 : #endif
1094 467 : HCCL_DEBUG("Call aclrtPointerGetAttributes, return value[%d], para: ptr[%p].", ret, ptr);
1095 467 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Get][PointAttr]errNo[0x%016llx] rt get point attr failed, "\
1096 : "return[%d], para: ptrAttrAddr[%p], ptrAddr[%p].", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, ptrAttr, ptr),
1097 : HCCL_E_RUNTIME);
1098 :
1099 467 : return HCCL_SUCCESS;
1100 : }
1101 :
1102 0 : HcclResult hrtIpcSetMemoryName(void *ptr, u8 *name, u64 ptrMaxLen, u32 nameMaxLen)
1103 : {
1104 : // 参数有效性检查
1105 0 : CHK_PTR_NULL(ptr);
1106 0 : CHK_PTR_NULL(name);
1107 : #ifndef HCCD
1108 : // flag 预留字段填 0
1109 0 : aclError rtRet = aclrtIpcMemGetExportKey(ptr, ptrMaxLen, reinterpret_cast<char *>(name), nameMaxLen, 0UL);
1110 : #else
1111 : static auto funcPtr =
1112 : (aclError(*)(void *, size_t, char *, size_t, uint64_t))g_dlAcl.Handle<ACL_RT_IPC_MEM_GET_EXPORT_KEY>();
1113 : CHK_PTR_NULL(funcPtr);
1114 : aclError rtRet = funcPtr(ptr, ptrMaxLen, reinterpret_cast<char *>(name), nameMaxLen, 0UL);
1115 : #endif
1116 0 : HCCL_INFO("Call aclrtIpcMemGetExportKey, return value[%d], para: ptr[%p], name[%s], byteCount[%llu], nameLen[%u]",
1117 : rtRet, ptr, name, ptrMaxLen, nameMaxLen);
1118 0 : CHK_PRT_RET(rtRet != ACL_SUCCESS, HCCL_ERROR("[Set][IpcMemoryName]errNo[0x%016llx] rtSet Ipc Memory Name, "\
1119 : "return[%d], para: ptr[%p] byteCount[%llu]. Possible Cause: The memory addr or size is not aligned with pagesize.",
1120 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), rtRet, ptr, ptrMaxLen), HCCL_E_RUNTIME);
1121 :
1122 0 : return HCCL_SUCCESS;
1123 : }
1124 :
1125 0 : HcclResult hrtIpcDestroyMemoryName(const u8 *name)
1126 : {
1127 : // 参数有效性检查
1128 0 : CHK_PTR_NULL(name);
1129 :
1130 : #ifndef HCCD
1131 0 : aclError ret = aclrtIpcMemClose(reinterpret_cast<const char *>(name));
1132 : #else
1133 : static auto funcPtr = (aclError(*)(const char *))g_dlAcl.Handle<ACL_RT_DESTORY_MEM_NAME>();
1134 : CHK_PTR_NULL(funcPtr);
1135 : aclError ret = funcPtr(reinterpret_cast<const char *>(name));
1136 : #endif
1137 0 : HCCL_INFO("Call aclrtIpcMemClose, return[%d], para: name[%s]", ret, name);
1138 0 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[Destroy][IpcMemoryName]errNo[0x%016llx] "\
1139 : "rtDestroy Ipc memory name fail. return[%d], para: name[%s]",
1140 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, name), HCCL_E_RUNTIME);
1141 :
1142 0 : return HCCL_SUCCESS;
1143 : }
1144 :
1145 0 : HcclResult hrtIpcSetMemoryAttr(const u8 *name, aclrtIpcMemAttrType type, u64 attr)
1146 : {
1147 : #ifndef HCCD
1148 : // 参数有效性检查
1149 0 : CHK_PTR_NULL(name);
1150 0 : rtError_t ret = aclrtIpcMemSetAttr(reinterpret_cast<const char *>(name), type, attr);
1151 0 : HCCL_INFO("Call aclrtIpcMemSetAttr, return[%d], para: name: %s, type: %u, attr: %llu", ret, name, type, attr);
1152 0 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[%s]errNo[0x%016llx] "\
1153 : "aclrtIpcMemSetAttr fail. return[%d], para: name: %s, type: %u, attr: %llu",
1154 : __func__, HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, name, type, attr), HCCL_E_RUNTIME);
1155 0 : return HCCL_SUCCESS;
1156 : #else
1157 : HCCL_ERROR("Call aclrtIpcMemSetAttr not support");
1158 : return HCCL_E_NOT_SUPPORT;
1159 : #endif
1160 : }
1161 :
1162 0 : HcclResult hrtIpcOpenMemory(void **ptr, const u8 *name)
1163 : {
1164 0 : CHK_PTR_NULL(ptr);
1165 0 : CHK_PTR_NULL(name);
1166 : #ifndef HCCD
1167 : // flag 预留字段填 0
1168 0 : aclError ret = aclrtIpcMemImportByKey(ptr, reinterpret_cast<const char *>(name), 0UL);
1169 : #else
1170 : static auto funcPtr = (aclError(*)(void**, const char*, uint64_t))g_dlAcl.Handle<ACL_RT_IPC_MEM_IMPORT_BY_KEY>();
1171 : CHK_PTR_NULL(funcPtr);
1172 : aclError ret = funcPtr(ptr, reinterpret_cast<const char *>(name), 0UL);
1173 : #endif
1174 0 : RPT_CALL_ERR(ret != ACL_SUCCESS, "aclrtIpcMemImportByKey failed. return[%d], ptr[%p], name[%s]", ret, ptr, name);
1175 0 : CHK_PRT_RET(ret == ACL_ERROR_RT_MEMORY_ALLOCATION, HCCL_ERROR("[Open][IpcMemory]errNo[0x%016llx] "\
1176 : "rtIpc memory allocation error. return[%d], para: ptr[%p], name[%s]",
1177 : HCCL_ERROR_CODE(HCCL_E_MEMORY), ret, *ptr, name), HCCL_E_MEMORY);
1178 :
1179 0 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Open][IpcMemory]errNo[0x%016llx] "\
1180 : "rtOpen ipc memory fail. return[%d], para: ptr[%p], name[%s]",
1181 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, *ptr, name), HCCL_E_RUNTIME);
1182 :
1183 0 : HCCL_INFO("Call aclrtIpcMemImportByKey, return value[%d], para: ptr[%p], name[%s].", ret, *ptr, name);
1184 :
1185 0 : return HCCL_SUCCESS;
1186 : }
1187 :
1188 0 : HcclResult hrtIpcSetMemoryPid(const u8 *name, int pid[], int num)
1189 : {
1190 0 : CHK_PTR_NULL(name);
1191 0 : CHK_PTR_NULL(pid);
1192 : #ifndef HCCD
1193 0 : aclError ret = aclrtIpcMemSetImportPid(reinterpret_cast<const char *>(name), pid, static_cast<size_t>(num));
1194 : #else
1195 : static auto funcPtr = (aclError(*)(const char *, int32_t *, size_t))g_dlAcl.Handle<ACL_RT_IPC_MEM_SET_IMPORT_PID>();
1196 : CHK_PTR_NULL(funcPtr);
1197 : aclError ret = funcPtr(reinterpret_cast<const char *>(name), pid, static_cast<size_t>(num));
1198 : #endif
1199 0 : CHK_PRT_RET(ret != ACL_SUCCESS,
1200 : HCCL_ERROR("[Set][IpcMemoryPid]errNo[0x%016llx] rtSet ipc memory pid fail. return[%d], num[%d], name[%s]",
1201 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, num, name),
1202 : HCCL_E_RUNTIME);
1203 0 : HCCL_INFO("Call aclrtIpcMemSetImportPid, return value[%d], num[%d], name[%s].", ret, num, name);
1204 :
1205 0 : return HCCL_SUCCESS;
1206 : }
1207 :
1208 1 : HcclResult hrtSetIpcMemorySuperPodPid(const u8 *name, s32 peerSdid, s32 peerPid[], s32 pidNum)
1209 : {
1210 : #ifndef HCCD
1211 1 : CHK_PTR_NULL(name);
1212 1 : CHK_PTR_NULL(peerPid);
1213 :
1214 : // 批量设置共享内存的 SDID
1215 1 : aclrtServerPid serverPid = {};
1216 1 : serverPid.sdid = static_cast<u32>(peerSdid); // 白名单 Server Device Id,整网设备编号,配置在 BIOS 中
1217 1 : serverPid.pid = peerPid; // Host 侧进程 ID 白名单数组
1218 1 : serverPid.num = static_cast<size_t>(pidNum); // pid 数组长度
1219 1 : aclError ret = aclrtIpcMemImportPidInterServer(reinterpret_cast<const char *>(name), &serverPid, 1U);
1220 1 : if (ret != ACL_SUCCESS) {
1221 0 : std::string pidStr;
1222 0 : for (int i = 0; i < pidNum; ++i) {
1223 0 : pidStr += std::to_string(*(peerPid + i)) + " ";
1224 : }
1225 0 : HCCL_ERROR("[Set][IpcMemorySuperPodPid]errNo[0x%016llx] "\
1226 : "rtSet ipc memory pid fail. return[%d], name[%s], peerSdid[%016llx], peerPid[%s], pidNum[%d]",
1227 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, name, peerSdid, pidStr.c_str(), pidNum);
1228 0 : return HCCL_E_RUNTIME;
1229 0 : }
1230 1 : HCCL_INFO("Call aclrtIpcMemImportPidInterServer, return value[%d], name[%s], peerSdid[%016llx], "\
1231 : "peerPid[%d], pidNum[%d].", ret, name, peerSdid, *peerPid, pidNum);
1232 1 : return HCCL_SUCCESS;
1233 : #else
1234 : HCCL_ERROR("[hrtSetIpcMemorySuperPodPid]Does not support this interface.");
1235 : return HCCL_E_NOT_SUPPORT;
1236 : #endif
1237 : }
1238 :
1239 0 : HcclResult hrtDevMemAlignWithPage(void* &ptr, u64 &size)
1240 : {
1241 : // 参数有效性检查
1242 0 : CHK_PTR_NULL(ptr);
1243 :
1244 : // 获取页表属性大小
1245 0 : HcclRtPointAttr ptrAttr = nullptr;
1246 0 : HcclResult ret = hrtMallocHost(&ptrAttr, sizeof(aclrtPtrAttributes));
1247 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[hrtDevMemAlignWithPage]runtime malloc host fail. return[%d]",
1248 : ret), HCCL_E_INTERNAL);
1249 :
1250 0 : ret = hrtGetPointAttr(ptrAttr, ptr);
1251 0 : if (ret != HCCL_SUCCESS) {
1252 0 : ret = hrtFreeHost(ptrAttr);
1253 0 : ptrAttr = nullptr;
1254 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[hrtDevMemAlignWithPage]runtime free host fail.return[%d]",
1255 : ret), HCCL_E_INTERNAL);
1256 0 : HCCL_ERROR("[hrtDevMemAlignWithPage]runtime get point attr fail. return[%d]", ret);
1257 0 : return HCCL_E_INTERNAL;
1258 : }
1259 0 : int32_t pageSize = (reinterpret_cast<aclrtPtrAttributes *>(ptrAttr))->pageSize;
1260 0 : CHK_PRT_RET(pageSize < 0,
1261 : {
1262 : ret = hrtFreeHost(ptrAttr);
1263 : ptrAttr = nullptr;
1264 : HCCL_ERROR("[hrtDevMemAlignWithPage]ptr[%p] pageSize[%d] is invalid", ptr, pageSize);
1265 : }, HCCL_E_DRV);
1266 0 : HCCL_INFO("[hrtDevMemAlignWithPage]get pageSize[%d]", pageSize);
1267 0 : ret = hrtFreeHost(ptrAttr);
1268 0 : ptrAttr = nullptr;
1269 0 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[hrtDevMemAlignWithPage]runtime free host fail. return[%d]",
1270 : ret), HCCL_E_INTERNAL);
1271 :
1272 : // 按照page_size = 0当做没有跨进程映射对齐要求
1273 0 : if (pageSize == 0) {
1274 0 : u64 offset = 0;
1275 0 : size = size + offset;
1276 0 : return HCCL_SUCCESS;
1277 : }
1278 : // 按页表大小对齐指针
1279 0 : u64 tmpPtr = reinterpret_cast<u64>(ptr);
1280 0 : ptr = reinterpret_cast<void *>((reinterpret_cast<u64>(ptr)) & (~(static_cast<u64>(pageSize) - 1)));
1281 0 : u64 offset = tmpPtr - reinterpret_cast<u64>(ptr);
1282 :
1283 : // 计算size值
1284 0 : size = size + offset;
1285 :
1286 0 : return HCCL_SUCCESS;
1287 : }
1288 :
1289 : #endif
1290 :
1291 : #if T_DESC("host memory管理", true)
1292 :
1293 2038 : HcclResult hrtMallocHost(void **hostPtr, u64 size)
1294 : {
1295 : // 参数有效性检查
1296 2038 : CHK_PTR_NULL(hostPtr);
1297 : aclrtMallocAttrValue moduleIdValue;
1298 2038 : moduleIdValue.moduleId = HCCL;
1299 2038 : aclrtMallocAttribute attrs{.attr = ACL_RT_MEM_ATTR_MODULE_ID, .value = moduleIdValue};
1300 2038 : aclrtMallocConfig cfg{.attrs = &attrs, .numAttrs = 1};
1301 : #ifndef HCCD
1302 2038 : aclError ret = aclrtMallocHostWithCfg(hostPtr, size, &cfg);
1303 : #else
1304 : static auto funcPtr =
1305 : (aclError(*)(void **, uint64_t, aclrtMallocConfig *))g_dlAcl.Handle<ACL_RT_MALLOC_HOST_WITH_CFG>();
1306 : CHK_PTR_NULL(funcPtr);
1307 : aclError ret = funcPtr(hostPtr, size, &cfg);
1308 : #endif
1309 2054 : RPT_ENV_ERR((ret != ACL_SUCCESS), "EI0007", std::vector<std::string>({"resource_type", "resource_info"}), \
1310 : std::vector<std::string>({"HostMemory", std::string("MallocHost, size:") + std::to_string(size)+ " bytes"}));
1311 :
1312 2044 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[%s][%s]errNo[0x%016llx] rt malloc host fail. return[%d], "\
1313 : "para: hostPtr[%p], size[%llu Byte].", LOG_KEYWORDS_INIT_GROUP.c_str(), LOG_KEYWORDS_RESOURCE.c_str(),
1314 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, *hostPtr, size), HCCL_E_RUNTIME);
1315 2043 : PLF_CONFIG_DEBUG(PLF_RES, "Malloc HostMem para: hostPtr[%p], size[%llu Byte]", *hostPtr, size);
1316 2043 : return HCCL_SUCCESS;
1317 3 : }
1318 :
1319 2040 : HcclResult hrtFreeHost(void *hostPtr)
1320 : {
1321 : // 参数有效性检查
1322 2040 : CHK_PTR_NULL(hostPtr);
1323 2040 : PLF_CONFIG_DEBUG(PLF_RES, "Free HostMem para: hostPtr[%p].", hostPtr);
1324 : #ifndef HCCD
1325 2043 : aclError ret = aclrtFreeHost(hostPtr);
1326 : #else
1327 : static auto funcPtr = (aclError(*)(void*))g_dlAcl.Handle<ACL_RT_FREE_HOST>();
1328 : CHK_PTR_NULL(funcPtr);
1329 : aclError ret = funcPtr(hostPtr);
1330 : #endif
1331 2042 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Free][Host]errNo[0x%016llx] rt free host fail. return[%d], "\
1332 : "para: hostPtr[%p].", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, hostPtr), HCCL_E_RUNTIME);
1333 2042 : HCCL_DEBUG("Call aclrtFreeHost, return value[%d].", ret);
1334 2042 : return HCCL_SUCCESS;
1335 : }
1336 :
1337 : #endif
1338 :
1339 : #if T_DESC("stream管理", true)
1340 :
1341 0 : HcclResult hrtStreamActive(HcclRtStream activeStream, HcclRtStream stream)
1342 : {
1343 : #ifndef HCCD
1344 : // 参数有效性检查
1345 0 : CHK_PTR_NULL(activeStream);
1346 0 : CHK_PTR_NULL(stream);
1347 :
1348 0 : aclrtStream rtActiveStream = activeStream;
1349 0 : aclrtStream rtStream = stream;
1350 0 : aclError ret = aclrtActiveStream(rtActiveStream, rtStream);
1351 0 : HCCL_DEBUG("Call aclrtActiveStream, return value[%d].", ret);
1352 0 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Activate][Stream]errNo[0x%016llx] "\
1353 : "rt stream active fail. return[%d].", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret), HCCL_E_RUNTIME);
1354 :
1355 0 : return HCCL_SUCCESS;
1356 : #else
1357 : HCCL_ERROR("[hrtStreamActive]Does not support this interface.");
1358 : return HCCL_E_NOT_SUPPORT;
1359 : #endif
1360 : }
1361 :
1362 2775 : HcclResult hrtGetStreamId(HcclRtStream stream, s32 &streamId)
1363 : {
1364 : #ifndef HCCD
1365 : // 参数有效性检查
1366 2775 : CHK_PTR_NULL(stream);
1367 :
1368 2775 : aclrtStream aclStream = stream;
1369 2775 : aclError ret = aclrtStreamGetId(aclStream, &streamId);
1370 :
1371 2778 : HCCL_DEBUG("Call aclrtStreamGetId, return value[%d] streamId[%d].", ret, streamId);
1372 2822 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Get][StreamId]errNo[0x%016llx] "\
1373 : "rt get stream ID fail. return[%d].", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret), HCCL_E_RUNTIME);
1374 :
1375 2822 : return HCCL_SUCCESS;
1376 : #else
1377 : HCCL_ERROR("[hrtGetStreamId]Does not support this interface.");
1378 : return HCCL_E_NOT_SUPPORT;
1379 : #endif
1380 : }
1381 :
1382 312 : HcclResult hrtGetTaskIdAndStreamID(u32 &taskId, u32 &streamId)
1383 : {
1384 : #ifndef HCCD
1385 312 : rtError_t ret = rtGetTaskIdAndStreamID(&taskId, &streamId);
1386 312 : HCCL_DEBUG("Call rtGetTaskIdAndStreamId, return value[%d], para: taskId[%u], streamId[%u].", \
1387 : ret, taskId, streamId);
1388 312 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[Get][TaskIdAndStreamID]errNo[0x%016llx] "\
1389 : "rt get task ID and stream ID fail. return[%d].", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret), HCCL_E_RUNTIME);
1390 :
1391 312 : return HCCL_SUCCESS;
1392 : #else
1393 : HCCL_ERROR("[hrtGetTaskIdAndStreamID]Does not support this interface.");
1394 : return HCCL_E_NOT_SUPPORT;
1395 : #endif
1396 : }
1397 :
1398 : #endif
1399 :
1400 : #if T_DESC("event 同步机制", true)
1401 0 : HcclResult hrtEventCreate(aclrtEvent *event)
1402 : {
1403 : #ifndef HCCD
1404 0 : CHK_PTR_NULL(event);
1405 0 : aclError ret = aclrtCreateEvent(event);
1406 0 : RPT_ENV_ERR(ret != ACL_SUCCESS, "EI0007", std::vector<std::string>({"resource_type","resource_info"}),\
1407 : std::vector<std::string>({"event", "null"}));
1408 :
1409 0 : HCCL_DEBUG("Call aclrtCreateEvent, return value[%d], para: event[%p]", ret, *event);
1410 0 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[%s][%s]errNo[0x%016llx] rt event create, return[%d], "\
1411 : "event[%p]", LOG_KEYWORDS_INIT_GROUP.c_str(), LOG_KEYWORDS_RESOURCE.c_str(), HCCL_ERROR_CODE(HCCL_E_RUNTIME),
1412 : ret, event), HCCL_E_RUNTIME);
1413 0 : return HCCL_SUCCESS;
1414 : #else
1415 : HCCL_ERROR("[hrtEventCreate]Does not support this interface.");
1416 : return HCCL_E_NOT_SUPPORT;
1417 : #endif
1418 : }
1419 :
1420 1 : HcclResult hrtEventDestroy(HcclRtEvent event)
1421 : {
1422 : #ifndef HCCD
1423 1 : CHK_PTR_NULL(event);
1424 1 : aclError ret = aclrtDestroyEvent(event);
1425 1 : HCCL_DEBUG("Call aclrtDestroyEvent, return value[%d], para: event[%p]", ret, event);
1426 1 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Destroy][Event]errNo[0x%016llx] rt event destroy, return[%d], "\
1427 : "event[%p]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, event), HCCL_E_RUNTIME);
1428 1 : return HCCL_SUCCESS;
1429 : #else
1430 : HCCL_ERROR("[hrtEventDestroy]Does not support this interface.");
1431 : return HCCL_E_NOT_SUPPORT;
1432 : #endif
1433 : }
1434 :
1435 0 : HcclResult hrtEventRecord(aclrtEvent event, aclrtStream stream)
1436 : {
1437 : #ifndef HCCD
1438 0 : CHK_PTR_NULL(event);
1439 0 : CHK_PTR_NULL(stream);
1440 0 : aclError ret = aclrtRecordEvent(event, stream);
1441 0 : HCCL_DEBUG("Call aclrtRecordEvent, return value[%d], para: event[%p]", ret, event);
1442 0 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Record][Event]errNo[0x%016llx] rt event record, return[%d], "\
1443 : "event[%p]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, event), HCCL_E_RUNTIME);
1444 0 : return HCCL_SUCCESS;
1445 : #else
1446 : HCCL_ERROR("[hrtEventRecord]Does not support this interface.");
1447 : return HCCL_E_NOT_SUPPORT;
1448 : #endif
1449 : }
1450 :
1451 0 : HcclResult hrtStreamWaitEvent(aclrtStream stream, aclrtEvent event)
1452 : {
1453 : #ifndef HCCD
1454 0 : CHK_PTR_NULL(event);
1455 0 : CHK_PTR_NULL(stream);
1456 0 : aclError ret = aclrtStreamWaitEvent(stream, event);
1457 0 : HCCL_DEBUG("Call aclrtStreamWaitEvent, return value[%d], para: event[%p]", ret, event);
1458 0 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("errNo[0x%016llx] rt stream wait event, return[%d], event[%p], ",\
1459 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, event), HCCL_E_RUNTIME);
1460 0 : return HCCL_SUCCESS;
1461 : #else
1462 : HCCL_ERROR("[hrtStreamWaitEvent]Does not support this interface.");
1463 : return HCCL_E_NOT_SUPPORT;
1464 : #endif
1465 : }
1466 :
1467 0 : HcclResult hrtEventQuery(aclrtEvent event)
1468 : {
1469 : #ifndef HCCD
1470 0 : CHK_PTR_NULL(event);
1471 0 : aclrtEventRecordedStatus status = ACL_EVENT_RECORDED_STATUS_NOT_READY;
1472 0 : aclError ret = aclrtQueryEventStatus(event, &status);
1473 0 : HCCL_DEBUG("Call aclrtQueryEventStatus, return value[%d], status[%d], para: event[%p]", ret, status, event);
1474 0 : CHK_PRT_RET(ret != ACL_SUCCESS,
1475 : HCCL_ERROR("[aclrtQueryEventStatus] query event status failed, event:%p, return value[%d], status[%d].",
1476 : event, ret, status), HCCL_E_RUNTIME);
1477 0 : return (status == ACL_EVENT_RECORDED_STATUS_COMPLETE) ? HCCL_SUCCESS : HCCL_E_RUNTIME;
1478 : #else
1479 : HCCL_ERROR("[hrtEventQuery]Does not support this interface.");
1480 : return HCCL_E_NOT_SUPPORT;
1481 : #endif
1482 : }
1483 : #endif
1484 :
1485 :
1486 : #if T_DESC("RDMA异步", true)
1487 : // 进行单元测试时对改函数打桩可完成条件测试
1488 0 : bool CompareDevType(DevType left, DevType right)
1489 : {
1490 0 : return left == right;
1491 : }
1492 :
1493 78 : HcclResult hrtGetNotifySize(u32 ¬ifySize)
1494 : {
1495 : #ifndef HCCD
1496 : DevType deviceType;
1497 78 : CHK_RET(hrtGetDeviceType(deviceType));
1498 78 : if (deviceType == DevType::DEV_TYPE_910) {
1499 78 : notifySize = 8; // 910A 每个notify占8个字节
1500 0 : } else if (deviceType == DevType::DEV_TYPE_910B || deviceType == DevType::DEV_TYPE_910_93) {
1501 0 : notifySize = 4; // 910B & 910_93 每个notify占4个字节
1502 : } else {
1503 0 : notifySize = 8; // 其余芯片类型每个notify占8个字节
1504 : }
1505 78 : return HCCL_SUCCESS;
1506 : #else
1507 : HCCL_ERROR("[hrtGetNotifySize]Does not support this interface.");
1508 : return HCCL_E_NOT_SUPPORT;
1509 : #endif
1510 : }
1511 :
1512 1102 : HcclResult hrtNotifyGetOffset(HcclRtNotify notify, u64 &offset)
1513 : {
1514 : #ifndef HCCD
1515 1102 : CHK_PTR_NULL(notify);
1516 0 : auto getEventOffsetFuncPtr = [](HcclRtNotify notify, u64 &offset) -> s32 {
1517 0 : u32 eventId = 0;
1518 0 : aclError ret = aclrtGetEventId(notify, &eventId);
1519 0 : CHK_PRT_RET(ret != ACL_SUCCESS,
1520 : HCCL_ERROR("[aclrtGetEventId] get event id failed, event:%p, return value[%d].", notify, ret),
1521 : HCCL_E_RUNTIME);
1522 0 : offset = eventId * 0x8;
1523 0 : HCCL_INFO("event id[%u] get offset[%llu]", eventId, offset);
1524 0 : return HCCL_SUCCESS;
1525 : };
1526 :
1527 1102 : REPLACE_NOTIFY_WITH_EVENT(rtNotifyGetAddrOffset(notify, reinterpret_cast<uint64_t *>(&offset)),
1528 : getEventOffsetFuncPtr(notify, offset));
1529 1102 : return HCCL_SUCCESS;
1530 : #else
1531 : HCCL_ERROR("[hrtNotifyGetOffset]Does not support this interface.");
1532 : return HCCL_E_NOT_SUPPORT;
1533 : #endif
1534 : }
1535 :
1536 : // hrtNotifyCreate 要求当前线程设置过 setDevice
1537 624 : HcclResult hrtNotifyCreate(s32 deviceId, aclrtNotify *notify)
1538 : {
1539 : #ifndef HCCD
1540 624 : CHK_PTR_NULL(notify);
1541 0 : auto creatEventFuncPtr = [](rtNotify_t *notify) -> s32 {
1542 0 : CHK_RT_RET(aclrtCreateEvent(notify));
1543 0 : aclrtStream stream = nullptr;
1544 0 : aclError ret = aclrtCreateStream(&stream);
1545 0 : if (ret != ACL_SUCCESS) {
1546 0 : HCCL_ERROR("[hrtNotifyCreate] aclrtCreateStream fail, ret[%d], destroy event.", ret);
1547 0 : aclrtDestroyEvent(*notify);
1548 0 : return ret;
1549 : }
1550 0 : ret = aclrtRecordEvent(*notify, stream);
1551 0 : if (ret != ACL_SUCCESS) {
1552 0 : HCCL_ERROR("[hrtNotifyCreate] aclrtRecordEvent fail, ret[%d], destroy stream and event.", ret);
1553 0 : aclrtDestroyStream(stream);
1554 0 : aclrtDestroyEvent(*notify);
1555 0 : return ret;
1556 : }
1557 0 : ret = aclrtResetEvent(*notify, stream);
1558 0 : if (ret != ACL_SUCCESS) {
1559 0 : HCCL_ERROR("[hrtNotifyCreate] aclrtResetEvent fail, ret[%d], destroy stream and event.", ret);
1560 0 : aclrtDestroyStream(stream);
1561 0 : aclrtDestroyEvent(*notify);
1562 0 : return ret;
1563 : }
1564 0 : ret = aclrtSynchronizeStream(stream);
1565 0 : if (ret != ACL_SUCCESS) {
1566 0 : HCCL_ERROR("[hrtNotifyCreate] aclrtSynchronizeStream fail, ret[%d], destroy stream and event.", ret);
1567 0 : aclrtDestroyStream(stream);
1568 0 : aclrtDestroyEvent(*notify);
1569 0 : return ret;
1570 : }
1571 0 : ret = aclrtDestroyStream(stream);
1572 0 : if (ret != ACL_SUCCESS) {
1573 0 : HCCL_ERROR("[hrtNotifyCreate] aclrtDestroyStream fail, ret[%d], destroy event.", ret);
1574 0 : aclrtDestroyEvent(*notify);
1575 0 : return ret;
1576 : }
1577 0 : return 0;
1578 : }; // 使用event替换notify后需要获取event id,get event id 前必须先record,因此在创建event时执行一把record
1579 :
1580 : // aclrtCreateNotify 中通过 aclrtGetDevice 获取 deviceId,所以要求当前线程设置过 setDevice
1581 : // flag 预留字段填 0
1582 624 : REPLACE_NOTIFY_WITH_EVENT(aclrtCreateNotify(notify, ACL_NOTIFY_DEFAULT), creatEventFuncPtr(notify));
1583 624 : HCCL_DEBUG("[hrtNotifyCreate] deviceId[%d]", deviceId);
1584 :
1585 624 : u32 notifyId = 0;
1586 624 : REPLACE_NOTIFY_WITH_EVENT(aclrtGetNotifyId(*notify, ¬ifyId), aclrtGetEventId(*notify, ¬ifyId));
1587 624 : PLF_CONFIG_INFO(PLF_RES, "Create Notify para: deviceId[%d] notifyId[%u]", deviceId, notifyId);
1588 624 : return HCCL_SUCCESS;
1589 : #else
1590 : HCCL_ERROR("[hrtNotifyCreate]Does not support this interface.");
1591 : return HCCL_E_NOT_SUPPORT;
1592 : #endif
1593 : }
1594 :
1595 1106 : HcclResult hrtNotifyDestroy(rtNotify_t notify)
1596 : {
1597 : #ifndef HCCD
1598 1106 : CHK_PTR_NULL(notify);
1599 :
1600 1106 : u32 notifyId = 0;
1601 1106 : REPLACE_NOTIFY_WITH_EVENT(aclrtGetNotifyId(notify, ¬ifyId), aclrtGetEventId(notify, ¬ifyId));
1602 1106 : s32 deviceId = GetDeviceLogicalId();
1603 1106 : PLF_CONFIG_INFO(PLF_RES, "Destroy Notify para: deviceId[%d] notifyId[%u]", deviceId, notifyId);
1604 1106 : HCCL_INFO("Destroy Notify begin, para: deviceId[%d] notifyId[%u]", deviceId, notifyId);
1605 1106 : REPLACE_NOTIFY_WITH_EVENT(aclrtDestroyNotify(notify), aclrtDestroyEvent(notify));
1606 1106 : HCCL_INFO("Destroy Notify end, para: deviceId[%d] notifyId[%u]", deviceId, notifyId);
1607 1106 : return HCCL_SUCCESS;
1608 : #else
1609 : HCCL_ERROR("[hrtNotifyDestroy]Does not support this interface.");
1610 : return HCCL_E_NOT_SUPPORT;
1611 : #endif
1612 : }
1613 :
1614 1 : HcclResult hrtNotifyRecord(rtNotify_t notify, rtStream_t stream)
1615 : {
1616 : #ifndef HCCD
1617 1 : u32 streamId = 0;
1618 1 : u32 taskId = 0;
1619 1 : CHK_PTR_NULL(notify);
1620 1 : CHK_PTR_NULL(stream);
1621 1 : REPLACE_NOTIFY_WITH_EVENT(aclrtRecordNotify(notify, stream), aclrtRecordEvent(notify, stream));
1622 1 : CHK_RT_RET(rtGetTaskIdAndStreamID(&taskId, &streamId));
1623 1 : HCCL_INFO("hrtNotifyRecord notify[%p] taskId[%u] streamId[%u]", notify, taskId, streamId);
1624 1 : return HCCL_SUCCESS;
1625 : #else
1626 : HCCL_ERROR("[hrtNotifyRecord]Does not support this interface.");
1627 : return HCCL_E_NOT_SUPPORT;
1628 : #endif
1629 : }
1630 :
1631 1 : HcclResult hrtNotifyWaitWithTimeOut(rtNotify_t notify, rtStream_t stream, uint32_t timeOut)
1632 : {
1633 : #ifndef HCCD
1634 1 : CHK_PTR_NULL(notify);
1635 1 : CHK_PTR_NULL(stream);
1636 :
1637 1 : u32 streamId = 0;
1638 1 : u32 taskId = 0;
1639 0 : auto eventWaitFuncPtr = [](rtNotify_t notify, rtStream_t stream) -> s32 {
1640 0 : CHK_RT_RET(aclrtStreamWaitEvent(stream, notify));
1641 0 : CHK_RT_RET(aclrtResetEvent(notify, stream));
1642 0 : return 0;
1643 : };
1644 1 : REPLACE_NOTIFY_WITH_EVENT(aclrtWaitAndResetNotify(notify, stream, timeOut), eventWaitFuncPtr(stream, notify));
1645 1 : CHK_RT_RET(rtGetTaskIdAndStreamID(&taskId, &streamId));
1646 1 : HCCL_INFO("hrtNotifyWaitWithTimeOut notify[%p] taskId[%u] streamId[%u]", notify, taskId, streamId);
1647 1 : return HCCL_SUCCESS;
1648 : #else
1649 : HCCL_ERROR("[hrtNotifyWaitWithTimeOut]Does not support this interface.");
1650 : return HCCL_E_NOT_SUPPORT;
1651 : #endif
1652 : }
1653 :
1654 0 : HcclResult hrtNotifyReset(aclrtNotify notify)
1655 : {
1656 : #ifndef HCCD
1657 0 : HCCL_INFO("hrtNotifyReset notify[%p]", notify);
1658 0 : CHK_PTR_NULL(notify);
1659 0 : CHK_RT_RET(aclrtNotifyBatchReset(¬ify, 1));
1660 0 : return HCCL_SUCCESS;
1661 : #else
1662 : HCCL_ERROR("[hrtNotifyRecord]Does not support this interface.");
1663 : return HCCL_E_NOT_SUPPORT;
1664 : #endif
1665 : }
1666 : #endif
1667 :
1668 : #if T_DESC("EnableP2P", true)
1669 :
1670 0 : HcclResult hrtEnableP2P(u32 deviceLogicId, u32 devicePhyId)
1671 : {
1672 : #ifndef HCCD
1673 0 : rtError_t ret = rtEnableP2P(deviceLogicId, devicePhyId, 0);
1674 :
1675 0 : HCCL_INFO("rt enableP2P deviceLogicId[%u] and devicePhyId[%u] fail[%d]", deviceLogicId, devicePhyId, ret);
1676 :
1677 0 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[Enable][P2P]errNo[0x%016llx] rt enableP2P deviceLogicId[%u] and "\
1678 : "devicePhyId[%u] fail[%d]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), deviceLogicId, devicePhyId, ret), HCCL_E_RUNTIME);
1679 :
1680 0 : return HCCL_SUCCESS;
1681 : #else
1682 : HCCL_ERROR("[hrtEnableP2P]Does not support this interface.");
1683 : return HCCL_E_NOT_SUPPORT;
1684 : #endif
1685 : }
1686 :
1687 0 : HcclResult hrtDisableP2P(u32 deviceLogicId, u32 devicePhyId)
1688 : {
1689 : #ifndef HCCD
1690 0 : rtError_t ret = rtDisableP2P(deviceLogicId, devicePhyId);
1691 :
1692 0 : HCCL_INFO("rt disableP2P deviceLogicId[%u] and devicePhyId[%u] fail[%d]", deviceLogicId, devicePhyId, ret);
1693 :
1694 0 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[Disable][P2P]errNo[0x%016llx] rt disableP2P deviceLogicId[%u] and "\
1695 : "devicePhyId[%u] fail[%d]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), deviceLogicId, devicePhyId, ret), HCCL_E_RUNTIME);
1696 0 : return HCCL_SUCCESS;
1697 : #else
1698 : HCCL_ERROR("[hrtDisableP2P]Does not support this interface.");
1699 : return HCCL_E_NOT_SUPPORT;
1700 : #endif
1701 : }
1702 :
1703 0 : HcclResult hrtGetP2PStatus(u32 deviceLogicId, u32 devicePhyId, uint32_t *status)
1704 : {
1705 : #ifndef HCCD
1706 0 : rtError_t ret = rtGetP2PStatus(deviceLogicId, devicePhyId, status);
1707 :
1708 0 : HCCL_DEBUG("rt getp2pstatus deviceLogicId[%u] and devicePhyId[%u] fail[%d], status[%u]",
1709 : deviceLogicId, devicePhyId, ret, *status);
1710 0 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[Get][P2PStatus]errNo[0x%016llx]Call rtGetP2PStatus failed, "
1711 : "ret[%d], deviceLogicId[%u], devicePhyId[%u]",
1712 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, deviceLogicId, devicePhyId), HCCL_E_RUNTIME);
1713 0 : return HCCL_SUCCESS;
1714 : #else
1715 : HCCL_ERROR("[hrtGetP2PStatus]Does not support this interface.");
1716 : return HCCL_E_NOT_SUPPORT;
1717 : #endif
1718 : }
1719 : #endif
1720 :
1721 2 : s32 GetMsTimeFromExecTimeout(s32 execTimeOut)
1722 : {
1723 2 : s64 timeOutMs = 0;
1724 2 : timeOutMs = (execTimeOut + HCCL_EXEC_TIME_OUT_OFFSET_S) * TIME_S_TO_MS;
1725 2 : timeOutMs = (timeOutMs > 0x7FFFFFFF) ? 0x7FFFFFFF : timeOutMs;
1726 2 : return static_cast<s32>(timeOutMs & (0x7FFFFFFF));
1727 : }
1728 :
1729 2 : HcclResult hcclStreamSynchronize(HcclRtStream stream, s32 execTimeOut)
1730 : {
1731 : #ifndef HCCD
1732 2 : CHK_PTR_NULL(stream);
1733 2 : aclError ret = aclrtSynchronizeStreamWithTimeout(stream, GetMsTimeFromExecTimeout(execTimeOut));
1734 2 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Synchronize][Stream]errNo[0x%016llx] rt "\
1735 : "streamsynchronizewithtimeout fail. return[%d].", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret), HCCL_E_RUNTIME);
1736 2 : return HCCL_SUCCESS;
1737 : #else
1738 : HCCL_ERROR("[hcclStreamSynchronize]Does not support this interface.");
1739 : return HCCL_E_NOT_SUPPORT;
1740 : #endif
1741 : }
1742 :
1743 497 : HcclResult hrtTaskAbortHandleCallback(aclrtDeviceTaskAbortCallback callback, void *args)
1744 : {
1745 : #ifndef HCCD
1746 497 : aclError ret = aclrtSetDeviceTaskAbortCallback("HCCL", callback, args);
1747 497 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Reg][TaskAbortCallBack]errNo[0x%016llx] rt reg taskabortcallback "\
1748 : "fail. return[%d], para: callback[%p].", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, callback), HCCL_E_RUNTIME);
1749 497 : return HCCL_SUCCESS;
1750 : #else
1751 : HCCL_ERROR("[hrtTaskAbortHandleCallback]Does not support this interface.");
1752 : return HCCL_E_NOT_SUPPORT;
1753 : #endif
1754 : }
1755 :
1756 467 : HcclResult PrintMemoryAttr(const void *memAddr)
1757 : {
1758 : #ifndef HCCD
1759 467 : if (LIKELY(!HcclCheckLogLevel(HCCL_LOG_INFO))) {
1760 0 : return HCCL_SUCCESS;
1761 : }
1762 :
1763 : HcclResult ret;
1764 : aclrtPtrAttributes memAttr;
1765 467 : CHK_PTR_NULL(memAddr);
1766 467 : s32 sRet = memset_s(&memAttr, sizeof(aclrtPtrAttributes), 0, sizeof(aclrtPtrAttributes));
1767 467 : CHK_PRT_RET(sRet != EOK, HCCL_ERROR("[Print][MemoryAttr]errNo[0x%016llx]memory set 0 failed for memAttr. "\
1768 : "params: dest[%p], destMaxSize[%zu], count[%zu]", HCOM_ERROR_CODE(HCCL_E_MEMORY), &memAttr,
1769 : sizeof(aclrtPtrAttributes), sizeof(aclrtPtrAttributes)), HCCL_E_MEMORY);
1770 467 : ret = hrtGetPointAttr(&memAttr, memAddr);
1771 467 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Print][MemoryAttr]errNo[0x%016llx] runtime get memory attr failed",
1772 : HCOM_ERROR_CODE(ret)), ret);
1773 467 : HCCL_INFO("memory attributes: address[%p], page size[%u]", memAddr, memAttr.pageSize);
1774 467 : return HCCL_SUCCESS;
1775 : #else
1776 : HCCL_ERROR("[PrintMemoryAttr]Does not support this interface.");
1777 : return HCCL_E_NOT_SUPPORT;
1778 : #endif
1779 : }
1780 359 : HcclResult hrtRegTaskFailCallbackByModule(rtTaskFailCallback callback)
1781 : {
1782 : #ifndef HCCD
1783 359 : rtError_t ret = rtRegTaskFailCallbackByModule("HCCL", callback);
1784 359 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[Reg][TaskFailCallback]errNo[0x%016llx] rt reg taskFailCallback "\
1785 : "fail. return[%d], para: callback[%p].", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, callback), HCCL_E_RUNTIME);
1786 359 : return HCCL_SUCCESS;
1787 : #else
1788 : HCCL_ERROR("[hrtRegTaskFailCallbackByModule]Does not support this interface.");
1789 : return HCCL_E_NOT_SUPPORT;
1790 : #endif
1791 : }
1792 :
1793 178 : HcclResult hrtGetStreamAvailableNum(u32 &maxStrCount)
1794 : {
1795 : #ifndef HCCD
1796 178 : aclError ret = aclrtGetStreamAvailableNum(&maxStrCount);
1797 178 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Get][StreamAvailableNum]errNo[0x%016llx] aclrtGetStreamAvailableNum "\
1798 : "fail. return[%d]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret), HCCL_E_RUNTIME);
1799 178 : return HCCL_SUCCESS;
1800 : #else
1801 : HCCL_ERROR("[hrtGetStreamAvailableNum]Does not support this interface.");
1802 : return HCCL_E_NOT_SUPPORT;
1803 : #endif
1804 : }
1805 :
1806 0 : HcclResult hrtSubscribeReport(u64 threadId, rtStream_t &stream)
1807 : {
1808 : #ifndef HCCD
1809 0 : aclError ret = aclrtSubscribeReport(threadId, stream);
1810 0 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[HostNic][RegStream]errNo[0x%016llx] aclrtSubscribeReport fail,"
1811 : "return[%d], para: threadId[%llu].", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, threadId), HCCL_E_RUNTIME);
1812 0 : return HCCL_SUCCESS;
1813 : #else
1814 : HCCL_ERROR("[hrtSubscribeReport]Does not support this interface.");
1815 : return HCCL_E_NOT_SUPPORT;
1816 : #endif
1817 : }
1818 0 : HcclResult hrtUnSubscribeReport(uint64_t threadId, aclrtStream &stream)
1819 : {
1820 : #ifndef HCCD
1821 0 : aclError ret = aclrtUnSubscribeReport(threadId, stream);
1822 0 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Close][HostNicThread]errNo[0x%016llx] aclrtUnSubscribeReport fail,"
1823 : "return[%d], para: threadId[%llu].", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, threadId), HCCL_E_RUNTIME);
1824 0 : return HCCL_SUCCESS;
1825 : #else
1826 : HCCL_ERROR("[hrtUnSubscribeReport]Does not support this interface.");
1827 : return HCCL_E_NOT_SUPPORT;
1828 : #endif
1829 : }
1830 0 : HcclResult hrtProcessReport(s32 timeout)
1831 : {
1832 : #ifndef HCCD
1833 0 : aclError ret = aclrtProcessReport(timeout);
1834 0 : if (ret != ACL_SUCCESS) {
1835 0 : HCCL_INFO("aclrtProcessReport timeout, return[%d]", ret);
1836 0 : return HCCL_E_TIMEOUT;
1837 : }
1838 0 : return HCCL_SUCCESS;
1839 : #else
1840 : HCCL_ERROR("[hrtProcessReport]Does not support this interface.");
1841 : return HCCL_E_NOT_SUPPORT;
1842 : #endif
1843 : }
1844 :
1845 1045 : HcclResult hrtDeviceGetBareTgid(s32 *pid)
1846 : {
1847 1045 : CHK_PTR_NULL(pid);
1848 : #ifndef HCCD
1849 1045 : aclError ret = aclrtDeviceGetBareTgid(pid);
1850 1045 : HCCL_DEBUG("Call rtDeviceGetBareTgid, return value[%d], rtGet pid[%u].", ret, *pid);
1851 1045 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Get][BareTgid]errNo[0x%016llx] rtGet pid fail, "
1852 : "return[%d], rtGet pid[%u]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, *pid), HCCL_E_RUNTIME);
1853 1045 : return HCCL_SUCCESS;
1854 : #else
1855 : if (g_workModeAicpu) {
1856 : // aicpu不使用PID。
1857 : *pid = 0;
1858 : return HCCL_SUCCESS;
1859 : }
1860 : HCCL_ERROR("[hrtDeviceGetBareTgid]Does not support this interface.");
1861 : return HCCL_E_NOT_SUPPORT;
1862 : #endif
1863 : }
1864 :
1865 0 : HcclResult hrtIpcOpenNotify(aclrtNotify* notify, const u8 *name)
1866 : {
1867 : #ifndef HCCD
1868 0 : CHK_PTR_NULL(notify);
1869 0 : CHK_PTR_NULL(name);
1870 :
1871 0 : aclError ret = aclrtNotifyImportByKey(notify, reinterpret_cast<const char *>(name), ACL_NOTIFY_DEFAULT);
1872 0 : HCCL_INFO("Call aclrtNotifyImportByKey, return value[%d] para: notify[%p], name[%s].", ret, *notify, name);
1873 0 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[rt][IpcOpenNotify]errNo[0x%016llx] rt ipc notify open fail,"\
1874 : "return[%d]. para: notify[%p], name[%s]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, *notify, name),
1875 : HCCL_E_RUNTIME);
1876 0 : return HCCL_SUCCESS;
1877 : #else
1878 : HCCL_ERROR("[hrtIpcOpenNotify]Does not support this interface.");
1879 : return HCCL_E_NOT_SUPPORT;
1880 : #endif
1881 : }
1882 :
1883 0 : HcclResult hrtSetIpcNotifyPid(aclrtNotify notify, int32_t pid[], int num)
1884 : {
1885 : #ifndef HCCD
1886 0 : CHK_PTR_NULL(notify);
1887 0 : CHK_PTR_NULL(pid);
1888 :
1889 0 : aclError ret = aclrtNotifySetImportPid(notify, pid, num);
1890 0 : HCCL_DEBUG("Call aclrtNotifySetImportPid, return value[%d]. Params: num[%d].", ret, num);
1891 0 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Set][IpcNotifyPid]errNo[0x%016llx] "
1892 : "rtSet ipc Notify pid fail. return[%d], num[%d]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, num), HCCL_E_RUNTIME);
1893 0 : return HCCL_SUCCESS;
1894 : #else
1895 : HCCL_ERROR("[hrtSetIpcNotifyPid]Does not support this interface.");
1896 : return HCCL_E_NOT_SUPPORT;
1897 : #endif
1898 : }
1899 :
1900 0 : HcclResult hrtSetIpcNotifySuperPodPid(rtNotify_t notify, s32 peerSdid, s32 peerPid[], s32 pidNum)
1901 : {
1902 : #ifndef HCCD
1903 0 : CHK_PTR_NULL(notify);
1904 0 : CHK_PTR_NULL(peerPid);
1905 :
1906 : // 批量设置共享 Notify 的 SDID
1907 0 : aclrtServerPid serverPid = {};
1908 0 : serverPid.sdid = static_cast<u32>(peerSdid); // 白名单 Server Device Id,整网设备编号,配置在 BIOS 中
1909 0 : serverPid.pid = peerPid; // 白名单进程 ID 数组
1910 0 : serverPid.num = static_cast<size_t>(pidNum); // pid 数组长度
1911 0 : aclError ret = aclrtNotifySetImportPidInterServer(notify, &serverPid, 1U); // 设置 1 组 SDID
1912 0 : if (ret != ACL_SUCCESS) {
1913 0 : std::string pidStr;
1914 0 : for (int i = 0; i < pidNum; ++i) {
1915 0 : pidStr += std::to_string(*(peerPid + i)) + " ";
1916 : }
1917 0 : HCCL_ERROR("[Set][IpcNotifyPid]errNo[0x%016llx] "
1918 : "rtSet ipc Notify pid fail. return[%d], notify[%p], peerSdid[%016llx], peerPid[%s], pidNum[%d]",
1919 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, notify, peerSdid, pidStr.c_str(), pidNum);
1920 0 : return HCCL_E_RUNTIME;
1921 0 : }
1922 0 : HCCL_DEBUG("Call aclrtNotifySetImportPidInterServer, return value[%d]. "\
1923 : "Params: notify[%p], peerSdid[%016llx], peerPid[%d], pidNum[%d].", ret, notify, peerSdid, *peerPid, pidNum);
1924 0 : return HCCL_SUCCESS;
1925 : #else
1926 : HCCL_ERROR("[hrtSetIpcNotifySuperPodPid]Does not support this interface.");
1927 : return HCCL_E_NOT_SUPPORT;
1928 : #endif
1929 : }
1930 :
1931 88 : HcclResult hrtCtxGetOverflowAddr(void **overflowAddr)
1932 : {
1933 : #ifndef HCCD
1934 88 : CHK_PTR_NULL(overflowAddr);
1935 :
1936 88 : aclError ret = aclrtCtxGetFloatOverflowAddr(overflowAddr);
1937 88 : HCCL_DEBUG("Call aclrtCtxGetFloatOverflowAddr, return value[%d].", ret);
1938 88 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[rt][aclrtCtxGetFloatOverflowAddr]errNo[0x%016llx] "
1939 : "rtCtx get overflow addr fail. return[%d]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret), HCCL_E_RUNTIME);
1940 88 : return HCCL_SUCCESS;
1941 : #else
1942 : HCCL_ERROR("[hrtCtxGetOverflowAddr]Does not support this interface.");
1943 : return HCCL_E_NOT_SUPPORT;
1944 : #endif
1945 : }
1946 :
1947 9 : HcclResult hrtReduceAsync(void* dst, uint64_t destMax, const void* src, uint64_t count, aclrtReduceKind kind,
1948 : aclDataType type, aclrtStream stream)
1949 : {
1950 : #ifndef HCCD
1951 9 : CHK_PTR_NULL(dst);
1952 9 : CHK_PTR_NULL(src);
1953 :
1954 : // reserve 预留字段填 nullptr
1955 9 : aclError ret = aclrtReduceAsync(dst, src, count, kind, type, stream, nullptr);
1956 9 : HCCL_DEBUG("Call aclrtReduceAsync, return value[%d]. para: dst[%p] destMax[%llu] src[%p] count[%llu] rtReduceOp[%d]"
1957 : " runtimeDataType[%d].", ret, dst, destMax, src, count, kind, type);
1958 9 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[rt][ReduceAsync]errNo[0x%016llx] rt Reduce async fail,"\
1959 : "return[%d]. para: dst[%p] destMax[%llu] src[%p] count[%llu] rtReduceOp[%d] runtimeDataType[%d].", \
1960 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, dst, destMax, src, count, kind, type), HCCL_E_RUNTIME);
1961 9 : return HCCL_SUCCESS;
1962 : #else
1963 : HCCL_ERROR("[hrtReduceAsync]Does not support this interface.");
1964 : return HCCL_E_NOT_SUPPORT;
1965 : #endif
1966 : }
1967 :
1968 0 : HcclResult hrtCallbackLaunch(aclrtCallback callBackFunc, void *fnData, aclrtStream stream, bool isBlock)
1969 : {
1970 : #ifndef HCCD
1971 0 : CHK_PTR_NULL(fnData);
1972 0 : aclrtCallbackBlockType blockType = isBlock ? ACL_CALLBACK_BLOCK : ACL_CALLBACK_NO_BLOCK;
1973 0 : aclError ret = aclrtLaunchCallback(callBackFunc, fnData, blockType, stream);
1974 0 : HCCL_DEBUG("Call aclrtLaunchCallback, return value[%d].", ret);
1975 0 : CHK_PRT_RET(ret != ACL_SUCCESS,
1976 : HCCL_ERROR("[rt][CallbackLaunch]callback launch failed, ret[%d], isBlock[%d]", ret, isBlock),
1977 : HCCL_E_RUNTIME);
1978 0 : return HCCL_SUCCESS;
1979 : #else
1980 : HCCL_ERROR("[hrtCallbackLaunch]Does not support this interface.");
1981 : return HCCL_E_NOT_SUPPORT;
1982 : #endif
1983 : }
1984 :
1985 0 : HcclResult hrtRDMASend(u32 qpn, u32 wqe_index, rtStream_t stream)
1986 : {
1987 : #ifndef HCCD
1988 0 : rtError_t ret = rtRDMASend(qpn, wqe_index, stream);
1989 0 : HCCL_DEBUG("Call rtRDMASend, return value[%d]. Params: qpn[%u] wqe_index[%u].", ret, qpn, wqe_index);
1990 0 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[rt][RdmaSend]errNo[0x%016llx] rt rdma send fail, "\
1991 : "return[%d]. para: qpn[%u] wqe_index[%u].", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, qpn, wqe_index),\
1992 : HCCL_E_RUNTIME);
1993 0 : return HCCL_SUCCESS;
1994 : #else
1995 : HCCL_ERROR("[hrtRDMASend]Does not support this interface.");
1996 : return HCCL_E_NOT_SUPPORT;
1997 : #endif
1998 : }
1999 :
2000 71 : HcclResult hrtIpcSetNotifyName(aclrtNotify notify, u8* name, uint32_t len)
2001 : {
2002 : #ifndef HCCD
2003 71 : CHK_PTR_NULL(notify);
2004 71 : CHK_PTR_NULL(name);
2005 :
2006 71 : aclError ret = aclrtNotifyGetExportKey(notify, reinterpret_cast<char *>(name), len, 0UL);
2007 71 : HCCL_INFO("[hrtIpcSetNotifyName] Call aclrtNotifyGetExportKey, name[%s] return value[%d].", name, ret);
2008 71 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Set][IPCNotify]errNo[0x%016llx] IPC set notify name[%s] fail. "\
2009 : "return[%d].", HCCL_ERROR_CODE(HCCL_E_RUNTIME), name, ret), HCCL_E_RUNTIME);
2010 71 : return HCCL_SUCCESS;
2011 : #else
2012 : HCCL_ERROR("[hrtIpcSetNotifyName]Does not support this interface.");
2013 : return HCCL_E_NOT_SUPPORT;
2014 : #endif
2015 : }
2016 :
2017 673 : HcclResult hrtStreamDestroy(rtStream_t stream)
2018 : {
2019 : #ifndef HCCD
2020 673 : CHK_PTR_NULL(stream);
2021 673 : s32 streamId = 0;
2022 673 : CHK_RET(hrtGetStreamId(stream, streamId));
2023 673 : s32 deviceId = GetDeviceLogicalId();
2024 673 : PLF_CONFIG_DEBUG(PLF_RES, "Destroy Stream para: deviceId[%d] streamId[%d]", deviceId, streamId);
2025 673 : HCCL_INFO("Destroy Stream begin, para: deviceId[%d] streamId[%d]", deviceId, streamId);
2026 673 : aclError ret = aclrtDestroyStreamForce(stream);
2027 673 : HCCL_INFO("Call aclrtDestroyStreamForce, return value[%d].", ret);
2028 673 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Stream][Destroy]errNo[0x%016llx] rt stream Destroy fail, "
2029 : "return[%d]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret), HCCL_E_RUNTIME);
2030 673 : return HCCL_SUCCESS;
2031 : #else
2032 : HCCL_ERROR("[hrtStreamDestroy]Does not support this interface.");
2033 : return HCCL_E_NOT_SUPPORT;
2034 : #endif
2035 : }
2036 :
2037 1 : HcclResult hrtStreamCreate(aclrtStream *stream)
2038 : {
2039 : #ifndef HCCD
2040 1 : CHK_PTR_NULL(stream);
2041 :
2042 1 : aclError ret = aclrtCreateStream(stream);
2043 1 : HCCL_DEBUG("Call aclrtCreateStream, return value[%d].", ret);
2044 1 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Stream][Create]errNo[0x%016llx] aclrtCreateStream error, "
2045 : "rtRet[%d]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret), HCCL_E_RUNTIME);
2046 :
2047 1 : s32 streamId = 0;
2048 1 : HcclResult hcclRet = hrtGetStreamId(*stream, streamId);
2049 1 : if (hcclRet != HCCL_SUCCESS) {
2050 1 : HCCL_ERROR("[hrtStreamCreate] hrtGetStreamId fail, ret[%d], destroy stream.", ret);
2051 1 : aclrtDestroyStream(*stream);
2052 1 : return hcclRet;
2053 : }
2054 0 : s32 deviceId = GetDeviceLogicalId();
2055 0 : PLF_CONFIG_DEBUG(PLF_RES, "Create Stream para: deviceId[%d] streamId[%d]", deviceId, streamId);
2056 0 : return HCCL_SUCCESS;
2057 : #else
2058 : HCCL_ERROR("[hrtStreamCreate]Does not support this interface.");
2059 : return HCCL_E_NOT_SUPPORT;
2060 : #endif
2061 : }
2062 :
2063 685 : HcclResult hrtStreamCreateWithFlags(aclrtStream *stream, int32_t priority, uint32_t flags)
2064 : {
2065 : #ifndef HCCD
2066 685 : CHK_PTR_NULL(stream);
2067 :
2068 685 : aclError ret = aclrtCreateStreamWithConfig(stream, static_cast<uint32_t>(priority), flags);
2069 688 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Stream][CreateWithFlags]errNo[0x%016llx] aclrtCreateStreamWithConfig "
2070 : "error, rtRet[%d], flags[%u]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, flags), HCCL_E_RUNTIME);
2071 :
2072 686 : s32 streamId = 0;
2073 686 : HcclResult hcclRet = hrtGetStreamId(*stream, streamId);
2074 686 : if (hcclRet != HCCL_SUCCESS) {
2075 3 : HCCL_ERROR("[hrtStreamCreateWithFlags] hrtGetStreamId fail, ret[%d], destroy stream.", ret);
2076 3 : aclrtDestroyStream(*stream);
2077 3 : return hcclRet;
2078 : }
2079 683 : s32 deviceId = GetDeviceLogicalId();
2080 683 : PLF_CONFIG_DEBUG(PLF_RES, "Create Stream para: deviceId[%d] streamId[%d] priority[%d] flags[%u]",
2081 : deviceId, streamId, priority, flags);
2082 683 : return HCCL_SUCCESS;
2083 : #else
2084 : HCCL_ERROR("[hrtStreamCreateWithFlags]Does not support this interface.");
2085 : return HCCL_E_NOT_SUPPORT;
2086 : #endif
2087 : }
2088 :
2089 182 : HcclResult hrtStreamSetMode(HcclRtStream stream, const uint64_t stmMode)
2090 : {
2091 : #ifndef HCCD
2092 182 : CHK_PTR_NULL(stream);
2093 182 : s32 streamId = -1;
2094 182 : aclError ret = aclrtStreamGetId(stream, &streamId);
2095 182 : HCCL_DEBUG("Call aclrtStreamGetId, return value[%d].", ret);
2096 :
2097 : aclrtStreamAttrValue value;
2098 182 : value.failureMode = stmMode;
2099 182 : ret = aclrtSetStreamAttribute(stream, ACL_STREAM_ATTR_FAILURE_MODE, &value);
2100 182 : HCCL_DEBUG("Call aclrtSetStreamAttribute return value[%d]. stmMode[%llu], streamId[%d].", ret, stmMode, streamId);
2101 182 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_WARNING("[Stream][SetMode]errNo[0x%016llx] aclrtSetStreamAttribute fail, "
2102 : "nothing changed. rtRet[%d], stmMode[%llu]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, stmMode), HCCL_SUCCESS);
2103 182 : return HCCL_SUCCESS;
2104 : #else
2105 : HCCL_ERROR("[hrtStreamSetMode]Does not support this interface.");
2106 : return HCCL_E_NOT_SUPPORT;
2107 : #endif
2108 : }
2109 :
2110 99 : HcclResult hrtStreamGetMode(HcclRtStream const stream, uint64_t *const stmMode)
2111 : {
2112 : #ifndef HCCD
2113 99 : CHK_PTR_NULL(stream);
2114 :
2115 99 : s32 streamId = -1;
2116 99 : aclError ret = aclrtStreamGetId(stream, &streamId);
2117 99 : HCCL_DEBUG("Call aclrtStreamGetId, return value[%d].", ret);
2118 :
2119 : aclrtStreamAttrValue value;
2120 99 : ret = aclrtGetStreamAttribute(stream, ACL_STREAM_ATTR_FAILURE_MODE, &value);
2121 99 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[Stream][GetMode]errNo[0x%016llx] aclrtGetStreamAttribute error, "
2122 : "rtRet[%d]", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret), HCCL_E_RUNTIME);
2123 99 : *stmMode = value.failureMode;
2124 99 : HCCL_DEBUG("Call aclrtGetStreamAttribute return value[%d]. stmMode[%llu], streamId[%d].", ret, *stmMode, streamId);
2125 99 : return HCCL_SUCCESS;
2126 : #else
2127 : HCCL_ERROR("[hrtStreamGetMode]Does not support this interface.");
2128 : return HCCL_E_NOT_SUPPORT;
2129 : #endif
2130 : }
2131 :
2132 1 : HcclResult hrtMemcpy(void *dst, uint64_t destMax, const void *src, uint64_t count, HcclRtMemcpyKind kind)
2133 : {
2134 1 : CHK_PTR_NULL(dst);
2135 1 : CHK_PTR_NULL(src);
2136 1 : CHK_PRT_RET(count > destMax, HCCL_ERROR("[hrtMemcpy] count[%llu] exceeds destMax[%llu].",
2137 : count, destMax), HCCL_E_PARA);
2138 : aclrtMemcpyKind rtKind;
2139 0 : CHK_RET(MemcpyKindTranslate(kind, &rtKind));
2140 : #ifndef HCCD
2141 0 : aclmdlRICaptureMode mode = aclmdlRICaptureMode::ACL_MODEL_RI_CAPTURE_MODE_RELAXED;
2142 0 : HcclResult hcclRet = hrtThreadExchangeCaptureMode(&mode);
2143 0 : CHK_PRT_CONT(hcclRet != HCCL_SUCCESS && hcclRet != HCCL_E_NOT_SUPPORT,
2144 : HCCL_ERROR("[hrtMemcpy] hrtThreadExchangeCaptureMode return [%d]", hcclRet));
2145 :
2146 0 : aclError ret = aclrtMemcpy(dst, destMax, src, count, rtKind);
2147 0 : HCCL_DEBUG("Call aclrtMemcpy, return[%d], para: dstAddr[%p], destMax[%llu], srcAddr[%p], count[%llu], rtKind[%d]",
2148 : ret, dst, destMax, src, count, rtKind);
2149 :
2150 0 : hcclRet = hrtThreadExchangeCaptureMode(&mode);
2151 0 : CHK_PRT_CONT(hcclRet != HCCL_SUCCESS && hcclRet != HCCL_E_NOT_SUPPORT,
2152 : HCCL_ERROR("[hrtMemcpy] hrtThreadExchangeCaptureMode return [%d]", hcclRet));
2153 : #else
2154 : aclError ret = ACL_SUCCESS;
2155 : static auto funcPtr =
2156 : (aclError(*)(void *, size_t, const void *, size_t, aclrtMemcpyKind))g_dlAcl.Handle<ACL_RT_MEMCPY>();
2157 : CHK_PTR_NULL(funcPtr);
2158 : ret = funcPtr(dst, destMax, src, count, rtKind);
2159 : #endif
2160 0 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[aclrtMemcpy] rt data memcpy host to device failed,"
2161 : "size[%llu Byte] src[%p]", destMax, src), HCCL_E_RUNTIME);
2162 0 : return HCCL_SUCCESS;
2163 : }
2164 :
2165 0 : HcclResult hrtRDMADBSend(uint32_t dbindex, uint64_t dbinfo, rtStream_t stream)
2166 : {
2167 : #ifndef HCCD
2168 : // stream为空时使用rts内部set device后的默认stream
2169 0 : rtError_t ret = rtRDMADBSend(dbindex, dbinfo, stream);
2170 0 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[rtRDMADBSend]errNo[0x%016llx] rt rdma send fail, "
2171 : "return[%d]. para: dbindex[%u]dbinfo[%llu].", HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, dbindex,
2172 : dbinfo), HCCL_E_RUNTIME);
2173 0 : return HCCL_SUCCESS;
2174 : #else
2175 : static auto funcPtr = (rtError_t(*)(uint32_t, uint64_t, rtStream_t))g_dlRts.Handle<RT_RDMA_DB_SEND>();
2176 : CHK_PTR_NULL(funcPtr);
2177 : rtError_t ret = funcPtr(dbindex, dbinfo, stream);
2178 : HCCL_DEBUG("Call rtRDMADBSend, return value[%d]", ret);
2179 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("rtRDMADBSend errNo[0x%016llx] RDMADBSend fail, return[%d]",
2180 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret), HCCL_E_RUNTIME);
2181 : return HCCL_SUCCESS;
2182 : #endif
2183 : }
2184 :
2185 11 : HcclResult hrtSetLocalDeviceSatMode(aclrtFloatOverflowMode floatOverflowMode)
2186 : {
2187 : #ifdef HCCD
2188 : g_deviceSatMode = floatOverflowMode;
2189 : #endif
2190 11 : return HCCL_SUCCESS;
2191 : }
2192 :
2193 178 : HcclResult hrtGetDeviceSatMode(aclrtFloatOverflowMode *floatOverflowMode)
2194 : {
2195 178 : CHK_PTR_NULL(floatOverflowMode);
2196 : #ifndef HCCD
2197 178 : aclError ret = aclrtGetDeviceSatMode(floatOverflowMode);
2198 177 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[hrtGetDeviceSatMode]rt get dev satmode failed,"),
2199 : HCCL_E_RUNTIME);
2200 177 : return HCCL_SUCCESS;
2201 : #else
2202 : if (g_workModeAicpu) {
2203 : *floatOverflowMode = g_deviceSatMode;
2204 : return HCCL_SUCCESS;
2205 : }
2206 : HCCL_ERROR("[hrtGetDeviceSatMode]Does not support this interface.");
2207 : return HCCL_E_NOT_SUPPORT;
2208 : #endif
2209 : }
2210 :
2211 72 : HcclResult hrtNotifyGetAddr(HcclRtNotify signal, u64 *notifyAddr)
2212 : {
2213 : #ifndef HCCD
2214 72 : uint64_t* const addr = reinterpret_cast<uint64_t*>(notifyAddr);
2215 72 : rtError_t ret = rtGetNotifyAddress(signal, addr);
2216 72 : HCCL_DEBUG("Call rtGetNotifyAddress, signal[%p], notifyAddr[%016llx]", signal, *notifyAddr);
2217 72 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[rtGetNotifyAddress]rt get notify address failed."), HCCL_E_RUNTIME);
2218 72 : return HCCL_SUCCESS;
2219 : #else
2220 : HCCL_ERROR("[hrtNotifyGetAddr]Does not support this interface.");
2221 : return HCCL_E_NOT_SUPPORT;
2222 : #endif
2223 : }
2224 :
2225 1569 : HcclResult hrtGetNotifyID(HcclRtNotify signal, u32 *notifyID)
2226 : {
2227 : #ifndef HCCD
2228 1569 : CHK_PTR_NULL(signal);
2229 1569 : CHK_PTR_NULL(notifyID);
2230 1569 : aclError ret = aclrtGetNotifyId(signal, notifyID);
2231 1569 : HCCL_DEBUG("Call aclrtGetNotifyId signal:%p, notifyID:%u.", signal, *notifyID);
2232 1569 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[hrtGetNotifyID]rt get notify id failed."), HCCL_E_RUNTIME);
2233 1569 : return HCCL_SUCCESS;
2234 : #else
2235 : HCCL_ERROR("[hrtGetNotifyID]Does not support this interface.");
2236 : return HCCL_E_NOT_SUPPORT;
2237 : #endif
2238 : }
2239 :
2240 6 : HcclResult hrtGetDeviceInfo(u32 deviceId, HcclRtDeviceModuleType hcclModuleType,
2241 : HcclRtDeviceInfoType hcclInfoType, s64 &val)
2242 : {
2243 : #ifndef HCCD
2244 : static const std::map<HcclRtDeviceInfoType, aclrtDevAttr> systemInfoTypeMap = {
2245 : {HcclRtDeviceInfoType::HCCL_INFO_TYPE_PHY_CHIP_ID, ACL_DEV_ATTR_PHY_CHIP_ID},
2246 : {HcclRtDeviceInfoType::HCCL_INFO_TYPE_SDID, ACL_DEV_ATTR_SUPER_POD_DEVIDE_ID},
2247 : {HcclRtDeviceInfoType::HCCL_INFO_TYPE_SERVER_ID, ACL_DEV_ATTR_SUPER_POD_SERVER_ID},
2248 : {HcclRtDeviceInfoType::HCCL_INFO_TYPE_SUPER_POD_ID, ACL_DEV_ATTR_SUPER_POD_ID},
2249 : {HcclRtDeviceInfoType::HCCL_INFO_TYPE_CUST_OP_ENHANCE, ACL_DEV_ATTR_CUST_OP_PRIVILEGE},
2250 8 : };
2251 6 : CHK_PRT_RET(hcclModuleType != HcclRtDeviceModuleType::HCCL_RT_MODULE_TYPE_SYSTEM,
2252 : HCCL_ERROR("[hrtGetDeviceInfo]Unsupported moduleType[%d].", hcclModuleType),
2253 : HCCL_E_NOT_SUPPORT);
2254 :
2255 6 : auto it = systemInfoTypeMap.find(hcclInfoType);
2256 6 : CHK_PRT_RET(it == systemInfoTypeMap.end(),
2257 : HCCL_ERROR("[hrtGetDeviceInfo]Unsupported infoType[%d] for moduleType=SYSTEM.", hcclInfoType),
2258 : HCCL_E_NOT_SUPPORT);
2259 6 : aclrtDevAttr attr = it->second;
2260 :
2261 6 : aclError ret = aclrtGetDeviceInfo(deviceId, attr, reinterpret_cast<int64_t *>(&val));
2262 6 : CHK_PRT_RET(ret != ACL_SUCCESS,
2263 : HCCL_ERROR("[hrtGetDeviceInfo]rt get device info failed. ret[%d], attr[%d], val[%ld]", ret, attr, val),
2264 : HCCL_E_RUNTIME);
2265 6 : HCCL_DEBUG("Call aclrtGetDeviceInfo, ret[%d], attr[%d], val[%ld]", ret, attr, val);
2266 6 : return HCCL_SUCCESS;
2267 : #else
2268 : HCCL_ERROR("[hrtGetDeviceInfo]Does not support this interface.");
2269 : return HCCL_E_NOT_SUPPORT;
2270 : #endif
2271 : }
2272 :
2273 0 : HcclResult hrtGetRdmaDoorbellAddr(u32 dbIndex, u64 &dbAddr)
2274 : {
2275 : #ifndef HCCD
2276 0 : s32 devLogID = 0;
2277 0 : s64 chipID = 0;
2278 : static std::mutex devChipIdMapSpinMutex; // devLogID 和 chipID 关系表的读写互斥锁
2279 :
2280 0 : CHK_RET(hrtGetDevice(&devLogID));
2281 :
2282 : // 读写表前先加锁
2283 0 : std::unique_lock<std::mutex> lockDevChipIdMap(devChipIdMapSpinMutex);
2284 :
2285 0 : if (g_deviceChipIdMap.find(devLogID) != g_deviceChipIdMap.end()) {
2286 : // 若已有记录,则直接获取chipID
2287 0 : chipID = g_deviceChipIdMap[devLogID];
2288 : } else {
2289 0 : CHK_RET(hrtGetDeviceInfo(devLogID, HcclRtDeviceModuleType::HCCL_RT_MODULE_TYPE_SYSTEM,
2290 : HcclRtDeviceInfoType::HCCL_INFO_TYPE_PHY_CHIP_ID, chipID));
2291 0 : g_deviceChipIdMap[devLogID] = chipID;
2292 : }
2293 : // 解锁
2294 0 : lockDevChipIdMap.unlock();
2295 :
2296 : u64 roceBaseAddr;
2297 : u64 roceVfDbCfg0Reg;
2298 : u64 chipAddrOffset;
2299 : u64 dieAddrOffset;
2300 : u32 dbDieIdMask;
2301 : u32 dbDieIdShift;
2302 :
2303 : DevType deviceType;
2304 0 : CHK_RET(hrtGetDeviceType(deviceType));
2305 0 : if (deviceType == DevType::DEV_TYPE_910_93) {
2306 0 : HCCL_DEBUG("[hrtGetRdmaDoorbellAddr] The roceBaseAddr and dieAddrOffset has changed, when deviceType is 910_93.");
2307 : // 910_93 HCCS_SW 组网
2308 0 : roceBaseAddr = 0x202000000000ULL;
2309 0 : roceVfDbCfg0Reg = 0x230ULL;
2310 0 : chipAddrOffset = 0x20000000000ULL;
2311 0 : dieAddrOffset = 0x10000000000ULL;
2312 0 : dbDieIdMask = 0x00ff0000;
2313 0 : dbDieIdShift = 16; // 16 is dbDieIdShift
2314 : } else {
2315 0 : roceBaseAddr = 0x2000000000ULL;
2316 0 : roceVfDbCfg0Reg = 0x230ULL;
2317 0 : chipAddrOffset = 0x80000000000ULL;
2318 0 : dieAddrOffset = 0x10000000000ULL;
2319 0 : dbDieIdMask = 0x00ff0000;
2320 0 : dbDieIdShift = 16; // 16 is dbDieIdShift
2321 : }
2322 :
2323 0 : dbAddr = roceBaseAddr + roceVfDbCfg0Reg + chipAddrOffset * chipID +
2324 0 : dieAddrOffset * ((dbIndex & dbDieIdMask) >> dbDieIdShift);
2325 0 : return HCCL_SUCCESS;
2326 : #else
2327 : HCCL_ERROR("[hrtGetRdmaDoorbellAddr]Does not support this interface.");
2328 : return HCCL_E_NOT_SUPPORT;
2329 : #endif
2330 0 : }
2331 :
2332 0 : HcclResult hrtGetDevArgsAddr(rtStream_t stm, rtArgsEx_t *argsInfo, void **devArgsAddr, void **argsHandle)
2333 : {
2334 : #ifndef HCCD
2335 0 : rtError_t ret = rtGetDevArgsAddr(stm, argsInfo, devArgsAddr, argsHandle);
2336 0 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[rtGetDevArgsAddr]rtKernel Get Addr failed."), HCCL_E_RUNTIME);
2337 0 : return HCCL_SUCCESS;
2338 : #else
2339 : HCCL_ERROR("[hrtGetDevArgsAddr]Does not support this interface.");
2340 : return HCCL_E_NOT_SUPPORT;
2341 : #endif
2342 : }
2343 :
2344 2547 : HcclResult hrtMemSet(void *dst, uint64_t destMax, uint64_t count)
2345 : {
2346 : #ifndef HCCD
2347 : // 参数有效性检查
2348 2547 : CHK_PTR_NULL(dst);
2349 2547 : aclmdlRICaptureMode mode = aclmdlRICaptureMode::ACL_MODEL_RI_CAPTURE_MODE_RELAXED;
2350 2547 : HcclResult hcclRet = hrtThreadExchangeCaptureMode(&mode);
2351 2547 : CHK_PRT_CONT(hcclRet != HCCL_SUCCESS && hcclRet != HCCL_E_NOT_SUPPORT,
2352 : HCCL_ERROR("[hrtMemSet] hrtThreadExchangeCaptureMode return [%d]", hcclRet));
2353 2547 : aclError ret = aclrtMemset(dst, destMax, 0, count);
2354 :
2355 2547 : HCCL_DEBUG("Call aclrtMemset, return value[%d]", ret);
2356 2547 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[AsyncCopy][Mem]errNo[0x%016llx] rt memory async set failed, "\
2357 : "return[%d], para: dstAddr[%p], destMax[%llu], count[%llu].",\
2358 : HCCL_ERROR_CODE(HCCL_E_RUNTIME), ret, dst, destMax, count), HCCL_E_RUNTIME);
2359 2547 : hcclRet = hrtThreadExchangeCaptureMode(&mode);
2360 2547 : CHK_PRT_CONT(hcclRet != HCCL_SUCCESS && hcclRet != HCCL_E_NOT_SUPPORT,
2361 : HCCL_ERROR("[hrtMemSet] hrtThreadExchangeCaptureMode return [%d]", hcclRet));
2362 2547 : return HCCL_SUCCESS;
2363 : #else
2364 : HCCL_ERROR("[hrtMemSet]Does not support this interface.");
2365 : return HCCL_E_NOT_SUPPORT;
2366 : #endif
2367 : }
2368 :
2369 1 : HcclResult hrtEventCreateWithFlag(aclrtEvent *evt)
2370 : {
2371 : #ifndef HCCD
2372 1 : CHK_PTR_NULL(evt);
2373 :
2374 1 : aclError ret = aclrtCreateEventWithFlag(evt, ACL_EVENT_DEVICE_USE_ONLY);
2375 1 : HCCL_DEBUG("Call aclrtCreateEventWithFlag, return value[%d] evt[%p].", ret, evt);
2376 1 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[aclrtCreateEventWithFlag]rtEvent Create WithFlags failed "\
2377 : "value[%d] evt[%p].", ret, evt), HCCL_E_RUNTIME);
2378 1 : return HCCL_SUCCESS;
2379 : #else
2380 : HCCL_ERROR("[aclrtCreateEventWithFlag]Does not support this interface.");
2381 : return HCCL_E_NOT_SUPPORT;
2382 : #endif
2383 : }
2384 :
2385 482 : HcclResult hrtNotifyCreateWithFlag(int32_t deviceId, aclrtNotify *notify)
2386 : {
2387 : #ifndef HCCD
2388 482 : CHK_PTR_NULL(notify);
2389 :
2390 482 : aclError ret = aclrtCreateNotify(notify, ACL_NOTIFY_DEVICE_USE_ONLY);
2391 482 : HCCL_DEBUG("Call aclrtCreateNotify deviceId:[%d], return value[%d].", deviceId, ret);
2392 482 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[aclrtCreateNotify]rtNotify Create WithFlags failed "\
2393 : "deviceId:%d, notify:%p, return value[%d].", deviceId, notify, ret), HCCL_E_RUNTIME);
2394 :
2395 482 : u32 notifyId = 0;
2396 482 : CHK_RET(hrtGetNotifyID(*notify, ¬ifyId));
2397 482 : PLF_CONFIG_INFO(PLF_RES, "Create Notify para: deviceId[%d] notifyId[%u]", deviceId, notifyId);
2398 482 : return HCCL_SUCCESS;
2399 : #else
2400 : HCCL_ERROR("[aclrtCreateNotify]Does not support this interface.");
2401 : return HCCL_E_NOT_SUPPORT;
2402 : #endif
2403 : }
2404 :
2405 0 : HcclResult hrtIpcOpenNotifyWithFlag(rtNotify_t *notify, const u8 *name, uint32_t flags)
2406 : {
2407 : #ifndef HCCD
2408 0 : CHK_PTR_NULL(notify);
2409 0 : CHK_PTR_NULL(name);
2410 :
2411 0 : rtError_t ret = aclrtNotifyImportByKey(notify, reinterpret_cast<const char *>(name), static_cast<uint64_t>(flags));
2412 0 : HCCL_DEBUG("Call aclrtNotifyImportByKey notify:[%p], name:[%s], flags[%u], return value[%d].", notify, name,
2413 : flags, ret);
2414 0 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[aclrtNotifyImportByKey]rtIpc OpenNotify WithFlags failed "\
2415 : "notify:%p, name:%s, flags[%u], return value[%d].", notify, name, flags, ret), HCCL_E_RUNTIME);
2416 0 : return HCCL_SUCCESS;
2417 : #else
2418 : HCCL_ERROR("[aclrtNotifyImportByKey]Does not support this interface.");
2419 : return HCCL_E_NOT_SUPPORT;
2420 : #endif
2421 : }
2422 :
2423 0 : HcclResult hrtNotifyImportByKey(rtNotify_t *notify, const u8 *name)
2424 : {
2425 : #ifndef HCCD
2426 0 : CHK_PTR_NULL(notify);
2427 0 : CHK_PTR_NULL(name);
2428 :
2429 0 : constexpr u64 notifyFlag = 0;
2430 0 : auto ret = aclrtNotifyImportByKey(notify,
2431 : reinterpret_cast<const char *>(name), notifyFlag);
2432 0 : HCCL_DEBUG("Call aclrtNotifyImportByKey notify:[%p], name:[%s], flags[%u], return value[%d].", notify, name,
2433 : notifyFlag, ret);
2434 0 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[hrtNotifyImportByKey]aclrtIpc OpenNotify WithFlags failed "\
2435 : "notify:%p, name:%s, return value[%d].", notify, name, ret), HCCL_E_RUNTIME);
2436 0 : return HCCL_SUCCESS;
2437 : #else
2438 : HCCL_ERROR("[hrtNotifyImportByKey]Does not support this interface.");
2439 : return HCCL_E_NOT_SUPPORT;
2440 : #endif
2441 : }
2442 :
2443 348 : HcclResult hrtNotifyGetPhyInfo(rtNotify_t notify, uint32_t *phyDevId, uint32_t *tsId)
2444 : {
2445 : #ifndef HCCD
2446 348 : CHK_PTR_NULL(notify);
2447 348 : CHK_PTR_NULL(phyDevId);
2448 348 : CHK_PTR_NULL(tsId);
2449 :
2450 348 : rtError_t ret = rtNotifyGetPhyInfo(notify, phyDevId, tsId);
2451 348 : HCCL_DEBUG("Call rtNotifyGetPhyInfo notify:%p, phyDevId:%u, tsId:%u, return value[%d].", notify, *phyDevId,
2452 : *tsId, ret);
2453 348 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[rtNotifyGetPhyInfo]rtNotify GetPhy failed notify:%p, phyDevId:%u, "\
2454 : "tsId:%u, return value[%d].", notify, *phyDevId, *tsId, ret), HCCL_E_RUNTIME);
2455 348 : return HCCL_SUCCESS;
2456 : #else
2457 : HCCL_ERROR("[rtNotifyGetPhyInfo]Does not support this interface.");
2458 : return HCCL_E_NOT_SUPPORT;
2459 : #endif
2460 : }
2461 :
2462 348 : HcclResult hrtNotifyGetPhyInfoExt(rtNotify_t notify, rtNotifyPhyInfo *notifyInfo)
2463 : {
2464 : #ifndef HCCD
2465 348 : CHK_PTR_NULL(notify);
2466 348 : CHK_PTR_NULL(notifyInfo);
2467 :
2468 348 : rtError_t ret = rtNotifyGetPhyInfoExt(notify, notifyInfo);
2469 348 : HCCL_DEBUG("Call rtNotifyGetPhyInfoExt notify:%p, phyId:%u, tsId:%u, idType:%u, notifyid:[%u], flag:[%u], "
2470 : "return value[%d].", notify, notifyInfo->phyId, notifyInfo->tsId, notifyInfo->idType, notifyInfo->shrId,
2471 : notifyInfo->flag, ret);
2472 348 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("Call rtNotifyGetPhyInfoExt notify:%p, phyId:%u, tsId:%u, "
2473 : "idType:%u, notifyid:[%u], flag:[%u], return value[%d].", notify, notifyInfo->phyId, notifyInfo->tsId,
2474 : notifyInfo->idType, notifyInfo->shrId, notifyInfo->flag, ret), HCCL_E_RUNTIME);
2475 348 : return HCCL_SUCCESS;
2476 : #else
2477 : HCCL_ERROR("[rtNotifyGetPhyInfoExt]Does not support this interface.");
2478 : return HCCL_E_NOT_SUPPORT;
2479 : #endif
2480 : }
2481 :
2482 1 : HcclResult hrtGetEventID(rtEvent_t event, uint32_t *eventId)
2483 : {
2484 : #ifndef HCCD
2485 1 : CHK_PTR_NULL(event);
2486 1 : CHK_PTR_NULL(eventId);
2487 :
2488 1 : aclError ret = aclrtGetEventId(event, eventId);
2489 1 : HCCL_DEBUG("Call aclrtGetEventId event:%p, eventId:%u, return value[%d].", event, *eventId, ret);
2490 1 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[aclrtGetEventId]rtGet EventID failed event:%p, eventId:%u"\
2491 : "return value[%d].", event, *eventId, ret), HCCL_E_RUNTIME);
2492 1 : return HCCL_SUCCESS;
2493 : #else
2494 : HCCL_ERROR("[hrtGetEventID]Does not support this interface.");
2495 : return HCCL_E_NOT_SUPPORT;
2496 : #endif
2497 : }
2498 :
2499 1152 : HcclResult hrtStreamGetSqid(const rtStream_t stm, uint32_t *sqId)
2500 : {
2501 : #ifndef HCCD
2502 1152 : CHK_PTR_NULL(stm);
2503 1152 : CHK_PTR_NULL(sqId);
2504 :
2505 1152 : rtError_t ret = rtStreamGetSqid(stm, sqId);
2506 1148 : HCCL_DEBUG("Call rtStreamGetSqid stm:%p, sqId:%u value[%d].", stm, *sqId, ret);
2507 1155 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[rtStreamGetSqid]rtStream Get Sqid failed stm:%p, "\
2508 : "sqId:%u value[%d].", stm, *sqId, ret), HCCL_E_RUNTIME);
2509 1155 : return HCCL_SUCCESS;
2510 : #else
2511 : HCCL_ERROR("[rtStreamGetSqid]Does not support this interface.");
2512 : return HCCL_E_NOT_SUPPORT;
2513 : #endif
2514 : }
2515 :
2516 1153 : HcclResult hrtStreamGetCqid(const rtStream_t stm, uint32_t *cqId, uint32_t *logicCqId)
2517 : {
2518 : #ifndef HCCD
2519 1153 : CHK_PTR_NULL(stm);
2520 1153 : CHK_PTR_NULL(cqId);
2521 1153 : CHK_PTR_NULL(logicCqId);
2522 :
2523 1153 : rtError_t ret = rtStreamGetCqid(stm, cqId, logicCqId);
2524 1151 : HCCL_DEBUG("Call rtStreamGetCqid stm:%p, cqId:%u, logicCqId:%u value[%d].", stm, *cqId, *logicCqId, ret);
2525 1156 : CHK_PRT_RET(ret != RT_ERROR_NONE, HCCL_ERROR("[rtStreamGetCqid]rtStream Get logicCqId failed stm:%p, " \
2526 : "cqId:%u logicCqId:%u value[%d].", stm, *cqId, *logicCqId, ret), HCCL_E_RUNTIME);
2527 1156 : return HCCL_SUCCESS;
2528 : #else
2529 : HCCL_ERROR("[rtStreamGetCqid]Does not support this interface.");
2530 : return HCCL_E_NOT_SUPPORT;
2531 : #endif
2532 : }
2533 :
2534 : // 要求设置过 SetDevice
2535 1 : HcclResult hrtResourceClean()
2536 : {
2537 : #ifndef HCCD
2538 : // rts 接口内部通过 GetDevice 获得 deviceId
2539 1 : rtError_t ret = rtNotifyResetAll();
2540 1 : HCCL_DEBUG("Call aclrtNotifyBatchReset, ret: %d", ret);
2541 1 : CHK_PRT_RET(ret != ACL_SUCCESS,
2542 : HCCL_ERROR("[hrtResourceClean]aclrtNotifyBatchReset failed, return value[%d].", ret),
2543 : HCCL_E_RUNTIME);
2544 1 : return HCCL_SUCCESS;
2545 : #else
2546 : HCCL_ERROR("[hrtResourceClean]Does not support this interface.");
2547 : return HCCL_E_NOT_SUPPORT;
2548 : #endif
2549 : }
2550 :
2551 0 : HcclResult hrtGetHccsPortNum(u32 deviceLogicId, s32 &num)
2552 : {
2553 : #ifndef HCCD
2554 0 : constexpr s32 HCCS_PORT_NUM_UNKNOWN = -1;
2555 0 : constexpr s32 HCCS_PORT_NUM_910_93_UNKNOWN = -1;
2556 0 : constexpr s32 HCCS_PORT_NUM_910_93_6 = 6;
2557 0 : constexpr s32 HCCS_PORT_NUM_910_93_7 = 7;
2558 0 : constexpr int64_t MAINBORDID_910_93_PRODUCT_V1_2_4_4 = 0x1c;
2559 0 : constexpr int64_t MAINBORDID_910_93_PRODUCT_V1_4_8_8 = 0x1d;
2560 0 : constexpr int64_t MAINBORDID_910_93_PRODUCT_V2_4_8_7 = 0x18;
2561 0 : constexpr int64_t MAINBORDID_910_93_PRODUCT_V2_2_8_7 = 0x19;
2562 0 : constexpr int64_t MAINBORDID_910_93_PRODUCT_V3_4_8_7 = 0x14;
2563 0 : constexpr int64_t MAINBORDID_910_93_PRODUCT_V3_2_8_7 = 0x15;
2564 : DevType deviceType;
2565 0 : CHK_RET(hrtGetDeviceType(deviceType));
2566 0 : if (deviceType != DevType::DEV_TYPE_910_93) {
2567 0 : num = HCCS_PORT_NUM_UNKNOWN;
2568 0 : HCCL_WARNING("[hrtGetHccsPortNum]deviceType: %d, does not support this interface.", deviceType);
2569 0 : return HCCL_E_NOT_SUPPORT;
2570 : }
2571 0 : int64_t val = 0;
2572 0 : aclError ret = aclrtGetDeviceInfo(deviceLogicId, ACL_DEV_ATTR_MAINBOARD_ID, &val);
2573 0 : HCCL_DEBUG("Call aclrtGetDeviceInfo deviceLogicId:%u, val: %lld, ret:%d.", deviceLogicId, val, ret);
2574 0 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[rtGetHccsPortNum]rtGet Hccs Port Num failed deviceLogicId:%u, "
2575 : "return value[%d].", deviceLogicId, ret), HCCL_E_RUNTIME);
2576 0 : switch (val) {
2577 0 : case MAINBORDID_910_93_PRODUCT_V1_2_4_4: num = HCCS_PORT_NUM_910_93_6; break;
2578 0 : case MAINBORDID_910_93_PRODUCT_V1_4_8_8: num = HCCS_PORT_NUM_910_93_6; break;
2579 0 : case MAINBORDID_910_93_PRODUCT_V2_4_8_7: num = HCCS_PORT_NUM_910_93_7; break;
2580 0 : case MAINBORDID_910_93_PRODUCT_V2_2_8_7: num = HCCS_PORT_NUM_910_93_7; break;
2581 0 : case MAINBORDID_910_93_PRODUCT_V3_4_8_7: num = HCCS_PORT_NUM_910_93_7; break;
2582 0 : case MAINBORDID_910_93_PRODUCT_V3_2_8_7: num = HCCS_PORT_NUM_910_93_7; break;
2583 0 : default: num = HCCS_PORT_NUM_910_93_UNKNOWN;
2584 : }
2585 0 : return HCCL_SUCCESS;
2586 : #else
2587 : HCCL_ERROR("[hrtGetHccsPortNum]Does not support this interface.");
2588 : return HCCL_E_NOT_SUPPORT;
2589 : #endif
2590 : }
2591 :
2592 6699 : HcclResult hrtThreadExchangeCaptureMode(aclmdlRICaptureMode *mode)
2593 : {
2594 : #ifndef HCCD
2595 6699 : HCCL_DEBUG("Call aclmdlRICaptureThreadExchangeMode mode after: %d", *mode);
2596 6700 : aclError ret = aclmdlRICaptureThreadExchangeMode(mode);
2597 6698 : HCCL_DEBUG("Call aclmdlRICaptureThreadExchangeMode mode before: %d, ret: %d", *mode, ret);
2598 6698 : if (ret == ACL_ERROR_RT_FEATURE_NOT_SUPPORT) {
2599 0 : HCCL_INFO("[hrtThreadExchangeCaptureMode]aclmdlRICaptureThreadExchangeMode not support!");
2600 0 : return HCCL_E_NOT_SUPPORT;
2601 : } else {
2602 6698 : CHK_PRT_RET(ret != ACL_SUCCESS, HCCL_ERROR("[hrtThreadExchangeCaptureMode]aclmdlRICaptureThreadExchangeMode "
2603 : "failed mode:%d, return value[%d].", *mode, ret), HCCL_E_RUNTIME);
2604 : }
2605 6698 : return HCCL_SUCCESS;
2606 : #else
2607 : HCCL_ERROR("[hrtThreadExchangeCaptureMode]Does not support this interface.");
2608 : return HCCL_E_NOT_SUPPORT;
2609 : #endif
2610 : }
2611 :
2612 6 : HcclResult hrtCacheLastTaskExtendInfo(const char *tag, size_t tagLen)
2613 : {
2614 : #ifndef HCCD
2615 6 : auto funcPtr = (aclError(*)(const char*, size_t))g_dlAcl.Handle<ACL_RT_CACHE_LAST_TASK_EXTEND_INFO>();
2616 6 : if (funcPtr == nullptr) {
2617 2 : HCCL_INFO("[hrtCacheLastTaskExtendInfo] aclrtCacheLastTaskExtendInfo not supported.");
2618 2 : return HCCL_E_NOT_SUPPORT;
2619 : }
2620 4 : aclError ret = funcPtr(tag, tagLen);
2621 4 : CHK_PRT_RET(ret != ACL_SUCCESS,
2622 : HCCL_ERROR("[hrtCacheLastTaskExtendInfo] call aclrtCacheLastTaskExtendInfo fail, return[%d]", ret),
2623 : HCCL_E_RUNTIME);
2624 2 : return HCCL_SUCCESS;
2625 : #else
2626 : HCCL_ERROR("[hrtCacheLastTaskExtendInfo]Does not support this interface.");
2627 : return HCCL_E_NOT_SUPPORT;
2628 : #endif
2629 : }
2630 :
2631 46 : __attribute__((constructor)) void CallBackInitRts()
2632 : {
2633 46 : g_deviceType = DevType::DEV_TYPE_COUNT;
2634 46 : g_deviceLogicId = INVALID_INT;
2635 46 : g_devicePhyId = INVALID_UINT;
2636 46 : HCCL_RUN_INFO("[adapter_rts.cc][CallBackInitRts] g_deviceType [%d] g_deviceLogicId [%d] g_devicePhyId [%d]",
2637 : g_deviceType, g_deviceLogicId, g_devicePhyId);
2638 46 : }
2639 :
2640 5 : HcclResult hrtMemcpyEx(void *dst, uint64_t destMax, void *src, uint64_t count, rtMemcpyKind_t kind)
2641 : {
2642 : #ifndef HCCD
2643 5 : CHK_PTR_NULL(dst);
2644 4 : CHK_PTR_NULL(src);
2645 3 : CHK_PRT_RET(count > destMax, HCCL_ERROR("[hrtMemcpyEx] count[%llu] exceeds destMax[%llu].",
2646 : count, destMax), HCCL_E_PARA);
2647 2 : rtError_t ret = rtMemcpyEx(dst, destMax, src, count, kind);
2648 2 : HCCL_DEBUG("[hrtMemcpyEx] Call rtMemcpyEx, ret[%d], dstAddr[%p], destMax[%llu], srcAddr[%p], count[%llu], "
2649 : "rtKind[%d]", ret, dst, destMax, src, count, kind);
2650 2 : CHK_PRT_RET(ret != RT_ERROR_NONE,
2651 : HCCL_ERROR("[hrtMemcpyEx] rtMemcpyEx failed, return[%d], dstAddr[%p], destMax[%llu], srcAddr[%p], count[%llu], "
2652 : "rtKind[%d].", ret, dst, destMax, src, count, kind), HCCL_E_RUNTIME);
2653 1 : return HCCL_SUCCESS;
2654 : #else
2655 : HCCL_ERROR("[hrtMemcpyEx] Does not support this interface.");
2656 : return HCCL_E_NOT_SUPPORT;
2657 : #endif
2658 : }
|