Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: trigger #24

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Cargo.lock

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
.python-version
2 changes: 2 additions & 0 deletions crates/ratchet-core/src/storage/cpu_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl RawCPUBuffer {
assert!(!ptr.is_null());
ptr
} as *mut u8;
println!("Uninitialized tensor ptr: {:p}", data);
Self(data, layout)
}

Expand Down Expand Up @@ -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) }
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/ratchet-core/src/storage/gpu_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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();
Expand Down
10 changes: 4 additions & 6 deletions crates/ratchet-core/src/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,9 @@ impl Tensor {
Ok(())
}

async fn to_cpu(&self) -> Result<Tensor, TensorError> {
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<Tensor, TensorError> {
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(),
Expand All @@ -290,7 +288,7 @@ impl Tensor {

pub fn to(&self, device: Device) -> Result<Tensor, TensorError> {
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()),
}
Expand Down