From b4557bd71a44aeed7d4a71597c259505101ff7c2 Mon Sep 17 00:00:00 2001 From: Min Xu Date: Wed, 27 Jan 2021 18:19:15 -0800 Subject: [PATCH 1/4] make it build on arch/py39 --- setup.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index 2e59f85..a8e3ff2 100644 --- a/setup.py +++ b/setup.py @@ -8,17 +8,24 @@ root_dir = os.path.dirname(os.path.abspath(__file__)) - -mpi_home = os.environ.get("MPI_HOME") -if mpi_home is None: - mpi_home = "/usr/lib/openmpi/" -if not os.path.exists(mpi_home): - mpi_home = "/usr/lib/x86_64-linux-gnu/openmpi/" -if not os.path.exists(mpi_home): - print("Couldn't find MPI install dir, please set MPI_HOME env variable") +# Sensible defaults. +mpi_lib_path = os.environ.get("MPI_LIB_PATH", "/usr/lib/openmpi") +mpi_inc_path = os.environ.get("MPI_INC_PATH", "/usr/include/openmpi") +mpi_home = os.environ.get("MPI_HOME", "/usr/lib/x86_64-linux-gnu/openmpi/") + +# If MPI_HOME is valid, derive inc/lib. +if os.path.exists(mpi_home): + mpi_lib_path = os.path.join(mpi_home, "lib") + mpi_inc_path = os.path.join(mpi_home, "include") + +if not (os.path.exists(mpi_lib_path) and os.path.exists(mpi_inc_path)): + logging.warn(mpi_lib_path) + logging.warn(mpi_inc_path) + print("Couldn't find MPI install dir, please set MPI_HOME env variable or " + "set MPI_LIB_PATH and MPI_INC_PATH separately for include files " + "and library files") sys.exit(1) - nccl_home = os.environ.get("NCCL_HOME") if nccl_home is None or not os.path.exists(nccl_home): nccl_home = None @@ -40,11 +47,11 @@ "src/ProcessGroupMPI.cpp", ], include_dirs=[ - os.path.join(root_dir, "include"), - os.path.join(mpi_home, "include"), + os.path.join(root_dir, "include"), + mpi_inc_path, ], library_dirs=[ - os.path.join(mpi_home, "lib"), + mpi_lib_path, ], libraries=["mpi",], extra_compile_args=["-DOMPI_SKIP_MPICXX=1"] + torch_version_defines, @@ -86,6 +93,7 @@ "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", "License :: OSI Approved :: BSD License", "Topic :: Scientific/Engineering :: Artificial Intelligence", "Operating System :: OS Independent", From 2051575f54f394fe490fcfe633f3f67cd6b21e6c Mon Sep 17 00:00:00 2001 From: Min Xu Date: Thu, 28 Jan 2021 13:32:13 -0800 Subject: [PATCH 2/4] update shared_ptr to new type --- include/c10d/ProcessGroupMPI.hpp | 38 ++++++++++++++++---------------- src/ProcessGroupMPI.cpp | 38 ++++++++++++++++---------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/include/c10d/ProcessGroupMPI.hpp b/include/c10d/ProcessGroupMPI.hpp index 4f54462..e02de56 100644 --- a/include/c10d/ProcessGroupMPI.hpp +++ b/include/c10d/ProcessGroupMPI.hpp @@ -112,95 +112,95 @@ class ProcessGroupMPI : public ProcessGroup { // Abort the MPI program, needs to be called when exception is detected void abort(); - std::shared_ptr broadcast( + c10::intrusive_ptr broadcast( std::vector& data, const BroadcastOptions& opts = BroadcastOptions()) override; - std::shared_ptr allreduce( + c10::intrusive_ptr allreduce( std::vector& tensors, const AllreduceOptions& opts = AllreduceOptions()) override; - std::shared_ptr allreduce_coalesced( + c10::intrusive_ptr allreduce_coalesced( std::vector& tensors, const AllreduceCoalescedOptions& opts = AllreduceCoalescedOptions()) override; - std::shared_ptr reduce( + c10::intrusive_ptr reduce( std::vector& tensors, const ReduceOptions& opts = ReduceOptions()) override; - std::shared_ptr allgather( + c10::intrusive_ptr allgather( std::vector>& outputTensors, std::vector& inputTensors, const AllgatherOptions& opts = AllgatherOptions()) override; - std::shared_ptr allgather_base( + c10::intrusive_ptr allgather_base( at::Tensor& outputbuffer, at::Tensor& inputbuffer, const AllgatherOptions& opts = AllgatherOptions()) override; - std::shared_ptr allgather_coalesced( + c10::intrusive_ptr allgather_coalesced( std::vector>& outputTensorLists, std::vector& inputTensors, const AllgatherOptions& opts = AllgatherOptions()) override; - std::shared_ptr gather( + c10::intrusive_ptr gather( std::vector>& outputTensors, std::vector& inputTensors, const GatherOptions& opts = GatherOptions()) override; - std::shared_ptr scatter( + c10::intrusive_ptr scatter( std::vector& outputTensors, std::vector>& inputTensors, const ScatterOptions& opts = ScatterOptions()) override; - std::shared_ptr reduce_scatter( + c10::intrusive_ptr reduce_scatter( std::vector& outputTensors, std::vector>& inputTensors, const ReduceScatterOptions& opts = ReduceScatterOptions()) override; - std::shared_ptr alltoall_base( + c10::intrusive_ptr alltoall_base( at::Tensor& outputTensor, at::Tensor& inputTensor, std::vector& outputSplitSizes, std::vector& inputSplitSizes, const AllToAllOptions& opts = AllToAllOptions()) override; - std::shared_ptr alltoall( + c10::intrusive_ptr alltoall( std::vector& outputTensors, std::vector& inputTensors, const AllToAllOptions& opts = AllToAllOptions()) override; - std::shared_ptr send( + c10::intrusive_ptr send( std::vector& tensors, int dstRank, int tag); - std::shared_ptr recv( + c10::intrusive_ptr recv( std::vector& tensors, int srcRank, int tag); - std::shared_ptr recvAnysource( + c10::intrusive_ptr recvAnysource( std::vector& tensor, int tag); - std::shared_ptr barrier( + c10::intrusive_ptr barrier( const BarrierOptions& opts = BarrierOptions()) override; // Creating a new ProcessGroupMPI, will initiialize MPI if not initialized - static std::shared_ptr createProcessGroupMPI( + static c10::intrusive_ptr createProcessGroupMPI( std::vector ranks = {}); protected: using WorkType = - std::tuple, std::shared_ptr>; + std::tuple, c10::intrusive_ptr>; // Worker thread loop void runLoop(); // Helper function that is called by the destructor void destroy(); - std::shared_ptr enqueue(std::unique_ptr entry); + c10::intrusive_ptr enqueue(std::unique_ptr entry); bool stop_; diff --git a/src/ProcessGroupMPI.cpp b/src/ProcessGroupMPI.cpp index c26d0a3..6c8a02c 100644 --- a/src/ProcessGroupMPI.cpp +++ b/src/ProcessGroupMPI.cpp @@ -204,7 +204,7 @@ void ProcessGroupMPI::initMPIOnce() { }); } -std::shared_ptr ProcessGroupMPI::createProcessGroupMPI( +c10::intrusive_ptr ProcessGroupMPI::createProcessGroupMPI( std::vector ranks) { // Once initialization initMPIOnce(); @@ -243,7 +243,7 @@ std::shared_ptr ProcessGroupMPI::createProcessGroupMPI( // process group instance. This is in line with the semantics of the // other process group types. if (groupComm == MPI_COMM_NULL) { - return std::shared_ptr(); + return c10::intrusive_ptr(); } return std::make_shared(rank, size, groupComm); @@ -313,7 +313,7 @@ void ProcessGroupMPI::runLoop() { } } -std::shared_ptr ProcessGroupMPI::enqueue( +c10::intrusive_ptr ProcessGroupMPI::enqueue( std::unique_ptr entry) { auto work = std::make_shared(); std::unique_lock lock(pgMutex_); @@ -323,7 +323,7 @@ std::shared_ptr ProcessGroupMPI::enqueue( return work; } -std::shared_ptr ProcessGroupMPI::broadcast( +c10::intrusive_ptr ProcessGroupMPI::broadcast( std::vector& tensors, const BroadcastOptions& opts) { checkSingleTensor(tensors); @@ -344,7 +344,7 @@ std::shared_ptr ProcessGroupMPI::broadcast( return enqueue(std::move(entry)); } -std::shared_ptr ProcessGroupMPI::allreduce( +c10::intrusive_ptr ProcessGroupMPI::allreduce( std::vector& tensors, const AllreduceOptions& opts) { checkSingleTensor(tensors); @@ -367,14 +367,14 @@ std::shared_ptr ProcessGroupMPI::allreduce( return enqueue(std::move(entry)); } -std::shared_ptr ProcessGroupMPI::allreduce_coalesced( +c10::intrusive_ptr ProcessGroupMPI::allreduce_coalesced( std::vector& tensors, const AllreduceCoalescedOptions& opts) { throw std::runtime_error( "allreduce_coalesced is currently not supported with MPI"); } -std::shared_ptr ProcessGroupMPI::reduce( +c10::intrusive_ptr ProcessGroupMPI::reduce( std::vector& tensors, const ReduceOptions& opts) { checkSingleTensor(tensors); @@ -402,7 +402,7 @@ std::shared_ptr ProcessGroupMPI::reduce( return enqueue(std::move(entry)); } -std::shared_ptr ProcessGroupMPI::allgather( +c10::intrusive_ptr ProcessGroupMPI::allgather( std::vector>& outputTensors, std::vector& inputTensors, const AllgatherOptions& opts) { @@ -446,7 +446,7 @@ std::shared_ptr ProcessGroupMPI::allgather( return enqueue(std::move(entry)); } -std::shared_ptr ProcessGroupMPI::allgather_coalesced( +c10::intrusive_ptr ProcessGroupMPI::allgather_coalesced( std::vector>& /* unused */, std::vector& /* unused */, const AllgatherOptions& /* unused */) { @@ -454,7 +454,7 @@ std::shared_ptr ProcessGroupMPI::allgather_coalesced( "ProcessGroupMPI does not support allgather_coalesced"); } -std::shared_ptr ProcessGroupMPI::gather( +c10::intrusive_ptr ProcessGroupMPI::gather( std::vector>& outputTensors, std::vector& inputTensors, const GatherOptions& opts) { @@ -521,7 +521,7 @@ std::shared_ptr ProcessGroupMPI::gather( } } -std::shared_ptr ProcessGroupMPI::scatter( +c10::intrusive_ptr ProcessGroupMPI::scatter( std::vector& outputTensors, std::vector>& inputTensors, const ScatterOptions& opts) { @@ -587,14 +587,14 @@ std::shared_ptr ProcessGroupMPI::scatter( } } -std::shared_ptr ProcessGroupMPI::reduce_scatter( +c10::intrusive_ptr ProcessGroupMPI::reduce_scatter( std::vector& outputTensors, std::vector>& inputTensors, const ReduceScatterOptions& opts) { throw std::runtime_error("ProcessGroupMPI does not support reduce_scatter"); } -std::shared_ptr ProcessGroupMPI::alltoall_base( +c10::intrusive_ptr ProcessGroupMPI::alltoall_base( at::Tensor& outputTensor, at::Tensor& inputTensor, std::vector& outputSplitSizes, @@ -670,7 +670,7 @@ std::shared_ptr ProcessGroupMPI::alltoall_base( return enqueue(std::move(entry)); } } -std::shared_ptr ProcessGroupMPI::alltoall( +c10::intrusive_ptr ProcessGroupMPI::alltoall( std::vector& outputTensors, std::vector& inputTensors, const AllToAllOptions& opts) { @@ -727,7 +727,7 @@ std::shared_ptr ProcessGroupMPI::alltoall( return enqueue(std::move(entry)); } -std::shared_ptr ProcessGroupMPI::send( +c10::intrusive_ptr ProcessGroupMPI::send( std::vector& tensors, int dstRank, int tag) { @@ -752,7 +752,7 @@ std::shared_ptr ProcessGroupMPI::send( return std::make_shared(tensor, request); } -std::shared_ptr ProcessGroupMPI::recv( +c10::intrusive_ptr ProcessGroupMPI::recv( std::vector& tensors, int srcRank, int tag) { @@ -777,7 +777,7 @@ std::shared_ptr ProcessGroupMPI::recv( return std::make_shared(tensor, request); } -std::shared_ptr ProcessGroupMPI::recvAnysource( +c10::intrusive_ptr ProcessGroupMPI::recvAnysource( std::vector& tensors, int tag) { checkSingleTensor(tensors); @@ -801,7 +801,7 @@ std::shared_ptr ProcessGroupMPI::recvAnysource( return std::make_shared(tensor, request); } -std::shared_ptr ProcessGroupMPI::barrier( +c10::intrusive_ptr ProcessGroupMPI::barrier( const BarrierOptions& opts) { std::function&)> runFunc = [this](std::unique_ptr& entry) { @@ -813,7 +813,7 @@ std::shared_ptr ProcessGroupMPI::barrier( return enqueue(std::move(entry)); } -std::shared_ptr ProcessGroupMPI::allgather_base( +c10::intrusive_ptr ProcessGroupMPI::allgather_base( at::Tensor& /*unused */, at::Tensor& /*unused */, const AllgatherOptions& /*unused */) { From 7050075d85879602ec3b55a0482580e206d90b3b Mon Sep 17 00:00:00 2001 From: Min Xu Date: Thu, 28 Jan 2021 13:38:30 -0800 Subject: [PATCH 3/4] change make_shared too --- include/c10d/NCCLUtils.hpp | 4 +- include/c10d/ProcessGroupNCCL.hpp | 76 +++++++++++++++---------------- src/CUDABindings.cpp | 6 +-- src/ProcessGroupMPI.cpp | 10 ++-- src/ProcessGroupNCCL.cpp | 72 ++++++++++++++--------------- 5 files changed, 84 insertions(+), 84 deletions(-) diff --git a/include/c10d/NCCLUtils.hpp b/include/c10d/NCCLUtils.hpp index 804667e..fc058da 100644 --- a/include/c10d/NCCLUtils.hpp +++ b/include/c10d/NCCLUtils.hpp @@ -82,11 +82,11 @@ class NCCLComm { } } - static std::shared_ptr create( + static c10::intrusive_ptr create( int numRanks, int rank, ncclUniqueId commId) { - auto comm = std::make_shared(); + auto comm = c10::make_instrusive(); C10D_NCCL_CHECK( ncclCommInitRank(&(comm->ncclComm_), numRanks, commId, rank)); comm->ncclId_ = commId; diff --git a/include/c10d/ProcessGroupNCCL.hpp b/include/c10d/ProcessGroupNCCL.hpp index c2467d5..0b2a077 100644 --- a/include/c10d/ProcessGroupNCCL.hpp +++ b/include/c10d/ProcessGroupNCCL.hpp @@ -56,7 +56,7 @@ enum class NCCLCommType : std::uint8_t { // Example on using the NCCL process group // // ProcessGroupNCCL pg(store, rank, size); -// std::shared_ptr work = pg.allreduce(tensors); +// c10::intrusive_ptr work = pg.allreduce(tensors); // // // At this point, NCCL kernel has already by queued successfully // // Now, let current stream wait for the NCCL to finish, this function is @@ -129,10 +129,10 @@ class ProcessGroupNCCL : public ProcessGroup { std::vector devices_; // The CUDA events tracking this work item on multiple CUDA devices - std::shared_ptr> cudaEvents_; + c10::intrusive_ptr> cudaEvents_; // The NCCL communicators used for this work item. - std::vector> ncclComms_; + std::vector> ncclComms_; // Tensors used for barrier op std::vector barrierTensors_; @@ -149,7 +149,7 @@ class ProcessGroupNCCL : public ProcessGroup { // Wrapper method for the static checkForNCCLErrors which can be overridden // for tests. virtual std::exception_ptr checkForNCCLErrors( - const std::vector>& ncclComms) const; + const std::vector>& ncclComms) const; private: // Helper function for synchronize @@ -166,12 +166,12 @@ class ProcessGroupNCCL : public ProcessGroup { // Reference to the store so that we can write aborted communicators // to the store. - std::shared_ptr store_; + c10::intrusive_ptr store_; // Store a reference to NCCL collective's outputs to be used by getFuture. - std::shared_ptr> outputs_; + c10::intrusive_ptr> outputs_; // Store streams that run FutureNCCL then callbacks. - std::vector> + std::vector> futureNCCLCallbackStreams_; friend class ProcessGroupNCCL; @@ -199,7 +199,7 @@ class ProcessGroupNCCL : public ProcessGroup { // communicator. These NCCL communicators are cached and reused if possible. // ProcessGroupNCCL( - const std::shared_ptr& store, + const c10::intrusive_ptr& store, int rank, int size, Options options = Options()); @@ -208,7 +208,7 @@ class ProcessGroupNCCL : public ProcessGroup { // If you have existing code that uses the `groupName`, you can replace // it by specifying a `c10d::PrefixStore(groupName, store)` for store. C10_DEPRECATED ProcessGroupNCCL( - const std::shared_ptr& store, + const c10::intrusive_ptr& store, int rank, int size, const std::string& groupName, @@ -217,64 +217,64 @@ class ProcessGroupNCCL : public ProcessGroup { virtual ~ProcessGroupNCCL(); - std::shared_ptr broadcast( + c10::intrusive_ptr broadcast( std::vector& tensors, const BroadcastOptions& opts = BroadcastOptions()) override; - std::shared_ptr allreduce( + c10::intrusive_ptr allreduce( std::vector& tensors, const AllreduceOptions& opts = AllreduceOptions()) override; - std::shared_ptr allreduce_coalesced( + c10::intrusive_ptr allreduce_coalesced( std::vector& tensors, const AllreduceCoalescedOptions& opts = AllreduceCoalescedOptions()) override; - std::shared_ptr reduce( + c10::intrusive_ptr reduce( std::vector& tensors, const ReduceOptions& opts = ReduceOptions()) override; - std::shared_ptr allgather( + c10::intrusive_ptr allgather( std::vector>& outputTensors, std::vector& inputTensors, const AllgatherOptions& opts = AllgatherOptions()) override; - std::shared_ptr allgather_base( + c10::intrusive_ptr allgather_base( at::Tensor& outputbuffer, at::Tensor& inputbuffer, const AllgatherOptions& opts = AllgatherOptions()) override; - std::shared_ptr allgather_coalesced( + c10::intrusive_ptr allgather_coalesced( std::vector>& outputTensorLists, std::vector& inputTensors, const AllgatherOptions& opts = AllgatherOptions()) override; - std::shared_ptr reduce_scatter( + c10::intrusive_ptr reduce_scatter( std::vector& outputTensors, std::vector>& inputTensors, const ReduceScatterOptions& opts = ReduceScatterOptions()) override; - std::shared_ptr barrier( + c10::intrusive_ptr barrier( const BarrierOptions& opts = BarrierOptions()) override; - std::shared_ptr alltoall_base( + c10::intrusive_ptr alltoall_base( at::Tensor& outputTensor, at::Tensor& inputTensor, std::vector& outputSplitSizes, std::vector& inputSplitSizes, const AllToAllOptions& opts = AllToAllOptions()) override; - std::shared_ptr alltoall( + c10::intrusive_ptr alltoall( std::vector& outputTensors, std::vector& inputTensors, const AllToAllOptions& opts = AllToAllOptions()) override; - std::shared_ptr send( + c10::intrusive_ptr send( std::vector& tensors, int dstRank, int tag) override; - std::shared_ptr recv( + c10::intrusive_ptr recv( std::vector& tensors, int srcRank, int tag) override; @@ -284,17 +284,17 @@ class ProcessGroupNCCL : public ProcessGroup { static void groupEnd(); // Unsupported Ops - std::shared_ptr gather( + c10::intrusive_ptr gather( std::vector>& outputTensors, std::vector& inputTensors, const GatherOptions& opts = GatherOptions()) override; - std::shared_ptr scatter( + c10::intrusive_ptr scatter( std::vector& outputTensors, std::vector>& inputTensors, const ScatterOptions& opts = ScatterOptions()) override; - std::shared_ptr recvAnysource( + c10::intrusive_ptr recvAnysource( std::vector& tensors, int tag) override; @@ -310,7 +310,7 @@ class ProcessGroupNCCL : public ProcessGroup { // Helper that either looks up the cached NCCL communicators or creates // a new set of NCCL communicators as a cache entry - std::vector>& getNCCLComm( + std::vector>& getNCCLComm( const std::string& devicesKey, const std::vector& devices, NCCLCommType commType = NCCLCommType::COLL, @@ -319,9 +319,9 @@ class ProcessGroupNCCL : public ProcessGroup { // Wrapper method which can be overridden for tests. virtual std::exception_ptr checkForNCCLErrors( - const std::vector>& ncclComms); + const std::vector>& ncclComms); - virtual std::shared_ptr initWork( + virtual c10::intrusive_ptr initWork( std::vector devices); private: @@ -332,12 +332,12 @@ class ProcessGroupNCCL : public ProcessGroup { // ncclComm_t, at::cuda::CUDAStream&); // void {pre,post}(std::vector); template - std::shared_ptr collective( + c10::intrusive_ptr collective( std::vector& input, std::vector& output, Fn fn); template - std::shared_ptr collective( + c10::intrusive_ptr collective( std::vector& input, std::vector& output, Fn fn, @@ -348,13 +348,13 @@ class ProcessGroupNCCL : public ProcessGroup { // primitives. It is the same structure as the helper used for collective // communicaiton primitives. template - std::shared_ptr pointToPoint( + c10::intrusive_ptr pointToPoint( std::vector& tensor, Fn fn, int peer, NCCLCommType commType); template - std::shared_ptr pointToPoint( + c10::intrusive_ptr pointToPoint( std::vector& tensor, Fn fn, int peer, @@ -365,7 +365,7 @@ class ProcessGroupNCCL : public ProcessGroup { // Checks for NCCL errors on each of the communicators and returns an // appropriate exception_ptr (nullptr if no errors). static std::exception_ptr checkForNCCLErrorsInternal( - const std::vector>& ncclComms); + const std::vector>& ncclComms); // Function that runs as part of a separate thread and checks for errors on // NCCL communicators. We need a separate thread to check for NCCL errors @@ -395,7 +395,7 @@ class ProcessGroupNCCL : public ProcessGroup { static const int64_t kWorkCleanupThreadSleepMillis; // The store is used to broadcast the NCCL unique ID of rank 0. - std::shared_ptr store_; + c10::intrusive_ptr store_; // The number of NCCL communicators that have been created during // the lifetime of this process group. This sequence number is @@ -430,11 +430,11 @@ class ProcessGroupNCCL : public ProcessGroup { // the key will be "1:2" on both processes. // Note: this is for the scenario where there is only 1 GPU per process. // When it comes to multiple GPUs per process, this part may need to redesigned. - std::unordered_map>> + std::unordered_map>> devNCCLCommMap_; // Map from ncclUniqueId to appropriate communicator. - std::unordered_map>> + std::unordered_map>> ncclIdToCommMap_; // Mutex to guard maps like devNCCLCommMap_ and ncclIdToCommMap_. @@ -465,7 +465,7 @@ class ProcessGroupNCCL : public ProcessGroup { std::list workMetaList_; // Add Work Pointer to workVector - void workEnqueue(std::shared_ptr); + void workEnqueue(c10::intrusive_ptr); // The CUDA steams used by NCCL kernels std::unordered_map> @@ -522,7 +522,7 @@ class ProcessGroupNCCL : public ProcessGroup { // device of the NCCL collective's outputs, we later set the callback stream // of the corresponding device inside ProcessGroupNCCL::getNCCLComm if not set // before. - std::vector> futureNCCLCallbackStreams_; + std::vector> futureNCCLCallbackStreams_; // Schedule NCCL operations on high priority CUDA streams. bool isHighPriorityStream_ = false; diff --git a/src/CUDABindings.cpp b/src/CUDABindings.cpp index 1e4bc82..82aec18 100644 --- a/src/CUDABindings.cpp +++ b/src/CUDABindings.cpp @@ -9,15 +9,15 @@ namespace c10d { namespace { -std::shared_ptr createProcessGroupNCCL( - const std::shared_ptr<::c10d::Store>& store, +c10::intrusive_ptr createProcessGroupNCCL( + const c10::intrusive_ptr<::c10d::Store>& store, int rank, int size, const std::chrono::milliseconds& timeout) { ProcessGroupNCCL::Options options; options.isHighPriorityStream = false; options.opTimeout = timeout; - return std::make_shared(store, rank, size, options); + return c10::make_instrusive(store, rank, size, options); } } // namespacef diff --git a/src/ProcessGroupMPI.cpp b/src/ProcessGroupMPI.cpp index 6c8a02c..48c16aa 100644 --- a/src/ProcessGroupMPI.cpp +++ b/src/ProcessGroupMPI.cpp @@ -246,7 +246,7 @@ c10::intrusive_ptr ProcessGroupMPI::createProcessGroupMPI( return c10::intrusive_ptr(); } - return std::make_shared(rank, size, groupComm); + return c10::make_instrusive(rank, size, groupComm); } ProcessGroupMPI::ProcessGroupMPI(int rank, int size, MPI_Comm pgComm) @@ -315,7 +315,7 @@ void ProcessGroupMPI::runLoop() { c10::intrusive_ptr ProcessGroupMPI::enqueue( std::unique_ptr entry) { - auto work = std::make_shared(); + auto work = c10::make_instrusive(); std::unique_lock lock(pgMutex_); queue_.push_back(std::make_tuple(std::move(entry), work)); lock.unlock(); @@ -749,7 +749,7 @@ c10::intrusive_ptr ProcessGroupMPI::send( &request)); } - return std::make_shared(tensor, request); + return c10::make_instrusive(tensor, request); } c10::intrusive_ptr ProcessGroupMPI::recv( @@ -774,7 +774,7 @@ c10::intrusive_ptr ProcessGroupMPI::recv( &request)); } - return std::make_shared(tensor, request); + return c10::make_instrusive(tensor, request); } c10::intrusive_ptr ProcessGroupMPI::recvAnysource( @@ -798,7 +798,7 @@ c10::intrusive_ptr ProcessGroupMPI::recvAnysource( &request)); } - return std::make_shared(tensor, request); + return c10::make_instrusive(tensor, request); } c10::intrusive_ptr ProcessGroupMPI::barrier( diff --git a/src/ProcessGroupNCCL.cpp b/src/ProcessGroupNCCL.cpp index 5cfe88e..7f66088 100644 --- a/src/ProcessGroupNCCL.cpp +++ b/src/ProcessGroupNCCL.cpp @@ -247,7 +247,7 @@ ProcessGroupNCCL::WorkNCCL::WorkNCCL(const std::vector& devices) // Note: The actual events are lazily created when first recorded to with // DEFAULT_FLAGS = cudaEventDisableTiming. cudaEvents_ = - std::make_shared>(devices.size()); + c10::make_instrusive>(devices.size()); ncclComms_.resize(devices.size()); } @@ -450,7 +450,7 @@ bool ProcessGroupNCCL::WorkNCCL::timedOut() { } ProcessGroupNCCL::ProcessGroupNCCL( - const std::shared_ptr& store, + const c10::intrusive_ptr& store, int rank, int size, Options options) @@ -684,17 +684,17 @@ void ProcessGroupNCCL::workCleanupLoop() { } std::exception_ptr ProcessGroupNCCL::WorkNCCL::checkForNCCLErrors( - const std::vector>& ncclComms) const { + const std::vector>& ncclComms) const { return checkForNCCLErrorsInternal(ncclComms); } std::exception_ptr ProcessGroupNCCL::checkForNCCLErrors( - const std::vector>& ncclComms) { + const std::vector>& ncclComms) { return checkForNCCLErrorsInternal(ncclComms); } std::exception_ptr ProcessGroupNCCL::checkForNCCLErrorsInternal( - const std::vector>& ncclComms) { + const std::vector>& ncclComms) { for (const auto& ncclComm : ncclComms) { ncclResult_t ncclAsyncErr = ncclComm->checkForNcclError(); if (ncclAsyncErr != ncclSuccess) { @@ -743,7 +743,7 @@ void ProcessGroupNCCL::broadcastUniqueNCCLID( } } -std::vector>& ProcessGroupNCCL::getNCCLComm( +std::vector>& ProcessGroupNCCL::getNCCLComm( const std::string& devicesKey, const std::vector& devices, NCCLCommType commType, @@ -769,7 +769,7 @@ std::vector>& ProcessGroupNCCL::getNCCLComm( } // NCCL communicator not cached, create a new entry - std::vector> ncclComms; + std::vector> ncclComms; ncclComms.resize(devices.size()); // Create the unique NCCL ID and broadcast it @@ -844,7 +844,7 @@ std::vector>& ProcessGroupNCCL::getNCCLComm( std::lock_guard lock(mutex_); if (futureNCCLCallbackStreams_[deviceIndex] == nullptr) { futureNCCLCallbackStreams_[deviceIndex] = - std::make_shared(at::cuda::getStreamFromPool(isHighPriorityStream_)); + c10::make_instrusive(at::cuda::getStreamFromPool(isHighPriorityStream_)); } } @@ -974,9 +974,9 @@ std::vector flatten_for_scatter_gather( } // namespace -std::shared_ptr ProcessGroupNCCL::initWork( +c10::intrusive_ptr ProcessGroupNCCL::initWork( std::vector devices) { - return std::make_shared(devices); + return c10::make_instrusive(devices); } #if (TORCH_MAJOR >= 1) && (TORCH_MINOR >= 7) @@ -988,7 +988,7 @@ std::vector ProcessGroupNCCL::WorkNCCL::result() const { } void ProcessGroupNCCL::workEnqueue( - std::shared_ptr work) { + c10::intrusive_ptr work) { if (!terminateProcessGroup_.load()) { std::lock_guard lock(workMetaListMutex_); // Avoid view tensors to be processed in cleanup thread. @@ -1002,7 +1002,7 @@ ProcessGroupNCCL::Options::Options() : opTimeout(kProcessGroupNCCLOpTimeoutMillis), isHighPriorityStream(false) {} template -std::shared_ptr ProcessGroupNCCL::collective( +c10::intrusive_ptr ProcessGroupNCCL::collective( std::vector& inputs, std::vector& outputs, Fn fn, @@ -1020,7 +1020,7 @@ std::shared_ptr ProcessGroupNCCL::collective( // Store references to outputs and futureNCCLCallbackStream to be used by // WorkNCCL::getFuture. - work->outputs_ = std::make_shared>(outputs); + work->outputs_ = c10::make_instrusive>(outputs); work->futureNCCLCallbackStreams_ = futureNCCLCallbackStreams_; at::cuda::OptionalCUDAGuard gpuGuard; @@ -1073,7 +1073,7 @@ std::shared_ptr ProcessGroupNCCL::collective( } template -std::shared_ptr ProcessGroupNCCL::pointToPoint( +c10::intrusive_ptr ProcessGroupNCCL::pointToPoint( std::vector& tensors, Fn fn, int peer, @@ -1095,7 +1095,7 @@ std::shared_ptr ProcessGroupNCCL::pointToPoint( if (commType == NCCLCommType::RECV) { // Store references to outputs and futureNCCLCallbackStream to be used by // WorkNCCL::getFuture. - work->outputs_ = std::make_shared>(tensors); + work->outputs_ = c10::make_instrusive>(tensors); work->futureNCCLCallbackStreams_ = futureNCCLCallbackStreams_; } @@ -1145,7 +1145,7 @@ std::shared_ptr ProcessGroupNCCL::pointToPoint( } template -std::shared_ptr ProcessGroupNCCL::collective( +c10::intrusive_ptr ProcessGroupNCCL::collective( std::vector& inputs, std::vector& outputs, Fn fn) { @@ -1158,7 +1158,7 @@ std::shared_ptr ProcessGroupNCCL::collective( } template -std::shared_ptr ProcessGroupNCCL::pointToPoint( +c10::intrusive_ptr ProcessGroupNCCL::pointToPoint( std::vector& tensor, Fn fn, int peer, @@ -1172,7 +1172,7 @@ std::shared_ptr ProcessGroupNCCL::pointToPoint( [](std::vector&) {}); } -std::shared_ptr ProcessGroupNCCL::allreduce( +c10::intrusive_ptr ProcessGroupNCCL::allreduce( std::vector& tensors, const AllreduceOptions& opts) { check_gpu_tensors(tensors); @@ -1195,14 +1195,14 @@ std::shared_ptr ProcessGroupNCCL::allreduce( }); } -std::shared_ptr ProcessGroupNCCL::allreduce_coalesced( +c10::intrusive_ptr ProcessGroupNCCL::allreduce_coalesced( std::vector& tensors, const AllreduceCoalescedOptions& opts) { throw std::runtime_error( "allreduce_coalesced is currently not supported with NCCL"); } -std::shared_ptr ProcessGroupNCCL::broadcast( +c10::intrusive_ptr ProcessGroupNCCL::broadcast( std::vector& tensors, const BroadcastOptions& opts) { check_gpu_tensors(tensors); @@ -1225,7 +1225,7 @@ std::shared_ptr ProcessGroupNCCL::broadcast( }); } -std::shared_ptr ProcessGroupNCCL::reduce( +c10::intrusive_ptr ProcessGroupNCCL::reduce( std::vector& tensors, const ReduceOptions& opts) { check_gpu_tensors(tensors); @@ -1250,7 +1250,7 @@ std::shared_ptr ProcessGroupNCCL::reduce( }); } -std::shared_ptr ProcessGroupNCCL::allgather( +c10::intrusive_ptr ProcessGroupNCCL::allgather( std::vector>& outputTensors, std::vector& inputTensors, const AllgatherOptions& opts) { @@ -1293,7 +1293,7 @@ std::shared_ptr ProcessGroupNCCL::allgather( }); } -std::shared_ptr ProcessGroupNCCL::allgather_coalesced( +c10::intrusive_ptr ProcessGroupNCCL::allgather_coalesced( std::vector>& /* unused */, std::vector& /* unused */, const AllgatherOptions& /* unused */) { @@ -1301,7 +1301,7 @@ std::shared_ptr ProcessGroupNCCL::allgather_coalesced( "ProcessGroupNCCL does not support allgather_coalesced"); } -std::shared_ptr ProcessGroupNCCL::reduce_scatter( +c10::intrusive_ptr ProcessGroupNCCL::reduce_scatter( std::vector& outputTensors, std::vector>& inputTensors, const ReduceScatterOptions& opts) { @@ -1345,7 +1345,7 @@ std::shared_ptr ProcessGroupNCCL::reduce_scatter( [&](std::vector& ncclStreams) {}); } -std::shared_ptr ProcessGroupNCCL::barrier( +c10::intrusive_ptr ProcessGroupNCCL::barrier( const BarrierOptions& opts) { std::vector devices; if (usedDeviceIdxs_.empty()) { @@ -1386,7 +1386,7 @@ std::shared_ptr ProcessGroupNCCL::barrier( } #ifdef ENABLE_NCCL_P2P_SUPPORT -std::shared_ptr ProcessGroupNCCL::alltoall_base( +c10::intrusive_ptr ProcessGroupNCCL::alltoall_base( at::Tensor& outputTensor, at::Tensor& inputTensor, std::vector& outputSplitSizes, @@ -1448,7 +1448,7 @@ std::shared_ptr ProcessGroupNCCL::alltoall_base( } } -std::shared_ptr ProcessGroupNCCL::send( +c10::intrusive_ptr ProcessGroupNCCL::send( std::vector& tensors, int dstRank, int /* unused */) { @@ -1472,7 +1472,7 @@ std::shared_ptr ProcessGroupNCCL::send( return ret; } -std::shared_ptr ProcessGroupNCCL::recv( +c10::intrusive_ptr ProcessGroupNCCL::recv( std::vector& tensors, int srcRank, int /* unused */) { @@ -1496,7 +1496,7 @@ std::shared_ptr ProcessGroupNCCL::recv( return ret; } #else -std::shared_ptr ProcessGroupNCCL::alltoall_base( +c10::intrusive_ptr ProcessGroupNCCL::alltoall_base( at::Tensor& /* unused */, at::Tensor& /* unused */, std::vector& /* unused */, @@ -1506,7 +1506,7 @@ std::shared_ptr ProcessGroupNCCL::alltoall_base( "ProcessGroupNCCL only supports alltoall* for NCCL lib version >= 2.7.0"); } -std::shared_ptr ProcessGroupNCCL::send( +c10::intrusive_ptr ProcessGroupNCCL::send( std::vector& /* unused */, int /* unused */, int /* unused */) { @@ -1514,7 +1514,7 @@ std::shared_ptr ProcessGroupNCCL::send( "ProcessGroupNCCL only supports send for NCCL lib version >= 2.7.0"); } -std::shared_ptr ProcessGroupNCCL::recv( +c10::intrusive_ptr ProcessGroupNCCL::recv( std::vector& /* unused */, int /* unused */, int /* unused */) { @@ -1537,34 +1537,34 @@ void ProcessGroupNCCL::groupEnd() { --ncclActiveGroupCounter_; } -std::shared_ptr ProcessGroupNCCL::alltoall( +c10::intrusive_ptr ProcessGroupNCCL::alltoall( std::vector& /* unused */, std::vector& /* unused */, const AllToAllOptions& /* unused */) { throw std::runtime_error("ProcessGroupNCCL does not support alltoall"); } -std::shared_ptr ProcessGroupNCCL::gather( +c10::intrusive_ptr ProcessGroupNCCL::gather( std::vector>& /* unused */, std::vector& /* unused */, const GatherOptions& /* unused */) { throw std::runtime_error("ProcessGroupNCCL does not support gather"); } -std::shared_ptr ProcessGroupNCCL::scatter( +c10::intrusive_ptr ProcessGroupNCCL::scatter( std::vector& /* unused */, std::vector>& /* unused */, const ScatterOptions& /* unused */) { throw std::runtime_error("ProcessGroupNCCL does not support scatter"); } -std::shared_ptr ProcessGroupNCCL::recvAnysource( +c10::intrusive_ptr ProcessGroupNCCL::recvAnysource( std::vector& /* unused */, int /* unused */) { throw std::runtime_error("ProcessGroupNCCL does not support recvAnysource"); } -std::shared_ptr ProcessGroupNCCL::allgather_base( +c10::intrusive_ptr ProcessGroupNCCL::allgather_base( at::Tensor& /*unused */, at::Tensor& /*unused */, const AllgatherOptions& /*unused */) { From c723ab41298aa8f20a455585728c764ebacbe7ba Mon Sep 17 00:00:00 2001 From: Min Xu Date: Thu, 28 Jan 2021 13:40:42 -0800 Subject: [PATCH 4/4] typo --- include/c10d/NCCLUtils.hpp | 2 +- src/CUDABindings.cpp | 2 +- src/ProcessGroupMPI.cpp | 10 +++++----- src/ProcessGroupNCCL.cpp | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/c10d/NCCLUtils.hpp b/include/c10d/NCCLUtils.hpp index fc058da..236e59a 100644 --- a/include/c10d/NCCLUtils.hpp +++ b/include/c10d/NCCLUtils.hpp @@ -86,7 +86,7 @@ class NCCLComm { int numRanks, int rank, ncclUniqueId commId) { - auto comm = c10::make_instrusive(); + auto comm = c10::make_intrusive(); C10D_NCCL_CHECK( ncclCommInitRank(&(comm->ncclComm_), numRanks, commId, rank)); comm->ncclId_ = commId; diff --git a/src/CUDABindings.cpp b/src/CUDABindings.cpp index 82aec18..318ca3d 100644 --- a/src/CUDABindings.cpp +++ b/src/CUDABindings.cpp @@ -17,7 +17,7 @@ c10::intrusive_ptr createProcessGroupNCCL( ProcessGroupNCCL::Options options; options.isHighPriorityStream = false; options.opTimeout = timeout; - return c10::make_instrusive(store, rank, size, options); + return c10::make_intrusive(store, rank, size, options); } } // namespacef diff --git a/src/ProcessGroupMPI.cpp b/src/ProcessGroupMPI.cpp index 48c16aa..6ec1bb9 100644 --- a/src/ProcessGroupMPI.cpp +++ b/src/ProcessGroupMPI.cpp @@ -246,7 +246,7 @@ c10::intrusive_ptr ProcessGroupMPI::createProcessGroupMPI( return c10::intrusive_ptr(); } - return c10::make_instrusive(rank, size, groupComm); + return c10::make_intrusive(rank, size, groupComm); } ProcessGroupMPI::ProcessGroupMPI(int rank, int size, MPI_Comm pgComm) @@ -315,7 +315,7 @@ void ProcessGroupMPI::runLoop() { c10::intrusive_ptr ProcessGroupMPI::enqueue( std::unique_ptr entry) { - auto work = c10::make_instrusive(); + auto work = c10::make_intrusive(); std::unique_lock lock(pgMutex_); queue_.push_back(std::make_tuple(std::move(entry), work)); lock.unlock(); @@ -749,7 +749,7 @@ c10::intrusive_ptr ProcessGroupMPI::send( &request)); } - return c10::make_instrusive(tensor, request); + return c10::make_intrusive(tensor, request); } c10::intrusive_ptr ProcessGroupMPI::recv( @@ -774,7 +774,7 @@ c10::intrusive_ptr ProcessGroupMPI::recv( &request)); } - return c10::make_instrusive(tensor, request); + return c10::make_intrusive(tensor, request); } c10::intrusive_ptr ProcessGroupMPI::recvAnysource( @@ -798,7 +798,7 @@ c10::intrusive_ptr ProcessGroupMPI::recvAnysource( &request)); } - return c10::make_instrusive(tensor, request); + return c10::make_intrusive(tensor, request); } c10::intrusive_ptr ProcessGroupMPI::barrier( diff --git a/src/ProcessGroupNCCL.cpp b/src/ProcessGroupNCCL.cpp index 7f66088..4930707 100644 --- a/src/ProcessGroupNCCL.cpp +++ b/src/ProcessGroupNCCL.cpp @@ -247,7 +247,7 @@ ProcessGroupNCCL::WorkNCCL::WorkNCCL(const std::vector& devices) // Note: The actual events are lazily created when first recorded to with // DEFAULT_FLAGS = cudaEventDisableTiming. cudaEvents_ = - c10::make_instrusive>(devices.size()); + c10::make_intrusive>(devices.size()); ncclComms_.resize(devices.size()); } @@ -844,7 +844,7 @@ std::vector>& ProcessGroupNCCL::getNCCLComm( std::lock_guard lock(mutex_); if (futureNCCLCallbackStreams_[deviceIndex] == nullptr) { futureNCCLCallbackStreams_[deviceIndex] = - c10::make_instrusive(at::cuda::getStreamFromPool(isHighPriorityStream_)); + c10::make_intrusive(at::cuda::getStreamFromPool(isHighPriorityStream_)); } } @@ -976,7 +976,7 @@ std::vector flatten_for_scatter_gather( c10::intrusive_ptr ProcessGroupNCCL::initWork( std::vector devices) { - return c10::make_instrusive(devices); + return c10::make_intrusive(devices); } #if (TORCH_MAJOR >= 1) && (TORCH_MINOR >= 7) @@ -1020,7 +1020,7 @@ c10::intrusive_ptr ProcessGroupNCCL::collective( // Store references to outputs and futureNCCLCallbackStream to be used by // WorkNCCL::getFuture. - work->outputs_ = c10::make_instrusive>(outputs); + work->outputs_ = c10::make_intrusive>(outputs); work->futureNCCLCallbackStreams_ = futureNCCLCallbackStreams_; at::cuda::OptionalCUDAGuard gpuGuard; @@ -1095,7 +1095,7 @@ c10::intrusive_ptr ProcessGroupNCCL::pointToPoint( if (commType == NCCLCommType::RECV) { // Store references to outputs and futureNCCLCallbackStream to be used by // WorkNCCL::getFuture. - work->outputs_ = c10::make_instrusive>(tensors); + work->outputs_ = c10::make_intrusive>(tensors); work->futureNCCLCallbackStreams_ = futureNCCLCallbackStreams_; }