candding 0.1.0

Pure candle embeddings for Rust with no ONNX: dense, sparse, multi-vector and rerank models today, image models on the roadmap
Documentation
use candle_core::Device;

use super::*;

/// `sysctl` reads the key apart from this crate; the free or available memory would fall far below it.
#[cfg(target_os = "macos")]
#[test]
fn the_cpu_budget_is_the_machine_s_physical_memory() {
  let output = std::process::Command::new("sysctl")
    .args(["-n", "hw.memsize"])
    .output()
    .unwrap();
  let physical: u64 = String::from_utf8(output.stdout)
    .unwrap()
    .trim()
    .parse()
    .unwrap();
  assert_eq!(budget_bytes(&Device::Cpu), Some(physical));
}

#[cfg(target_os = "linux")]
#[test]
fn the_cpu_budget_is_the_machine_s_physical_memory() {
  let meminfo = std::fs::read_to_string("/proc/meminfo").unwrap();
  let line = meminfo
    .lines()
    .find(|line| line.starts_with("MemTotal:"))
    .unwrap();
  let kib: u64 = line.split_whitespace().nth(1).unwrap().parse().unwrap();
  assert_eq!(budget_bytes(&Device::Cpu), Some(kib * 1024));
}

/// The `metal` unit tests run serialized, since an allocation elsewhere would move the figure.
#[cfg(feature = "metal")]
#[test]
fn metal_subtracts_what_the_device_already_holds() {
  let device = crate::device::metal(0).unwrap();
  let before = budget_bytes(&device).unwrap();
  let held = candle_core::Tensor::zeros(16 << 20, candle_core::DType::F32, &device).unwrap();
  let after = budget_bytes(&device).unwrap();
  assert!(
    before.saturating_sub(after) >= 64 << 20,
    "{before} then {after}"
  );
  drop(held);
}