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 235 : inline const char* HcclCommStateToString(HcclCommState state) {
37 235 : switch (state) {
38 235 : case HcclCommState::IDLE: return "IDLE";
39 0 : case HcclCommState::BUILDING: return "BUILDING";
40 0 : case HcclCommState::INUSE: return "INUSE";
41 0 : case HcclCommState::RESERVED: return "RESERVED";
42 0 : default: return "UNKNOWN";
43 : }
44 : }
45 :
46 15 : using HcclCommConnections = struct HcclCommConnectionsDef {
47 : bool isRoot{false};
48 : std::shared_ptr<HcclSocket> agentConnection{nullptr};
49 : std::map<u32, std::shared_ptr<HcclSocket>> serverConnections;
50 : };
51 :
52 15 : using HcclSocketPortConfig = struct HcclSocketPortConfigDef {
53 : // devPortSwitchOn 用于判断是否开启了用户配置的端口(通过环境变量配置的端口范围或者通过ranktable指定的端口)。
54 : // devPortSwitchOn开启时,将启用独立的vnic端口;即nic和vnic使用的端口可能不一致。
55 : bool devPortSwitchOn{ false };
56 : std::pair<std::shared_ptr<HcclSocket>, HcclNetDevCtx> devNicListen{ nullptr, nullptr }; // 抢占的device nic socket
57 : std::pair<std::shared_ptr<HcclSocket>, HcclNetDevCtx> devVnicListen{ nullptr, nullptr }; // 抢占的device vnic socket
58 : std::pair<std::shared_ptr<HcclSocket>, HcclNetDevCtx> backupDevNicListen{ nullptr, nullptr }; // 抢占的backup nic socket
59 : };
60 :
61 : using HcclCommParams = struct TagHCCLCollectiveParams {
62 : /**
63 : 通信域的基本构建信息,通信域标识、节点数及本节点的编号
64 : 通信域通过如下条件构建:
65 : 1.用户在某个计算实体(rank)内调用hcclGetUniqueId作为本通信域的id
66 : 2.将此id发往通信域的其它计算实体(rank)
67 : 3.用户指定本comm对应的device, 本comm实例对应的device将会是用户set的device
68 : 4.每个计算实体根据id, rank和total_ranks创建通信域
69 : */
70 : HcclRootInfo id; /* * 用于标识不同的通信域 */
71 : u32 rank; /* * 用于标识通信域内不同节点 */
72 : u32 userRank;
73 : u32 totalRanks; /* * 用于指示通信域内的节点总数, rank范围[0, totalRanks-1] */
74 : s32 logicDevId;
75 : std::string serverId;
76 : DevType deviceType; // 芯片类型信息
77 : HcomProfilingMode profilingMode;
78 : std::string profilingOption;
79 : bool profilingInitiated;
80 : HcclComm commHandle;
81 : bool isHeterogComm;
82 : bool hcomGroupNicInit; // 在子group中对应world group NIC初始化标识
83 : CommAttr attr;
84 : WorkMode commWorkMode = WorkMode::HCCL_MODE_NORMAL;
85 : std::string identifier;
86 : std::string cclBuffName;
87 : u32 ranktableCrc;
88 : HcclCommConnections commConnections;
89 : HcclSocketPortConfig commPortConfig;
90 4723 : TagHCCLCollectiveParams()
91 4723 : : id{0}, rank(INVALID_VALUE_RANKID), userRank(INVALID_VALUE_RANKID), totalRanks(0xFFFFFFFF),
92 9431 : logicDevId(-1), deviceType(DevType::DEV_TYPE_COUNT), profilingMode(HcomProfilingMode::PROFILING_CLOSE),
93 4723 : profilingInitiated(false), commHandle(nullptr), isHeterogComm(false), hcomGroupNicInit(false),
94 23555 : identifier(""), cclBuffName(""), ranktableCrc(0)
95 : {
96 4723 : }
97 : };
98 :
99 : using WorldGroupInfo = struct worldGroupInfo {
100 : bool inlineReduceSwitchOn;
101 : DevType deviceType;
102 : s32 deviceLogicId;
103 : bool profilingInitiated;
104 : std::string serverId;
105 : std::unordered_map<std::string, std::map<u32, HcclIpAddress>> phyIdNicInfoMap;
106 : std::vector<RankInfo> worldRankInfoList;
107 : std::vector<u32> ranksPort;
108 : std::vector<u32> vnicRanksPort;
109 : bool devPortSwitchOn{ false };
110 : bool useSuperPodMode;
111 38 : worldGroupInfo()
112 38 : :inlineReduceSwitchOn(true), deviceType(DevType::DEV_TYPE_COUNT), deviceLogicId(-1), profilingInitiated(false),
113 38 : useSuperPodMode(false)
114 : {
115 38 : }
116 : };
117 : } // hccl
118 : #endif // COMM_H
|