use core::fmt::Debug;
use crate::{
memory_management::{MemoryHandle, MemoryManagement},
storage::ComputeStorage,
tune::AutotuneKey,
};
use alloc::vec::Vec;
use burn_common::reader::Reader;
pub trait ComputeServer: Send + core::fmt::Debug
where
Self: Sized,
{
type Kernel: Send;
type Storage: ComputeStorage;
type MemoryManagement: MemoryManagement<Self::Storage>;
type AutotuneKey: AutotuneKey;
fn read(&mut self, handle: &Handle<Self>) -> Reader<Vec<u8>>;
fn create(&mut self, data: &[u8]) -> Handle<Self>;
fn empty(&mut self, size: usize) -> Handle<Self>;
fn execute(&mut self, kernel: Self::Kernel, handles: &[&Handle<Self>]);
fn sync(&mut self);
}
#[derive(new, Debug)]
pub struct Handle<Server: ComputeServer> {
pub memory: <Server::MemoryManagement as MemoryManagement<Server::Storage>>::Handle,
}
impl<Server: ComputeServer> Handle<Server> {
pub fn can_mut(&self) -> bool {
self.memory.can_mut()
}
}
impl<Server: ComputeServer> Clone for Handle<Server> {
fn clone(&self) -> Self {
Self {
memory: self.memory.clone(),
}
}
}