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 : #ifndef COMM_H
12 : #define COMM_H
13 :
14 : #include "hccl_common.h"
15 : #include "common.h"
16 : #include "hccl_socket.h"
17 :
18 : static constexpr uint32_t HCCL_ALG_MESH = 0b1U;
19 : static constexpr uint32_t HCCL_ALG_SWITCH = (HCCL_ALG_MESH << 1U);
20 : static constexpr uint32_t HCCL_ALG_RING = (HCCL_ALG_MESH << 2U);
21 : static constexpr uint32_t HCCL_ALG_PAIRWISE = (HCCL_ALG_MESH << 3U);
22 : enum class HcclTopoLevel {
23 : HCCL_TOPO_L0 = 0,
24 : HCCL_TOPO_L1,
25 : HCCL_TOPO_MAX,
26 : };
27 :
28 : namespace hccl {
29 : enum class HcclCommState {
30 : IDLE = 0, // 初始化完成,未使用
31 : BUILDING, // 正在使用,且在建链
32 : INUSE, // 正在使用,建链完成或未建链
33 : RESERVED
34 : };
35 :
36 236 : inline const char* HcclCommStateToString(HcclCommState state)
37 : {
38 236 : switch (state) {
39 236 : case HcclCommState::IDLE:
40 236 : return "IDLE";
41 0 : case HcclCommState::BUILDING:
42 0 : return "BUILDING";
43 0 : case HcclCommState::INUSE:
44 0 : return "INUSE";
45 0 : case HcclCommState::RESERVED:
46 0 : return "RESERVED";
47 0 : default:
48 0 : return "UNKNOWN";
49 : }
50 : }
51 :
52 15 : using HcclCommConnections = struct HcclCommConnectionsDef {
53 : bool isRoot{false};
54 : std::shared_ptr<HcclSocket> agentConnection{nullptr};
55 : std::map<u32, std::shared_ptr<HcclSocket>> serverConnections;
56 : };
57 :
58 15 : using HcclSocketPortConfig = struct HcclSocketPortConfigDef {
59 : // devPortSwitchOn 用于判断是否开启了用户配置的端口(通过环境变量配置的端口范围或者通过ranktable指定的端口)。
60 : // devPortSwitchOn开启时,将启用独立的vnic端口;即nic和vnic使用的端口可能不一致。
61 : bool devPortSwitchOn{false};
62 : std::pair<std::shared_ptr<HcclSocket>, HcclNetDevCtx> devNicListen{nullptr, nullptr}; // 抢占的device nic socket
63 : std::pair<std::shared_ptr<HcclSocket>, HcclNetDevCtx> devVnicListen{nullptr, nullptr}; // 抢占的device vnic socket
64 : std::pair<std::shared_ptr<HcclSocket>, HcclNetDevCtx> backupDevNicListen{
65 : nullptr, nullptr}; // 抢占的backup nic socket
66 : };
67 :
68 : using HcclCommParams = struct TagHCCLCollectiveParams {
69 : /**
70 : 通信域的基本构建信息,通信域标识、节点数及本节点的编号
71 : 通信域通过如下条件构建:
72 : 1.用户在某个计算实体(rank)内调用hcclGetUniqueId作为本通信域的id
73 : 2.将此id发往通信域的其它计算实体(rank)
74 : 3.用户指定本comm对应的device, 本comm实例对应的device将会是用户set的device
75 : 4.每个计算实体根据id, rank和total_ranks创建通信域
76 : */
77 : HcclRootInfo id; /* * 用于标识不同的通信域 */
78 : u32 rank; /* * 用于标识通信域内不同节点 */
79 : u32 userRank;
80 : u32 totalRanks; /* * 用于指示通信域内的节点总数, rank范围[0, totalRanks-1] */
81 : s32 logicDevId;
82 : std::string serverId;
83 : DevType deviceType; // 芯片类型信息
84 : HcomProfilingMode profilingMode;
85 : std::string profilingOption;
86 : bool profilingInitiated;
87 : HcclComm commHandle;
88 : bool isHeterogComm;
89 : bool hcomGroupNicInit; // 在子group中对应world group NIC初始化标识
90 : CommAttr attr;
91 : WorkMode commWorkMode = WorkMode::HCCL_MODE_NORMAL;
92 : std::string identifier;
93 : std::string cclBuffName;
94 : u32 ranktableCrc;
95 : HcclCommConnections commConnections;
96 : HcclSocketPortConfig commPortConfig;
97 5188 : TagHCCLCollectiveParams()
98 5188 : : id{0},
99 5188 : rank(INVALID_VALUE_RANKID),
100 5188 : userRank(INVALID_VALUE_RANKID),
101 5188 : totalRanks(0xFFFFFFFF),
102 5188 : logicDevId(-1),
103 5189 : deviceType(DevType::DEV_TYPE_COUNT),
104 5189 : profilingMode(HcomProfilingMode::PROFILING_CLOSE),
105 5189 : profilingInitiated(false),
106 5189 : commHandle(nullptr),
107 5189 : isHeterogComm(false),
108 5189 : hcomGroupNicInit(false),
109 5174 : identifier(""),
110 10361 : cclBuffName(""),
111 10376 : ranktableCrc(0)
112 5188 : {}
113 : };
114 :
115 : using WorldGroupInfo = struct worldGroupInfo {
116 : bool inlineReduceSwitchOn;
117 : DevType deviceType;
118 : s32 deviceLogicId;
119 : bool profilingInitiated;
120 : std::string serverId;
121 : std::unordered_map<std::string, std::map<u32, HcclIpAddress>> phyIdNicInfoMap;
122 : std::vector<RankInfo> worldRankInfoList;
123 : std::vector<u32> ranksPort;
124 : std::vector<u32> vnicRanksPort;
125 : bool devPortSwitchOn{false};
126 : bool useSuperPodMode;
127 38 : worldGroupInfo()
128 38 : : inlineReduceSwitchOn(true),
129 38 : deviceType(DevType::DEV_TYPE_COUNT),
130 38 : deviceLogicId(-1),
131 38 : profilingInitiated(false),
132 38 : useSuperPodMode(false)
133 38 : {}
134 : };
135 : } // namespace hccl
136 : #endif // COMM_H
|