pub struct CnnConvolution { /* private fields */ }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>
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}pub fn input_feature_channels(&self) -> usize
pub fn output_feature_channels(&self) -> usize
pub fn groups(&self) -> usize
pub fn sub_pixel_scale_factor(&self) -> usize
pub fn channel_multiplier(&self) -> usize
pub fn accumulator_precision_option(&self) -> usize
Sourcepub fn set_accumulator_precision_option(&self, value: usize)
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}Sourcepub fn encode_image(
&self,
command_buffer: &CommandBuffer,
source: &Image,
destination: &Image,
)
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
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