use alloc::vec::Vec;
use burn_backend::distributed::DistributedOps;
use burn_dispatch::Dispatch;
pub use burn_std::distributed::*;
use crate::Device;
#[derive(Debug)]
pub struct DistributedContext {
devices: Vec<Device>,
}
impl DistributedContext {
pub fn init(devices: Vec<Device>, config: DistributedConfig) -> Self {
let dispatch_devices = devices
.iter()
.map(|d| d.as_dispatch().clone())
.collect::<Vec<_>>();
Dispatch::start_communication_server(&dispatch_devices, config);
Self { devices }
}
}
impl Drop for DistributedContext {
fn drop(&mut self) {
if !self.devices.is_empty() {
Dispatch::close_communication_server(self.devices[0].as_dispatch());
}
}
}