#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum Backend {
Auto,
#[default]
Cpu,
Metal,
CoreMl,
OpenCl,
OpenGl,
Vulkan,
Cuda,
}
impl Backend {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Auto => "auto",
Self::Cpu => "cpu",
Self::Metal => "metal",
Self::CoreMl => "coreml",
Self::OpenCl => "opencl",
Self::OpenGl => "opengl",
Self::Vulkan => "vulkan",
Self::Cuda => "cuda",
}
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum PrecisionMode {
#[default]
Normal,
High,
Low,
LowBf16,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum PowerMode {
Low,
#[default]
Normal,
High,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum MemoryMode {
Low,
#[default]
Normal,
High,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum ExecutionMode {
#[default]
Serialized,
Parallel,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum GpuTuning {
#[default]
Auto,
None,
Fast,
Normal,
Wide,
Heavy,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum GpuMemoryMode {
#[default]
Buffer,
Image,
Auto,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RuntimeConfig {
pub backend: Backend,
pub threads: usize,
pub precision: PrecisionMode,
pub power: PowerMode,
pub memory: MemoryMode,
pub execution: ExecutionMode,
pub queue_capacity: usize,
pub gpu_tuning: GpuTuning,
pub gpu_memory: GpuMemoryMode,
pub gpu_cache_dir: Option<std::path::PathBuf>,
}
impl Default for RuntimeConfig {
fn default() -> Self {
Self {
backend: Backend::Cpu,
threads: 4,
precision: PrecisionMode::Normal,
power: PowerMode::Normal,
memory: MemoryMode::Normal,
execution: ExecutionMode::Serialized,
queue_capacity: 2,
gpu_tuning: GpuTuning::Auto,
gpu_memory: GpuMemoryMode::Buffer,
gpu_cache_dir: None,
}
}
}
impl RuntimeConfig {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub const fn with_backend(mut self, backend: Backend) -> Self {
self.backend = backend;
self
}
#[must_use]
pub const fn with_threads(mut self, threads: usize) -> Self {
self.threads = threads;
self
}
#[must_use]
pub const fn with_precision(mut self, precision: PrecisionMode) -> Self {
self.precision = precision;
self
}
#[must_use]
pub const fn with_queue_capacity(mut self, capacity: usize) -> Self {
self.queue_capacity = capacity;
self
}
#[must_use]
pub const fn with_gpu_tuning(mut self, tuning: GpuTuning) -> Self {
self.gpu_tuning = tuning;
self
}
#[must_use]
pub const fn with_gpu_memory(mut self, memory: GpuMemoryMode) -> Self {
self.gpu_memory = memory;
self
}
#[must_use]
pub fn with_gpu_cache_dir(mut self, directory: impl Into<std::path::PathBuf>) -> Self {
self.gpu_cache_dir = Some(directory.into());
self
}
#[must_use]
pub const fn with_execution(mut self, execution: ExecutionMode) -> Self {
self.execution = execution;
self
}
}