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//! This library contains core types and utilities shared across Burn, including shapes, indexing,
8//! and data types.
9
10#[macro_use]
11extern crate derive_new;
12
13extern crate alloc;
14
15/// Id module contains types for unique identifiers.
16pub mod id;
17
18/// Tensor utilities.
19pub mod tensor;
20pub use tensor::*;
21
22/// Tensor data representation and helpers.
23pub mod data;
24pub use data::*;
25
26/// Random value distributions.
27pub mod distribution;
28pub use distribution::*;
29
30/// Traits for tensor element types and conversions.
31pub mod element;
32pub use element::*;
33
34mod device_settings;
35pub use device_settings::*;
36
37/// Runtime kind of the host program (async / sync / no-std).
38pub mod runtime_kind;
39pub use runtime_kind::*;
40
41/// Distributed configurations.
42pub mod distributed;
43
44/// Configuration types for tensor operations (conv, pool, interpolate, pad, etc).
45pub mod ops;
46pub use ops::*;
47
48/// Burn runtime configurations.
49pub mod config;
50
51/// Common Errors.
52pub use cubecl_zspace::errors::{self, *};
53
54/// Network utilities.
55#[cfg(feature = "network")]
56pub mod network;
57
58/// An ID unique to any unordered combination of devices, used by collective /
59/// communication primitives (distributed training etc.).
60///
61/// Mirrors `cubecl_runtime::server::CommunicationId` so that the
62/// `burn_fusion::FusionUtilities::initialized_comms` set (and other consumers)
63/// can be reused without depending on cubecl directly.
64#[derive(Clone, Debug, Hash, Eq, PartialEq)]
65pub struct CommunicationId {
66    /// Stable hash of the (sorted) set of device ids that participate.
67    pub id: u64,
68}
69
70impl From<alloc::vec::Vec<cubecl_common::device::DeviceId>> for CommunicationId {
71    fn from(mut value: alloc::vec::Vec<cubecl_common::device::DeviceId>) -> Self {
72        use core::hash::{Hash, Hasher};
73        // Sort so any permutation of the same devices yields the same id.
74        value.sort();
75        let mut hasher = ahash::AHasher::default();
76        value.hash(&mut hasher);
77        CommunicationId {
78            id: hasher.finish(),
79        }
80    }
81}
82
83pub use cubecl_common::bytes::*;
84pub use cubecl_common::device_handle::DeviceHandle;
85pub use cubecl_common::*;
86pub use half::{bf16, f16};
87
88pub use cubecl_common::flex32;