1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//! Hardware-specific configuration structures for different execution providers.
//!
//! This module provides specialized configuration structures for various hardware
//! accelerators, promoting better separation of concerns and maintainability.
use serde::{Deserialize, Serialize};
/// CPU execution provider configuration.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CpuConfig {
/// Enable CPU arena allocator for memory management.
pub arena_allocator: bool,
}
/// NVIDIA TensorRT execution provider configuration.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct TensorRtConfig {
/// Enable FP16 precision for faster inference.
pub fp16: bool,
/// Enable engine caching to speed up subsequent runs.
pub engine_cache: bool,
/// Enable timing cache for optimization.
pub timing_cache: bool,
}
/// Intel OpenVINO execution provider configuration.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct OpenVinoConfig {
/// Enable dynamic shapes support.
pub dynamic_shapes: bool,
/// Enable OpenCL throttling.
pub opencl_throttling: bool,
/// Enable QDQ (Quantize-Dequantize) optimizer.
pub qdq_optimizer: bool,
/// Number of threads for OpenVINO execution.
pub num_threads: Option<usize>,
}
/// Intel oneDNN execution provider configuration.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct OneDnnConfig {
/// Enable arena allocator for memory management.
pub arena_allocator: bool,
}
/// Apple CoreML execution provider configuration.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CoreMlConfig {
/// Use static input shapes for optimization.
pub static_input_shapes: bool,
/// Enable subgraph running mode.
pub subgraph_running: bool,
}
/// Huawei CANN execution provider configuration.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CannConfig {
/// Enable graph inference mode.
pub graph_inference: bool,
/// Enable graph dumping for debugging.
pub dump_graphs: bool,
/// Enable OM model dumping.
pub dump_om_model: bool,
}
/// Android NNAPI execution provider configuration.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct NnapiConfig {
/// Force CPU-only execution.
pub cpu_only: bool,
/// Disable CPU fallback.
pub disable_cpu: bool,
/// Enable FP16 precision.
pub fp16: bool,
/// Use NCHW data layout.
pub nchw: bool,
}
/// ARM NN execution provider configuration.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ArmNnConfig {
/// Enable arena allocator for memory management.
pub arena_allocator: bool,
}
/// AMD MIGraphX execution provider configuration.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct MiGraphXConfig {
/// Enable FP16 precision.
pub fp16: bool,
/// Enable exhaustive tuning for optimization.
pub exhaustive_tune: bool,
}
/// Unified hardware configuration containing all execution provider configs.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct HardwareConfig {
/// CPU execution provider configuration.
pub cpu: CpuConfig,
/// TensorRT execution provider configuration.
pub tensorrt: TensorRtConfig,
/// OpenVINO execution provider configuration.
pub openvino: OpenVinoConfig,
/// oneDNN execution provider configuration.
pub onednn: OneDnnConfig,
/// CoreML execution provider configuration.
pub coreml: CoreMlConfig,
/// CANN execution provider configuration.
pub cann: CannConfig,
/// NNAPI execution provider configuration.
pub nnapi: NnapiConfig,
/// ARM NN execution provider configuration.
pub armnn: ArmNnConfig,
/// MIGraphX execution provider configuration.
pub migraphx: MiGraphXConfig,
}
impl HardwareConfig {
/// Create a new hardware configuration with sensible defaults.
pub fn new() -> Self {
Self {
cpu: CpuConfig {
arena_allocator: true,
},
tensorrt: TensorRtConfig {
fp16: true,
engine_cache: true,
timing_cache: false,
},
openvino: OpenVinoConfig {
dynamic_shapes: true,
opencl_throttling: true,
qdq_optimizer: true,
num_threads: None,
},
onednn: OneDnnConfig {
arena_allocator: true,
},
coreml: CoreMlConfig {
static_input_shapes: false,
subgraph_running: true,
},
cann: CannConfig {
graph_inference: true,
dump_graphs: false,
dump_om_model: true,
},
nnapi: NnapiConfig {
cpu_only: false,
disable_cpu: false,
fp16: true,
nchw: false,
},
armnn: ArmNnConfig {
arena_allocator: true,
},
migraphx: MiGraphXConfig {
fp16: true,
exhaustive_tune: false,
},
}
}
/// Get CPU configuration.
pub fn cpu(&self) -> &CpuConfig {
&self.cpu
}
/// Get TensorRT configuration.
pub fn tensorrt(&self) -> &TensorRtConfig {
&self.tensorrt
}
/// Get OpenVINO configuration.
pub fn openvino(&self) -> &OpenVinoConfig {
&self.openvino
}
/// Get oneDNN configuration.
pub fn onednn(&self) -> &OneDnnConfig {
&self.onednn
}
/// Get CoreML configuration.
pub fn coreml(&self) -> &CoreMlConfig {
&self.coreml
}
/// Get CANN configuration.
pub fn cann(&self) -> &CannConfig {
&self.cann
}
/// Get NNAPI configuration.
pub fn nnapi(&self) -> &NnapiConfig {
&self.nnapi
}
/// Get ARM NN configuration.
pub fn armnn(&self) -> &ArmNnConfig {
&self.armnn
}
/// Get MIGraphX configuration.
pub fn migraphx(&self) -> &MiGraphXConfig {
&self.migraphx
}
}