diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7c62f447..3f36e9f6 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -46,6 +46,6 @@ jobs: - name: Build run: cargo build - name: Run tests - run: cargo test + run: cargo test -- --nocapture - name: Run integration tests run: (cd crates/ratchet-integration-tests;sh run-tests.sh) diff --git a/crates/ratchet-core/src/storage/cpu_buffer.rs b/crates/ratchet-core/src/storage/cpu_buffer.rs index 1a4b3d21..5feecce7 100644 --- a/crates/ratchet-core/src/storage/cpu_buffer.rs +++ b/crates/ratchet-core/src/storage/cpu_buffer.rs @@ -94,8 +94,10 @@ impl CPUBuffer { pub fn deep_clone(&self) -> Self { let (ptr, layout) = self.inner().into_raw_parts(); + println!("before deep clone: {:p}", ptr); let alloc = unsafe { std::alloc::alloc(layout) }; unsafe { ptr.copy_to_nonoverlapping(alloc, layout.size()) }; + println!("after deep clone: {:p}", alloc); Self::from_raw_parts(alloc, layout) } diff --git a/crates/ratchet-core/src/tensor.rs b/crates/ratchet-core/src/tensor.rs index 3d3ca2d3..40cb2978 100644 --- a/crates/ratchet-core/src/tensor.rs +++ b/crates/ratchet-core/src/tensor.rs @@ -340,6 +340,7 @@ impl Tensor { let storage_guard = self.storage(); let buffer = storage_guard.as_ref().unwrap().try_cpu().unwrap(); let (ptr, _) = buffer.inner().into_raw_parts(); + println!("INTO NDARRAY: {:?}", ptr); unsafe { ArrayViewD::from_shape_ptr(shape, ptr as *const T).to_owned() } } else { ArrayViewD::from_shape(shape, &[]).unwrap().to_owned() @@ -426,45 +427,46 @@ mod tests { Ok(()) } - /* - #[test] - fn test_pyo3() -> anyhow::Result<()> { - let cpu_device = Device::request_device(DeviceRequest::CPU)?; - let a = Tensor::randn::(shape![1024, 1024], cpu_device.clone()); - let b = Tensor::randn::(shape![1024, 1024], cpu_device.clone()); - - let ground: anyhow::Result = Python::with_gil(|py| { - let prg = PyModule::from_code( - py, - r#" - import torch - - def matmul(a, b): - return torch.matmul(torch.from_numpy(a), torch.from_numpy(b)).numpy() + #[test] + fn test_pyo3() -> anyhow::Result<()> { + let cpu_device = Device::request_device(DeviceRequest::CPU)?; + let a = Tensor::randn::(shape![1024, 1024], cpu_device.clone()); + let b = Tensor::randn::(shape![1024, 1024], cpu_device.clone()); + + let ground: anyhow::Result = Python::with_gil(|py| { + let prg = PyModule::from_code( + py, + r#" +import torch + +def matmul(a, b): + return torch.matmul(torch.from_numpy(a), torch.from_numpy(b)).numpy() "#, - "x.py", - "x", - )?; + "x.py", + "x", + )?; + + let result = prg + .getattr("matmul")? + .call1((a.to_py::(&py), b.to_py::(&py)))? + .extract::<&PyArrayDyn>()?; + Ok(Tensor::from(result)) + }); + println!("\nTORCH: {:#?}", ground); - let result = prg - .getattr("matmul")? - .call1((a.to_py::(&py), b.to_py::(&py)))? - .extract::<&PyArrayDyn>()?; - Ok(Tensor::from(result)) - }); + println!("\nA: {:#?}", a); + println!("\nB: {:#?}", b); - let gpu_device = Device::request_device(DeviceRequest::GPU)?; - let a = a.to(gpu_device.clone())?; - let b = b.to(gpu_device)?; + let gpu_device = Device::request_device(DeviceRequest::GPU)?; + let a = a.to(gpu_device.clone())?; + let b = b.to(gpu_device)?; - let c = a.matmul(&b)?; - c.resolve()?; + let c = a.matmul(&b)?; + c.resolve()?; - let our_result = c.to(cpu_device)?; - println!("\nTORCH: {:#?}", ground); - println!("\nOURS: {:#?}", our_result); + let our_result = c.to(cpu_device)?; + println!("\nOURS: {:#?}", our_result); - Ok(()) - } - */ + Ok(()) + } }