diff --git a/.gitignore b/.gitignore index 6985cf1b..ce0eaee0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb +.python-version diff --git a/crates/ratchet-core/src/storage/cpu_buffer.rs b/crates/ratchet-core/src/storage/cpu_buffer.rs index b63147a7..a360a13b 100644 --- a/crates/ratchet-core/src/storage/cpu_buffer.rs +++ b/crates/ratchet-core/src/storage/cpu_buffer.rs @@ -30,6 +30,7 @@ impl RawCPUBuffer { assert!(!ptr.is_null()); ptr } as *mut u8; + println!("Uninitialized tensor ptr: {:p}", data); Self(data, layout) } @@ -65,6 +66,7 @@ impl Clone for RawCPUBuffer { impl Drop for RawCPUBuffer { fn drop(&mut self) { if !self.0.is_null() && self.1.size() > 0 { + println!("Dropping tensor ptr: {:p}", self.0); unsafe { std::alloc::dealloc(self.0, self.1) } } } diff --git a/crates/ratchet-core/src/storage/gpu_buffer.rs b/crates/ratchet-core/src/storage/gpu_buffer.rs index e7aa856a..722e8fc6 100644 --- a/crates/ratchet-core/src/storage/gpu_buffer.rs +++ b/crates/ratchet-core/src/storage/gpu_buffer.rs @@ -91,7 +91,7 @@ impl DeviceStorage for RawGPUBuffer { self.validate_usages(BufferUsages::COPY_SRC)?; let device = device.try_gpu()?; let buffer_slice = self.inner.slice(..); - let (tx, rx) = futures_intrusive::channel::shared::oneshot_channel(); + let (tx, rx) = std::sync::mpsc::channel(); let alignment = self.alignment; wgpu::util::DownloadBuffer::read_buffer( @@ -108,8 +108,8 @@ impl DeviceStorage for RawGPUBuffer { ); device.poll(wgpu::Maintain::Wait); //TODO: fix unwrap - let storage = pollster::block_on(async { rx.receive().await }) - .ok_or(TensorError::TransferError) + let storage = rx + .recv() .unwrap() .map_err(|_| TensorError::TransferError) .unwrap(); diff --git a/crates/ratchet-core/src/tensor.rs b/crates/ratchet-core/src/tensor.rs index ef72021d..ea66de7e 100644 --- a/crates/ratchet-core/src/tensor.rs +++ b/crates/ratchet-core/src/tensor.rs @@ -275,11 +275,9 @@ impl Tensor { Ok(()) } - async fn to_cpu(&self) -> Result { - let raw_gpu_buf = { - let storage_resource = self.storage().try_read().ok_or(TensorError::NotResolved)?; - storage_resource.try_gpu()?.clone() - }; + fn to_cpu(&self) -> Result { + let storage_resource = self.storage().try_read().ok_or(TensorError::NotResolved)?; + let raw_gpu_buf = storage_resource.try_gpu()?.clone(); Ok(Tensor::new( LazyOp::Const, self.view.clone(), @@ -290,7 +288,7 @@ impl Tensor { pub fn to(&self, device: Device) -> Result { match (self.device(), device) { - (Device::GPU(_), Device::CPU) => pollster::block_on(self.to_cpu()), + (Device::GPU(_), Device::CPU) => self.to_cpu(), (Device::CPU, Device::GPU(_)) => todo!(), _ => Ok(self.clone()), }