Skip to main content

CnnConvolution

Struct CnnConvolution 

Source
pub struct CnnConvolution { /* private fields */ }

Implementations§

Source§

impl CnnConvolution

Source

pub const fn as_ptr(&self) -> *mut c_void

Source§

impl CnnConvolution

Source

pub fn new( device: &MetalDevice, descriptor: &CnnConvolutionDescriptor, kernel_weights: &[f32], bias_terms: Option<&[f32]>, flags: usize, ) -> Option<Self>

Examples found in repository?
examples/08_cnn_convolution.rs (lines 12-18)
7fn main() {
8    let device = MetalDevice::system_default().expect("no Metal device available");
9    let queue = device.new_command_queue().expect("command queue");
10
11    let descriptor = CnnConvolutionDescriptor::new(1, 1, 1, 1).expect("descriptor");
12    let convolution = CnnConvolution::new(
13        &device,
14        &descriptor,
15        &[2.0],
16        Some(&[0.5]),
17        cnn_convolution_flags::NONE,
18    )
19    .expect("convolution");
20    convolution.set_accumulator_precision_option(cnn_accumulator_precision_option::FLOAT);
21
22    let image_descriptor = ImageDescriptor::new(2, 2, 1, feature_channel_format::FLOAT32);
23    let source = Image::new(&device, image_descriptor).expect("source image");
24    let destination = Image::new(&device, image_descriptor).expect("destination image");
25    source.write_f32(&[1.0, 2.0, 3.0, 4.0]).expect("write source");
26
27    let command_buffer = queue.new_command_buffer().expect("command buffer");
28    convolution.encode_image(&command_buffer, &source, &destination);
29    command_buffer.commit();
30    command_buffer.wait_until_completed();
31
32    let output = destination.read_f32().expect("output");
33    println!("{output:?}");
34}
Source

pub fn input_feature_channels(&self) -> usize

Source

pub fn output_feature_channels(&self) -> usize

Source

pub fn groups(&self) -> usize

Source

pub fn sub_pixel_scale_factor(&self) -> usize

Source

pub fn channel_multiplier(&self) -> usize

Source

pub fn accumulator_precision_option(&self) -> usize

Source

pub fn set_accumulator_precision_option(&self, value: usize)

Examples found in repository?
examples/08_cnn_convolution.rs (line 20)
7fn main() {
8    let device = MetalDevice::system_default().expect("no Metal device available");
9    let queue = device.new_command_queue().expect("command queue");
10
11    let descriptor = CnnConvolutionDescriptor::new(1, 1, 1, 1).expect("descriptor");
12    let convolution = CnnConvolution::new(
13        &device,
14        &descriptor,
15        &[2.0],
16        Some(&[0.5]),
17        cnn_convolution_flags::NONE,
18    )
19    .expect("convolution");
20    convolution.set_accumulator_precision_option(cnn_accumulator_precision_option::FLOAT);
21
22    let image_descriptor = ImageDescriptor::new(2, 2, 1, feature_channel_format::FLOAT32);
23    let source = Image::new(&device, image_descriptor).expect("source image");
24    let destination = Image::new(&device, image_descriptor).expect("destination image");
25    source.write_f32(&[1.0, 2.0, 3.0, 4.0]).expect("write source");
26
27    let command_buffer = queue.new_command_buffer().expect("command buffer");
28    convolution.encode_image(&command_buffer, &source, &destination);
29    command_buffer.commit();
30    command_buffer.wait_until_completed();
31
32    let output = destination.read_f32().expect("output");
33    println!("{output:?}");
34}
Source

pub fn encode_image( &self, command_buffer: &CommandBuffer, source: &Image, destination: &Image, )

Examples found in repository?
examples/08_cnn_convolution.rs (line 28)
7fn main() {
8    let device = MetalDevice::system_default().expect("no Metal device available");
9    let queue = device.new_command_queue().expect("command queue");
10
11    let descriptor = CnnConvolutionDescriptor::new(1, 1, 1, 1).expect("descriptor");
12    let convolution = CnnConvolution::new(
13        &device,
14        &descriptor,
15        &[2.0],
16        Some(&[0.5]),
17        cnn_convolution_flags::NONE,
18    )
19    .expect("convolution");
20    convolution.set_accumulator_precision_option(cnn_accumulator_precision_option::FLOAT);
21
22    let image_descriptor = ImageDescriptor::new(2, 2, 1, feature_channel_format::FLOAT32);
23    let source = Image::new(&device, image_descriptor).expect("source image");
24    let destination = Image::new(&device, image_descriptor).expect("destination image");
25    source.write_f32(&[1.0, 2.0, 3.0, 4.0]).expect("write source");
26
27    let command_buffer = queue.new_command_buffer().expect("command buffer");
28    convolution.encode_image(&command_buffer, &source, &destination);
29    command_buffer.commit();
30    command_buffer.wait_until_completed();
31
32    let output = destination.read_f32().expect("output");
33    println!("{output:?}");
34}

Trait Implementations§

Source§

impl Drop for CnnConvolution

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 CnnConvolution

Source§

impl Sync for CnnConvolution

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.