pub struct CnnConvolution { /* private fields */ }Expand description
Wraps MPSCNNConvolution.
Implementations§
Source§impl CnnConvolution
impl CnnConvolution
Sourcepub fn new(
device: &MetalDevice,
descriptor: &CnnConvolutionDescriptor,
kernel_weights: &[f32],
bias_terms: Option<&[f32]>,
flags: usize,
) -> Option<Self>
pub fn new( device: &MetalDevice, descriptor: &CnnConvolutionDescriptor, kernel_weights: &[f32], bias_terms: Option<&[f32]>, flags: usize, ) -> Option<Self>
Wraps a constructor on MPSCNNConvolution.
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
26 .write_f32(&[1.0, 2.0, 3.0, 4.0])
27 .expect("write source");
28
29 let command_buffer = queue.new_command_buffer().expect("command buffer");
30 convolution.encode_image(&command_buffer, &source, &destination);
31 command_buffer.commit();
32 command_buffer.wait_until_completed();
33
34 let output = destination.read_f32().expect("output");
35 println!("{output:?}");
36}Sourcepub fn input_feature_channels(&self) -> usize
pub fn input_feature_channels(&self) -> usize
Wraps the corresponding MPSCNNConvolution method.
Sourcepub fn output_feature_channels(&self) -> usize
pub fn output_feature_channels(&self) -> usize
Wraps the corresponding MPSCNNConvolution method.
Sourcepub fn sub_pixel_scale_factor(&self) -> usize
pub fn sub_pixel_scale_factor(&self) -> usize
Wraps the corresponding MPSCNNConvolution method.
Sourcepub fn channel_multiplier(&self) -> usize
pub fn channel_multiplier(&self) -> usize
Wraps the corresponding MPSCNNConvolution method.
Sourcepub fn accumulator_precision_option(&self) -> usize
pub fn accumulator_precision_option(&self) -> usize
Wraps the corresponding MPSCNNConvolution method.
Sourcepub fn set_accumulator_precision_option(&self, value: usize)
pub fn set_accumulator_precision_option(&self, value: usize)
Wraps the corresponding MPSCNNConvolution setter.
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
26 .write_f32(&[1.0, 2.0, 3.0, 4.0])
27 .expect("write source");
28
29 let command_buffer = queue.new_command_buffer().expect("command buffer");
30 convolution.encode_image(&command_buffer, &source, &destination);
31 command_buffer.commit();
32 command_buffer.wait_until_completed();
33
34 let output = destination.read_f32().expect("output");
35 println!("{output:?}");
36}Sourcepub fn encode_image(
&self,
command_buffer: &CommandBuffer,
source: &Image,
destination: &Image,
)
pub fn encode_image( &self, command_buffer: &CommandBuffer, source: &Image, destination: &Image, )
Wraps the corresponding MPSCNNConvolution encode entry point.
Examples found in repository?
examples/08_cnn_convolution.rs (line 30)
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
26 .write_f32(&[1.0, 2.0, 3.0, 4.0])
27 .expect("write source");
28
29 let command_buffer = queue.new_command_buffer().expect("command buffer");
30 convolution.encode_image(&command_buffer, &source, &destination);
31 command_buffer.commit();
32 command_buffer.wait_until_completed();
33
34 let output = destination.read_f32().expect("output");
35 println!("{output:?}");
36}Trait Implementations§
Source§impl Drop for CnnConvolution
impl Drop for CnnConvolution
impl Send for CnnConvolution
impl Sync for CnnConvolution
Auto Trait Implementations§
impl Freeze for CnnConvolution
impl RefUnwindSafe for CnnConvolution
impl Unpin for CnnConvolution
impl UnsafeUnpin for CnnConvolution
impl UnwindSafe for CnnConvolution
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