Skip to content

Commit

Permalink
factorize buffer creation code
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieupoumeyrolsonos authored and kali committed Dec 13, 2024
1 parent 0c0573b commit d6837f8
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions metal/src/tensor/owned.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::MetalTensor;
use anyhow::Result;
use metal::{Buffer, MTLResourceOptions, NSUInteger};
use metal::Buffer;
use num_traits::AsPrimitive;
use std::fmt::Display;
use tract_core::internal::*;
Expand Down Expand Up @@ -136,13 +136,7 @@ impl OwnedMetalTensor {
"Tensor of {:?} is not copied. No Metal buffer can be allocated for it.",
tensor_view.datum_type(),
);
let size = (tensor_view.datum_type().size_of() * tensor_view.len()) as NSUInteger;
let buffer = ctxt.device().new_buffer_with_bytes_no_copy(
tensor_view.tensor.as_bytes().as_ptr() as *const core::ffi::c_void,
size,
MTLResourceOptions::StorageModeShared,
None,
);
let buffer = ctxt.buffer_from_slice(tensor_view.tensor.as_bytes());
Ok(OwnedMetalTensor { inner: m_value, metal: buffer })
})
}
Expand Down

0 comments on commit d6837f8

Please sign in to comment.