use std::fmt::Debug;
use crate::device::{Device, DeviceCpu};
use crate::error::{TypeConvertError};
use crate::layer::BatchDataType;
use crate::ope::UnitValue;
#[cfg(feature = "cuda")]
use crate::cuda::allocator::CudaAllocator;
#[cfg(feature = "cuda")]
use crate::cuda::{ToCuda};
#[cfg(feature = "cuda")]
use crate::device::{DeviceGpu};
pub trait DeviceInput<U,I>: Device<U>
where U: UnitValue<U>,
I: BatchDataType + Debug + 'static,
<I as BatchDataType>::Type: Debug + 'static {
type Output: Debug + 'static;
type BatchOutput: Debug + 'static;
fn forward_input(&self,input: I) -> Result<Self::Output,TypeConvertError>;
fn batch_forward_input(&self,input: <I as BatchDataType>::Type) -> Result<Self::BatchOutput,TypeConvertError>;
}
impl<U,I> DeviceInput<U,I> for DeviceCpu<U>
where U: UnitValue<U>,
I: BatchDataType + Debug + 'static,
<I as BatchDataType>::Type: Debug + 'static {
type Output = I;
type BatchOutput = <I as BatchDataType>::Type;
fn forward_input(&self,input: I) -> Result<Self::Output,TypeConvertError> {
Ok(input)
}
fn batch_forward_input(&self,input: <I as BatchDataType>::Type) -> Result<Self::BatchOutput,TypeConvertError> {
Ok(input)
}
}
#[cfg(feature = "cuda")]
impl<U,I,A> DeviceInput<U,I> for DeviceGpu<U,A>
where U: UnitValue<U>,
I: BatchDataType + ToCuda<U,A> + Debug + 'static,
<I as BatchDataType>::Type: ToCuda<U,A> + Debug + 'static,
<I as ToCuda<U,A>>::Output: Debug + 'static,
<<I as BatchDataType>::Type as ToCuda<U,A>>::Output: Debug + 'static,
A: CudaAllocator,
DeviceGpu<U,A>: Device<U> {
type Output = <I as ToCuda<U,A>>::Output;
type BatchOutput = <<I as BatchDataType>::Type as ToCuda<U,A>>::Output;
fn forward_input(&self,input: I) -> Result<Self::Output,TypeConvertError> {
input.to_cuda(self)
}
fn batch_forward_input(&self, input: <I as BatchDataType>::Type) -> Result<Self::BatchOutput, TypeConvertError> {
input.to_cuda(self)
}
}