Function grpc_vision_svc::image_captioning::utils::device

source ·
pub fn device(cpu: bool, utils: &impl DeviceUtils) -> Result<Device>
Expand description

Selects the computing device based on the given preferences.

§Arguments

  • cpu - A boolean indicating whether CPU is preferred over GPU.
  • device_utils - An implementation of the DeviceUtils trait.

§Returns

Returns a Result containing the selected Device if successful, or an error if the selection fails.

§Examples

// Select CPU as the computing device.
let device: Device = device(true, &DefaultDeviceUtils).unwrap();
assert!(device.is_cpu());

// Select GPU (CUDA) as the computing device.
// This example assumes that the `cuda` feature is enabled.
let device: Device = device(false, &DefaultDeviceUtils).unwrap();
assert!(matches!(device, Device::Cuda(_)));