pub struct GraphCompileOptions { /* private fields */ }Expand description
Owned BNNS Graph compile-options handle backed by the Swift bridge.
Implementations§
Source§impl GraphCompileOptions
impl GraphCompileOptions
Sourcepub fn new() -> Option<Self>
pub fn new() -> Option<Self>
Creates BNNS graph compile options backed by the BNNS graph compile-options API.
Examples found in repository?
examples/06_bnns_activation.rs (line 16)
5fn main() {
6 let relu = bnns_relu_f32(&[-2.0_f32, 0.5, 3.0]).expect("relu");
7 assert!(relu
8 .iter()
9 .zip([0.0_f32, 0.5, 3.0])
10 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
11
12 let sigmoid = bnns_sigmoid_f32(&[0.0_f32, 2.0]).expect("sigmoid");
13 assert!((sigmoid[0] - 0.5).abs() < 1.0e-6);
14 assert!((sigmoid[1] - 0.880_797).abs() < 1.0e-5);
15
16 if let Some(mut options) = BnnsGraphCompileOptions::new() {
17 options
18 .set_target_single_thread(true)
19 .expect("single thread");
20 options.set_generate_debug_info(true).expect("debug info");
21 options
22 .set_optimization_preference(bnns_graph_optimization_preference::IR_SIZE)
23 .expect("optimization preference");
24 assert!(options.target_single_thread());
25 assert!(options.generate_debug_info());
26 assert_eq!(
27 options.optimization_preference(),
28 bnns_graph_optimization_preference::IR_SIZE
29 );
30 }
31
32 println!("bnns smoke passed: relu={relu:?} sigmoid={sigmoid:?}");
33}Sourcepub fn set_target_single_thread(&mut self, value: bool) -> Result<()>
pub fn set_target_single_thread(&mut self, value: bool) -> Result<()>
Sets the BNNS graph compile option that targets single-thread execution.
Examples found in repository?
examples/06_bnns_activation.rs (line 18)
5fn main() {
6 let relu = bnns_relu_f32(&[-2.0_f32, 0.5, 3.0]).expect("relu");
7 assert!(relu
8 .iter()
9 .zip([0.0_f32, 0.5, 3.0])
10 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
11
12 let sigmoid = bnns_sigmoid_f32(&[0.0_f32, 2.0]).expect("sigmoid");
13 assert!((sigmoid[0] - 0.5).abs() < 1.0e-6);
14 assert!((sigmoid[1] - 0.880_797).abs() < 1.0e-5);
15
16 if let Some(mut options) = BnnsGraphCompileOptions::new() {
17 options
18 .set_target_single_thread(true)
19 .expect("single thread");
20 options.set_generate_debug_info(true).expect("debug info");
21 options
22 .set_optimization_preference(bnns_graph_optimization_preference::IR_SIZE)
23 .expect("optimization preference");
24 assert!(options.target_single_thread());
25 assert!(options.generate_debug_info());
26 assert_eq!(
27 options.optimization_preference(),
28 bnns_graph_optimization_preference::IR_SIZE
29 );
30 }
31
32 println!("bnns smoke passed: relu={relu:?} sigmoid={sigmoid:?}");
33}Sourcepub fn target_single_thread(&self) -> bool
pub fn target_single_thread(&self) -> bool
Returns whether BNNS graph compilation targets single-thread execution.
Examples found in repository?
examples/06_bnns_activation.rs (line 24)
5fn main() {
6 let relu = bnns_relu_f32(&[-2.0_f32, 0.5, 3.0]).expect("relu");
7 assert!(relu
8 .iter()
9 .zip([0.0_f32, 0.5, 3.0])
10 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
11
12 let sigmoid = bnns_sigmoid_f32(&[0.0_f32, 2.0]).expect("sigmoid");
13 assert!((sigmoid[0] - 0.5).abs() < 1.0e-6);
14 assert!((sigmoid[1] - 0.880_797).abs() < 1.0e-5);
15
16 if let Some(mut options) = BnnsGraphCompileOptions::new() {
17 options
18 .set_target_single_thread(true)
19 .expect("single thread");
20 options.set_generate_debug_info(true).expect("debug info");
21 options
22 .set_optimization_preference(bnns_graph_optimization_preference::IR_SIZE)
23 .expect("optimization preference");
24 assert!(options.target_single_thread());
25 assert!(options.generate_debug_info());
26 assert_eq!(
27 options.optimization_preference(),
28 bnns_graph_optimization_preference::IR_SIZE
29 );
30 }
31
32 println!("bnns smoke passed: relu={relu:?} sigmoid={sigmoid:?}");
33}Sourcepub fn set_generate_debug_info(&mut self, value: bool) -> Result<()>
pub fn set_generate_debug_info(&mut self, value: bool) -> Result<()>
Sets the BNNS graph compile option that emits debug information.
Examples found in repository?
examples/06_bnns_activation.rs (line 20)
5fn main() {
6 let relu = bnns_relu_f32(&[-2.0_f32, 0.5, 3.0]).expect("relu");
7 assert!(relu
8 .iter()
9 .zip([0.0_f32, 0.5, 3.0])
10 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
11
12 let sigmoid = bnns_sigmoid_f32(&[0.0_f32, 2.0]).expect("sigmoid");
13 assert!((sigmoid[0] - 0.5).abs() < 1.0e-6);
14 assert!((sigmoid[1] - 0.880_797).abs() < 1.0e-5);
15
16 if let Some(mut options) = BnnsGraphCompileOptions::new() {
17 options
18 .set_target_single_thread(true)
19 .expect("single thread");
20 options.set_generate_debug_info(true).expect("debug info");
21 options
22 .set_optimization_preference(bnns_graph_optimization_preference::IR_SIZE)
23 .expect("optimization preference");
24 assert!(options.target_single_thread());
25 assert!(options.generate_debug_info());
26 assert_eq!(
27 options.optimization_preference(),
28 bnns_graph_optimization_preference::IR_SIZE
29 );
30 }
31
32 println!("bnns smoke passed: relu={relu:?} sigmoid={sigmoid:?}");
33}Sourcepub fn generate_debug_info(&self) -> bool
pub fn generate_debug_info(&self) -> bool
Returns whether the BNNS graph compile option emits debug information.
Examples found in repository?
examples/06_bnns_activation.rs (line 25)
5fn main() {
6 let relu = bnns_relu_f32(&[-2.0_f32, 0.5, 3.0]).expect("relu");
7 assert!(relu
8 .iter()
9 .zip([0.0_f32, 0.5, 3.0])
10 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
11
12 let sigmoid = bnns_sigmoid_f32(&[0.0_f32, 2.0]).expect("sigmoid");
13 assert!((sigmoid[0] - 0.5).abs() < 1.0e-6);
14 assert!((sigmoid[1] - 0.880_797).abs() < 1.0e-5);
15
16 if let Some(mut options) = BnnsGraphCompileOptions::new() {
17 options
18 .set_target_single_thread(true)
19 .expect("single thread");
20 options.set_generate_debug_info(true).expect("debug info");
21 options
22 .set_optimization_preference(bnns_graph_optimization_preference::IR_SIZE)
23 .expect("optimization preference");
24 assert!(options.target_single_thread());
25 assert!(options.generate_debug_info());
26 assert_eq!(
27 options.optimization_preference(),
28 bnns_graph_optimization_preference::IR_SIZE
29 );
30 }
31
32 println!("bnns smoke passed: relu={relu:?} sigmoid={sigmoid:?}");
33}Sourcepub fn set_optimization_preference(&mut self, preference: u32) -> Result<()>
pub fn set_optimization_preference(&mut self, preference: u32) -> Result<()>
Sets the BNNSGraphOptimizationPreference used by BNNS graph compilation.
Examples found in repository?
examples/06_bnns_activation.rs (line 22)
5fn main() {
6 let relu = bnns_relu_f32(&[-2.0_f32, 0.5, 3.0]).expect("relu");
7 assert!(relu
8 .iter()
9 .zip([0.0_f32, 0.5, 3.0])
10 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
11
12 let sigmoid = bnns_sigmoid_f32(&[0.0_f32, 2.0]).expect("sigmoid");
13 assert!((sigmoid[0] - 0.5).abs() < 1.0e-6);
14 assert!((sigmoid[1] - 0.880_797).abs() < 1.0e-5);
15
16 if let Some(mut options) = BnnsGraphCompileOptions::new() {
17 options
18 .set_target_single_thread(true)
19 .expect("single thread");
20 options.set_generate_debug_info(true).expect("debug info");
21 options
22 .set_optimization_preference(bnns_graph_optimization_preference::IR_SIZE)
23 .expect("optimization preference");
24 assert!(options.target_single_thread());
25 assert!(options.generate_debug_info());
26 assert_eq!(
27 options.optimization_preference(),
28 bnns_graph_optimization_preference::IR_SIZE
29 );
30 }
31
32 println!("bnns smoke passed: relu={relu:?} sigmoid={sigmoid:?}");
33}Sourcepub fn optimization_preference(&self) -> u32
pub fn optimization_preference(&self) -> u32
Returns the BNNSGraphOptimizationPreference used by BNNS graph compilation.
Examples found in repository?
examples/06_bnns_activation.rs (line 27)
5fn main() {
6 let relu = bnns_relu_f32(&[-2.0_f32, 0.5, 3.0]).expect("relu");
7 assert!(relu
8 .iter()
9 .zip([0.0_f32, 0.5, 3.0])
10 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
11
12 let sigmoid = bnns_sigmoid_f32(&[0.0_f32, 2.0]).expect("sigmoid");
13 assert!((sigmoid[0] - 0.5).abs() < 1.0e-6);
14 assert!((sigmoid[1] - 0.880_797).abs() < 1.0e-5);
15
16 if let Some(mut options) = BnnsGraphCompileOptions::new() {
17 options
18 .set_target_single_thread(true)
19 .expect("single thread");
20 options.set_generate_debug_info(true).expect("debug info");
21 options
22 .set_optimization_preference(bnns_graph_optimization_preference::IR_SIZE)
23 .expect("optimization preference");
24 assert!(options.target_single_thread());
25 assert!(options.generate_debug_info());
26 assert_eq!(
27 options.optimization_preference(),
28 bnns_graph_optimization_preference::IR_SIZE
29 );
30 }
31
32 println!("bnns smoke passed: relu={relu:?} sigmoid={sigmoid:?}");
33}Trait Implementations§
Source§impl Drop for GraphCompileOptions
impl Drop for GraphCompileOptions
impl Send for GraphCompileOptions
impl Sync for GraphCompileOptions
Auto Trait Implementations§
impl Freeze for GraphCompileOptions
impl RefUnwindSafe for GraphCompileOptions
impl Unpin for GraphCompileOptions
impl UnsafeUnpin for GraphCompileOptions
impl UnwindSafe for GraphCompileOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more