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
//! Device selection for the neural diffusion backend (v4.2.0+).
//!
//! Picks a CUDA device when the `neural-cuda` Cargo feature is on
//! AND a GPU is available at runtime, falls back to CPU otherwise.
//! This keeps the neural pathway runnable in three modes:
//!
//! 1. `cargo build --features neural` → CPU-only (no CUDA deps).
//! 2. `cargo build --features neural-cuda` on a machine with CUDA
//! drivers + GPU → uses `Device::Cuda(0)`.
//! 3. `cargo build --features neural-cuda` on a machine without a
//! GPU → gracefully falls back to CPU at runtime.
//!
//! All existing call sites that previously hardcoded `Device::Cpu`
//! should call [`preferred_device`] instead.
use Device;
/// Return the preferred device for neural diffusion work.
///
/// With `neural-cuda` feature: probes `cuda_if_available(0)`, falls
/// back to CPU if no GPU is present. Without the feature: always CPU.
/// Is CUDA actually being used at runtime?
///
/// Returns `true` only when the `neural-cuda` feature is compiled in
/// AND the machine has a working GPU. Useful for conditional logging
/// and feature-flag smoke tests.