use crate::{
channel::ComputeChannel,
server::{ComputeServer, Handle},
tune::AutotuneOperation,
};
use alloc::boxed::Box;
use alloc::vec::Vec;
use burn_common::reader::Reader;
use core::marker::PhantomData;
#[derive(Debug)]
pub struct ComputeClient<Server, Channel> {
channel: Channel,
_server: PhantomData<Server>,
}
impl<S, C> Clone for ComputeClient<S, C>
where
S: ComputeServer,
C: ComputeChannel<S>,
{
fn clone(&self) -> Self {
Self {
channel: self.channel.clone(),
_server: PhantomData,
}
}
}
impl<Server, Channel> ComputeClient<Server, Channel>
where
Server: ComputeServer,
Channel: ComputeChannel<Server>,
{
pub fn new(channel: Channel) -> Self {
Self {
channel,
_server: PhantomData,
}
}
pub fn read(&self, handle: &Handle<Server>) -> Reader<Vec<u8>> {
self.channel.read(handle)
}
pub fn create(&self, data: &[u8]) -> Handle<Server> {
self.channel.create(data)
}
pub fn empty(&self, size: usize) -> Handle<Server> {
self.channel.empty(size)
}
pub fn execute(&self, kernel: Server::Kernel, handles: &[&Handle<Server>]) {
self.channel.execute(kernel, handles)
}
pub fn sync(&self) {
self.channel.sync()
}
pub fn execute_autotune(
&self,
autotune_kernel: Box<dyn AutotuneOperation<Server>>,
handles: &[&Handle<Server>],
) {
self.channel.execute_autotune(autotune_kernel, handles);
}
}