preferred_compute_devices

Function preferred_compute_devices 

Source
pub fn preferred_compute_devices(
    space: LogicalMemorySpace,
    _op_kind: OpKind,
) -> Result<Vec<ComputeDevice>>
Expand description

Return the preferred compute devices for a given memory space.

Returns compute devices that can execute operations on tensors in the specified memory space. The selection follows these rules:

  • MainMemory: Returns CPU devices
  • GpuMemory: Returns the corresponding CUDA device (when compiled with cuda feature and device is available)
  • PinnedMemory: Prefers GPU compute if available, falls back to CPU
  • ManagedMemory: Prefers GPU compute if available, falls back to CPU

The returned list is ordered by preference (most preferred first).

§Errors

Returns Error::NoCompatibleComputeDevice if no compute device can execute the given operation on the specified memory space.

§Examples

use tenferro_device::{
    preferred_compute_devices, ComputeDevice, LogicalMemorySpace, OpKind,
};

let devices = preferred_compute_devices(
    LogicalMemorySpace::MainMemory,
    OpKind::BatchedGemm,
).unwrap();

// Typically includes CPU for main memory workloads.
assert!(devices.contains(&ComputeDevice::Cpu { device_id: 0 }));