1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//! Burn's tensor API.
//!
//! [`Tensor<D, K>`](Tensor) is a tensor of rank `D` and kind `K` ([`Float`] by default, [`Int`]
//! or [`Bool`]). Its [`Device`] decides which backend runs it, at runtime: the same `Tensor<2>`
//! can live on CUDA, wgpu or the CPU, and code that uses tensors has no backend type parameter.
//! Applications use this crate through `burn::tensor`.
//!
//! ```rust,no_run
//! use burn_tensor::{Device, Tensor, s};
//!
//! let device = Device::default();
//! let x = Tensor::<2>::from_floats([[1.0, 2.0], [3.0, 4.0]], &device);
//! let y = x.clone().matmul(x.transpose()).exp();
//! let first_row = y.slice(s![0..1, ..]);
//! ```
//!
//! - [`Device`]: backend selection, configuration and enumeration. A backend's constructor
//! (`Device::cuda`, `Device::wgpu`, `Device::flex`, ...) exists when its feature is enabled.
//! - [`TensorData`], [`DType`] and [`Shape`]: tensor contents and metadata, independent of any
//! backend.
//! - [`activation`], [`loss`] and [`module`]: functional forms of activations, losses and neural
//! network operations such as convolution and pooling.
//! - [`quantization`], [`grid`] and [`distributed`]: quantized tensors, grid sampling and
//! collective operations across devices.
//! - `einsum!`, `assert_shape!` and [`s!`]: macros for Einstein summation, shape checks and
//! slicing.
//!
//! With the `autodiff` feature, create tensors on a `device.autodiff()` device and mark source
//! leaves with [`Tensor::require_grad`] to record gradients.
//!
//! # Feature flags
//!
//! - `std` (default): standard library support. Without it the crate is `no_std` with `alloc`.
//! - Backends: `cuda`, `rocm`, `wgpu`, `metal`, `vulkan`, `webgpu`, `cpu`, `flex`, and the
//! deprecated `ndarray` and `tch`.
//! - `autodiff`, `fusion`: backend decorators.
//! - `remote`, `remote-server`, `remote-websocket`: devices hosted by another machine.
//! - `capture`: record operation graphs instead of executing them.
//! - `extension`: access to backend primitives for backend extensions.
//! - `tracing`: instrument operations with the `tracing` crate.
//!
//! # Note for contributors: `*_impl` helpers
//!
//! Throughout this crate (e.g. in `tensor::api::float`, `tensor::api::int`,
//! `tensor::api::bool`, `tensor::api::cast`, and `tensor::activation`), public
//! generic methods on `Tensor<D, K>` that need to call into `burn_dispatch` are
//! routed through small non-generic helper functions named `*_impl`, grouped
//! together at the bottom of each file under a banner like:
//!
//! ```text
//! // =====================================================================
//! // Non-generic implementation helpers (outlined from the generic API).
//! // =====================================================================
//! ```
//!
//! These helpers take and return only `BridgeTensor` (a type-erased blob — no
//! `DispatchTensor` or other `burn_dispatch` types appear in their
//! signatures). Because the helpers are not generic over `D`, they are
//! compiled once, and the MIR of the public generic methods does not mention
//! any `burn_dispatch` types. Downstream crates that monomorphize the public
//! generic API therefore never have to resolve the cubecl-backed type tree,
//! which drastically cuts compile times for user code.
//!
//! When adding a new public method that calls a `Dispatch::*` op, follow the
//! same pattern: keep the generic method body thin and forward to a
//! non-generic `*_impl` helper alongside the existing ones.
extern crate derive_new;
extern crate alloc;
pub use check;
pub use *;
pub use ;
// Re-exported types
pub use GradientCheckpointingStrategy;
pub use ;
pub use *;
/// Configure a wgpu runtime or share an application's existing wgpu setup.
pub use TensorPrimitive;