Skip to content

Commit

Permalink
Error checking for metal
Browse files Browse the repository at this point in the history
  • Loading branch information
EricLBuehler committed Oct 13, 2024
1 parent e51ecb6 commit f2b6941
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions candle-core/src/metal_backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl BackendStorage for MetalStorage {
DType::BF16 => Ok(CpuStorage::BF16(self.to_cpu()?)),
DType::F32 => Ok(CpuStorage::F32(self.to_cpu()?)),
DType::F64 => Ok(CpuStorage::F64(self.to_cpu()?)),
DType::F8E4M3 => Ok(CpuStorage::F64(self.to_cpu()?)),
}
}

Expand Down Expand Up @@ -2133,6 +2134,7 @@ impl BackendDevice for MetalDevice {
DType::F32 => "fill_f32",
DType::I32 => "fill_i32",
DType::I16 => "fill_i16",
DType::F8E4M3 => crate::bail!("Metal device does not yet support F8E4M3."),
DType::F64 => {
let cpu_storage = crate::cpu_backend::CpuDevice.ones_impl(shape, dtype)?;
return self.storage_from_cpu_storage(&cpu_storage);
Expand Down Expand Up @@ -2170,6 +2172,7 @@ impl BackendDevice for MetalDevice {
CpuStorageRef::F16(storage) => (storage.len(), self.new_buffer_with_data(storage)),
CpuStorageRef::F32(storage) => (storage.len(), self.new_buffer_with_data(storage)),
CpuStorageRef::F64(storage) => (storage.len(), self.new_buffer_with_data(storage)),
CpuStorageRef::F8E4M3(_) => crate::bail!("Metal device does not yet support F8E4M3."),
};
Ok(Self::Storage::new(buffer?, self.clone(), count, T::DTYPE))
}
Expand All @@ -2185,6 +2188,7 @@ impl BackendDevice for MetalDevice {
CpuStorage::F16(storage) => (storage.len(), self.new_buffer_with_data(storage)),
CpuStorage::F32(storage) => (storage.len(), self.new_buffer_with_data(storage)),
CpuStorage::F64(storage) => (storage.len(), self.new_buffer_with_data(storage)),
CpuStorage::F8E4M3(_) => crate::bail!("Metal device does not yet support F8E4M3."),
};
Ok(Self::Storage::new(
buffer?,
Expand Down
2 changes: 2 additions & 0 deletions candle-core/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl crate::CustomOp1 for ArgSort {
DType::I64 => "asort_asc_i64",
DType::I32 => "asort_asc_i32",
DType::I16 => "asort_asc_i16",
DType::F8E4M3 => crate::bail!("Metal device does not yet support F8E4M3."),
}
} else {
match storage.dtype() {
Expand All @@ -166,6 +167,7 @@ impl crate::CustomOp1 for ArgSort {
DType::I64 => "asort_desc_i64",
DType::I32 => "asort_desc_i32",
DType::I16 => "asort_desc_i16",
DType::F8E4M3 => crate::bail!("Metal device does not yet support F8E4M3."),
}
}
};
Expand Down

0 comments on commit f2b6941

Please sign in to comment.