ffai_core/lib.rs
1//! # ffai-core
2//!
3//! The spine of FFai: shared media/AI types, one trait per task, and the
4//! engine registry that makes implementations interchangeable.
5//!
6//! The design borrows ffmpeg's load-bearing idea: `AVCodec` is a registry of
7//! interchangeable implementations selected by name (`-c:v libx264`). FFai's
8//! equivalent: [`engine::AsrEngine`], [`engine::TtsEngine`],
9//! [`engine::OcrEngine`], and [`engine::VlmEngine`] are traits with many
10//! competing engines behind them, selected with `--engine <name>`.
11//!
12//! Candle is the tensor spine — re-exported here as [`candle`] so every engine
13//! crate shares one `Tensor`/`Device` and buffers flow between models without
14//! copies.
15
16pub mod engine;
17pub mod error;
18pub mod registry;
19pub mod types;
20
21/// The shared tensor framework (Hugging Face candle).
22pub use candle_core as candle;
23
24pub use error::{Error, Result};
25
26/// Pick the best available compute device.
27///
28/// CPU always works; CUDA/Metal are behind the crate features of the same
29/// name and fall back to CPU when unavailable.
30pub fn best_device() -> candle::Device {
31 #[cfg(feature = "cuda")]
32 if let Ok(dev) = candle::Device::new_cuda(0) {
33 return dev;
34 }
35 #[cfg(feature = "metal")]
36 if let Ok(dev) = candle::Device::new_metal(0) {
37 return dev;
38 }
39 candle::Device::Cpu
40}