Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/runtime/disco/nccl/nccl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,21 @@ void InitCCLPerWorker(IntTuple device_ids, std::string unique_id_bytes) {
CCLThreadLocalContext* ctx = CCLThreadLocalContext::Get();
DiscoWorker* worker = DiscoWorker::ThreadLocal();
ICHECK(worker != nullptr);

CHECK_EQ(unique_id_bytes.size(), NCCL_UNIQUE_ID_BYTES)
<< "ValueError: The length of unique_id must be " << NCCL_UNIQUE_ID_BYTES << ", but got "
<< unique_id_bytes.size() << ".";

CHECK(!ctx->comm) << "Cannot initialize CCL, "
<< "the previous thread-global comm still exists, "
<< "and has not been destructed";
CHECK(!ctx->default_stream) << "Cannot initialize CCL, "
<< "the previous thread-global stream still exists, "
<< "and has not been destructed";
CHECK(!ctx->worker) << "Cannot initialize CCL, "
<< "the previous thread-global worker still exists, "
<< "and has not been destructed";

// Step up local context of NCCL
int device_id = device_ids[worker->worker_id];
SetDevice(device_id);
Expand Down
15 changes: 11 additions & 4 deletions src/runtime/disco/nccl/nccl_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,23 @@ inline ncclDataType_t AsNCCLDataType(runtime::DataType dtype) {
}

struct CCLThreadLocalContext {
DiscoWorker* worker;
DiscoWorker* worker = nullptr;
int device_id;
deviceStream_t default_stream = nullptr;
ncclComm_t comm;
ncclComm_t comm = nullptr;

~CCLThreadLocalContext() { Clear(); }

void Clear() {
NCCL_CALL(ncclCommDestroy(comm));
if (default_stream != nullptr) {
if (comm) {
NCCL_CALL(ncclCommDestroy(comm));
comm = nullptr;
}
if (default_stream) {
StreamDestroy(default_stream);
default_stream = nullptr;
}
worker = nullptr;
}

deviceStream_t GetDefaultStream() {
Expand Down