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