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