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
use Device;
/// The CPU device, `Flex`, for trivial plumbing tests.
///
/// Use it where a test checks mechanics rather than numbers: setup and
/// teardown, config round trips, shape bookkeeping. It is always present
/// under the `testing` feature, and it has no accelerator memory pool to
/// share, so such a test has no device memory to manage.
///
/// It is **not** the numerically trustworthy choice. A pass on the CPU says
/// nothing about the kernels an accelerator runs, and a test does not move
/// here to get better numbers. A test that does real tensor math uses
/// [`performance_device`], and compares within a tolerance. See
/// [Test devices](crate::support::testing#test-devices).
/// The device for tests that do tensor math: the best accelerator that this
/// build of bunsen enables.
///
/// # Selection
///
/// 1. With `BURN_DEVICE` set in the environment, burn's own choice,
/// `Device::default()`, which reads it.
/// 2. Otherwise the first backend feature enabled **on bunsen**, in this order:
/// 1. `cuda`: `Device::cuda(0)`;
/// 2. `metal`: `Device::metal(DeviceKind::DefaultDevice)`;
/// 3. `vulkan`: `Device::vulkan(DeviceKind::DefaultDevice)`;
/// 4. `wgpu`: `Device::wgpu(DeviceKind::DefaultDevice)`;
/// 5. none of them: [`cpu_device`], which is `Flex`.
///
/// Only `bunsen/<backend>` moves the choice. A dependent that enables
/// `burn/wgpu` but not `bunsen/wgpu` still gets the CPU here.
///
/// # The CPU fallback is silent
///
/// Without a backend feature, this *is* [`cpu_device`]. A bare `cargo test`
/// builds and passes every test written against it, having run them all on
/// the CPU, so a regression that only an accelerator shows passes too. Run
/// tensor tests with a backend feature, e.g.
/// `cargo test -p bunsen --features wgpu`.
///
/// # Compare within a tolerance
///
/// Backends do not agree bit for bit, so a test compares computed floats
/// within a tolerance, not with exact equality. The rule and the assertions
/// for it are under [Test devices](crate::support::testing#test-devices).
/// The [`performance_device`] that bunsen's backend features select.