multiscreen_rs/device.rs
1//! Device abstraction for CPU and CUDA.
2
3use crate::error::Result;
4use crate::runtime::Device;
5
6/// Returns the default device for the active backend.
7///
8/// - Without `cuda` feature: returns Flex (CPU) device.
9/// - With `cuda` feature: returns CUDA device (GPU 0).
10///
11/// ```rust,no_run
12/// use multiscreen_rs::prelude::*;
13/// fn main() -> multiscreen_rs::Result<()> {
14/// let device = auto_device()?;
15/// Ok(())
16/// }
17/// ```
18pub fn auto_device() -> Result<Device> {
19 Ok(Device::default())
20}
21
22/// Returns the default CPU device.
23///
24/// Only available without the `cuda` feature. When compiled with CUDA,
25/// use [`auto_device`] instead.
26///
27/// ```rust,no_run
28/// use multiscreen_rs::prelude::*;
29/// fn main() -> multiscreen_rs::Result<()> {
30/// let device = cpu()?;
31/// Ok(())
32/// }
33/// ```
34#[cfg(not(feature = "cuda"))]
35pub fn cpu() -> Result<Device> {
36 Ok(Device::default())
37}
38
39/// Returns a CUDA device for the given GPU index.
40///
41/// Only available with the `cuda` feature.
42///
43/// ```toml
44/// [dependencies]
45/// multiscreen-rs = { version = "0.1", features = ["cuda"] }
46/// ```
47#[cfg(feature = "cuda")]
48pub fn cuda(_index: usize) -> Result<Device> {
49 // Burn's Cuda device doesn't support selecting GPU index via
50 // the simple API yet. The index parameter is reserved for future use.
51 Ok(Device::default())
52}
53
54/// Returns an error — CUDA is not compiled in.
55#[cfg(not(feature = "cuda"))]
56pub fn cuda(_index: usize) -> Result<Device> {
57 Err(crate::error::Error::Config(
58 "CUDA is not available. Enable the 'cuda' feature in Cargo.toml:\n\
59 [dependencies]\n\
60 multiscreen-rs = { version = \"0.1\", features = [\"cuda\"] }"
61 .to_string(),
62 ))
63}