mlx/mlx/distributed/distributed_impl.h

39 lines
1.1 KiB
C
Raw Normal View History

// Copyright © 2024 Apple Inc.
#pragma once
#include "mlx/distributed/distributed.h"
namespace mlx::core::distributed::detail {
2025-01-07 09:33:15 +08:00
/**
* Abstract base class of a distributed group implementation.
*/
class GroupImpl {
public:
2025-01-28 14:15:01 +08:00
virtual ~GroupImpl() {}
2025-01-07 09:33:15 +08:00
virtual int rank() = 0;
virtual int size() = 0;
virtual std::shared_ptr<GroupImpl> split(int color, int key = -1) = 0;
virtual void all_sum(const array& input, array& output, Stream stream) = 0;
virtual void all_gather(const array& input, array& output, Stream stream) = 0;
virtual void send(const array& input, int dst, Stream stream) = 0;
virtual void recv(array& out, int src, Stream stream) = 0;
2025-01-07 09:33:15 +08:00
};
/* Perform an all reduce sum operation */
void all_sum(Group group, const array& input, array& output, Stream stream);
/* Perform an all gather operation */
void all_gather(Group group, const array& input, array& output, Stream stream);
/** Send an array to the dst rank */
void send(Group group, const array& input, int dst, Stream stream);
/** Recv an array from the src rank */
void recv(Group group, array& out, int src, Stream stream);
} // namespace mlx::core::distributed::detail