Skip to content

Commit

Permalink
Removed device from CopyToDevice for metal
Browse files Browse the repository at this point in the history
  • Loading branch information
jafioti committed Apr 26, 2024
1 parent 194f221 commit c49507e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/luminal_metal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Data for MetalBuffer {
}
}

pub trait MetalFloat: Copy + Debug + PartialEq + 'static {
pub trait MetalFloat: Copy + Debug + PartialEq + 'static + Default {
fn to_f32(self) -> f32;
fn from_f32(a: f32) -> Self;
fn is_f32() -> bool;
Expand Down
14 changes: 4 additions & 10 deletions crates/luminal_metal/src/prim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,10 @@ impl<T: MetalFloat> Operator for MetalCopyToDevice<T> {
}

/// Copy a tensor from the GPU
#[derive(Clone)]
pub struct MetalCopyFromDevice<T>(Device, PhantomData<T>);
#[derive(Clone, Default)]
pub struct MetalCopyFromDevice<T>(PhantomData<T>);
crate::debug_type!(MetalCopyFromDevice<T>);

impl<T> MetalCopyFromDevice<T> {
pub fn new(dev: Device) -> Self {
Self(dev, Default::default())
}
}

impl<T: MetalFloat> Operator for MetalCopyFromDevice<T> {
fn process(&mut self, mut inp: Vec<(InputTensor, ShapeTracker)>) -> Vec<Tensor> {
if inp[0].0.borrowed().is::<Vec<f32>>() {
Expand Down Expand Up @@ -1620,7 +1614,7 @@ impl<T: MetalFloat + 'static> Compiler for PrimitiveCompiler<T> {
{
let (input_order, output_order, shape) = edge_weight.as_data().unwrap();
let copy_from_node = graph
.add_op(MetalCopyFromDevice::<T>::new(dev.clone()))
.add_op(MetalCopyFromDevice::<T>::default())
.input(source, output_order, shape)
.finish();
graph.add_edge(
Expand Down Expand Up @@ -1663,7 +1657,7 @@ impl<T: MetalFloat + 'static> Compiler for PrimitiveCompiler<T> {
} else {
// Create copy node
let copy_node = graph
.add_op(MetalCopyFromDevice::<T>::new(dev.clone()))
.add_op(MetalCopyFromDevice::<T>::default())
.input(output_node, 0, output_shape)
.finish();

Expand Down

0 comments on commit c49507e

Please sign in to comment.