2019-11-19 14:57:39 -08:00
|
|
|
/*************************************************************************
|
2022-01-07 06:39:55 -08:00
|
|
|
* Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved.
|
2023-02-04 01:43:38 +00:00
|
|
|
* Modifications Copyright (c) 2019-2023 Advanced Micro Devices, Inc. All rights reserved.
|
2019-11-19 14:57:39 -08:00
|
|
|
*
|
|
|
|
|
* See LICENSE.txt for license information
|
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef NCCL_GRAPH_H_
|
|
|
|
|
#define NCCL_GRAPH_H_
|
|
|
|
|
|
|
|
|
|
#include "nccl.h"
|
2023-09-26 05:47:28 -07:00
|
|
|
#include "device.h"
|
2019-11-19 14:57:39 -08:00
|
|
|
#include <limits.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <stdio.h>
|
2021-07-08 14:12:04 -07:00
|
|
|
#include <sched.h>
|
2019-11-19 14:57:39 -08:00
|
|
|
|
|
|
|
|
ncclResult_t ncclTopoCudaPath(int cudaDev, char** path);
|
|
|
|
|
|
|
|
|
|
struct ncclTopoSystem;
|
|
|
|
|
// Build the topology
|
2024-12-18 08:26:06 -08:00
|
|
|
ncclResult_t ncclTopoGetSystem(struct ncclComm* comm, struct ncclTopoSystem** system, const char* dumpXmlFile=NULL);
|
2019-11-19 14:57:39 -08:00
|
|
|
ncclResult_t ncclTopoSortSystem(struct ncclTopoSystem* system);
|
|
|
|
|
ncclResult_t ncclTopoPrint(struct ncclTopoSystem* system);
|
|
|
|
|
|
2022-05-24 02:02:31 -07:00
|
|
|
ncclResult_t ncclTopoComputePaths(struct ncclTopoSystem* system, struct ncclComm* comm);
|
2019-11-19 14:57:39 -08:00
|
|
|
void ncclTopoFree(struct ncclTopoSystem* system);
|
|
|
|
|
ncclResult_t ncclTopoTrimSystem(struct ncclTopoSystem* system, struct ncclComm* comm);
|
2020-05-12 14:40:18 -07:00
|
|
|
ncclResult_t ncclTopoComputeP2pChannels(struct ncclComm* comm);
|
2021-05-11 18:16:30 -07:00
|
|
|
ncclResult_t ncclTopoGetNvbGpus(struct ncclTopoSystem* system, int rank, int* nranks, int** ranks);
|
2025-01-27 03:30:22 -08:00
|
|
|
ncclResult_t ncclTopoPathAllNVLink(struct ncclTopoSystem* system, int* allNvLink);
|
|
|
|
|
|
2024-06-11 01:28:01 -07:00
|
|
|
ncclResult_t ncclTopoComputeCommCPU(struct ncclComm* comm);
|
2019-11-19 14:57:39 -08:00
|
|
|
|
|
|
|
|
// Query topology
|
2024-03-26 06:08:55 -07:00
|
|
|
ncclResult_t ncclTopoGetNetDev(struct ncclComm* comm, int rank, struct ncclTopoGraph* graph, int channelId, int peerRank, int64_t* id, int* dev, int* proxyRank);
|
2024-12-18 08:26:06 -08:00
|
|
|
ncclResult_t ncclTopoCheckP2p(struct ncclComm* comm, struct ncclTopoSystem* system, int rank1, int rank2, int* p2p, int *read, int* intermediateRank);
|
2024-02-05 05:06:02 -08:00
|
|
|
ncclResult_t ncclTopoCheckMNNVL(struct ncclTopoSystem* system, struct ncclPeerInfo* info1, struct ncclPeerInfo* info2, int* ret);
|
2025-03-12 13:46:21 -07:00
|
|
|
enum ncclTopoGdrMode {
|
|
|
|
|
ncclTopoGdrModeDisable = 0,
|
|
|
|
|
ncclTopoGdrModeDefault = 1,
|
|
|
|
|
ncclTopoGdrModePci = 2,
|
|
|
|
|
ncclTopoGdrModeNum = 3
|
|
|
|
|
};
|
|
|
|
|
ncclResult_t ncclTopoCheckGdr(struct ncclTopoSystem* topo, int rank, int64_t netId, int read, enum ncclTopoGdrMode* gdrMode);
|
2025-04-22 13:50:40 -07:00
|
|
|
ncclResult_t ncclTopoNeedFlush(struct ncclComm* comm, int64_t netId, int netDev, int rank, int* flush);
|
2024-12-18 08:26:06 -08:00
|
|
|
ncclResult_t ncclTopoIsGdrAvail(struct ncclTopoSystem* system, int rank, bool *avail);
|
2024-09-10 05:57:10 -07:00
|
|
|
ncclResult_t ncclTopoCheckNet(struct ncclTopoSystem* system, int rank1, int rank2, int* net);
|
2022-05-24 02:02:31 -07:00
|
|
|
int ncclPxnDisable(struct ncclComm* comm);
|
2022-01-07 06:39:55 -08:00
|
|
|
ncclResult_t ncclTopoGetPxnRanks(struct ncclComm* comm, int** intermediateRanks, int* nranks);
|
2024-09-10 05:57:10 -07:00
|
|
|
ncclResult_t ncclGetLocalCpu(struct ncclTopoSystem* system, int gpu, int* retCpu);
|
2020-01-16 16:02:42 -08:00
|
|
|
|
2025-05-29 20:56:40 -07:00
|
|
|
ncclResult_t ncclGetUserP2pLevel(int* level);
|
|
|
|
|
|
2025-06-20 07:53:59 -05:00
|
|
|
#define MAX_XGMI_INTER_GPUS 4
|
|
|
|
|
ncclResult_t ncclTopoGetIntraNetDev(struct ncclTopoSystem* system, int rank, struct ncclTopoGraph* graph, int channelId, int type, int64_t* id, int* dev);
|
|
|
|
|
ncclResult_t ncclTopoGetLinkType(struct ncclTopoSystem* system, int cudaDev1, int cudaDev2, bool* isXGMI, int maxInter=MAX_XGMI_INTER_GPUS, int nInter=0, int *inter=nullptr);
|
|
|
|
|
|
2021-07-08 14:12:04 -07:00
|
|
|
// Find CPU affinity
|
|
|
|
|
ncclResult_t ncclTopoGetCpuAffinity(struct ncclTopoSystem* system, int rank, cpu_set_t* affinity);
|
2020-01-16 16:02:42 -08:00
|
|
|
|
|
|
|
|
#define NCCL_TOPO_CPU_ARCH_X86 1
|
|
|
|
|
#define NCCL_TOPO_CPU_ARCH_POWER 2
|
|
|
|
|
#define NCCL_TOPO_CPU_ARCH_ARM 3
|
2024-06-11 01:28:01 -07:00
|
|
|
#define NCCL_TOPO_CPU_ARCH_MIXED 4
|
2020-01-16 16:02:42 -08:00
|
|
|
#define NCCL_TOPO_CPU_VENDOR_INTEL 1
|
|
|
|
|
#define NCCL_TOPO_CPU_VENDOR_AMD 2
|
2020-11-27 16:20:55 +08:00
|
|
|
#define NCCL_TOPO_CPU_VENDOR_ZHAOXIN 3
|
2024-06-11 01:28:01 -07:00
|
|
|
#define NCCL_TOPO_CPU_VENDOR_MIXED 4
|
2025-03-12 13:46:21 -07:00
|
|
|
#define NCCL_TOPO_CPU_MODEL_INTEL_BDW 1
|
|
|
|
|
#define NCCL_TOPO_CPU_MODEL_INTEL_SKL 2
|
|
|
|
|
#define NCCL_TOPO_CPU_MODEL_INTEL_SRP 3
|
|
|
|
|
#define NCCL_TOPO_CPU_MODEL_INTEL_ERP 4
|
2025-06-20 07:53:59 -05:00
|
|
|
#define NCCL_TOPO_CPU_MODEL_AMD_ZEN 5
|
|
|
|
|
#define NCCL_TOPO_CPU_MODEL_AMD_ROME 6
|
2025-03-12 13:46:21 -07:00
|
|
|
#define NCCL_TOPO_CPU_MODEL_YONGFENG 1
|
2020-01-16 16:02:42 -08:00
|
|
|
ncclResult_t ncclTopoCpuType(struct ncclTopoSystem* system, int* arch, int* vendor, int* model);
|
2023-04-03 05:32:07 -07:00
|
|
|
ncclResult_t ncclTopoGetGpuCount(struct ncclTopoSystem* system, int* count);
|
2024-02-05 05:06:02 -08:00
|
|
|
ncclResult_t ncclTopoGetNetCount(struct ncclTopoSystem* system, int* count);
|
2023-04-03 05:32:07 -07:00
|
|
|
ncclResult_t ncclTopoGetNvsCount(struct ncclTopoSystem* system, int* count);
|
2024-03-26 06:08:55 -07:00
|
|
|
ncclResult_t ncclTopoGetLocalNet(struct ncclTopoSystem* system, int rank, int channelId, int64_t* id, int* dev);
|
|
|
|
|
ncclResult_t ncclTopoGetLocalGpu(struct ncclTopoSystem* system, int64_t netId, int* gpuIndex);
|
2024-02-05 05:06:02 -08:00
|
|
|
ncclResult_t getLocalNetCountByBw(struct ncclTopoSystem* system, int gpu, int *count);
|
2019-11-19 14:57:39 -08:00
|
|
|
|
2025-05-29 20:56:40 -07:00
|
|
|
// Allows for up to 32 NICs per node on GB200-NVL72
|
2024-04-27 23:41:11 -05:00
|
|
|
#define NCCL_TOPO_MAX_NODES 64
|
2025-05-29 20:56:40 -07:00
|
|
|
ncclResult_t ncclTopoGetLocal(struct ncclTopoSystem* system, int type, int index, int resultType, int locals[NCCL_TOPO_MAX_NODES], int* localCount, int* pathType);
|
2019-11-19 14:57:39 -08:00
|
|
|
|
2020-01-16 16:02:42 -08:00
|
|
|
// Init search. Needs to be done before calling ncclTopoCompute
|
|
|
|
|
ncclResult_t ncclTopoSearchInit(struct ncclTopoSystem* system);
|
|
|
|
|
|
2020-09-04 14:35:05 -07:00
|
|
|
#define NCCL_TOPO_PATTERN_BALANCED_TREE 1 // Spread NIC traffic between two GPUs (Tree parent + one child on first GPU, second child on second GPU)
|
|
|
|
|
#define NCCL_TOPO_PATTERN_SPLIT_TREE 2 // Spread NIC traffic between two GPUs (Tree parent on first GPU, tree children on the second GPU)
|
|
|
|
|
#define NCCL_TOPO_PATTERN_TREE 3 // All NIC traffic going to/from the same GPU
|
2019-11-19 14:57:39 -08:00
|
|
|
#define NCCL_TOPO_PATTERN_RING 4 // Ring
|
2023-04-03 05:32:07 -07:00
|
|
|
#define NCCL_TOPO_PATTERN_NVLS 5 // NVLS+SHARP and NVLS+Tree
|
2024-06-11 01:28:01 -07:00
|
|
|
#define NCCL_TOPO_PATTERN_COLLNET_DIRECT 6 // Collnet Direct
|
2019-11-19 14:57:39 -08:00
|
|
|
struct ncclTopoGraph {
|
|
|
|
|
// Input / output
|
2024-09-10 05:57:10 -07:00
|
|
|
int id; // ring : 0, tree : 1, collnet : 2, nvls : 3, collnetDirect : 4
|
2019-11-19 14:57:39 -08:00
|
|
|
int pattern;
|
|
|
|
|
int crossNic;
|
2020-01-16 16:02:42 -08:00
|
|
|
int collNet;
|
|
|
|
|
int minChannels;
|
|
|
|
|
int maxChannels;
|
2019-11-19 14:57:39 -08:00
|
|
|
// Output
|
|
|
|
|
int nChannels;
|
2022-08-18 02:53:17 -07:00
|
|
|
float bwIntra;
|
|
|
|
|
float bwInter;
|
2022-01-07 06:39:55 -08:00
|
|
|
float latencyInter;
|
2020-01-16 16:02:42 -08:00
|
|
|
int typeIntra;
|
|
|
|
|
int typeInter;
|
2019-11-19 14:57:39 -08:00
|
|
|
int sameChannels;
|
|
|
|
|
int nHops;
|
|
|
|
|
int intra[MAXCHANNELS*NCCL_TOPO_MAX_NODES];
|
2024-03-26 06:08:55 -07:00
|
|
|
int64_t inter[MAXCHANNELS*2];
|
2021-06-08 07:37:59 -07:00
|
|
|
int nIntraChannels;
|
|
|
|
|
int intraNets[MAXCHANNELS*NCCL_TOPO_MAX_NODES*2];
|
2023-09-15 15:01:33 -06:00
|
|
|
char treeBase[NCCL_TOPO_MAX_NODES][NCCL_TOPO_MAX_NODES*4];
|
2019-11-19 14:57:39 -08:00
|
|
|
};
|
|
|
|
|
ncclResult_t ncclTopoCompute(struct ncclTopoSystem* system, struct ncclTopoGraph* graph);
|
|
|
|
|
|
|
|
|
|
ncclResult_t ncclTopoPrintGraph(struct ncclTopoSystem* system, struct ncclTopoGraph* graph);
|
2020-01-16 16:02:42 -08:00
|
|
|
ncclResult_t ncclTopoDumpGraphs(struct ncclTopoSystem* system, int ngraphs, struct ncclTopoGraph** graphs);
|
2019-11-19 14:57:39 -08:00
|
|
|
|
|
|
|
|
struct ncclTopoRanks {
|
|
|
|
|
int ringRecv[MAXCHANNELS];
|
|
|
|
|
int ringSend[MAXCHANNELS];
|
|
|
|
|
int ringPrev[MAXCHANNELS];
|
|
|
|
|
int ringNext[MAXCHANNELS];
|
2020-09-04 14:35:05 -07:00
|
|
|
int treeToParent[MAXCHANNELS];
|
|
|
|
|
int treeToChild0[MAXCHANNELS];
|
|
|
|
|
int treeToChild1[MAXCHANNELS];
|
2023-04-03 05:32:07 -07:00
|
|
|
int nvlsHeads[MAXCHANNELS];
|
2024-02-05 05:06:02 -08:00
|
|
|
int nvlsHeadNum;
|
2019-11-19 14:57:39 -08:00
|
|
|
};
|
|
|
|
|
|
2023-04-03 05:32:07 -07:00
|
|
|
ncclResult_t ncclTopoPreset(struct ncclComm* comm, struct ncclTopoGraph** graphs, struct ncclTopoRanks* topoRanks);
|
2019-11-19 14:57:39 -08:00
|
|
|
|
2020-09-04 14:35:05 -07:00
|
|
|
ncclResult_t ncclTopoPostset(struct ncclComm* comm, int* firstRanks, int* treePatterns,
|
2024-10-02 09:29:22 -05:00
|
|
|
struct ncclTopoRanks** allTopoRanks, int* rings, struct ncclTopoGraph** graphs, struct ncclComm* parent, int nc);
|
2022-05-25 18:55:14 -04:00
|
|
|
ncclResult_t ncclTreeBasePostset(struct ncclComm* comm, struct ncclTopoGraph* treeGraph);
|
|
|
|
|
|
2023-04-03 05:32:07 -07:00
|
|
|
ncclResult_t ncclTopoTuneModel(struct ncclComm* comm, int minCompCap, int maxCompCap, struct ncclTopoGraph** graphs);
|
2024-12-18 08:26:06 -08:00
|
|
|
ncclResult_t ncclTopoGetAlgoTime(struct ncclComm* comm, int coll, int algorithm, int protocol, size_t nBytes, int numPipeOps, float* time);
|
2019-11-19 14:57:39 -08:00
|
|
|
|
|
|
|
|
#endif
|