pub struct RnnImageInferenceLayer { /* private fields */ }Expand description
Wraps MPSRNNImageInferenceLayer.
Implementations§
Source§impl RnnImageInferenceLayer
impl RnnImageInferenceLayer
Sourcepub fn new(device: &MetalDevice, descriptor: &RnnDescriptor) -> Option<Self>
pub fn new(device: &MetalDevice, descriptor: &RnnDescriptor) -> Option<Self>
Wraps a constructor on MPSRNNImageInferenceLayer.
Examples found in repository?
examples/09_rnn_image_inference.rs (line 13)
6fn main() {
7 let device = MetalDevice::system_default().expect("no Metal device available");
8 let queue = device.new_command_queue().expect("command queue");
9
10 let single_gate = RnnSingleGateDescriptor::new(1, 1).expect("single gate descriptor");
11 single_gate.set_use_layer_input_unit_transform_mode(true);
12 let descriptor = single_gate.as_descriptor().expect("base descriptor");
13 let layer = RnnImageInferenceLayer::new(&device, &descriptor).expect("rnn layer");
14
15 let image_descriptor = ImageDescriptor::new(1, 1, 1, feature_channel_format::FLOAT32);
16 let src0 = Image::new(&device, image_descriptor).expect("src0");
17 let src1 = Image::new(&device, image_descriptor).expect("src1");
18 let dst0 = Image::new(&device, image_descriptor).expect("dst0");
19 let dst1 = Image::new(&device, image_descriptor).expect("dst1");
20 src0.write_f32(&[0.25]).expect("write src0");
21 src1.write_f32(&[0.75]).expect("write src1");
22
23 let command_buffer = queue.new_command_buffer().expect("command buffer");
24 let recurrent_state = layer
25 .encode_sequence(&command_buffer, &[&src0, &src1], &[&dst0, &dst1], None)
26 .expect("recurrent state");
27 command_buffer.commit();
28 command_buffer.wait_until_completed();
29
30 let recurrent_output = recurrent_state
31 .recurrent_output_image_for_layer_index(0)
32 .expect("recurrent output image");
33 println!(
34 "{:?} {}x{}x{}",
35 dst1.read_f32().expect("dst1 output"),
36 recurrent_output.width(),
37 recurrent_output.height(),
38 recurrent_output.feature_channels()
39 );
40}Sourcepub fn new_stack(
device: &MetalDevice,
descriptors: &[&RnnDescriptor],
) -> Option<Self>
pub fn new_stack( device: &MetalDevice, descriptors: &[&RnnDescriptor], ) -> Option<Self>
Wraps a constructor on MPSRNNImageInferenceLayer.
Sourcepub fn input_feature_channels(&self) -> usize
pub fn input_feature_channels(&self) -> usize
Wraps the corresponding MPSRNNImageInferenceLayer method.
Sourcepub fn output_feature_channels(&self) -> usize
pub fn output_feature_channels(&self) -> usize
Wraps the corresponding MPSRNNImageInferenceLayer method.
Sourcepub fn number_of_layers(&self) -> usize
pub fn number_of_layers(&self) -> usize
Wraps the corresponding MPSRNNImageInferenceLayer method.
Sourcepub fn recurrent_output_is_temporary(&self) -> bool
pub fn recurrent_output_is_temporary(&self) -> bool
Wraps the corresponding MPSRNNImageInferenceLayer method.
Sourcepub fn set_recurrent_output_is_temporary(&self, value: bool)
pub fn set_recurrent_output_is_temporary(&self, value: bool)
Wraps the corresponding MPSRNNImageInferenceLayer setter.
Sourcepub fn store_all_intermediate_states(&self) -> bool
pub fn store_all_intermediate_states(&self) -> bool
Wraps the corresponding MPSRNNImageInferenceLayer method.
Sourcepub fn set_store_all_intermediate_states(&self, value: bool)
pub fn set_store_all_intermediate_states(&self, value: bool)
Wraps the corresponding MPSRNNImageInferenceLayer setter.
Sourcepub fn bidirectional_combine_mode(&self) -> usize
pub fn bidirectional_combine_mode(&self) -> usize
Wraps the corresponding MPSRNNImageInferenceLayer method.
Sourcepub fn set_bidirectional_combine_mode(&self, value: usize)
pub fn set_bidirectional_combine_mode(&self, value: usize)
Wraps the corresponding MPSRNNImageInferenceLayer setter.
Sourcepub fn encode_sequence(
&self,
command_buffer: &CommandBuffer,
source_images: &[&Image],
destination_images: &[&Image],
recurrent_input_state: Option<&RnnRecurrentImageState>,
) -> Option<RnnRecurrentImageState>
pub fn encode_sequence( &self, command_buffer: &CommandBuffer, source_images: &[&Image], destination_images: &[&Image], recurrent_input_state: Option<&RnnRecurrentImageState>, ) -> Option<RnnRecurrentImageState>
Wraps the corresponding MPSRNNImageInferenceLayer encode entry point.
Examples found in repository?
examples/09_rnn_image_inference.rs (line 25)
6fn main() {
7 let device = MetalDevice::system_default().expect("no Metal device available");
8 let queue = device.new_command_queue().expect("command queue");
9
10 let single_gate = RnnSingleGateDescriptor::new(1, 1).expect("single gate descriptor");
11 single_gate.set_use_layer_input_unit_transform_mode(true);
12 let descriptor = single_gate.as_descriptor().expect("base descriptor");
13 let layer = RnnImageInferenceLayer::new(&device, &descriptor).expect("rnn layer");
14
15 let image_descriptor = ImageDescriptor::new(1, 1, 1, feature_channel_format::FLOAT32);
16 let src0 = Image::new(&device, image_descriptor).expect("src0");
17 let src1 = Image::new(&device, image_descriptor).expect("src1");
18 let dst0 = Image::new(&device, image_descriptor).expect("dst0");
19 let dst1 = Image::new(&device, image_descriptor).expect("dst1");
20 src0.write_f32(&[0.25]).expect("write src0");
21 src1.write_f32(&[0.75]).expect("write src1");
22
23 let command_buffer = queue.new_command_buffer().expect("command buffer");
24 let recurrent_state = layer
25 .encode_sequence(&command_buffer, &[&src0, &src1], &[&dst0, &dst1], None)
26 .expect("recurrent state");
27 command_buffer.commit();
28 command_buffer.wait_until_completed();
29
30 let recurrent_output = recurrent_state
31 .recurrent_output_image_for_layer_index(0)
32 .expect("recurrent output image");
33 println!(
34 "{:?} {}x{}x{}",
35 dst1.read_f32().expect("dst1 output"),
36 recurrent_output.width(),
37 recurrent_output.height(),
38 recurrent_output.feature_channels()
39 );
40}Trait Implementations§
Source§impl Drop for RnnImageInferenceLayer
impl Drop for RnnImageInferenceLayer
impl Send for RnnImageInferenceLayer
impl Sync for RnnImageInferenceLayer
Auto Trait Implementations§
impl Freeze for RnnImageInferenceLayer
impl RefUnwindSafe for RnnImageInferenceLayer
impl Unpin for RnnImageInferenceLayer
impl UnsafeUnpin for RnnImageInferenceLayer
impl UnwindSafe for RnnImageInferenceLayer
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