Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

Refactored NativeBuffer (#224)

Aleksandr Golokozc7d54ece3374
diff --git a/crates/uzu/src/array.rs b/crates/uzu/src/array.rs
index d4dd34cb5..730b54686 100644
--- a/crates/uzu/src/array.rs
+++ b/crates/uzu/src/array.rs
@@ -275,7 +275,7 @@ impl<C: Context> ArrayContextExt for C {
) -> Array<Self::Backend> {
let buffer_size_bytes = size_for_shape(shape, data_type);
- let buffer = self.create_buffer(buffer_size_bytes).expect("Failed to create buffer");
+ let mut buffer = self.create_buffer(buffer_size_bytes).expect("Failed to create buffer");
buffer.set_label(Some(label));
unsafe { Array::from_parts(Rc::new(buffer), 0, shape, data_type) }
diff --git a/crates/uzu/src/backends/common/native_buffer.rs b/crates/uzu/src/backends/common/native_buffer.rs
index 936f7bdd3..b5cb6c798 100644
--- a/crates/uzu/src/backends/common/native_buffer.rs
+++ b/crates/uzu/src/backends/common/native_buffer.rs
@@ -6,11 +6,13 @@ pub trait NativeBuffer: Debug {
type Backend: Backend;
fn set_label(
- &self,
+ &mut self,
label: Option<&str>,
);
fn cpu_ptr(&self) -> NonNull<c_void>;
+
fn length(&self) -> usize;
+
fn id(&self) -> usize;
}
diff --git a/crates/uzu/src/backends/metal/native_buffer.rs b/crates/uzu/src/backends/metal/native_buffer.rs
index 3f6d98e9d..c36646fe5 100644
--- a/crates/uzu/src/backends/metal/native_buffer.rs
+++ b/crates/uzu/src/backends/metal/native_buffer.rs
@@ -1,4 +1,4 @@
-use std::{ops::Deref, os::raw::c_void, ptr::NonNull};
+use std::{os::raw::c_void, ptr::NonNull};
use metal::{MTLBuffer, MTLResourceExt};
use objc2::{rc::Retained, runtime::ProtocolObject};
@@ -10,10 +10,10 @@ impl NativeBuffer for Retained<ProtocolObject<dyn MTLBuffer>> {
type Backend = Metal;
fn set_label(
- &self,
+ &mut self,
label: Option<&str>,
) {
- MTLResourceExt::set_label(self.deref(), label);
+ (**self).set_label(label);
}
fn cpu_ptr(&self) -> NonNull<c_void> {
@@ -21,7 +21,7 @@ impl NativeBuffer for Retained<ProtocolObject<dyn MTLBuffer>> {
}
fn length(&self) -> usize {
- self.deref().length()
+ (**self).length()
}
fn id(&self) -> usize {