1#![cfg_attr(not(feature = "std"), no_std)]
2#![warn(missing_docs)]
3#![cfg_attr(docsrs, feature(doc_cfg))]
4#![recursion_limit = "135"]
5
6#[macro_use]
9extern crate derive_new;
10
11pub use serde;
13
14pub mod config;
16
17#[cfg(feature = "std")]
19pub mod data;
20
21pub mod module;
23
24pub mod record;
26
27pub mod tensor;
29pub use tensor::Tensor;
31
32extern crate alloc;
33extern crate self as ruda_model;
34
35#[cfg(all(
37 test,
38 not(feature = "test-tch"),
39 not(feature = "test-wgpu"),
40 not(feature = "test-cuda"),
41 not(feature = "test-rocm")
42))]
43pub type TestBackend = ruda_tensor_host::Host;
44
45#[cfg(all(test, feature = "test-tch"))]
46pub type TestBackend = ruda_tensor_tch::LibTorch<f32>;
48
49#[cfg(all(test, feature = "test-wgpu"))]
50pub type TestBackend = ruda_tensor_wgpu::Wgpu;
52
53#[cfg(all(test, feature = "test-cuda"))]
54pub type TestBackend = ruda_tensor_device::cuda::Cuda;
56
57#[cfg(all(test, feature = "test-rocm"))]
58pub type TestBackend = ruda_tensor_rocm::Rocm;
60
61#[cfg(test)]
63pub type TestAutodiffBackend = ruda_autodiff::Autodiff<TestBackend>;
64
65#[cfg(all(test, feature = "test-memory-checks"))]
66mod tests {
67 ruda_fusion::memory_checks!();
68}
69
70#[cfg(test)]
71mod test_utils {
72 use crate::module::Module;
73 use crate::module::Param;
74 use ruda_tensor::api::Tensor;
75 use ruda_tensor::api::backend::Backend;
76
77 #[derive(Module, Debug)]
79 pub struct SimpleLinear<B: Backend> {
80 pub weight: Param<Tensor<B, 2>>,
81 pub bias: Option<Param<Tensor<B, 1>>>,
82 }
83
84 impl<B: Backend> SimpleLinear<B> {
85 pub fn new(in_features: usize, out_features: usize, device: &B::Device) -> Self {
86 let weight = Tensor::random(
87 [out_features, in_features],
88 ruda_tensor::api::Distribution::Default,
89 device,
90 );
91 let bias = Tensor::random([out_features], ruda_tensor::api::Distribution::Default, device);
92
93 Self {
94 weight: Param::from_tensor(weight),
95 bias: Some(Param::from_tensor(bias)),
96 }
97 }
98 }
99}
100
101pub mod prelude {
102 pub use crate::{
106 config::Config,
107 module::Module,
108 tensor::{
109 Bool, Device, ElementConversion, Float, Int, Shape, SliceArg, Tensor, TensorData,
110 backend::Backend, cast::ToElement, s,
111 },
112 };
113 pub use ruda_core::device::Device as DeviceOps;
114}