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 107 : static HcclResult GetHcclCommConfigVersion(const HcclCommConfig *config, uint32_t &version)
21 : {
22 107 : CHK_PTR_NULL(config);
23 :
24 107 : CommConfigInfo info{};
25 107 : s32 sRet = memcpy_s(&info, sizeof(info), config->reserved, sizeof(info));
26 107 : CHK_PRT_RET(sRet != EOK,
27 : HCCL_ERROR("[GetHcclCommConfigVersion] memcpy_s failed, errno[%d]", sRet),
28 : HCCL_E_MEMORY);
29 107 : version = info.version;
30 107 : return HCCL_SUCCESS;
31 : }
32 :
33 107 : static HcclResult ApplyHcclQos(const HcclCommConfig *hcclCommConfig, CommConfig &commConfig)
34 : {
35 107 : if (hcclCommConfig == nullptr) {
36 0 : return HCCL_SUCCESS;
37 : }
38 :
39 : // hcclQos 自 CommConfig version 10 起引入;低版本按未配置处理
40 107 : uint32_t configVersion = 0U;
41 107 : CHK_RET(GetHcclCommConfigVersion(hcclCommConfig, configVersion));
42 107 : if (configVersion < HCCL_COMM_CONFIG_QOS_VERSION) {
43 6 : HCCL_INFO("[ApplyHcclQos] skip hcclQos by version, configVersion[%u] < HCCL_COMM_CONFIG_QOS_VERSION[%u]",
44 : configVersion, HCCL_COMM_CONFIG_QOS_VERSION);
45 6 : CHK_RET(commConfig.SetConfigHcclQos(HCCL_COMM_QOS_CONFIG_NOT_SET));
46 6 : return HCCL_SUCCESS;
47 : }
48 :
49 101 : u32 qos = hcclCommConfig->hcclQos;
50 101 : 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 100 : CHK_RET(commConfig.SetConfigHcclQos(qos));
55 100 : HCCL_INFO("[ApplyHcclQos] hcclQos[%u]", qos);
56 100 : return HCCL_SUCCESS;
57 : }
58 :
59 111 : static HcclResult ApplyTrafficClassAndServiceLevel(const HcclCommConfig *hcclCommConfig, CommConfig &commConfig)
60 : {
61 111 : if (hcclCommConfig == nullptr) {
62 0 : return HCCL_SUCCESS;
63 : }
64 :
65 111 : u32 tc = hcclCommConfig->hcclRdmaTrafficClass;
66 111 : CHK_PRT_RET((tc != TC_DEFAULT) && (tc > TC_MAX || (tc % MULTIPLE != 0)),
67 : HCCL_ERROR("[ApplyHcclCommConfig]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 109 : CHK_RET(commConfig.SetConfigTrafficClass(tc));
72 :
73 109 : u32 sl = hcclCommConfig->hcclRdmaServiceLevel;
74 109 : CHK_PRT_RET((sl != SL_DEFAULT) && (sl > SL_MAX),
75 : HCCL_ERROR("[ApplyHcclCommConfig]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 107 : CHK_RET(commConfig.SetConfigServiceLevel(sl));
80 107 : return HCCL_SUCCESS;
81 : }
82 :
83 112 : HcclResult ApplyHcclCommConfig(const HcclCommConfig *hcclCommConfig, CommConfig &commConfig,
84 : uint32_t &opExpansionMode)
85 : {
86 112 : opExpansionMode = 0;
87 112 : if (hcclCommConfig == nullptr) {
88 1 : return HCCL_SUCCESS;
89 : }
90 :
91 111 : opExpansionMode = hcclCommConfig->hcclOpExpansionMode;
92 111 : CHK_RET(ApplyTrafficClassAndServiceLevel(hcclCommConfig, commConfig));
93 107 : CHK_RET(ApplyHcclQos(hcclCommConfig, commConfig));
94 106 : return HCCL_SUCCESS;
95 : }
96 : } // namespace hccl
|