LCOV - code coverage report
Current view: top level - acl/aclrt_impl - device.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 97.7 % 432 422
Test Date: 2026-07-28 10:53:01 Functions: 100.0 % 46 46

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #include "acl_rt_impl.h"
      12              : #include "acl_rt_impl_base.h"
      13              : #include "runtime/dev.h"
      14              : #include "runtime/kernel.h"
      15              : #include "runtime/config.h"
      16              : #include "runtime/rts/rts_device.h"
      17              : #include "runtime/rts/rts_stream.h"
      18              : #include "common/log_inner.h"
      19              : #include "common/error_codes_inner.h"
      20              : #include "common/prof_reporter.h"
      21              : #include "common/resource_statistics.h"
      22              : #include "runtime/rt_inner_device.h"
      23              : #include "utils/data_type_utils.h"
      24              : 
      25              : namespace {
      26              : constexpr int32_t DEVICE_UTILIZATION_NOT_SUPPORT = -1;
      27              : 
      28            6 : int32_t GetAllUtilizations(const int32_t deviceId, const rtTypeUtil_t utilType)
      29              : {
      30            6 :     uint8_t utilRate = 0U;
      31            6 :     const rtError_t rtErr = rtGetAllUtilizations(deviceId, utilType, &utilRate);
      32            6 :     if (rtErr == ACL_ERROR_RT_FEATURE_NOT_SUPPORT) {
      33            1 :         ACL_LOG_WARN(
      34              :             "rtGetAllUtilizations not to support this query, utilType = %d, runtime result = %d.",
      35              :             static_cast<int32_t>(utilType), static_cast<int32_t>(rtErr));
      36            1 :         return DEVICE_UTILIZATION_NOT_SUPPORT;
      37              :     }
      38            5 :     if (rtErr != RT_ERROR_NONE) {
      39            1 :         ACL_LOG_CALL_ERROR(
      40              :             "rtGetAllUtilizations failed, utilType = %d, runtime result = %d.", static_cast<int32_t>(utilType),
      41              :             static_cast<int32_t>(rtErr));
      42            1 :         return DEVICE_UTILIZATION_NOT_SUPPORT;
      43              :     }
      44            4 :     ACL_LOG_INFO(
      45              :         "successfully execute rtGetAllUtilizations, utilType = %d, utilRate = %u.", static_cast<int32_t>(utilType),
      46              :         utilRate);
      47            4 :     return static_cast<int32_t>(utilRate);
      48              : }
      49              : } // namespace
      50              : 
      51              : #ifdef __cplusplus
      52              : extern "C" {
      53              : #endif
      54              : 
      55           13 : aclError aclrtSetDeviceImpl(int32_t deviceId)
      56              : {
      57           13 :     ACL_PROFILING_REG(acl::AclProfType::AclrtSetDevice);
      58           13 :     ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
      59           13 :     ACL_LOG_INFO("start to execute aclrtSetDevice, deviceId = %d.", deviceId);
      60           13 :     ACL_REQUIRES_RTS_OK(rtSetDevice(deviceId));
      61           11 :     ACL_LOG_INFO("successfully execute aclrtSetDevice, deviceId = %d", deviceId);
      62           11 :     ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
      63              :     // update platform info
      64           11 :     const auto err = acl::UpdatePlatformInfoWithDevice(deviceId);
      65           11 :     if (err != ACL_SUCCESS) {
      66            7 :         ACL_LOG_WARN("update platform info with device failed, error code is [%d], deviceId is [%d]", err, deviceId);
      67              :     }
      68           11 :     return ACL_SUCCESS;
      69           13 : }
      70              : 
      71            4 : aclError aclrtSetDeviceWithoutTsdVXXImpl(int32_t deviceId)
      72              : {
      73            4 :     ACL_PROFILING_REG(acl::AclProfType::AclrtSetDeviceWithoutTsdVXX);
      74            4 :     ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
      75            4 :     ACL_LOG_INFO("start to execute aclrtSetDeviceWithoutTsdVXX, deviceId = %d.", deviceId);
      76            4 :     const std::string& socVersion = acl::GetSocVersion();
      77            4 :     if (strncmp(socVersion.c_str(), "Ascend910", (sizeof("Ascend910") - 1UL)) != 0) {
      78            0 :         ACL_LOG_INFO("The soc version is not Ascend910, which is not supported");
      79            0 :         acl::AclErrorLogManager::ReportInputError(
      80              :             acl::UNSUPPORTED_SYSTEM_MSG, {"func"},
      81              :             {"aclrtSetDeviceWithoutTsdVXX, only Ascend 910 chips are supported"});
      82            0 :         return ACL_ERROR_API_NOT_SUPPORT;
      83              :     }
      84            4 :     ACL_REQUIRES_RTS_OK(rtSetDeviceWithoutTsd(deviceId));
      85            2 :     ACL_LOG_INFO("open device %d successfully.", deviceId);
      86            2 :     ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
      87            2 :     return ACL_SUCCESS;
      88            4 : }
      89              : 
      90            5 : aclError aclrtResetDeviceImpl(int32_t deviceId)
      91              : {
      92            5 :     ACL_PROFILING_REG(acl::AclProfType::AclrtResetDevice);
      93            5 :     ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
      94            5 :     ACL_LOG_INFO("start to execute aclrtResetDevice, deviceId = %d.", deviceId);
      95            5 :     ACL_REQUIRES_RTS_OK(rtDeviceReset(deviceId));
      96            2 :     ACL_LOG_INFO("successfully execute aclrtResetDevice, reset device %d.", deviceId);
      97            2 :     ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
      98            2 :     return ACL_SUCCESS;
      99            5 : }
     100              : 
     101            5 : aclError aclrtResetDeviceForceImpl(int32_t deviceId)
     102              : {
     103            5 :     ACL_PROFILING_REG(acl::AclProfType::AclrtResetDeviceForce);
     104            5 :     ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
     105            5 :     ACL_LOG_INFO("start to execute aclrtResetDeviceForce, deviceId = %d.", deviceId);
     106            5 :     ACL_REQUIRES_RTS_OK(rtDeviceResetForce(deviceId));
     107            3 :     ACL_LOG_INFO("successfully execute aclrtResetDeviceForce, reset device %d.", deviceId);
     108            3 :     ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
     109            3 :     return ACL_SUCCESS;
     110            5 : }
     111              : 
     112            4 : aclError aclrtResetDeviceWithoutTsdVXXImpl(int32_t deviceId)
     113              : {
     114            4 :     ACL_PROFILING_REG(acl::AclProfType::AclrtResetDeviceWithoutTsdVXX);
     115            4 :     ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
     116            4 :     ACL_LOG_INFO("start to execute aclrtResetDeviceWithoutTsdVXX, deviceId = %d.", deviceId);
     117            4 :     const std::string& socVersion = acl::GetSocVersion();
     118            4 :     if (strncmp(socVersion.c_str(), "Ascend910", (sizeof("Ascend910") - 1UL)) != 0) {
     119            0 :         ACL_LOG_ERROR("The soc version is not Ascend910, which is not supported");
     120            0 :         acl::AclErrorLogManager::ReportInputError(
     121              :             acl::UNSUPPORTED_SYSTEM_MSG, {"func"},
     122              :             {"aclrtResetDeviceWithoutTsdVXX, only Ascend 910 chips are supported"});
     123            0 :         return ACL_ERROR_API_NOT_SUPPORT;
     124              :     }
     125            4 :     ACL_REQUIRES_RTS_OK(rtDeviceResetWithoutTsd(deviceId));
     126            2 :     ACL_LOG_INFO("successfully execute aclrtResetDeviceWithoutTsdVXX, reset device %d", deviceId);
     127            2 :     ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_SET_RESET_DEVICE);
     128            2 :     return ACL_SUCCESS;
     129            4 : }
     130              : 
     131            6 : aclError aclrtGetDeviceImpl(int32_t* deviceId)
     132              : {
     133            6 :     ACL_LOG_INFO("start to execute aclrtGetDevice");
     134            6 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(deviceId);
     135            4 :     const rtError_t rtErr = rtGetDevice(deviceId);
     136            4 :     if (rtErr != RT_ERROR_NONE) {
     137            2 :         ACL_LOG_INFO("Cannot get device id, runtime result = %d.", static_cast<int32_t>(rtErr));
     138            2 :         return ACL_GET_ERRCODE_RTS(rtErr);
     139              :     }
     140            2 :     ACL_LOG_DEBUG("successfully execute aclrtGetDevice, get device id is %d.", *deviceId);
     141            2 :     return ACL_SUCCESS;
     142              : }
     143              : 
     144           20 : aclError aclrtGetRunModeImpl(aclrtRunMode* runMode)
     145              : {
     146           20 :     ACL_LOG_INFO("start to execute aclrtGetRunMode");
     147           20 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(runMode);
     148              :     rtRunMode rtMode;
     149           20 :     ACL_REQUIRES_RTS_OK(rtGetRunMode(&rtMode));
     150           17 :     if (rtMode == RT_RUN_MODE_OFFLINE) {
     151           15 :         *runMode = ACL_DEVICE;
     152           15 :         return ACL_SUCCESS;
     153              :     }
     154            2 :     *runMode = ACL_HOST;
     155            2 :     ACL_LOG_INFO("successfully execute aclrtGetRunMode, current runMode is %d.", static_cast<int32_t>(*runMode));
     156            2 :     return ACL_SUCCESS;
     157              : }
     158              : 
     159            4 : aclError aclrtSynchronizeDeviceImpl()
     160              : {
     161            4 :     ACL_PROFILING_REG(acl::AclProfType::AclrtSynchronizeDevice);
     162            4 :     ACL_LOG_INFO("start to execute aclrtSynchronizeDevice");
     163            4 :     ACL_REQUIRES_RTS_OK(rtDeviceSynchronize());
     164            2 :     ACL_LOG_INFO("device synchronize successfully.");
     165            2 :     return ACL_SUCCESS;
     166            4 : }
     167              : 
     168            7 : aclError aclrtSynchronizeDeviceWithTimeoutImpl(int32_t timeout)
     169              : {
     170            7 :     ACL_PROFILING_REG(acl::AclProfType::AclrtSynchronizeDeviceWithTimeout);
     171            7 :     ACL_LOG_INFO("start to execute aclrtSynchronizeDeviceWithTimeout, timeout %dms", timeout);
     172            7 :     constexpr int32_t defaultTimeout = -1;
     173           13 :     ACL_CHECK_INVALID_VALUE_WITH_EXPECT_RET(
     174              :         timeout >= defaultTimeout, timeout, "[-1, INT_MAX]", ACL_ERROR_RT_PARAM_INVALID);
     175              : 
     176            5 :     const rtError_t rtErr = rtDeviceSynchronizeWithTimeout(timeout);
     177            5 :     if (rtErr == ACL_ERROR_RT_STREAM_SYNC_TIMEOUT) {
     178            1 :         return ACL_ERROR_RT_STREAM_SYNC_TIMEOUT;
     179            4 :     } else if (rtErr != RT_ERROR_NONE) {
     180            1 :         return ACL_GET_ERRCODE_RTS(rtErr);
     181              :     }
     182            3 :     ACL_LOG_INFO("device synchronize with timeout %dms successfully.", timeout);
     183            3 :     return ACL_SUCCESS;
     184            7 : }
     185              : 
     186            6 : aclError aclrtSetTsDeviceImpl(aclrtTsId tsId)
     187              : {
     188            6 :     ACL_PROFILING_REG(acl::AclProfType::AclrtSetTsDevice);
     189            6 :     ACL_LOG_INFO("start to execute aclrtSetTsDevice, tsId = %d.", static_cast<int32_t>(tsId));
     190            6 :     if ((tsId != ACL_TS_ID_AICORE) && (tsId != ACL_TS_ID_AIVECTOR)) {
     191            2 :         std::string funcName = acl::AclErrorLogManager::GetFuncNameWithoutImplSuffix(__func__);
     192            2 :         acl::AclErrorLogManager::ReportInputError(
     193            4 :             acl::INVALID_VALUE_MSG, std::vector<const char*>({"func", "value", "param", "expect"}),
     194            2 :             std::vector<const char*>(
     195            4 :                 {funcName.c_str(), acl::GetTsIdDesc(tsId), "tsId", "ACL_TS_ID_AICORE or ACL_TS_ID_AIVECTOR"}));
     196            2 :         return ACL_ERROR_INVALID_PARAM;
     197            2 :     }
     198            4 :     ACL_REQUIRES_RTS_OK(rtSetTSDevice(static_cast<uint32_t>(tsId)));
     199            2 :     ACL_LOG_INFO("successfully execute aclrtSetTsDevice, set device ts %d", static_cast<int32_t>(tsId));
     200            2 :     return ACL_SUCCESS;
     201            6 : }
     202              : 
     203            3 : aclError aclrtGetDeviceUtilizationRateImpl(int32_t deviceId, aclrtUtilizationInfo* utilizationInfo)
     204              : {
     205            3 :     ACL_LOG_INFO("start to execute aclrtGetDeviceUtilizationRate, device is %d.", deviceId);
     206            3 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(utilizationInfo);
     207            3 :     aclrtUtilizationExtendInfo* utilizationExtend = utilizationInfo->utilizationExtend;
     208              : 
     209            3 :     ACL_CHECK_INVALID_PARAM_NO_VALUE(
     210              :         utilizationExtend == nullptr, "utilizationInfo->utilizationExtend",
     211              :         "utilizationExtend is a reserved parameter and must be nullptr");
     212            2 :     utilizationInfo->cubeUtilization = GetAllUtilizations(deviceId, RT_UTIL_TYPE_AICORE);
     213            2 :     utilizationInfo->vectorUtilization = GetAllUtilizations(deviceId, RT_UTIL_TYPE_AIVECTOR);
     214            2 :     utilizationInfo->aicpuUtilization = GetAllUtilizations(deviceId, RT_UTIL_TYPE_AICPU);
     215              :     // Currently, memory is not supported
     216            2 :     utilizationInfo->memoryUtilization = DEVICE_UTILIZATION_NOT_SUPPORT;
     217            2 :     ACL_LOG_INFO("successfully execute aclrtGetDeviceUtilizationRate, device is %d.", deviceId);
     218            2 :     return ACL_SUCCESS;
     219              : };
     220              : 
     221            6 : aclError aclrtGetDeviceCountImpl(uint32_t* count)
     222              : {
     223            6 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetDeviceCount);
     224            6 :     ACL_LOG_INFO("start to execute aclrtGetDeviceCount");
     225            6 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(count);
     226              : 
     227            4 :     ACL_REQUIRES_RTS_OK(rtGetDeviceCount(reinterpret_cast<int32_t*>(count)));
     228            2 :     ACL_LOG_INFO("successfully execute aclrtGetDeviceCount, get device count is %u.", *count);
     229            2 :     return ACL_SUCCESS;
     230            6 : }
     231              : 
     232            2 : aclError aclrtGetDeviceSatModeImpl(aclrtFloatOverflowMode* mode)
     233              : {
     234            2 :     ACL_LOG_INFO("start to execute aclrtGetDeviceSatMode");
     235            2 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(mode);
     236            2 :     rtFloatOverflowMode_t rtMode = RT_OVERFLOW_MODE_UNDEF;
     237            2 :     ACL_REQUIRES_RTS_OK(rtGetDeviceSatMode(&rtMode));
     238            1 :     *mode = static_cast<aclrtFloatOverflowMode>(rtMode);
     239            1 :     ACL_LOG_INFO("successfully execute aclrtGetDeviceSatMode, mode is %d.", *mode);
     240            1 :     return ACL_SUCCESS;
     241              : }
     242              : 
     243            2 : aclError aclrtSetDeviceSatModeImpl(aclrtFloatOverflowMode mode)
     244              : {
     245            2 :     ACL_LOG_INFO("start to execute aclrtSetDeviceSatMode, mode is %d", mode);
     246            2 :     ACL_REQUIRES_RTS_OK(rtSetDeviceSatMode(static_cast<rtFloatOverflowMode_t>(mode)));
     247            1 :     ACL_LOG_INFO("successfully execute aclrtSetDeviceSatMode, mode is %d", mode);
     248            1 :     return ACL_SUCCESS;
     249              : }
     250              : 
     251            3 : aclError aclrtGetOverflowStatusImpl(void* outputAddr, size_t outputSize, aclrtStream stream)
     252              : {
     253            3 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetOverflowStatus);
     254            3 :     ACL_LOG_INFO("start to execute aclrtGetOverflowStatus, outputSize = %lu", outputSize);
     255            3 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(outputAddr);
     256            2 :     ACL_REQUIRES_RTS_OK(rtGetDeviceSatStatus(outputAddr, outputSize, static_cast<rtStream_t>(stream)));
     257            1 :     ACL_LOG_INFO("successfully execute aclrtGetOverflowStatus");
     258            1 :     return ACL_SUCCESS;
     259            3 : }
     260              : 
     261            2 : aclError aclrtResetOverflowStatusImpl(aclrtStream stream)
     262              : {
     263            2 :     ACL_PROFILING_REG(acl::AclProfType::AclrtResetOverflowStatus);
     264            2 :     ACL_LOG_INFO("start to execute aclrtResetOverflowStatus");
     265            2 :     ACL_REQUIRES_RTS_OK(rtCleanDeviceSatStatus(static_cast<rtStream_t>(stream)));
     266            1 :     ACL_LOG_INFO("successfully execute aclrtResetOverflowStatus");
     267            1 :     return ACL_SUCCESS;
     268            2 : }
     269              : 
     270            3 : aclError aclrtQueryDeviceStatusImpl(int32_t deviceId, aclrtDeviceStatus* deviceStatus)
     271              : {
     272            3 :     ACL_PROFILING_REG(acl::AclProfType::AclrtQueryDeviceStatus);
     273            3 :     ACL_LOG_INFO("start to execute aclrtQueryDeviceStatus with device id:%d", deviceId);
     274            3 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(deviceStatus);
     275            2 :     rtDeviceStatus rtDevStatus = RT_DEVICE_STATUS_END;
     276            2 :     const rtError_t rtErr = rtDeviceStatusQuery(static_cast<uint32_t>(deviceId), &rtDevStatus);
     277            2 :     if (rtErr != RT_ERROR_NONE) {
     278            1 :         ACL_LOG_WARN("rtDeviceStatusQuery failed, runtime result = %d.", static_cast<int32_t>(rtErr));
     279            1 :         return ACL_GET_ERRCODE_RTS(rtErr);
     280              :     }
     281            1 :     *deviceStatus = static_cast<aclrtDeviceStatus>(rtDevStatus);
     282            1 :     ACL_LOG_INFO("successfully execute aclrtQueryDeviceStatus");
     283            1 :     return ACL_SUCCESS;
     284            3 : }
     285              : 
     286            2 : aclError aclrtDeviceTaskAbortImpl(int32_t deviceId, uint32_t timeout)
     287              : {
     288            2 :     ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceTaskAbort);
     289            2 :     ACL_LOG_INFO("start to execute aclrtDeviceTaskAbort on device %d, timeout %ums", deviceId, timeout);
     290            2 :     const rtError_t rtErr = rtDeviceTaskAbort(deviceId, timeout);
     291            2 :     if (rtErr != RT_ERROR_NONE) {
     292            1 :         ACL_LOG_ERROR(
     293              :             "rtDeviceTaskAbort for device %d, failed, runtime result = %d.", deviceId, static_cast<int32_t>(rtErr));
     294            1 :         return ACL_GET_ERRCODE_RTS(rtErr);
     295              :     }
     296            1 :     return ACL_SUCCESS;
     297            2 : }
     298              : 
     299            8 : aclError aclrtGetDeviceInfoImpl(uint32_t deviceId, aclrtDevAttr attr, int64_t* value)
     300              : {
     301            8 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetDeviceInfo);
     302            8 :     ACL_LOG_INFO("start to execute aclrtGetDeviceInfo");
     303            8 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
     304              : 
     305            5 :     ACL_REQUIRES_RTS_OK(rtsDeviceGetInfo(deviceId, static_cast<rtDevAttr>(attr), value));
     306              : 
     307            3 :     ACL_LOG_INFO("successfully execute aclrtGetDeviceInfo");
     308            3 :     return ACL_SUCCESS;
     309            8 : }
     310              : 
     311            4 : aclError aclrtDeviceGetStreamPriorityRangeImpl(int32_t* leastPriority, int32_t* greatestPriority)
     312              : {
     313            4 :     ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceGetStreamPriorityRange);
     314            4 :     ACL_LOG_INFO("start to execute aclrtDeviceGetStreamPriorityRange");
     315              : 
     316            4 :     ACL_REQUIRES_RTS_OK(rtsDeviceGetStreamPriorityRange(leastPriority, greatestPriority));
     317              : 
     318            4 :     ACL_LOG_INFO("successfully execute aclrtDeviceGetStreamPriorityRange");
     319            4 :     return ACL_SUCCESS;
     320            4 : }
     321              : 
     322            3 : aclError aclrtGetDeviceCapabilityImpl(int32_t deviceId, aclrtDevFeatureType devFeatureType, int32_t* value)
     323              : {
     324            3 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetDeviceCapability);
     325            3 :     ACL_LOG_INFO("start to execute aclrtGetDeviceCapability");
     326            3 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
     327              : 
     328            2 :     ACL_REQUIRES_RTS_OK(rtsDeviceGetCapability(deviceId, devFeatureType, value));
     329              : 
     330            1 :     ACL_LOG_INFO("successfully execute aclrtGetDeviceCapability");
     331            1 :     return ACL_SUCCESS;
     332            3 : }
     333              : 
     334            3 : aclError aclrtDeviceGetHostAtomicCapabilitiesImpl(
     335              :     uint32_t* capabilities, const aclrtAtomicOperation* operations, const uint32_t count, int32_t deviceId)
     336              : {
     337            3 :     ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceGetHostAtomicCapabilities);
     338            3 :     ACL_LOG_INFO(
     339              :         "start to execute aclrtDeviceGetHostAtomicCapabilities, deviceId is [%u], count is [%u]", deviceId, count);
     340              : 
     341            3 :     ACL_REQUIRES_RTS_OK(rtDeviceGetHostAtomicCapabilities(
     342              :         capabilities, reinterpret_cast<const rtAtomicOperation*>(operations), count, deviceId));
     343              : 
     344            1 :     ACL_LOG_INFO("successfully execute aclrtDeviceGetHostAtomicCapabilities");
     345            1 :     return ACL_SUCCESS;
     346            3 : }
     347              : 
     348            3 : aclError aclrtDeviceGetP2PAtomicCapabilitiesImpl(
     349              :     uint32_t* capabilities, const aclrtAtomicOperation* operations, const uint32_t count, int32_t srcDeviceId,
     350              :     int32_t dstDeviceId)
     351              : {
     352            3 :     ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceGetP2PAtomicCapabilities);
     353            3 :     ACL_LOG_INFO(
     354              :         "start to execute aclrtDeviceGetP2PAtomicCapabilities, srcDeviceId is [%u], dstDeviceId is [%u], "
     355              :         "count is [%u]",
     356              :         srcDeviceId, dstDeviceId, count);
     357              : 
     358            3 :     ACL_REQUIRES_RTS_OK(rtDeviceGetP2PAtomicCapabilities(
     359              :         capabilities, reinterpret_cast<const rtAtomicOperation*>(operations), count, srcDeviceId, dstDeviceId));
     360              : 
     361            1 :     ACL_LOG_INFO("successfully execute aclrtDeviceGetP2PAtomicCapabilities");
     362            1 :     return ACL_SUCCESS;
     363            3 : }
     364              : 
     365            4 : aclError aclrtDeviceGetUuidImpl(int32_t deviceId, aclrtUuid* uuid)
     366              : {
     367            4 :     ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceGetUuid);
     368            4 :     ACL_LOG_INFO("start to execute aclrtGetDeviceUuid, deviceId is [%d]", deviceId);
     369            4 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(uuid);
     370            3 :     ACL_REQUIRES_RTS_OK_WARN_NOT_SUPPORT(rtGetDeviceUuid(deviceId, reinterpret_cast<rtUuid_t*>(uuid)), rtGetDeviceUuid);
     371              : 
     372            1 :     ACL_LOG_INFO("successfully execute aclrtGetDeviceUuid");
     373            1 :     return ACL_SUCCESS;
     374            4 : }
     375              : 
     376            3 : aclError aclrtGetDeviceResLimitImpl(int32_t deviceId, aclrtDevResLimitType type, uint32_t* value)
     377              : {
     378            3 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetDeviceResLimit);
     379            3 :     ACL_LOG_INFO(
     380              :         "start to execute aclrtGetDeviceResLimit, deviceId is [%d], type is [%u]", deviceId,
     381              :         static_cast<uint32_t>(type));
     382            3 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
     383              : 
     384            2 :     ACL_REQUIRES_RTS_OK(rtsGetDeviceResLimit(deviceId, static_cast<rtDevResLimitType_t>(type), value));
     385              : 
     386            1 :     ACL_LOG_INFO("successfully execute aclrtGetDeviceResLimit");
     387            1 :     return ACL_SUCCESS;
     388            3 : }
     389              : 
     390            2 : aclError aclrtSetDeviceResLimitImpl(int32_t deviceId, aclrtDevResLimitType type, uint32_t value)
     391              : {
     392            2 :     ACL_PROFILING_REG(acl::AclProfType::AclrtSetDeviceResLimit);
     393            2 :     ACL_LOG_INFO(
     394              :         "start to execute aclrtSetDeviceResLimit, deviceId is [%d], type is [%u], value is [%u]", deviceId,
     395              :         static_cast<uint32_t>(type), value);
     396              : 
     397            2 :     ACL_REQUIRES_RTS_OK(rtsSetDeviceResLimit(deviceId, static_cast<rtDevResLimitType_t>(type), value));
     398              : 
     399            1 :     ACL_LOG_INFO("successfully execute aclrtSetDeviceResLimit");
     400            1 :     return ACL_SUCCESS;
     401            2 : }
     402              : 
     403            2 : aclError aclrtResetDeviceResLimitImpl(int32_t deviceId)
     404              : {
     405            2 :     ACL_PROFILING_REG(acl::AclProfType::AclrtResetDeviceResLimit);
     406            2 :     ACL_LOG_INFO("start to execute aclrtResetDeviceResLimit, deviceId is [%d]", deviceId);
     407              : 
     408            2 :     ACL_REQUIRES_RTS_OK(rtsResetDeviceResLimit(deviceId));
     409              : 
     410            1 :     ACL_LOG_INFO("successfully execute aclrtResetDeviceResLimit");
     411            1 :     return ACL_SUCCESS;
     412            2 : }
     413              : 
     414            4 : aclError aclrtGetStreamResLimitImpl(aclrtStream stream, aclrtDevResLimitType type, uint32_t* value)
     415              : {
     416            4 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetStreamResLimit);
     417            4 :     ACL_LOG_INFO("start to execute aclrtGetStreamResLimit, type is [%u]", static_cast<uint32_t>(type));
     418            4 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
     419            3 :     ACL_REQUIRES_RTS_OK(
     420              :         rtsGetStreamResLimit(static_cast<rtStream_t>(stream), static_cast<rtDevResLimitType_t>(type), value));
     421              : 
     422            1 :     ACL_LOG_INFO("successfully execute aclrtGetStreamResLimit, value is [%u]", *value);
     423            1 :     return ACL_SUCCESS;
     424            4 : }
     425              : 
     426            3 : aclError aclrtSetStreamResLimitImpl(aclrtStream stream, aclrtDevResLimitType type, uint32_t value)
     427              : {
     428            3 :     ACL_PROFILING_REG(acl::AclProfType::AclrtSetStreamResLimit);
     429            3 :     ACL_LOG_INFO(
     430              :         "start to execute aclrtSetStreamResLimit, type is [%u], value is [%u]", static_cast<uint32_t>(type), value);
     431            3 :     ACL_REQUIRES_RTS_OK(
     432              :         rtsSetStreamResLimit(static_cast<rtStream_t>(stream), static_cast<rtDevResLimitType_t>(type), value));
     433              : 
     434            1 :     ACL_LOG_INFO("successfully execute aclrtSetStreamResLimit");
     435            1 :     return ACL_SUCCESS;
     436            3 : }
     437              : 
     438            3 : aclError aclrtResetStreamResLimitImpl(aclrtStream stream)
     439              : {
     440            3 :     ACL_PROFILING_REG(acl::AclProfType::AclrtResetStreamResLimit);
     441            3 :     ACL_LOG_INFO("start to execute aclrtResetStreamResLimit");
     442            3 :     ACL_REQUIRES_RTS_OK(rtsResetStreamResLimit(static_cast<rtStream_t>(stream)));
     443              : 
     444            1 :     ACL_LOG_INFO("successfully execute aclrtResetStreamResLimit");
     445            1 :     return ACL_SUCCESS;
     446            3 : }
     447              : 
     448            3 : aclError aclrtUseStreamResInCurrentThreadImpl(aclrtStream stream)
     449              : {
     450            3 :     ACL_PROFILING_REG(acl::AclProfType::AclrtUseStreamResInCurrentThread);
     451            3 :     ACL_LOG_INFO("start to execute aclrtUseStreamResInCurrentThread");
     452            3 :     ACL_REQUIRES_RTS_OK(rtsUseStreamResInCurrentThread(static_cast<rtStream_t>(stream)));
     453              : 
     454            1 :     ACL_LOG_INFO("successfully execute aclrtUseStreamResInCurrentThread");
     455            1 :     return ACL_SUCCESS;
     456            3 : }
     457              : 
     458            3 : aclError aclrtUnuseStreamResInCurrentThreadImpl(aclrtStream stream)
     459              : {
     460            3 :     ACL_PROFILING_REG(acl::AclProfType::AclrtUnuseStreamResInCurrentThread);
     461            3 :     ACL_LOG_INFO("start to execute aclrtUnuseStreamResInCurrentThread");
     462            3 :     ACL_REQUIRES_RTS_OK(rtsNotUseStreamResInCurrentThread(static_cast<rtStream_t>(stream)));
     463              : 
     464            1 :     ACL_LOG_INFO("successfully execute aclrtUnuseStreamResInCurrentThread");
     465            1 :     return ACL_SUCCESS;
     466            3 : }
     467              : 
     468            3 : aclError aclrtGetResInCurrentThreadImpl(aclrtDevResLimitType type, uint32_t* value)
     469              : {
     470            3 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetResInCurrentThread);
     471            3 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
     472            2 :     ACL_REQUIRES_RTS_OK(rtsGetResInCurrentThread(static_cast<rtDevResLimitType_t>(type), value));
     473              : 
     474            1 :     return ACL_SUCCESS;
     475            3 : }
     476              : 
     477            3 : aclError aclrtGetDevicesTopoImpl(uint32_t deviceId, uint32_t otherDeviceId, uint64_t* value)
     478              : {
     479            3 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetDevicesTopo);
     480            3 :     ACL_LOG_INFO(
     481              :         "start to execute aclrtGetDevicesTopo, deviceId is [%u], otherDeviceId is [%u]", deviceId, otherDeviceId);
     482            3 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
     483              : 
     484            2 :     ACL_REQUIRES_RTS_OK(
     485              :         rtsGetPairDevicesInfo(deviceId, otherDeviceId, static_cast<int32_t>(RT_DEVS_INFO_TYPE_TOPOLOGY), value));
     486              : 
     487            1 :     ACL_LOG_INFO("successfully execute aclrtGetDevicesTopo");
     488            1 :     return ACL_SUCCESS;
     489            3 : }
     490              : 
     491            2 : aclError aclrtGetLogicDevIdByUserDevIdImpl(const int32_t userDevid, int32_t* const logicDevId)
     492              : {
     493            2 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetLogicDevIdByUserDevId);
     494            2 :     ACL_LOG_INFO("start to execute aclrtGetLogicDevIdByUserDevId, userDevid is [%d]", userDevid);
     495            2 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(logicDevId);
     496            2 :     ACL_REQUIRES_RTS_OK(rtsGetLogicDevIdByUserDevId(userDevid, logicDevId));
     497              : 
     498            1 :     ACL_LOG_INFO("successfully execute aclrtGetLogicDevIdByUserDevId");
     499            1 :     return ACL_SUCCESS;
     500            2 : }
     501              : 
     502            2 : aclError aclrtGetUserDevIdByLogicDevIdImpl(const int32_t logicDevId, int32_t* const userDevid)
     503              : {
     504            2 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetUserDevIdByLogicDevId);
     505            2 :     ACL_LOG_INFO("start to execute aclrtGetUserDevIdByLogicDevId, logicDevId is [%d]", logicDevId);
     506            2 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(userDevid);
     507            2 :     ACL_REQUIRES_RTS_OK(rtsGetUserDevIdByLogicDevId(logicDevId, userDevid));
     508              : 
     509            1 :     ACL_LOG_INFO("successfully execute aclrtGetUserDevIdByLogicDevId");
     510            1 :     return ACL_SUCCESS;
     511            2 : }
     512              : 
     513            2 : aclError aclrtGetLogicDevIdByPhyDevIdImpl(int32_t phyDevId, int32_t* const logicDevId)
     514              : {
     515            2 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetLogicDevIdByPhyDevId);
     516            2 :     ACL_LOG_INFO("start to execute aclrtGetLogicDevIdByPhyDevId, phyDevId is [%d]", phyDevId);
     517            2 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(logicDevId);
     518            2 :     ACL_REQUIRES_RTS_OK(rtsGetLogicDevIdByPhyDevId(phyDevId, logicDevId));
     519              : 
     520            1 :     ACL_LOG_INFO("successfully execute aclrtGetLogicDevIdByPhyDevId");
     521            1 :     return ACL_SUCCESS;
     522            2 : }
     523              : 
     524            2 : aclError aclrtGetPhyDevIdByLogicDevIdImpl(int32_t logicDevId, int32_t* const phyDevId)
     525              : {
     526            2 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetPhyDevIdByLogicDevId);
     527            2 :     ACL_LOG_INFO("start to execute aclrtGetPhyDevIdByLogicDevId, logicDevId is [%d]", logicDevId);
     528            2 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(phyDevId);
     529            2 :     ACL_REQUIRES_RTS_OK(rtsGetPhyDevIdByLogicDevId(logicDevId, phyDevId));
     530              : 
     531            1 :     ACL_LOG_INFO("successfully execute aclrtGetPhyDevIdByLogicDevId");
     532            1 :     return ACL_SUCCESS;
     533            2 : }
     534              : 
     535            4 : aclError aclrtGetUserDevIdByPhyDevIdImpl(const int32_t phyDevId, int32_t* const userDevId)
     536              : {
     537            4 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetUserDevIdByPhyDevId);
     538            4 :     ACL_LOG_INFO("start to execute aclrtGetUserDevIdByPhyDevId, phyDevId is [%d]", phyDevId);
     539            4 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(userDevId);
     540            3 :     ACL_REQUIRES_RTS_OK(rtsGetLogicDevIdByPhyDevId(phyDevId, userDevId));
     541              : 
     542            2 :     ACL_LOG_INFO("successfully execute aclrtGetUserDevIdByPhyDevId");
     543            2 :     return ACL_SUCCESS;
     544            4 : }
     545              : 
     546            4 : aclError aclrtGetPhyDevIdByUserDevIdImpl(const int32_t userDevId, int32_t* const phyDevId)
     547              : {
     548            4 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetPhyDevIdByUserDevId);
     549            4 :     ACL_LOG_INFO("start to execute aclrtGetPhyDevIdByUserDevId, userDevId is [%d]", userDevId);
     550            4 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(phyDevId);
     551            3 :     ACL_REQUIRES_RTS_OK(rtsGetPhyDevIdByLogicDevId(userDevId, phyDevId));
     552              : 
     553            2 :     ACL_LOG_INFO("successfully execute aclrtGetPhyDevIdByUserDevId");
     554            2 :     return ACL_SUCCESS;
     555            4 : }
     556              : 
     557            3 : aclError aclrtGetOpExecuteTimeoutImpl(uint32_t* const timeoutMs)
     558              : {
     559            3 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetOpExecuteTimeout);
     560            3 :     ACL_LOG_INFO("start to execute aclrtGetOpExecuteTimeout");
     561            3 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(timeoutMs);
     562            2 :     ACL_REQUIRES_RTS_OK(rtGetOpExecuteTimeoutV2(timeoutMs));
     563            1 :     ACL_LOG_INFO("successfully execute aclrtGetOpExecuteTimeout");
     564            1 :     return ACL_SUCCESS;
     565            3 : }
     566              : 
     567            2 : aclError aclrtCheckArchCompatibilityImpl(const char* socVersion, int32_t* canCompatible)
     568              : {
     569            2 :     ACL_PROFILING_REG(acl::AclProfType::AclrtCheckArchCompatibility);
     570            2 :     ACL_LOG_INFO("start to execute aclrtCheckArchCompatibility");
     571            2 :     ACL_REQUIRES_RTS_OK(rtCheckArchCompatibility(socVersion, canCompatible));
     572            1 :     ACL_LOG_INFO("successfully execute aclrtCheckArchCompatibility");
     573            1 :     return ACL_SUCCESS;
     574            2 : }
     575              : 
     576              : static constexpr rtLimitType_t ACL_TO_RT_LIMIT_TABLE[] = {
     577              :     RT_LIMIT_TYPE_SIMT_STACK_SIZE,
     578              :     RT_LIMIT_TYPE_SIMT_DVG_WARP_STACK_SIZE,
     579              :     RT_LIMIT_TYPE_STACK_SIZE,
     580              :     RT_LIMIT_TYPE_SIMD_PRINTF_FIFO_SIZE_PER_CORE,
     581              :     RT_LIMIT_TYPE_SIMT_PRINTF_FIFO_SIZE,
     582              : };
     583              : static constexpr size_t ACL_TO_RT_LIMIT_TABLE_SIZE = sizeof(ACL_TO_RT_LIMIT_TABLE) / sizeof(ACL_TO_RT_LIMIT_TABLE[0]);
     584              : 
     585           28 : static rtLimitType_t AclLimitToRtLimit(aclrtDeviceLimit limit)
     586              : {
     587           28 :     const auto idx = static_cast<size_t>(limit);
     588           28 :     if (idx >= ACL_TO_RT_LIMIT_TABLE_SIZE) {
     589            2 :         return RT_LIMIT_TYPE_RESERVED;
     590              :     }
     591           26 :     return ACL_TO_RT_LIMIT_TABLE[idx];
     592              : }
     593              : 
     594           17 : aclError aclrtDeviceSetLimitImpl(aclrtDeviceLimit limit, size_t value)
     595              : {
     596           17 :     ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceSetLimit);
     597           17 :     ACL_LOG_INFO(
     598              :         "start to execute aclrtDeviceSetLimit, limit is [%d], value is [%zu]", static_cast<int32_t>(limit), value);
     599           17 :     const auto rtType = AclLimitToRtLimit(limit);
     600           17 :     if (rtType == RT_LIMIT_TYPE_RESERVED) {
     601            1 :         std::string funcName = acl::AclErrorLogManager::GetFuncNameWithoutImplSuffix(__func__);
     602            1 :         std::string limitStr = std::to_string(static_cast<int32_t>(limit));
     603            1 :         acl::AclErrorLogManager::ReportInputError(
     604            2 :             acl::INVALID_VALUE_MSG, std::vector<const char*>({"func", "value", "param", "expect"}),
     605            2 :             std::vector<const char*>({funcName.c_str(), limitStr.c_str(), "limit", "[0, 4]"}));
     606            1 :         return ACL_ERROR_INVALID_PARAM;
     607            1 :     }
     608           16 :     if (value > static_cast<size_t>(UINT32_MAX)) {
     609            1 :         std::string funcName = acl::AclErrorLogManager::GetFuncNameWithoutImplSuffix(__func__);
     610            1 :         std::string valueStr = std::to_string(value);
     611            1 :         acl::AclErrorLogManager::ReportInputError(
     612            2 :             acl::INVALID_VALUE_MSG, std::vector<const char*>({"func", "value", "param", "expect"}),
     613            2 :             std::vector<const char*>({funcName.c_str(), valueStr.c_str(), "value", "[0, UINT32_MAX]"}));
     614            1 :         return ACL_ERROR_INVALID_PARAM;
     615            1 :     }
     616           15 :     const rtError_t rtSetErr = rtDeviceSetLimit(0, rtType, static_cast<uint32_t>(value));
     617           15 :     if (rtSetErr != RT_ERROR_NONE) {
     618            1 :         if (rtSetErr == ACL_ERROR_RT_FEATURE_NOT_SUPPORT) {
     619            0 :             ACL_LOG_WARN(
     620              :                 "aclrtDeviceSetLimit not supported, limit is [%d], value is [%zu].", static_cast<int32_t>(limit),
     621              :                 value);
     622            0 :             return rtSetErr;
     623              :         }
     624            1 :         ACL_LOG_CALL_ERROR("rtDeviceSetLimit failed, runtime result = %d.", static_cast<int32_t>(rtSetErr));
     625            1 :         return ACL_GET_ERRCODE_RTS(rtSetErr);
     626              :     }
     627           14 :     ACL_LOG_INFO(
     628              :         "successfully execute aclrtDeviceSetLimit, limit is [%d], value is [%zu]", static_cast<int32_t>(limit), value);
     629           14 :     return ACL_SUCCESS;
     630           17 : }
     631              : 
     632           12 : aclError aclrtDeviceGetLimitImpl(aclrtDeviceLimit limit, size_t* value)
     633              : {
     634           12 :     ACL_PROFILING_REG(acl::AclProfType::AclrtDeviceGetLimit);
     635           12 :     ACL_LOG_INFO("start to execute aclrtDeviceGetLimit, limit is [%d]", static_cast<int32_t>(limit));
     636           12 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(value);
     637           11 :     const auto rtType = AclLimitToRtLimit(limit);
     638           11 :     if (rtType == RT_LIMIT_TYPE_RESERVED) {
     639            1 :         std::string funcName = acl::AclErrorLogManager::GetFuncNameWithoutImplSuffix(__func__);
     640            1 :         std::string limitStr = std::to_string(static_cast<int32_t>(limit));
     641            1 :         acl::AclErrorLogManager::ReportInputError(
     642            2 :             acl::INVALID_VALUE_MSG, std::vector<const char*>({"func", "value", "param", "expect"}),
     643            2 :             std::vector<const char*>({funcName.c_str(), limitStr.c_str(), "limit", "[0, 4]"}));
     644            1 :         return ACL_ERROR_INVALID_PARAM;
     645            1 :     }
     646           10 :     uint32_t rtValue = 0U;
     647           10 :     const rtError_t rtGetErr = rtDeviceGetLimit(rtType, &rtValue);
     648           10 :     if (rtGetErr != RT_ERROR_NONE) {
     649            1 :         if (rtGetErr == ACL_ERROR_RT_FEATURE_NOT_SUPPORT) {
     650            1 :             ACL_LOG_WARN("aclrtDeviceGetLimit not supported, limit is [%d].", static_cast<int32_t>(limit));
     651            1 :             return rtGetErr;
     652              :         }
     653            0 :         ACL_LOG_CALL_ERROR("rtDeviceGetLimit failed, runtime result = %d.", static_cast<int32_t>(rtGetErr));
     654            0 :         return ACL_GET_ERRCODE_RTS(rtGetErr);
     655              :     }
     656            9 :     *value = static_cast<size_t>(rtValue);
     657            9 :     ACL_LOG_INFO(
     658              :         "successfully execute aclrtDeviceGetLimit, limit is [%d], value is [%zu]", static_cast<int32_t>(limit), *value);
     659            9 :     return ACL_SUCCESS;
     660           12 : }
     661              : #ifdef __cplusplus
     662              : }
     663              : #endif
        

Generated by: LCOV version 2.0-1