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;
24pub mod collective;
25#[cfg(feature = "distributed")]
26pub mod distributed;
27
28/// [`Backend`] trait and required types.
29pub mod backend;
30pub use backend::*;
31
32/// Backend tensor primitives and operations.
33pub mod tensor;
34
35/// Tensor operation graphs and backend resource handles.
36#[cfg(feature = "graph")]
37pub mod graph;
38
39// Re-exported types
40pub use ruda_core::reader::*; // Useful so that backends don't have to add `ruda_core` as a dependency.
41pub use ruda_core::bytes::{AllocationProperty, Bytes};
42pub use ruda_core::device_handle::DeviceHandle;
43pub use ruda_core::stream_id::StreamId;
44pub use ruda_core::tensor::{BoolDType, BoolStore, DType, FloatDType, IntDType};
45pub use half::{bf16, f16};
46
47/// Shape definition.
48pub mod shape {
49    pub use ruda_core::tensor::shape::*;
50}
51pub use shape::*;
52
53/// Slice utilities.
54pub mod slice {
55    pub use ruda_core::tensor::{s, slice::*};
56}
57pub use slice::*;
58
59/// Indexing utilities.
60pub mod indexing {
61    pub use ruda_core::tensor::indexing::*;
62}
63pub use indexing::*;
64
65/// Quantization data representation.
66pub mod quantization {
67    pub use crate::tensor::quantization::*;
68    pub use ruda_core::tensor::quantization::{
69        BlockSize, QuantLevel, QuantMode, QuantParam, QuantPropagation, QuantScheme, QuantStore,
70        QuantValue, QuantizedBytes,
71    };
72}
73
74/// Convenience macro to link to the `ruda-tensor` API docs.
75///
76/// Usage:
77/// ```rust,ignore
78/// # use ruda_tensor::doc_tensor;
79/// doc_tensor!();        // Links to `Tensor` struct
80/// doc_tensor!("zeros"); // Links to `Tensor::zeros` method
81/// ```
82#[macro_export]
83macro_rules! doc_tensor {
84    () => {
85        "[`Tensor`](crate::api::Tensor)"
86    };
87
88    ($method:literal) => {
89        concat!(
90            "[`Tensor::",
91            $method,
92            "`](crate::api::Tensor::",
93            $method,
94            ")"
95        )
96    };
97}
98
99/// Public tensor API built on the shared backend contracts and primitives.
100#[cfg(feature = "api")]
101pub mod api;