-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add executor to execute schedule-plan file (#283)
Add executor to execute the JSON schedule file generated by msccl-tools --------- Co-authored-by: Changho Hwang <[email protected]>
- Loading branch information
1 parent
9406123
commit 64d837f
Showing
27 changed files
with
2,857 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#ifndef MSCCLPP_EXECUTOR_HPP_ | ||
#define MSCCLPP_EXECUTOR_HPP_ | ||
|
||
#include <memory> | ||
#include <mscclpp/core.hpp> | ||
#include <unordered_map> | ||
|
||
namespace mscclpp { | ||
|
||
enum class DataType { | ||
INT32, | ||
UINT32, | ||
FLOAT16, | ||
FLOAT32, | ||
}; | ||
|
||
enum class PacketType { | ||
LL8, | ||
LL16, | ||
}; | ||
|
||
class ExecutionPlan { | ||
public: | ||
ExecutionPlan(const std::string& name, const std::string& planPath); | ||
~ExecutionPlan() = default; | ||
|
||
private: | ||
struct Impl; | ||
std::shared_ptr<Impl> impl_; | ||
|
||
friend class Executor; | ||
}; | ||
|
||
class Executor { | ||
public: | ||
Executor(std::shared_ptr<Communicator> comm); | ||
Executor(const Executor&) = delete; | ||
Executor& operator=(const Executor&) = delete; | ||
~Executor(); | ||
|
||
void execute(int rank, void* sendbuff, void* recvBuff, size_t sendBuffSize, size_t recvBuffSize, DataType dataType, | ||
int nthreads, const ExecutionPlan& plan, cudaStream_t stream, PacketType packetType = PacketType::LL16); | ||
|
||
private: | ||
struct Impl; | ||
std::unique_ptr<Impl> impl_; | ||
}; | ||
} // namespace mscclpp | ||
|
||
#endif // MSCCLPP_EXECUTOR_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#include <nanobind/nanobind.h> | ||
#include <nanobind/stl/shared_ptr.h> | ||
#include <nanobind/stl/string.h> | ||
|
||
#include <mscclpp/executor.hpp> | ||
#include <mscclpp/gpu.hpp> | ||
|
||
namespace nb = nanobind; | ||
using namespace mscclpp; | ||
|
||
void register_executor(nb::module_& m) { | ||
nb::enum_<DataType>(m, "DataType") | ||
.value("int32", DataType::INT32) | ||
.value("uint32", DataType::UINT32) | ||
.value("float16", DataType::FLOAT16) | ||
.value("float32", DataType::FLOAT32); | ||
|
||
nb::enum_<PacketType>(m, "PacketType").value("LL8", PacketType::LL8).value("LL16", PacketType::LL16); | ||
|
||
nb::class_<ExecutionPlan>(m, "ExecutionPlan") | ||
.def(nb::init<const std::string, const std::string>(), nb::arg("name"), nb::arg("planPath")); | ||
|
||
nb::class_<Executor>(m, "Executor") | ||
.def(nb::init<std::shared_ptr<Communicator>>(), nb::arg("comm")) | ||
.def( | ||
"execute", | ||
[](Executor* self, int rank, uintptr_t sendbuff, uintptr_t recvBuff, size_t sendBuffSize, size_t recvBuffSize, | ||
DataType dataType, int nthreads, const ExecutionPlan& plan, uintptr_t stream, PacketType packetType) { | ||
self->execute(rank, reinterpret_cast<void*>(sendbuff), reinterpret_cast<void*>(recvBuff), sendBuffSize, | ||
recvBuffSize, dataType, nthreads, plan, (cudaStream_t)stream, packetType); | ||
}, | ||
nb::arg("rank"), nb::arg("sendbuff"), nb::arg("recvBuff"), nb::arg("sendBuffSize"), nb::arg("recvBuffSize"), | ||
nb::arg("dataType"), nb::arg("nthreads"), nb::arg("plan"), nb::arg("stream"), | ||
nb::arg("packetType") = PacketType::LL16); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
from os import path | ||
from mscclpp import ( | ||
DataType, | ||
Executor, | ||
ExecutionPlan, | ||
) | ||
import mscclpp.comm as mscclpp_comm | ||
|
||
import cupy as cp | ||
from mpi4py import MPI | ||
|
||
MSCCLPP_ROOT_PATH = "/root/mscclpp" | ||
|
||
|
||
def bench_time(niters: int, ngraphIters: int, func): | ||
# capture cuda graph for niters of the kernel launch | ||
stream = cp.cuda.Stream(non_blocking=True) | ||
with stream: | ||
stream.begin_capture() | ||
for i in range(niters): | ||
func(stream) | ||
graph = stream.end_capture() | ||
|
||
# now run a warm up round | ||
graph.launch(stream) | ||
|
||
# now run the benchmark and measure time | ||
start = cp.cuda.Event() | ||
end = cp.cuda.Event() | ||
|
||
start.record(stream) | ||
for _ in range(ngraphIters): | ||
graph.launch(stream) | ||
end.record(stream) | ||
end.synchronize() | ||
|
||
return cp.cuda.get_elapsed_time(start, end) / niters * 1000.0 / ngraphIters | ||
|
||
|
||
if __name__ == "__main__": | ||
mscclpp_group = mscclpp_comm.CommGroup(MPI.COMM_WORLD) | ||
cp.cuda.Device(MPI.COMM_WORLD.rank % mscclpp_group.nranks_per_node).use() | ||
executor = Executor(mscclpp_group.communicator) | ||
execution_plan = ExecutionPlan( | ||
"allreduce_pairs", path.join(MSCCLPP_ROOT_PATH, "test", "execution-files", "allreduce.json") | ||
) | ||
|
||
nelems = 1024 * 1024 | ||
cp.random.seed(42) | ||
buffer = cp.random.random(nelems).astype(cp.float16) | ||
sub_arrays = cp.split(buffer, MPI.COMM_WORLD.size) | ||
sendbuf = sub_arrays[MPI.COMM_WORLD.rank] | ||
mscclpp_group.barrier() | ||
|
||
execution_time = bench_time( | ||
100, | ||
10, | ||
lambda stream: executor.execute( | ||
MPI.COMM_WORLD.rank, | ||
sendbuf.data.ptr, | ||
sendbuf.data.ptr, | ||
sendbuf.nbytes, | ||
sendbuf.nbytes, | ||
DataType.float16, | ||
512, | ||
execution_plan, | ||
stream.ptr, | ||
), | ||
) | ||
print(f"Rank: {MPI.COMM_WORLD.rank} Execution time: {execution_time} us, data size: {sendbuf.nbytes} bytes") | ||
executor = None | ||
mscclpp_group = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
|
||
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS *.cc) | ||
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS *.cc *.cu) | ||
target_sources(mscclpp_obj PRIVATE ${SOURCES}) | ||
target_include_directories(mscclpp_obj PRIVATE include) |
Oops, something went wrong.