Skip to main content

burn_std/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![warn(missing_docs)]
3#![cfg_attr(docsrs, feature(doc_cfg))]
4
5//! # Burn Standard Library
6//!
7//! Core types and utilities shared across the Burn crates.
8//!
9//! - [`Shape`], slicing ([`s!`]) and indexing helpers.
10//! - [`DType`], the element traits and conversions, and [`TensorData`], the backend-independent
11//!   representation of tensor contents.
12//! - [`Distribution`] for random tensor initialization.
13//! - [`DeviceSettings`], per-device defaults such as dtypes.
14//! - Quantization schemes, [`Bytes`], identifiers and errors.
15//! - [`config`]: runtime configuration read from `burn.toml`.
16//! - `network`: file downloads with a progress bar (`network` feature).
17//!
18//! Applications use these through `burn::tensor`. The crate supports `no_std` with `alloc`.
19//!
20//! # Feature flags
21//!
22//! - `std` (default): standard library support.
23//! - `network`: file downloads.
24//! - `tracing`: instrument operations with the `tracing` crate.
25
26#[macro_use]
27extern crate derive_new;
28
29extern crate alloc;
30
31/// Id module contains types for unique identifiers.
32pub mod id;
33
34/// Tensor utilities.
35pub mod tensor;
36pub use tensor::*;
37
38/// Tensor data representation and helpers.
39pub mod data;
40pub use data::*;
41
42/// Random value distributions.
43pub mod distribution;
44pub use distribution::*;
45
46/// Traits for tensor element types and conversions.
47pub mod element;
48pub use element::*;
49
50mod device_settings;
51pub use device_settings::*;
52
53/// Runtime kind of the host program (async / sync / no-std).
54pub mod runtime_kind;
55pub use runtime_kind::*;
56
57/// Distributed configurations.
58pub mod distributed;
59
60/// Configuration types for tensor operations (conv, pool, interpolate, pad, etc).
61pub mod ops;
62pub use ops::*;
63
64/// Burn runtime configurations.
65pub mod config;
66
67/// Common Errors.
68pub use cubecl_zspace::errors::{self, *};
69
70/// Network utilities.
71#[cfg(feature = "network")]
72pub mod network;
73
74/// An ID unique to any unordered combination of devices, used by collective /
75/// communication primitives (distributed training etc.).
76///
77/// Mirrors `cubecl_runtime::server::CommunicationId` so that the
78/// `burn_fusion::FusionUtilities::initialized_comms` set (and other consumers)
79/// can be reused without depending on cubecl directly.
80#[derive(Clone, Debug, Hash, Eq, PartialEq)]
81pub struct CommunicationId {
82    /// Stable hash of the (sorted) set of device ids that participate.
83    pub id: u64,
84}
85
86impl From<alloc::vec::Vec<cubecl_common::device::DeviceId>> for CommunicationId {
87    fn from(mut value: alloc::vec::Vec<cubecl_common::device::DeviceId>) -> Self {
88        use core::hash::{Hash, Hasher};
89        // Sort so any permutation of the same devices yields the same id.
90        value.sort();
91        let mut hasher = ahash::AHasher::default();
92        value.hash(&mut hasher);
93        CommunicationId {
94            id: hasher.finish(),
95        }
96    }
97}
98
99pub use cubecl_common::device_handle::DeviceHandle;
100pub use cubecl_common::*;
101pub use cubecl_environment::bytes::*;
102
103// Environment shims live in `cubecl-environment`. They are re-exported here so
104// backends and other burn crates don't have to depend on it directly.
105pub use cubecl_environment::future::reader;
106pub use cubecl_environment::{backtrace, future, rand, stream, sync};
107
108pub use half::{bf16, f16};
109
110pub use cubecl_common::flex32;