use ruda_core::device::DeviceId;
use crate::{
Backend,
distributed::CollectiveTensor,
tensor::{Device, FloatTensor},
};
use crate::distributed::{
DistributedConfig, DistributedParams, ReduceOperation, TensorRef, close_distributed_sync_server,
get_distributed_sync_client, start_distributed_sync_server,
};
pub trait DistributedBackend: Backend {
fn start_communication_server(devices: &[Self::Device], config: DistributedConfig) {
start_distributed_sync_server::<Self>(devices, config);
}
fn close_communication_server(_device: &Self::Device) {
close_distributed_sync_server::<Self>();
}
fn register_sync_parameters(
device: &Self::Device,
distributed_params: Vec<DistributedParams>,
) {
if let Some(sync_client) = get_distributed_sync_client::<Self>() {
sync_client.register_sync_parameters(device, distributed_params);
};
}
fn submit_sync_collective(device: &Self::Device) {
if let Some(sync_client) = get_distributed_sync_client::<Self>() {
sync_client.submit_sync_collective(device.clone());
};
}
fn submit_gradient_sync(tensor: TensorRef<Self>, distributed_params: DistributedParams) {
if let Some(sync_client) = get_distributed_sync_client::<Self>() {
sync_client.submit_gradient_sync(tensor, distributed_params);
};
}
fn all_reduce(
_tensor: FloatTensor<Self>,
_op: ReduceOperation,
_device_ids: Vec<DeviceId>,
) -> CollectiveTensor<Self> {
unimplemented!()
}
fn sync_collective(_device: &Self::Device) {
unimplemented!()
}
unsafe fn comm_device(tensor: &TensorRef<Self>) -> Device<Self> {
tensor.with_mut(|tensor| Self::float_device(tensor))
}
unsafe fn float_from_ref(tensor: &TensorRef<Self>) -> FloatTensor<Self> {
tensor.with_mut(|tensor| tensor.clone())
}
}