파일
rocm-systems/src/include/comm.h
T

255 라인
6.9 KiB
C
Raw 일반 보기 히스토리

2019-03-14 19:39:20 -07:00
/*************************************************************************
2022-01-07 06:39:55 -08:00
* Copyright (c) 2015-2022, NVIDIA CORPORATION. All rights reserved.
* Modifications Copyright (c) 2019-2022 Advanced Micro Devices, Inc. All rights reserved.
2019-03-14 19:39:20 -07:00
*
* See LICENSE.txt for license information
************************************************************************/
#ifndef NCCL_COMM_H_
#define NCCL_COMM_H_
2019-11-19 14:57:39 -08:00
#include "transport.h"
2020-05-12 14:40:18 -07:00
#include "p2p.h"
2021-01-28 09:45:01 -07:00
// [RCCL]
//#include "clique/CliqueManager.h"
2021-01-28 09:45:01 -07:00
// [/RCCL]
2019-11-19 14:57:39 -08:00
#if defined(__HIP_PLATFORM_HCC__) || defined(__HCC__) || defined(__HIPCC__)
#define HIPRT_CB
#else
2021-09-08 13:56:25 -07:00
#include "collectives.h"
2019-11-19 14:57:39 -08:00
2019-03-14 19:39:20 -07:00
#if CUDART_VERSION < 9000
struct cudaLaunchParams {
void *func;
dim3 gridDim;
dim3 blockDim;
void **args;
size_t sharedMem;
cudaStream_t stream;
};
#endif
#endif
2019-03-14 19:39:20 -07:00
2019-07-05 15:43:00 -07:00
#define CACHE_LINE_SIZE 64
2019-03-14 19:39:20 -07:00
#define MEM_ALIGN 4096
2019-07-12 08:30:05 -07:00
#define CUDA_IPC_MIN 2097152UL
2019-03-14 19:39:20 -07:00
2019-11-19 14:57:39 -08:00
// Channels / LL tuning
#define NCCL_LL_THREAD_THRESHOLD 8
#define NCCL_LL128_THREAD_THRESHOLD 8
#define NCCL_SIMPLE_THREAD_THRESHOLD 64
2019-03-14 19:39:20 -07:00
struct ncclSendMem {
union {
struct {
uint64_t head;
char pad1[CACHE_LINE_SIZE-sizeof(uint64_t)];
void* ptrExchange;
2021-09-08 13:56:25 -07:00
uint64_t redOpArgExchange[2];
char pad2[CACHE_LINE_SIZE-sizeof(void*)-2*sizeof(uint64_t)];
2022-01-07 06:39:55 -08:00
int offsFifo[NCCL_STEPS];
2019-03-14 19:39:20 -07:00
};
char pad3[MEM_ALIGN];
};
};
struct ncclRecvMem {
union {
struct {
uint64_t tail;
char pad1[CACHE_LINE_SIZE-sizeof(uint64_t)];
int sizesFifo[NCCL_STEPS];
2022-01-07 06:39:55 -08:00
int offsFifo[NCCL_STEPS];
int flush; // For GDRCopy-based flush
2019-03-14 19:39:20 -07:00
};
char pad4[MEM_ALIGN];
};
};
typedef hipError_t(*pfn_cuMemGetAddressRange_t)(void**, size_t*, void*);
2021-09-08 13:56:25 -07:00
enum helperThreadState {ThreadStart, ThreadStop};
2022-01-07 06:39:55 -08:00
#define NCCL_IPC_POOL_SIZE (2*NCCL_MAX_LOCAL_RANKS*NCCL_MAX_OPS)
2021-09-08 13:56:25 -07:00
struct ncclGraphHelperResources {
ncclComm* comm;
pthread_mutex_t threadLock;
pthread_cond_t threadCond;
enum helperThreadState threadState;
void* ipcBases[NCCL_IPC_POOL_SIZE];
int ipcTail;
int ipcHead;
};
struct ncclUserRedOp {
int freeNext; // -1=allocated, otherwise index of next free entry in array
ncclDataType_t datatype;
ncclDevRedOpFull opFull;
};
2022-01-07 06:39:55 -08:00
struct ncclNodeRanks {
int localRanks;
int* localRankToRank;
};
2019-03-14 19:39:20 -07:00
struct ncclComm {
struct ncclChannel channels[MAXCHANNELS];
struct ncclPeerInfo* peerInfo;
2019-11-19 14:57:39 -08:00
struct ncclTopoSystem* topo;
2019-03-14 19:39:20 -07:00
void* bootstrap;
2020-09-04 14:35:05 -07:00
// Bitmasks for ncclTransportP2pSetup
int connect[NCCL_MAX_CONNS];
2020-09-04 14:35:05 -07:00
uint32_t* connectSend;
uint32_t* connectRecv;
2019-03-14 19:39:20 -07:00
int rank; // my rank in the communicator
int nRanks; // number of GPUs in communicator
int cudaDev; // my cuda device index
2019-11-19 14:57:39 -08:00
int64_t busId; // my PCI bus ID in int format
2021-07-08 14:12:04 -07:00
cpu_set_t cpuAffinity; // CPU affinity of the GPU
int WarpSize;
2019-11-19 14:57:39 -08:00
int node;
int nNodes;
2022-01-07 06:39:55 -08:00
int localRank;
2019-11-19 14:57:39 -08:00
int localRanks;
2022-01-07 06:39:55 -08:00
int maxLocalRanks;
int* rankToNode;
int* rankToLocalRank;
int* localRankToRank;
// localRanks and localRanktoRank for all nodes
struct ncclNodeRanks* nodeRanks;
2019-03-14 19:39:20 -07:00
2021-04-12 16:00:11 -07:00
enum { GROUP, PARALLEL, GROUP_GRAPH } launchMode;
2019-07-05 15:43:00 -07:00
hipStream_t userStream;
2019-03-14 19:39:20 -07:00
bool userStreamSet;
2019-07-05 15:43:00 -07:00
hipEvent_t doneEvent;
hipEvent_t intDoneEvent;
2019-03-14 19:39:20 -07:00
bool checkPointers;
2021-04-12 16:00:11 -07:00
// Counter for tracking CUDA launches (P2P and collectives included)
2019-03-14 19:39:20 -07:00
uint64_t opCount;
2021-04-12 16:00:11 -07:00
// Collective operation counter
uint64_t collOpCount;
// P2P operation counter
uint64_t p2pOpCount;
2019-03-14 19:39:20 -07:00
// Channels for collectives
int nChannels;
2020-05-12 14:40:18 -07:00
// Channels (per peer) for p2p
int p2pnChannels;
int p2pnChannelsPerPeer;
int p2pChannels[MAXCHANNELS];
// Buffer sizes
int buffSizes[NCCL_NUM_PROTOCOLS];
2019-03-14 19:39:20 -07:00
2019-11-19 14:57:39 -08:00
// Algorithm/Protocols thresholds
ssize_t threadThresholds[NCCL_NUM_ALGORITHMS][NCCL_NUM_PROTOCOLS];
float latencies[NCCL_NUM_FUNCTIONS][NCCL_NUM_ALGORITHMS][NCCL_NUM_PROTOCOLS];
float bandwidths[NCCL_NUM_FUNCTIONS][NCCL_NUM_ALGORITHMS][NCCL_NUM_PROTOCOLS];
2020-01-16 16:02:42 -08:00
int maxThreads[NCCL_NUM_ALGORITHMS][NCCL_NUM_PROTOCOLS];
2019-03-14 19:39:20 -07:00
// An internal CUDA stream for NCCL kernel CGMD launches
int groupCudaStream;
2019-07-05 15:43:00 -07:00
hipStream_t groupStream;
2019-03-14 19:39:20 -07:00
// Whether there has been a fatal error in this communicator.
ncclResult_t fatalError;
// Flag to ask NCCL kernels to abort
volatile uint32_t *abortFlag;
// Flags for enable P2P NET
uint32_t p2pNet;
uint32_t useIntraNet;
2019-03-14 19:39:20 -07:00
// Device side of the communicator
struct ncclDevComm *devComm;
// Host copy of the devComm (to free CUDA allocs)
struct ncclDevComm hostDevComm;
// Intra-process sync
int intraRank;
int intraRanks;
int* intraBarrier;
int intraPhase;
// Storage for deferred intra-process launch
2019-07-05 15:43:00 -07:00
hipLaunchParams * intraParams;
hipLaunchParams *myParams;
2022-01-07 06:39:55 -08:00
pthread_t* intraThreads;
2019-03-14 19:39:20 -07:00
int* intraCudaDevs;
int* intraCGMode; // Whether we can use CUDA9 CGMD or not
int* intraCC; // Only to check all have the same ComputeCap and disable CGMode if not
2020-09-04 14:35:05 -07:00
struct ncclWorkElem args;
2022-01-07 06:39:55 -08:00
void* argsptrs[2];
2019-03-14 19:39:20 -07:00
struct ncclProxyState proxyState;
2020-01-16 16:02:42 -08:00
// Whether this communicator uses collNet
int collNetSupport;
2021-09-08 13:56:25 -07:00
int intraHighestTransportType;
2020-09-04 14:35:05 -07:00
// Store info of async operations
struct ncclInfo* asyncOps;
int asyncOpCount;
size_t asyncTotalSize;
2021-07-08 14:12:04 -07:00
ssize_t channelSize;
2021-04-12 16:00:11 -07:00
int lastChannel;
2021-07-08 14:12:04 -07:00
enum { ROUND_ROBIN, SHORTEST_QUEUE } asyncAllocMode;
2020-09-04 14:35:05 -07:00
2020-05-12 14:40:18 -07:00
//list of async p2p operation queued in a group semantics
2021-07-08 14:12:04 -07:00
ncclP2Plist** p2pSends;
ncclP2Plist** p2pRecvs;
2020-09-04 14:35:05 -07:00
int p2pSendCount;
int p2pRecvCount;
2021-01-28 09:45:01 -07:00
// [RCCL]
//CliqueManager* cliqueManager; // CliqueManager handles pointer collection / distribution for clique-based kernels
//int rootPid; // Process ID of root
2021-01-28 09:45:01 -07:00
// [/RCCL]
2021-04-12 16:00:11 -07:00
// Store info for cudaGraph
int usingCudaGraph; // Only use it during capture time, not launch time
struct ncclQueueInfo* enqueueInfo;
2021-09-08 13:56:25 -07:00
int nQueueInfoCreated;
int nQueueInfoDestroyed;
2022-01-10 08:26:01 -08:00
hipGraphNode_t lastSetupNode;
2021-04-12 16:00:11 -07:00
unsigned long long lastCudaGraphId;
2021-05-11 18:16:30 -07:00
int driverVersion;
2021-09-08 13:56:25 -07:00
pfn_cuMemGetAddressRange_t pfnCuMemGetAddressRange;
pthread_t graphHelperThread;
struct ncclGraphHelperResources* graphHelperResources;
int disableGraphHelper;
int graphRegister;
// user-created reduction ops
int userRedOpCapacity, userRedOpFreeHead;
ncclUserRedOp *userRedOps;
2019-03-14 19:39:20 -07:00
};
2021-09-08 13:56:25 -07:00
// Scrambles the bits of non-builtin values of ncclRedOp_t according to the
// communicator memory address. Used to catch bugs so that integer handles
// associated with this communicator won't collide with handles of other
// communicatrs. This function is its own inverse.
static inline ncclRedOp_t ncclUserRedOpMangle(ncclComm *comm, ncclRedOp_t op) {
// Preserve the built-in values.
if(int(op) < int(ncclNumOps))
return op;
uint64_t h = reinterpret_cast<uint64_t>(comm);
h ^= h >> 32;
h *= 0x9e3779b97f4a7c13u; // Knuth's 64-bit magical hash constant
h >>= 32; // h is now an excellent 32-bit hash of the comm pointer
h &= int(ncclMaxRedOp); // ncclMaxRedOp is a power of 2 minus 1
int op1 = int(h) ^ int(op);
// Since builtin values are preserved, we also have to preserve their preimage.
return op1 < int(ncclNumOps) ? op : ncclRedOp_t(op1);
}
2019-03-14 19:39:20 -07:00
#endif