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