mirror of
https://github.com/microsoft/mscclpp.git
synced 2026-05-13 09:46:00 +00:00
Reorganize current native algorithm implementation and DSL algorithm implementation. Provide unified API for DSL algo and native algo and provide interface to tune the algo Provide interface for pytorch integration with native API and DSL --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: chhwang <8018170+chhwang@users.noreply.github.com>
97 lines
3.2 KiB
C++
97 lines
3.2 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#ifndef MSCCLPP_EXECUTOR_HPP_
|
|
#define MSCCLPP_EXECUTOR_HPP_
|
|
|
|
#include <memory>
|
|
#include <mscclpp/core.hpp>
|
|
#include <mscclpp/gpu.hpp>
|
|
#include <unordered_map>
|
|
|
|
namespace mscclpp {
|
|
|
|
/// Packet formats used by low-latency transport.
|
|
enum class PacketType {
|
|
LL8, // 8-byte low-latency packet.
|
|
LL16, // 16-byte low-latency packet.
|
|
};
|
|
|
|
/// Represents a compiled execution plan loaded from disk.
|
|
///
|
|
/// An ExecutionPlan encapsulates metadata about a collective algorithm such as its name, the
|
|
/// collective it implements, and the supported message-size range. The concrete implementation
|
|
/// is hidden behind the PIMPL pointer.
|
|
class ExecutionPlan {
|
|
public:
|
|
/// Construct an ExecutionPlan by loading the plan file at `planPath`.
|
|
/// @param planPath Filesystem path to the serialized plan.
|
|
/// @param rank The rank of the current process.
|
|
ExecutionPlan(const std::string& planPath, int rank);
|
|
|
|
/// Destructor.
|
|
~ExecutionPlan() = default;
|
|
|
|
/// Return the human-readable name of the plan.
|
|
const std::string& name() const;
|
|
|
|
/// Return the collective implemented by this plan (e.g., "allreduce", "allgather").
|
|
const std::string& collective() const;
|
|
|
|
/// Minimum message size (in bytes) for which this plan is valid.
|
|
size_t minMessageSize() const;
|
|
|
|
/// Maximum message size (in bytes) for which this plan is valid.
|
|
size_t maxMessageSize() const;
|
|
|
|
/// Whether this plan performs the operation in-place.
|
|
bool isInPlace() const;
|
|
|
|
private:
|
|
struct Impl;
|
|
std::shared_ptr<Impl> impl_;
|
|
|
|
friend class Executor;
|
|
};
|
|
|
|
/// High-level executor responsible for invoking execution plans on a communicator.
|
|
class Executor {
|
|
public:
|
|
/// Construct an Executor using the provided communicator.
|
|
/// @param comm Communicator instance used for underlying communication.
|
|
/// @param defaultScratchBuffer Optional scratch buffer used by some plans (may be nullptr).
|
|
Executor(std::shared_ptr<Communicator> comm, std::shared_ptr<char> defaultScratchBuffer = nullptr);
|
|
|
|
/// Copy construction is disabled for Executor.
|
|
Executor(const Executor&) = delete;
|
|
|
|
/// Copy assignment is disabled for Executor.
|
|
Executor& operator=(const Executor&) = delete;
|
|
|
|
/// Destructor. Cleans up internal resources held by the Executor.
|
|
~Executor();
|
|
|
|
/// Execute a plan.
|
|
///
|
|
/// This method dispatches the given plan on the provided CUDA stream.
|
|
///
|
|
/// @param rank Rank of the calling process.
|
|
/// @param sendbuff Pointer to the send buffer.
|
|
/// @param recvBuff Pointer to the receive buffer.
|
|
/// @param sendBuffSize Size of the send buffer in bytes.
|
|
/// @param recvBuffSize Size of the receive buffer in bytes.
|
|
/// @param dataType Data type of elements in the buffers.
|
|
/// @param plan The execution plan to run.
|
|
/// @param stream CUDA stream to execute kernels/operations on.
|
|
/// @param packetType Packet type used for low-latency transports (default: LL16).
|
|
void execute(int rank, void* sendbuff, void* recvBuff, size_t sendBuffSize, size_t recvBuffSize, DataType dataType,
|
|
const ExecutionPlan& plan, cudaStream_t stream, PacketType packetType = PacketType::LL16);
|
|
|
|
private:
|
|
struct Impl;
|
|
std::unique_ptr<Impl> impl_;
|
|
};
|
|
} // namespace mscclpp
|
|
|
|
#endif // MSCCLPP_EXECUTOR_HPP_
|