1#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum Backend {
7 Auto,
9 #[default]
11 Cpu,
12 Metal,
14 CoreMl,
16 OpenCl,
18 OpenGl,
20 Vulkan,
22 Cuda,
24}
25
26impl Backend {
27 #[must_use]
29 pub const fn as_str(self) -> &'static str {
30 match self {
31 Self::Auto => "auto",
32 Self::Cpu => "cpu",
33 Self::Metal => "metal",
34 Self::CoreMl => "coreml",
35 Self::OpenCl => "opencl",
36 Self::OpenGl => "opengl",
37 Self::Vulkan => "vulkan",
38 Self::Cuda => "cuda",
39 }
40 }
41}
42
43#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
45pub enum PrecisionMode {
46 #[default]
48 Normal,
49 High,
51 Low,
53 LowBf16,
55}
56
57#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
59pub enum PowerMode {
60 Low,
62 #[default]
64 Normal,
65 High,
67}
68
69#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
71pub enum MemoryMode {
72 Low,
74 #[default]
76 Normal,
77 High,
79}
80
81#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
83pub enum ExecutionMode {
84 #[default]
89 Serialized,
90 Parallel,
92}
93
94#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
96pub enum GpuTuning {
97 #[default]
99 Auto,
100 None,
102 Fast,
104 Normal,
106 Wide,
108 Heavy,
110}
111
112#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
114pub enum GpuMemoryMode {
115 #[default]
117 Buffer,
118 Image,
120 Auto,
122}
123
124#[derive(Debug, Clone, PartialEq, Eq)]
126pub struct RuntimeConfig {
127 pub backend: Backend,
129 pub threads: usize,
131 pub precision: PrecisionMode,
133 pub power: PowerMode,
135 pub memory: MemoryMode,
137 pub execution: ExecutionMode,
139 pub queue_capacity: usize,
141 pub gpu_tuning: GpuTuning,
143 pub gpu_memory: GpuMemoryMode,
145 pub gpu_cache_dir: Option<std::path::PathBuf>,
148}
149
150impl Default for RuntimeConfig {
151 fn default() -> Self {
152 Self {
153 backend: Backend::Cpu,
154 threads: 4,
155 precision: PrecisionMode::Normal,
156 power: PowerMode::Normal,
157 memory: MemoryMode::Normal,
158 execution: ExecutionMode::Serialized,
159 queue_capacity: 2,
160 gpu_tuning: GpuTuning::Auto,
161 gpu_memory: GpuMemoryMode::Buffer,
162 gpu_cache_dir: None,
163 }
164 }
165}
166
167impl RuntimeConfig {
168 #[must_use]
170 pub fn new() -> Self {
171 Self::default()
172 }
173
174 #[must_use]
176 pub const fn with_backend(mut self, backend: Backend) -> Self {
177 self.backend = backend;
178 self
179 }
180
181 #[must_use]
183 pub const fn with_threads(mut self, threads: usize) -> Self {
184 self.threads = threads;
185 self
186 }
187
188 #[must_use]
190 pub const fn with_precision(mut self, precision: PrecisionMode) -> Self {
191 self.precision = precision;
192 self
193 }
194
195 #[must_use]
197 pub const fn with_queue_capacity(mut self, capacity: usize) -> Self {
198 self.queue_capacity = capacity;
199 self
200 }
201
202 #[must_use]
204 pub const fn with_gpu_tuning(mut self, tuning: GpuTuning) -> Self {
205 self.gpu_tuning = tuning;
206 self
207 }
208
209 #[must_use]
211 pub const fn with_gpu_memory(mut self, memory: GpuMemoryMode) -> Self {
212 self.gpu_memory = memory;
213 self
214 }
215
216 #[must_use]
218 pub fn with_gpu_cache_dir(mut self, directory: impl Into<std::path::PathBuf>) -> Self {
219 self.gpu_cache_dir = Some(directory.into());
220 self
221 }
222
223 #[must_use]
225 pub const fn with_execution(mut self, execution: ExecutionMode) -> Self {
226 self.execution = execution;
227 self
228 }
229}