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.9 % 39 37
Test Date: 2026-08-04 10:52:23 Functions: 100.0 % 4 4

            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 "coll_comm_config.h"
      11              : 
      12              : namespace hccl {
      13              : constexpr uint32_t MULTIPLE = 4;               // 用于A5判断TC是否为4的倍数
      14              : constexpr uint32_t TC_MAX = 255;               // TC的最大值(不区分芯片类型)
      15              : constexpr uint32_t SL_MAX = 7u;                // sl范围的最大值,sl即serviceLevel(不区分芯片类型)
      16              : constexpr uint32_t TC_DEFAULT = 0xFFFFFFFFu;   // TC的默认值(不区分芯片类型)
      17              : constexpr uint32_t SL_DEFAULT = 0xFFFFFFFFu;   // SL的默认值(不区分芯片类型)
      18              : constexpr uint32_t HCCL_COMM_CONFIG_QOS_VERSION = 10U;
      19              : 
      20          120 : static HcclResult GetHcclCommConfigVersion(const HcclCommConfig *config, uint32_t &version)
      21              : {
      22          120 :     CHK_PTR_NULL(config);
      23              : 
      24          120 :     CommConfigInfo info{};
      25          120 :     s32 sRet = memcpy_s(&info, sizeof(info), config->reserved, sizeof(info));
      26          120 :     CHK_PRT_RET(sRet != EOK,
      27              :         HCCL_ERROR("[GetHcclCommConfigVersion] memcpy_s failed, errNo[%d]", sRet),
      28              :         HCCL_E_MEMORY);
      29          120 :     version = info.version;
      30          120 :     return HCCL_SUCCESS;
      31              : }
      32              : 
      33          120 : static HcclResult ApplyHcclQos(const HcclCommConfig *hcclCommConfig, CommConfig &commConfig)
      34              : {
      35          120 :     if (hcclCommConfig == nullptr) {
      36            0 :         return HCCL_SUCCESS;
      37              :     }
      38              : 
      39              :     // hcclQos 自 CommConfig version 10 起引入;低版本按未配置处理
      40          120 :     uint32_t configVersion = 0U;
      41          120 :     CHK_RET(GetHcclCommConfigVersion(hcclCommConfig, configVersion));
      42          120 :     if (configVersion < HCCL_COMM_CONFIG_QOS_VERSION) {
      43            8 :         HCCL_INFO("[ApplyHcclQos] skip hcclQos by version, configVersion[%u] < HCCL_COMM_CONFIG_QOS_VERSION[%u]",
      44              :             configVersion, HCCL_COMM_CONFIG_QOS_VERSION);
      45            8 :         CHK_RET(commConfig.SetConfigHcclQos(HCCL_COMM_QOS_CONFIG_NOT_SET));
      46            8 :         return HCCL_SUCCESS;
      47              :     }
      48              : 
      49          112 :     u32 qos = hcclCommConfig->hcclQos;
      50          112 :     CHK_PRT_RET((qos != HCCL_COMM_QOS_CONFIG_NOT_SET) && (qos > 7u),
      51              :         HCCL_ERROR("[ApplyHcclQos]errNo[0x%016llx] invalid hcclQos[%u], must be 0xFFFFFFFF or in [0,7]",
      52              :             HCCL_ERROR_CODE(HCCL_E_PARA), qos),
      53              :         HCCL_E_PARA);
      54          110 :     CHK_RET(commConfig.SetConfigHcclQos(qos));
      55          110 :     HCCL_INFO("[ApplyHcclQos] hcclQos[%u]", qos);
      56          110 :     return HCCL_SUCCESS;
      57              : }
      58              : 
      59          128 : static HcclResult ApplyTrafficClassAndServiceLevel(const HcclCommConfig *hcclCommConfig, CommConfig &commConfig)
      60              : {
      61          128 :     if (hcclCommConfig == nullptr) {
      62            0 :         return HCCL_SUCCESS;
      63              :     }
      64              : 
      65          128 :     u32 tc = hcclCommConfig->hcclRdmaTrafficClass;
      66          128 :     CHK_PRT_RET((tc != TC_DEFAULT) && (tc > TC_MAX || (tc % MULTIPLE != 0)),
      67              :         HCCL_ERROR("[ApplyTrafficClassAndServiceLevel]errNo[0x%016llx] invalid hcclRdmaTrafficClass[%u], "
      68              :             "must be 0xFFFFFFFF or in [0,255] and a multiple of 4",
      69              :             HCCL_ERROR_CODE(HCCL_E_PARA), tc),
      70              :         HCCL_E_PARA);
      71          123 :     CHK_RET(commConfig.SetConfigTrafficClass(tc));
      72              : 
      73          123 :     u32 sl = hcclCommConfig->hcclRdmaServiceLevel;
      74          123 :     CHK_PRT_RET((sl != SL_DEFAULT) && (sl > SL_MAX),
      75              :         HCCL_ERROR("[ApplyTrafficClassAndServiceLevel]errNo[0x%016llx] invalid hcclRdmaServiceLevel[%u], "
      76              :             "must be 0xFFFFFFFF or in [0,7]",
      77              :             HCCL_ERROR_CODE(HCCL_E_PARA), sl),
      78              :         HCCL_E_PARA);
      79          120 :     CHK_RET(commConfig.SetConfigServiceLevel(sl));
      80          120 :     return HCCL_SUCCESS;
      81              : }
      82              : 
      83          130 : HcclResult ApplyHcclCommConfig(const HcclCommConfig *hcclCommConfig, CommConfig &commConfig,
      84              :     uint32_t &opExpansionMode)
      85              : {
      86          130 :     opExpansionMode = 0;
      87          130 :     if (hcclCommConfig == nullptr) {
      88            2 :         return HCCL_SUCCESS;
      89              :     }
      90              : 
      91          128 :     opExpansionMode = hcclCommConfig->hcclOpExpansionMode;
      92          128 :     CHK_RET(ApplyTrafficClassAndServiceLevel(hcclCommConfig, commConfig));
      93          120 :     CHK_RET(ApplyHcclQos(hcclCommConfig, commConfig));
      94          118 :     return HCCL_SUCCESS;
      95              : }
      96              : }  // namespace hccl
        

Generated by: LCOV version 2.0-1