@@ -52,6 +52,10 @@ pub enum OrtAccelerator {
5252 /// WebGPU via Dawn (Windows, Linux, WebAssembly).
5353 #[ serde( rename = "webgpu" ) ]
5454 WebGpu = 6 ,
55+ /// XNNPACK CPU acceleration (ARM, x86_64). Optimised for Conv/Gemm/MatMul
56+ /// kernels; uses its own threadpool independent of the session intra-op pool.
57+ #[ serde( rename = "xnnpack" ) ]
58+ Xnnpack = 8 ,
5559}
5660
5761static ORT_ACCELERATOR : AtomicU8 = AtomicU8 :: new ( OrtAccelerator :: Auto as u8 ) ;
@@ -95,6 +99,9 @@ impl OrtAccelerator {
9599 #[ cfg( feature = "ort-webgpu" ) ]
96100 v. push ( OrtAccelerator :: WebGpu ) ;
97101
102+ #[ cfg( feature = "ort-xnnpack" ) ]
103+ v. push ( OrtAccelerator :: Xnnpack ) ;
104+
98105 v
99106 }
100107
@@ -108,6 +115,7 @@ impl OrtAccelerator {
108115 5 => Self :: CoreMl ,
109116 6 => Self :: WebGpu ,
110117 7 => Self :: TensorRt ,
118+ 8 => Self :: Xnnpack ,
111119 _ => Self :: Auto ,
112120 }
113121 }
@@ -130,6 +138,7 @@ impl fmt::Display for OrtAccelerator {
130138 Self :: Rocm => "rocm" ,
131139 Self :: CoreMl => "coreml" ,
132140 Self :: WebGpu => "webgpu" ,
141+ Self :: Xnnpack => "xnnpack" ,
133142 } ;
134143 f. write_str ( s)
135144 }
@@ -148,6 +157,7 @@ impl FromStr for OrtAccelerator {
148157 "rocm" => Ok ( Self :: Rocm ) ,
149158 "coreml" | "core_ml" => Ok ( Self :: CoreMl ) ,
150159 "webgpu" | "web_gpu" => Ok ( Self :: WebGpu ) ,
160+ "xnnpack" => Ok ( Self :: Xnnpack ) ,
151161 other => Err ( format ! ( "unknown ORT accelerator: {other}" ) ) ,
152162 }
153163 }
@@ -336,6 +346,7 @@ mod tests {
336346 OrtAccelerator :: Rocm ,
337347 OrtAccelerator :: CoreMl ,
338348 OrtAccelerator :: WebGpu ,
349+ OrtAccelerator :: Xnnpack ,
339350 ] {
340351 let s = pref. to_string ( ) ;
341352 let parsed: OrtAccelerator = s. parse ( ) . unwrap ( ) ;
@@ -379,6 +390,7 @@ mod tests {
379390 ( OrtAccelerator :: Rocm , "\" rocm\" " ) ,
380391 ( OrtAccelerator :: CoreMl , "\" coreml\" " ) ,
381392 ( OrtAccelerator :: WebGpu , "\" webgpu\" " ) ,
393+ ( OrtAccelerator :: Xnnpack , "\" xnnpack\" " ) ,
382394 ] {
383395 let json = serde_json:: to_string ( & pref) . unwrap ( ) ;
384396 assert_eq ! ( json, expected, "serialize {:?}" , pref) ;
0 commit comments