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/// Native frozen AWQ projections and their packed-weight input derivatives.
26pub mod frozen_awq;
27/// Original RUDA byte-packed NF4 frozen projections and input derivatives.
28pub mod frozen_nf4;
29/// Original byte-packed NF4 selected expert projections and SwiGLU derivatives.
30pub mod grouped_nf4;
31/// Original independently selected AWQ/NF4 expert payloads and native derivatives.
32pub mod packed_experts;
33/// Original native trainable floating expert projections and source SwiGLU derivatives.
34pub mod expert_projection;
35/// Native selected router weights and complete local MoE training operations.
36pub mod moe;
37/// Original native expert-parallel dispatch/receive/combine contracts.
38pub mod moe_exchange;
39#[cfg(feature = "distributed")]
40pub mod distributed;
41
42/// [`Backend`] trait and required types.
43pub mod backend;
44pub use backend::*;
45
46/// Backend tensor primitives and operations.
47pub mod tensor;
48
49/// Tensor operation graphs and backend resource handles.
50#[cfg(feature = "graph")]
51pub mod graph;
52
53// Re-exported types
54pub use ruda_core::reader::*; // Useful so that backends don't have to add `ruda_core` as a dependency.
55pub use ruda_core::bytes::{AllocationProperty, Bytes};
56pub use ruda_core::device_handle::DeviceHandle;
57pub use ruda_core::stream_id::StreamId;
58pub use ruda_core::tensor::{BoolDType, BoolStore, DType, FloatDType, IntDType};
59pub use half::{bf16, f16};
60
61/// Shape definition.
62pub mod shape {
63    pub use ruda_core::tensor::shape::*;
64}
65pub use shape::*;
66
67/// Slice utilities.
68pub mod slice {
69    pub use ruda_core::tensor::{s, slice::*};
70}
71pub use slice::*;
72
73/// Indexing utilities.
74pub mod indexing {
75    pub use ruda_core::tensor::indexing::*;
76}
77pub use indexing::*;
78
79/// Quantization data representation.
80pub mod quantization {
81    pub use crate::tensor::quantization::*;
82    pub use ruda_core::tensor::quantization::{
83        BlockSize, QuantLevel, QuantMode, QuantParam, QuantPropagation, QuantScheme, QuantStore,
84        QuantValue, QuantizedBytes,
85    };
86}
87
88/// Convenience macro to link to the `ruda-tensor` API docs.
89///
90/// Usage:
91/// ```rust,ignore
92/// # use ruda_tensor::doc_tensor;
93/// doc_tensor!();        // Links to `Tensor` struct
94/// doc_tensor!("zeros"); // Links to `Tensor::zeros` method
95/// ```
96#[macro_export]
97macro_rules! doc_tensor {
98    () => {
99        "[`Tensor`](crate::api::Tensor)"
100    };
101
102    ($method:literal) => {
103        concat!(
104            "[`Tensor::",
105            $method,
106            "`](crate::api::Tensor::",
107            $method,
108            ")"
109        )
110    };
111}
112
113/// Public tensor API built on the shared backend contracts and primitives.
114#[cfg(feature = "api")]
115pub mod api;