LCOV - code coverage report
Current view: top level - acl/aclrt_impl - group.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 98.4 % 124 122
Test Date: 2026-08-06 15:29:52 Functions: 100.0 % 7 7

            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 <sstream>
      13              : #include "securec.h"
      14              : #include "runtime/context.h"
      15              : #include "common/log_inner.h"
      16              : #include "common/error_codes_inner.h"
      17              : #include "common/prof_reporter.h"
      18              : #include "common/resource_statistics.h"
      19              : #include "utils/data_type_utils.h"
      20              : 
      21              : namespace {
      22              : 
      23           14 : static aclError FillAttrValue(const void *const src, const size_t srcLen, void *const dst, const size_t dstLen,
      24              :     size_t *const paramRetSize, const char *funcName)
      25              : {
      26           14 :     ACL_REQUIRES_NOT_NULL(src);
      27           14 :     ACL_REQUIRES_NOT_NULL(dst);
      28           14 :     if (srcLen > dstLen) {
      29            2 :         ACL_LOG_ERROR("[Check][valueLen]valueLen[%zu] is smaller than required size[%zu] for group computing power info", 
      30              :             dstLen, srcLen);
      31            2 :         const std::string dstLenVal = std::to_string(dstLen);
      32            4 :         std::string reason = std::to_string(dstLen) + " is shorter than the length of the group computing power information, "
      33            6 :             "required size is " + std::to_string(srcLen) + ", cannot save the computing power information";
      34            2 :         acl::AclErrorLogManager::ReportInputError(acl::INVALID_PARAM_REASON_MSG,
      35            4 :             std::vector<const char *>({"func", "value", "param", "reason"}),
      36            4 :             std::vector<const char *>({funcName, dstLenVal.c_str(), "valueLen", reason.c_str()}));
      37            2 :         return ACL_ERROR_INVALID_PARAM;
      38            2 :     }
      39           12 :     const auto ret = memcpy_s(dst, dstLen, src, srcLen);
      40           12 :     if (ret != EOK) {
      41            1 :         ACL_LOG_ERROR("call memcpy_s failed, result = %d, srcLen = %zu, dstLen = %zu", ret, srcLen, dstLen);
      42            1 :         const std::string retVal = std::to_string(ret);
      43            1 :         std::stringstream ss;
      44            1 :         ss << std::hex << "src=0x" << reinterpret_cast<uintptr_t>(src)
      45            1 :             << ", attrValue=0x" << reinterpret_cast<uintptr_t>(dst)
      46            1 :             << std::dec << ", valueLen=" << dstLen << ", count=" << srcLen << ".";
      47            1 :         const std::string extendInfo = ss.str();
      48            1 :         acl::AclErrorLogManager::ReportInputError(acl::STANDARD_FUNC_FAILED_MSG,
      49            2 :             std::vector<const char *>({"func1", "func2", "ret_code", "reason", "extend_info"}),
      50            1 :             std::vector<const char *>({funcName, "memcpy_s", retVal.c_str(),
      51            2 :                 strerror(ret), extendInfo.c_str()}));
      52            1 :         return ACL_ERROR_FAILURE;
      53            1 :     }
      54           11 :     *paramRetSize = srcLen;
      55              : 
      56           11 :     return ACL_SUCCESS;
      57              : }
      58              : }
      59              : 
      60              : #ifdef __cplusplus
      61              : extern "C" {
      62              : #endif
      63              : 
      64            3 : aclError aclrtSetGroupImpl(int32_t groupId)
      65              : {
      66            3 :     ACL_PROFILING_REG(acl::AclProfType::AclrtSetGroup);
      67            3 :     ACL_LOG_INFO("start to execute aclrtSetGroup, groupId is %d.", groupId);
      68            3 :     ACL_REQUIRES_RTS_OK(rtSetGroup(groupId));
      69            2 :     ACL_LOG_INFO("successfully execute aclrtSetGroup, groupId is %d.", groupId);
      70              : 
      71            2 :     return ACL_SUCCESS;
      72            3 : }
      73              : 
      74            3 : aclError aclrtGetGroupCountImpl(uint32_t *count)
      75              : {
      76            3 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetGroupCount);
      77            3 :     ACL_LOG_INFO("start to execute aclrtGetGroupCount");
      78            3 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(count);
      79            3 :     ACL_REQUIRES_RTS_OK(rtGetGroupCount(count));
      80            2 :     ACL_LOG_INFO("successfully execute aclrtGetGroupCount, group number is %u.", *count);
      81              : 
      82            2 :     return ACL_SUCCESS;
      83            3 : }
      84              : 
      85            7 : aclrtGroupInfo *aclrtCreateGroupInfoImpl()
      86              : {
      87            7 :     ACL_ADD_APPLY_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_GROUP_INFO);
      88            7 :     ACL_LOG_INFO("start to execute aclrtCreateGroupInfo");
      89            7 :     uint32_t count = 0U;
      90            7 :     const rtError_t rtErr = rtGetGroupCount(&count);
      91            7 :     if (rtErr != RT_ERROR_NONE) {
      92            1 :         return nullptr;
      93              :     }
      94            6 :     if (count == 0U) { // 0 represents that no group
      95            0 :         ACL_LOG_WARN("group number is 0, no memory allocation");
      96            0 :         return nullptr;
      97              :     }
      98              : 
      99            6 :     aclrtGroupInfo *const groupInfo = new(std::nothrow) aclrtGroupInfo[count];
     100            6 :     ACL_CHECK_MALLOC_RESULT_REPORT_RET(groupInfo, sizeof(aclrtGroupInfo) * count, "new", nullptr);
     101              : 
     102            6 :     ACL_LOG_INFO("successfully execute aclrtCreateGroupInfo, group number is %u.", count);
     103            6 :     ACL_ADD_APPLY_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_GROUP_INFO);
     104              : 
     105            6 :     return groupInfo;
     106              : }
     107              : 
     108            6 : aclError aclrtDestroyGroupInfoImpl(aclrtGroupInfo *groupInfo)
     109              : {
     110            6 :     ACL_ADD_RELEASE_TOTAL_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_GROUP_INFO);
     111            6 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(groupInfo);
     112            6 :     ACL_DELETE_ARRAY_AND_SET_NULL(groupInfo);
     113            6 :     ACL_LOG_INFO("successfully execute aclrtDestroyGroupInfo");
     114              : 
     115            6 :     ACL_ADD_RELEASE_SUCCESS_COUNT(acl::ACL_STATISTICS_CREATE_DESTROY_GROUP_INFO);
     116              : 
     117            6 :     return ACL_SUCCESS;
     118              : }
     119              : 
     120            4 : aclError aclrtGetAllGroupInfoImpl(aclrtGroupInfo *groupInfo)
     121              : {
     122            4 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetAllGroupInfo);
     123            4 :     ACL_LOG_INFO("start to execute aclrtGetAllGroupInfo");
     124            4 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(groupInfo);
     125            4 :     uint32_t count = 0U;
     126            4 :     ACL_REQUIRES_RTS_OK(rtGetGroupCount(&count));
     127              : 
     128              :     // -1 represents that get all group information
     129            3 :     ACL_REQUIRES_RTS_OK(rtGetGroupInfo(-1, static_cast<rtGroupInfo_t *>(groupInfo), count));
     130              : 
     131            2 :     ACL_LOG_INFO("successfully execute aclrtGetAllGroupInfo, group number = %u", count);
     132              : 
     133            2 :     return ACL_SUCCESS;
     134            4 : }
     135              : 
     136           19 : aclError aclrtGetGroupInfoDetailImpl(const aclrtGroupInfo *groupInfo, int32_t groupIndex, aclrtGroupAttr attr,
     137              :                                      void *attrValue, size_t valueLen, size_t *paramRetSize)
     138              : {
     139           19 :     ACL_PROFILING_REG(acl::AclProfType::AclrtGetGroupInfoDetail);
     140           19 :     ACL_LOG_INFO("start to execute aclrtGetGroupInfoDetail, groupIndex = %d", groupIndex);
     141           19 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(groupInfo);
     142           19 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(attrValue);
     143           19 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(paramRetSize);
     144           19 :     uint32_t count = 0U;
     145           19 :     ACL_REQUIRES_RTS_OK(rtGetGroupCount(&count));
     146           18 :     if ((groupIndex < 0) || (static_cast<uint32_t>(groupIndex) >= count)) {
     147            2 :         ACL_LOG_ERROR("the index value of group is invalid, groupIndex = %d, not in range [0, %u)",
     148              :             groupIndex, count);
     149            2 :         const std::string groupIndexVal = std::to_string(groupIndex);
     150            2 :         std::string expect = "[0, " + std::to_string(count) + "]";
     151            2 :         std::string funcName = acl::AclErrorLogManager::GetFuncNameWithoutImplSuffix(__func__);
     152            2 :         acl::AclErrorLogManager::ReportInputError(acl::INVALID_VALUE_MSG,
     153            4 :             std::vector<const char *>({"func", "value", "param", "expect"}),
     154            4 :             std::vector<const char *>({funcName.c_str(), groupIndexVal.c_str(), "groupIndex", expect.c_str()}));
     155            2 :         return ACL_ERROR_INVALID_PARAM;
     156            2 :     }
     157              : 
     158              :     aclError aclRet;
     159           16 :     switch (attr) {
     160            3 :         case ACL_GROUP_AICORE_INT:
     161            3 :             aclRet = FillAttrValue(static_cast<const void *>(&groupInfo[groupIndex].aicoreNum),
     162              :                 sizeof(groupInfo[groupIndex].aicoreNum), attrValue, valueLen, paramRetSize, __func__);
     163            3 :             break;
     164            3 :         case ACL_GROUP_AIV_INT:
     165            3 :             aclRet = FillAttrValue(static_cast<const void *>(&groupInfo[groupIndex].aivectorNum),
     166              :                 sizeof(groupInfo[groupIndex].aivectorNum), attrValue, valueLen, paramRetSize, __func__);
     167            3 :             break;
     168            2 :         case ACL_GROUP_AIC_INT:
     169            2 :             aclRet = FillAttrValue(static_cast<const void *>(&groupInfo[groupIndex].aicpuNum),
     170              :                 sizeof(groupInfo[groupIndex].aicpuNum), attrValue, valueLen, paramRetSize, __func__);
     171            2 :             break;
     172            2 :         case ACL_GROUP_SDMANUM_INT:
     173            2 :             aclRet = FillAttrValue(static_cast<const void *>(&groupInfo[groupIndex].sdmaNum),
     174              :                 sizeof(groupInfo[groupIndex].sdmaNum), attrValue, valueLen, paramRetSize, __func__);
     175            2 :             break;
     176            2 :         case ACL_GROUP_ASQNUM_INT:
     177            2 :             aclRet = FillAttrValue(static_cast<const void *>(&groupInfo[groupIndex].activeStreamNum),
     178              :                 sizeof(groupInfo[groupIndex].activeStreamNum), attrValue, valueLen, paramRetSize, __func__);
     179            2 :             break;
     180            2 :         case ACL_GROUP_GROUPID_INT:
     181            2 :             aclRet = FillAttrValue(static_cast<const void *>(&groupInfo[groupIndex].groupId),
     182              :                 sizeof(groupInfo[groupIndex].groupId), attrValue, valueLen, paramRetSize, __func__);
     183            2 :             break;
     184            2 :         default:
     185            2 :             ACL_LOG_ERROR("invalid group attribute, attribute = %d", static_cast<int32_t>(attr));
     186            2 :             std::string funcName = acl::AclErrorLogManager::GetFuncNameWithoutImplSuffix(__func__);
     187            2 :             acl::AclErrorLogManager::ReportInputError(acl::INVALID_VALUE_MSG,
     188            4 :                 std::vector<const char *>({"func", "value", "param", "expect"}),
     189            4 :                 std::vector<const char *>({funcName.c_str(), acl::GetGroupAttrDesc(attr), "attr", "[ACL_GROUP_AICORE_INT, ACL_GROUP_GROUPID_INT]"}));
     190            2 :             return ACL_ERROR_INVALID_PARAM;
     191              :     }
     192              : 
     193           14 :     ACL_LOG_INFO("end to execute aclrtGetGroupInfoDetail, groupIndex = %d", groupIndex);
     194           14 :     return aclRet;
     195           19 : }
     196              : #ifdef __cplusplus
     197              : }
     198              : #endif
        

Generated by: LCOV version 2.0-1