pub struct FeedDescription<'a> {
pub tensor: &'a Tensor,
pub shape: &'a [usize],
pub data_type: u32,
}Expand description
Feed metadata used to compile a graph into an executable.
Fields§
§tensor: &'a Tensor§shape: &'a [usize]§data_type: u32Implementations§
Source§impl<'a> FeedDescription<'a>
impl<'a> FeedDescription<'a>
Sourcepub const fn new(tensor: &'a Tensor, shape: &'a [usize], data_type: u32) -> Self
pub const fn new(tensor: &'a Tensor, shape: &'a [usize], data_type: u32) -> Self
Examples found in repository?
examples/02_compile_matmul.rs (line 25)
4fn main() {
5 let device = MetalDevice::system_default().expect("no Metal device available");
6 let queue = device
7 .new_command_queue()
8 .expect("failed to create command queue");
9 let graph = Graph::new().expect("failed to create MPSGraph");
10
11 let left = graph
12 .placeholder(Some(&[2, 3]), data_type::FLOAT32, Some("left"))
13 .expect("failed to create left placeholder");
14 let right = graph
15 .placeholder(Some(&[3, 2]), data_type::FLOAT32, Some("right"))
16 .expect("failed to create right placeholder");
17 let output = graph
18 .matrix_multiplication(&left, &right, Some("matmul"))
19 .expect("failed to create matrix multiplication op");
20
21 let executable = graph
22 .compile(
23 &device,
24 &[
25 FeedDescription::new(&left, &[2, 3], data_type::FLOAT32),
26 FeedDescription::new(&right, &[3, 2], data_type::FLOAT32),
27 ],
28 &[&output],
29 )
30 .expect("failed to compile executable");
31
32 let left_data = TensorData::from_f32_slice(&device, &[1.0, 2.0, 3.0, 4.0, 5.0, 6.0], &[2, 3])
33 .expect("failed to create left tensor data");
34 let right_data =
35 TensorData::from_f32_slice(&device, &[7.0, 8.0, 9.0, 10.0, 11.0, 12.0], &[3, 2])
36 .expect("failed to create right tensor data");
37
38 let results = executable
39 .run(&queue, &[&left_data, &right_data])
40 .expect("failed to run executable");
41 let values = results[0].read_f32().expect("failed to read tensor output");
42 let expected = [58.0_f32, 64.0, 139.0, 154.0];
43 for (actual, expected_value) in values.iter().zip(expected) {
44 assert!(
45 (actual - expected_value).abs() < 1.0e-4,
46 "unexpected matrix multiply result: {values:?}"
47 );
48 }
49
50 println!("compile+matmul smoke passed: {values:?}");
51}Trait Implementations§
Source§impl<'a> Clone for FeedDescription<'a>
impl<'a> Clone for FeedDescription<'a>
Source§fn clone(&self) -> FeedDescription<'a>
fn clone(&self) -> FeedDescription<'a>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<'a> Copy for FeedDescription<'a>
Auto Trait Implementations§
impl<'a> Freeze for FeedDescription<'a>
impl<'a> RefUnwindSafe for FeedDescription<'a>
impl<'a> Send for FeedDescription<'a>
impl<'a> Sync for FeedDescription<'a>
impl<'a> Unpin for FeedDescription<'a>
impl<'a> UnsafeUnpin for FeedDescription<'a>
impl<'a> UnwindSafe for FeedDescription<'a>
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