Files
rocm-systems/projects/rccl/src/include/group.h
T

137 lines
4.7 KiB
C
Raw Normal View History

2018-09-24 16:06:59 -07:00
/*************************************************************************
* Copyright (c) 2015-2017, NVIDIA CORPORATION. All rights reserved.
*
* See LICENSE.txt for license information
************************************************************************/
#ifndef NCCL_GROUP_H_
#define NCCL_GROUP_H_
#include "nccl.h"
2019-11-19 14:57:39 -08:00
#include "comm.h"
2025-05-29 20:56:40 -07:00
#include "allocator.h"
#include "register.h"
2018-09-24 16:06:59 -07:00
2022-05-24 02:02:31 -07:00
ncclResult_t ncclGroupErrCheck(ncclResult_t ret);
2025-05-29 20:56:40 -07:00
void ncclGroupCommJoin(struct ncclComm* comm, int type);
2022-05-24 02:02:31 -07:00
void ncclGroupCommPreconnect(struct ncclComm* comm);
2022-08-18 02:53:17 -07:00
ncclResult_t ncclGroupCommLeave(struct ncclComm* comm);
2023-09-26 05:47:28 -07:00
ncclResult_t ncclGroupJobAbort(struct ncclGroupJob* groupJob);
ncclResult_t ncclGroupJobComplete(struct ncclGroupJob *groupJob);
2018-09-24 16:06:59 -07:00
2019-11-19 14:57:39 -08:00
typedef ncclResult_t(*ncclInitFunc_t)(ncclComm_t* newcomm, int ndev, ncclUniqueId commId, int myrank, int cudaDev);
2018-09-24 16:06:59 -07:00
2019-11-19 14:57:39 -08:00
ncclResult_t ncclAsyncInit(ncclInitFunc_t func, ncclComm_t* newcomm, int ndev, ncclUniqueId commId, int myrank, int cudaDev);
2018-09-24 16:06:59 -07:00
2022-08-18 02:53:17 -07:00
typedef enum ncclGroupJobState {
ncclGroupJobRunning = 0,
ncclGroupJobDone = 1,
ncclGroupJobJoined = 2,
} ncclGroupJobState_t;
2022-05-24 02:02:31 -07:00
struct ncclAsyncJob {
struct ncclAsyncJob* next;
pthread_t thread;
ncclResult_t result;
ncclResult_t(*func)(struct ncclAsyncJob*);
void(*undo)(struct ncclAsyncJob*);
void(*destructor)(void*);
2022-08-18 02:53:17 -07:00
ncclGroupJobState_t state;
2024-06-11 01:28:01 -07:00
uint32_t* abortFlag; /* point to comm abortFlag */
uint32_t* abortFlagDev; /* point to comm abortFlagDev */
uint32_t* childAbortFlag; /* point to child abortFlag */
uint32_t* childAbortFlagDev; /* point to child abortFlagDev */
2022-08-18 02:53:17 -07:00
ncclComm_t comm;
2024-06-11 01:28:01 -07:00
int destroyFlag;
2022-05-24 02:02:31 -07:00
};
ncclResult_t ncclAsyncLaunch(
struct ncclAsyncJob* job,
ncclResult_t(*func)(struct ncclAsyncJob*),
void(*undo)(struct ncclAsyncJob*),
2022-08-18 02:53:17 -07:00
void(*destructor)(void*), ncclComm_t comm
2022-05-24 02:02:31 -07:00
);
2022-08-18 02:53:17 -07:00
struct ncclGroupJob {
struct ncclAsyncJob base;
2025-05-29 20:56:40 -07:00
int groupRefCount;
bool nonBlockingInit;
bool joined;
struct ncclComm *groupCommHead[ncclGroupTaskTypeNum];
struct ncclComm *groupCommPreconnectHead;
ncclResult_t groupError;
bool abortFlag;
struct ncclIntruQueue<struct ncclAsyncJob, &ncclAsyncJob::next> asyncJobs;
2022-08-18 02:53:17 -07:00
};
2022-05-24 02:02:31 -07:00
ncclResult_t ncclGroupStartInternal();
2024-06-11 01:28:01 -07:00
ncclResult_t ncclGroupEndInternal(ncclSimInfo_t* simInfo = NULL);
2022-08-18 02:53:17 -07:00
ncclResult_t ncclAsyncJobComplete(struct ncclAsyncJob* job);
2022-05-24 02:02:31 -07:00
////////////////////////////////////////////////////////////////////////////////
extern __thread int ncclGroupDepth; // depth of ncclGroupStart nesting
extern __thread ncclResult_t ncclGroupError;
2025-05-29 20:56:40 -07:00
extern __thread struct ncclComm* ncclGroupCommHead[ncclGroupTaskTypeNum];
2022-05-24 02:02:31 -07:00
extern __thread struct ncclComm* ncclGroupCommPreconnectHead;
2022-08-18 02:53:17 -07:00
extern __thread int ncclGroupBlocking;
2022-05-24 02:02:31 -07:00
inline ncclResult_t ncclGroupStartInternal() {
ncclGroupDepth++;
return ncclSuccess;
}
inline ncclResult_t ncclGroupErrCheck(ncclResult_t ret) {
if (ncclGroupDepth > 0) {
2022-08-18 02:53:17 -07:00
if (ret != ncclSuccess && ret != ncclInProgress) ncclGroupError = ret;
2022-05-24 02:02:31 -07:00
}
return ret;
}
// Add comm to this thread's group
2025-05-29 20:56:40 -07:00
inline void ncclGroupCommJoin(struct ncclComm* comm, int type) {
if (comm->groupNext[type] == reinterpret_cast<struct ncclComm*>(0x1)) {
2022-05-24 02:02:31 -07:00
// Insert comm into ncclGroupCommHead adjacent to sibling comms. This preserves
// the users program order yet insures siblings occur consecutively. This
// is required by doLaunches() in "group.cc".
2025-05-29 20:56:40 -07:00
struct ncclComm** pp = &ncclGroupCommHead[type];
2022-05-24 02:02:31 -07:00
while (*pp != nullptr && comm->intraComm0 != (*pp)->intraComm0)
2025-05-29 20:56:40 -07:00
pp = &(*pp)->groupNext[type];
2025-03-12 13:46:21 -07:00
// didn't find its clique, we need to insert it with ascending order based on commHash
if (*pp == nullptr) {
2025-05-29 20:56:40 -07:00
pp = &ncclGroupCommHead[type];
while (*pp != nullptr && (*pp)->commHash < comm->commHash) pp = &(*pp)->groupNext[type];
2025-03-12 13:46:21 -07:00
}
2025-05-29 20:56:40 -07:00
comm->groupNext[type] = *pp;
2022-05-24 02:02:31 -07:00
*pp = comm;
// Comms gets a new memory stack scope upon joining. Each task batched for
// this comm is allocated there.
ncclMemoryStackPush(&comm->memScoped);
2025-05-29 20:56:40 -07:00
if (type == ncclGroupTaskTypeCollective) {
// Initialize planner
ncclKernelPlanner::Peer* tmp = comm->planner.peers;
memset(&comm->planner, 0, sizeof(comm->planner));
comm->planner.peers = tmp;
}
2022-05-24 02:02:31 -07:00
}
2023-04-03 05:32:07 -07:00
ncclGroupBlocking = comm->config.blocking;
2022-05-24 02:02:31 -07:00
}
// Add comm to this thread's group needing preconnect
inline void ncclGroupCommPreconnect(struct ncclComm* comm) {
if (comm->preconnectNext == reinterpret_cast<struct ncclComm*>(0x1)) {
comm->preconnectNext = ncclGroupCommPreconnectHead;
ncclGroupCommPreconnectHead = comm;
}
}
// Comm has left group
2025-05-29 20:56:40 -07:00
inline ncclResult_t ncclGroupCommLeave(struct ncclComm* comm, int type) {
comm->groupNext[type] = reinterpret_cast<struct ncclComm*>(0x1);
2022-05-24 02:02:31 -07:00
ncclMemoryStackPop(&comm->memScoped);
2022-08-18 02:53:17 -07:00
return ncclSuccess;
2022-05-24 02:02:31 -07:00
}
2018-09-24 16:06:59 -07:00
#endif