LCOV - code coverage report
Current view: top level - coll_communicator_mgr/config_mgr - coll_comm_config.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 94.5 % 55 52
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 5 5

            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 "coll_comm_config.h"
      12              : #include <cstring> // 包含strnlen函数
      13              : 
      14              : namespace hccl {
      15              : constexpr uint32_t MULTIPLE = 4;             // 用于A5判断TC是否为4的倍数
      16              : constexpr uint32_t TC_MAX = 255;             // TC的最大值(不区分芯片类型)
      17              : constexpr uint32_t SL_MAX = 7u;              // sl范围的最大值,sl即serviceLevel(不区分芯片类型)
      18              : constexpr uint32_t TC_DEFAULT = 0xFFFFFFFFu; // TC的默认值(不区分芯片类型)
      19              : constexpr uint32_t SL_DEFAULT = 0xFFFFFFFFu; // SL的默认值(不区分芯片类型)
      20              : constexpr uint32_t HCCL_COMM_CONFIG_QOS_VERSION = 10U;
      21              : 
      22          344 : static HcclResult GetHcclCommConfigVersion(const HcclCommConfig* config, uint32_t& version)
      23              : {
      24          344 :     CHK_PTR_NULL(config);
      25              : 
      26          344 :     CommConfigInfo info{};
      27          344 :     s32 sRet = memcpy_s(&info, sizeof(info), config->reserved, sizeof(info));
      28          344 :     CHK_PRT_RET(sRet != EOK, HCCL_ERROR("[GetHcclCommConfigVersion] memcpy_s failed, errNo[%d]", sRet), HCCL_E_MEMORY);
      29          344 :     version = info.version;
      30          344 :     return HCCL_SUCCESS;
      31              : }
      32              : 
      33          173 : static HcclResult ApplyHcclQos(const HcclCommConfig* hcclCommConfig, CommConfig& commConfig)
      34              : {
      35          173 :     if (hcclCommConfig == nullptr) {
      36            0 :         return HCCL_SUCCESS;
      37              :     }
      38              : 
      39              :     // hcclQos 自 CommConfig version 10 起引入;低版本按未配置处理
      40          173 :     uint32_t configVersion = 0U;
      41          173 :     CHK_RET(GetHcclCommConfigVersion(hcclCommConfig, configVersion));
      42          173 :     if (configVersion < HCCL_COMM_CONFIG_QOS_VERSION) {
      43            8 :         HCCL_INFO(
      44              :             "[ApplyHcclQos] skip hcclQos by version, configVersion[%u] < HCCL_COMM_CONFIG_QOS_VERSION[%u]",
      45              :             configVersion, HCCL_COMM_CONFIG_QOS_VERSION);
      46            8 :         CHK_RET(commConfig.SetConfigHcclQos(HCCL_COMM_QOS_CONFIG_NOT_SET));
      47            8 :         return HCCL_SUCCESS;
      48              :     }
      49              : 
      50          165 :     u32 qos = hcclCommConfig->hcclQos;
      51          165 :     CHK_PRT_RET(
      52              :         (qos != HCCL_COMM_QOS_CONFIG_NOT_SET) && (qos > 7u),
      53              :         HCCL_ERROR(
      54              :             "[ApplyHcclQos]errNo[0x%016llx] invalid hcclQos[%u], must be 0xFFFFFFFF or in [0,7]",
      55              :             HCCL_ERROR_CODE(HCCL_E_PARA), qos),
      56              :         HCCL_E_PARA);
      57          163 :     CHK_RET(commConfig.SetConfigHcclQos(qos));
      58          163 :     HCCL_INFO("[ApplyHcclQos] hcclQos[%u]", qos);
      59          163 :     return HCCL_SUCCESS;
      60              : }
      61              : 
      62          171 : static HcclResult ApplyHcclSqDepth(const HcclCommConfig* hcclCommConfig, CommConfig& commConfig)
      63              : {
      64          171 :     if (hcclCommConfig == nullptr) {
      65            0 :         return HCCL_SUCCESS;
      66              :     }
      67              : 
      68          171 :     uint32_t configVersion = 0U;
      69          171 :     CHK_RET(GetHcclCommConfigVersion(hcclCommConfig, configVersion));
      70          171 :     if (configVersion < HCCL_COMM_CONFIG_SQ_DEPTH_VERSION) {
      71           11 :         HCCL_INFO(
      72              :             "[ApplyHcclSqDepth] skip hcclSqDepth by version, configVersion[%u] < "
      73              :             "HCCL_COMM_CONFIG_SQ_DEPTH_VERSION[%u]",
      74              :             configVersion, HCCL_COMM_CONFIG_SQ_DEPTH_VERSION);
      75           11 :         return commConfig.SetConfigSqDepth(HCCL_COMM_SQ_DEPTH_CONFIG_NOT_SET);
      76              :     }
      77              : 
      78          160 :     const uint32_t sqDepth = hcclCommConfig->hcclChannelSqDepth;
      79          160 :     CHK_RET(commConfig.SetConfigSqDepth(sqDepth));
      80          160 :     HCCL_INFO("[ApplyHcclSqDepth] hcclSqDepth[%u]", sqDepth);
      81          160 :     return HCCL_SUCCESS;
      82              : }
      83              : 
      84          181 : static HcclResult ApplyTrafficClassAndServiceLevel(const HcclCommConfig* hcclCommConfig, CommConfig& commConfig)
      85              : {
      86          181 :     if (hcclCommConfig == nullptr) {
      87            0 :         return HCCL_SUCCESS;
      88              :     }
      89              : 
      90          181 :     u32 tc = hcclCommConfig->hcclRdmaTrafficClass;
      91          181 :     CHK_PRT_RET(
      92              :         (tc != TC_DEFAULT) && (tc > TC_MAX || (tc % MULTIPLE != 0)),
      93              :         HCCL_ERROR(
      94              :             "[ApplyTrafficClassAndServiceLevel]errNo[0x%016llx] invalid hcclRdmaTrafficClass[%u], "
      95              :             "must be 0xFFFFFFFF or in [0,255] and a multiple of 4",
      96              :             HCCL_ERROR_CODE(HCCL_E_PARA), tc),
      97              :         HCCL_E_PARA);
      98          176 :     CHK_RET(commConfig.SetConfigTrafficClass(tc));
      99              : 
     100          176 :     u32 sl = hcclCommConfig->hcclRdmaServiceLevel;
     101          176 :     CHK_PRT_RET(
     102              :         (sl != SL_DEFAULT) && (sl > SL_MAX),
     103              :         HCCL_ERROR(
     104              :             "[ApplyTrafficClassAndServiceLevel]errNo[0x%016llx] invalid hcclRdmaServiceLevel[%u], "
     105              :             "must be 0xFFFFFFFF or in [0,7]",
     106              :             HCCL_ERROR_CODE(HCCL_E_PARA), sl),
     107              :         HCCL_E_PARA);
     108          173 :     CHK_RET(commConfig.SetConfigServiceLevel(sl));
     109          173 :     return HCCL_SUCCESS;
     110              : }
     111              : 
     112          183 : HcclResult ApplyHcclCommConfig(const HcclCommConfig* hcclCommConfig, CommConfig& commConfig, uint32_t& opExpansionMode)
     113              : {
     114          183 :     opExpansionMode = 0;
     115          183 :     if (hcclCommConfig == nullptr) {
     116            2 :         return HCCL_SUCCESS;
     117              :     }
     118              : 
     119          181 :     opExpansionMode = hcclCommConfig->hcclOpExpansionMode;
     120          181 :     CHK_RET(ApplyTrafficClassAndServiceLevel(hcclCommConfig, commConfig));
     121          173 :     CHK_RET(ApplyHcclQos(hcclCommConfig, commConfig));
     122              : 
     123          171 :     if (hcclCommConfig->hcclAlgo[0] != '\0') {
     124            3 :         size_t algoLen = strnlen(hcclCommConfig->hcclAlgo, static_cast<size_t>(HCCL_COMM_ALGO_MAX_LENGTH));
     125            6 :         CHK_RET(commConfig.SetConfigHcclAlgoStr(std::string(hcclCommConfig->hcclAlgo, algoLen)));
     126              :     }
     127          171 :     CHK_RET(ApplyHcclSqDepth(hcclCommConfig, commConfig));
     128          171 :     return HCCL_SUCCESS;
     129              : }
     130              : } // namespace hccl
        

Generated by: LCOV version 2.0-1