ruda_runtime/runtime/
backend.rs1use alloc::boxed::Box;
2use alloc::vec::Vec;
3use ruda_core::device::{Device, DeviceId};
4use ruda_core::ir::TargetProperties;
5use ruda_core::tensor::{Shape, Strides};
6
7use crate::runtime::{
8 client::ComputeClient,
9 compiler::{Compiler, RudaTask},
10 server::ComputeServer,
11};
12
13pub trait Runtime: Sized + Send + Sync + 'static + core::fmt::Debug + Clone {
15 type Compiler: Compiler;
17 type Server: ComputeServer<Kernel = Box<dyn RudaTask<Self::Compiler>>>;
19 type Device: Device;
21
22 fn client(device: &Self::Device) -> ComputeClient<Self>;
24
25 fn has_native_layer_norm() -> bool { false }
27
28 fn layer_norm(
30 _client: &ComputeClient<Self>,
31 _input: super::normalization::TensorBuffer,
32 _weight: super::normalization::TensorBuffer,
33 _bias: Option<super::normalization::TensorBuffer>,
34 _epsilon: f64,
35 ) -> [super::normalization::TensorBuffer; 3] {
36 unimplemented!("runtime does not supply native LayerNorm")
37 }
38
39 fn layer_norm_backward(
41 _client: &ComputeClient<Self>,
42 _input: super::normalization::TensorBuffer,
43 _weight: super::normalization::TensorBuffer,
44 _grad: super::normalization::TensorBuffer,
45 _mean: super::normalization::TensorBuffer,
46 _rstd: super::normalization::TensorBuffer,
47 ) -> [super::normalization::TensorBuffer; 3] {
48 unimplemented!("runtime does not supply native LayerNorm backward")
49 }
50
51 fn name(client: &ComputeClient<Self>) -> &'static str;
53
54 fn autotune_driver_fingerprint(_client: &ComputeClient<Self>) -> Option<alloc::string::String> {
58 None
59 }
60
61 fn require_array_lengths() -> bool {
63 false
64 }
65
66 fn max_ruda_count() -> (u32, u32, u32);
68
69 fn can_read_tensor(shape: &Shape, strides: &Strides) -> bool;
72
73 fn target_properties() -> TargetProperties;
75
76 fn enumerate_devices(
78 type_id: u16,
79 info: &<Self::Server as ComputeServer>::Info,
80 ) -> Vec<DeviceId>;
81 fn enumerate_all_devices(info: &<Self::Server as ComputeServer>::Info) -> Vec<DeviceId> {
83 Self::enumerate_devices(0, info)
84 }
85}