LCOV - code coverage report
Current view: top level - legacy/ascend910/platform/common/adapter - adapter_rts.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 55.0 % 1087 598
Test Date: 2026-08-17 10:19:35 Functions: 64.1 % 117 75

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

Generated by: LCOV version 2.0-1