Skip to main content

GraphCompileOptions

Struct GraphCompileOptions 

Source
pub struct GraphCompileOptions { /* private fields */ }
Expand description

Owned BNNS Graph compile-options handle backed by the Swift bridge.

Implementations§

Source§

impl GraphCompileOptions

Source

pub fn new() -> Option<Self>

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
21            .set_generate_debug_info(true)
22            .expect("debug info");
23        options
24            .set_optimization_preference(bnns_graph_optimization_preference::IR_SIZE)
25            .expect("optimization preference");
26        assert!(options.target_single_thread());
27        assert!(options.generate_debug_info());
28        assert_eq!(
29            options.optimization_preference(),
30            bnns_graph_optimization_preference::IR_SIZE
31        );
32    }
33
34    println!("bnns smoke passed: relu={relu:?} sigmoid={sigmoid:?}");
35}
Source

pub fn set_target_single_thread(&mut self, value: bool) -> Result<()>

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
21            .set_generate_debug_info(true)
22            .expect("debug info");
23        options
24            .set_optimization_preference(bnns_graph_optimization_preference::IR_SIZE)
25            .expect("optimization preference");
26        assert!(options.target_single_thread());
27        assert!(options.generate_debug_info());
28        assert_eq!(
29            options.optimization_preference(),
30            bnns_graph_optimization_preference::IR_SIZE
31        );
32    }
33
34    println!("bnns smoke passed: relu={relu:?} sigmoid={sigmoid:?}");
35}
Source

pub fn target_single_thread(&self) -> bool

Examples found in repository?
examples/06_bnns_activation.rs (line 26)
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
21            .set_generate_debug_info(true)
22            .expect("debug info");
23        options
24            .set_optimization_preference(bnns_graph_optimization_preference::IR_SIZE)
25            .expect("optimization preference");
26        assert!(options.target_single_thread());
27        assert!(options.generate_debug_info());
28        assert_eq!(
29            options.optimization_preference(),
30            bnns_graph_optimization_preference::IR_SIZE
31        );
32    }
33
34    println!("bnns smoke passed: relu={relu:?} sigmoid={sigmoid:?}");
35}
Source

pub fn set_generate_debug_info(&mut self, value: bool) -> Result<()>

Examples found in repository?
examples/06_bnns_activation.rs (line 21)
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
21            .set_generate_debug_info(true)
22            .expect("debug info");
23        options
24            .set_optimization_preference(bnns_graph_optimization_preference::IR_SIZE)
25            .expect("optimization preference");
26        assert!(options.target_single_thread());
27        assert!(options.generate_debug_info());
28        assert_eq!(
29            options.optimization_preference(),
30            bnns_graph_optimization_preference::IR_SIZE
31        );
32    }
33
34    println!("bnns smoke passed: relu={relu:?} sigmoid={sigmoid:?}");
35}
Source

pub fn generate_debug_info(&self) -> bool

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
21            .set_generate_debug_info(true)
22            .expect("debug info");
23        options
24            .set_optimization_preference(bnns_graph_optimization_preference::IR_SIZE)
25            .expect("optimization preference");
26        assert!(options.target_single_thread());
27        assert!(options.generate_debug_info());
28        assert_eq!(
29            options.optimization_preference(),
30            bnns_graph_optimization_preference::IR_SIZE
31        );
32    }
33
34    println!("bnns smoke passed: relu={relu:?} sigmoid={sigmoid:?}");
35}
Source

pub fn set_optimization_preference(&mut self, preference: u32) -> Result<()>

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
21            .set_generate_debug_info(true)
22            .expect("debug info");
23        options
24            .set_optimization_preference(bnns_graph_optimization_preference::IR_SIZE)
25            .expect("optimization preference");
26        assert!(options.target_single_thread());
27        assert!(options.generate_debug_info());
28        assert_eq!(
29            options.optimization_preference(),
30            bnns_graph_optimization_preference::IR_SIZE
31        );
32    }
33
34    println!("bnns smoke passed: relu={relu:?} sigmoid={sigmoid:?}");
35}
Source

pub fn optimization_preference(&self) -> u32

Examples found in repository?
examples/06_bnns_activation.rs (line 29)
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
21            .set_generate_debug_info(true)
22            .expect("debug info");
23        options
24            .set_optimization_preference(bnns_graph_optimization_preference::IR_SIZE)
25            .expect("optimization preference");
26        assert!(options.target_single_thread());
27        assert!(options.generate_debug_info());
28        assert_eq!(
29            options.optimization_preference(),
30            bnns_graph_optimization_preference::IR_SIZE
31        );
32    }
33
34    println!("bnns smoke passed: relu={relu:?} sigmoid={sigmoid:?}");
35}

Trait Implementations§

Source§

impl Drop for GraphCompileOptions

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for GraphCompileOptions

Source§

impl Sync for GraphCompileOptions

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.