Skip to main content

ruda_tensor/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![warn(missing_docs)]
3#![cfg_attr(docsrs, feature(doc_cfg))]
4
5//! This library provides the core types that define how Ruda tensor data is represented, stored, and interpreted.
6
7#[macro_use]
8extern crate derive_new;
9
10extern crate alloc;
11
12use ruda_core::tensor::data;
13pub use data::*;
14
15pub use ruda_core::tensor::distribution;
16pub use distribution::*;
17pub use ruda_core::tensor::element;
18pub use ruda_core::make_element;
19pub use element::*;
20
21pub mod device;
22pub mod primitive;
23pub mod ops;
24#[cfg(feature = "distributed")]
25pub mod distributed;
26
27/// [`Backend`] trait and required types.
28pub mod backend;
29pub use backend::*;
30
31/// Backend tensor primitives and operations.
32pub mod tensor;
33
34/// Tensor operation graphs and backend resource handles.
35#[cfg(feature = "graph")]
36pub mod graph;
37
38// Re-exported types
39pub use ruda_core::reader::*; // Useful so that backends don't have to add `ruda_core` as a dependency.
40pub use ruda_core::bytes::{AllocationProperty, Bytes};
41pub use ruda_core::device_handle::DeviceHandle;
42pub use ruda_core::stream_id::StreamId;
43pub use ruda_core::tensor::{BoolDType, BoolStore, DType, FloatDType, IntDType};
44pub use half::{bf16, f16};
45
46/// Shape definition.
47pub mod shape {
48    pub use ruda_core::tensor::shape::*;
49}
50pub use shape::*;
51
52/// Slice utilities.
53pub mod slice {
54    pub use ruda_core::tensor::{s, slice::*};
55}
56pub use slice::*;
57
58/// Indexing utilities.
59pub mod indexing {
60    pub use ruda_core::tensor::indexing::*;
61}
62pub use indexing::*;
63
64/// Quantization data representation.
65pub mod quantization {
66    pub use crate::tensor::quantization::*;
67    pub use ruda_core::tensor::quantization::{
68        BlockSize, QuantLevel, QuantMode, QuantParam, QuantPropagation, QuantScheme, QuantStore,
69        QuantValue, QuantizedBytes,
70    };
71}
72
73/// Convenience macro to link to the `ruda-tensor` API docs.
74///
75/// Usage:
76/// ```rust,ignore
77/// # use ruda_tensor::doc_tensor;
78/// doc_tensor!();        // Links to `Tensor` struct
79/// doc_tensor!("zeros"); // Links to `Tensor::zeros` method
80/// ```
81#[macro_export]
82macro_rules! doc_tensor {
83    () => {
84        "[`Tensor`](crate::api::Tensor)"
85    };
86
87    ($method:literal) => {
88        concat!(
89            "[`Tensor::",
90            $method,
91            "`](crate::api::Tensor::",
92            $method,
93            ")"
94        )
95    };
96}
97
98/// Public tensor API built on the shared backend contracts and primitives.
99#[cfg(feature = "api")]
100pub mod api;