use alloc::boxed::Box;
use alloc::vec::Vec;
use ruda_core::device::{Device, DeviceId};
use ruda_core::ir::TargetProperties;
use ruda_core::tensor::{Shape, Strides};
use crate::runtime::{
client::ComputeClient,
compiler::{Compiler, RudaTask},
server::ComputeServer,
};
pub use super::monitoring::{DeviceUtilization, UtilizationUnavailable};
pub trait Runtime: Sized + Send + Sync + 'static + core::fmt::Debug + Clone {
type Compiler: Compiler;
type Server: ComputeServer<Kernel = Box<dyn RudaTask<Self::Compiler>>>;
type Device: Device;
fn client(device: &Self::Device) -> ComputeClient<Self>;
fn has_native_layer_norm() -> bool { false }
fn layer_norm(
_client: &ComputeClient<Self>,
_input: super::normalization::TensorBuffer,
_weight: super::normalization::TensorBuffer,
_bias: Option<super::normalization::TensorBuffer>,
_epsilon: f64,
) -> [super::normalization::TensorBuffer; 3] {
unimplemented!("runtime does not supply native LayerNorm")
}
fn layer_norm_backward(
_client: &ComputeClient<Self>,
_input: super::normalization::TensorBuffer,
_weight: super::normalization::TensorBuffer,
_grad: super::normalization::TensorBuffer,
_mean: super::normalization::TensorBuffer,
_rstd: super::normalization::TensorBuffer,
) -> [super::normalization::TensorBuffer; 3] {
unimplemented!("runtime does not supply native LayerNorm backward")
}
fn name(client: &ComputeClient<Self>) -> &'static str;
fn autotune_driver_fingerprint(_client: &ComputeClient<Self>) -> Option<alloc::string::String> {
None
}
fn require_array_lengths() -> bool {
false
}
fn max_ruda_count() -> (u32, u32, u32);
fn can_read_tensor(shape: &Shape, strides: &Strides) -> bool;
fn target_properties() -> TargetProperties;
fn enumerate_devices(
type_id: u16,
info: &<Self::Server as ComputeServer>::Info,
) -> Vec<DeviceId>;
fn enumerate_all_devices(info: &<Self::Server as ComputeServer>::Info) -> Vec<DeviceId> {
Self::enumerate_devices(0, info)
}
fn utilization(_device: &Self::Device) -> Result<DeviceUtilization, UtilizationUnavailable> {
Err(UtilizationUnavailable::RuntimeReadsNoCounter)
}
}