Skip to main content

warn_if_cpu

Function warn_if_cpu 

Source
pub fn warn_if_cpu(device: &Device, crate_name: &str)
Expand description

Emit a one-time warning if running on CPU.

This function should be called when entering performance-critical code paths to remind users that CUDA is preferred. The warning is emitted only once per process to avoid log spam.

§Arguments

  • device - The current device
  • crate_name - Name of the crate for the warning message

§Example

use rust_ai_core::warn_if_cpu;
use candle_core::Device;

fn expensive_operation(device: &Device) {
    warn_if_cpu(device, "my-crate");
    // ... perform operation
}