Retrieve data from the gpu.

This commit is contained in:
laurent
2023-06-22 11:01:49 +01:00
parent 083ced4428
commit 87a37b3bf3
2 changed files with 25 additions and 21 deletions

View File

@ -1,12 +1,14 @@
use anyhow::Result;
use candle::{Device, Tensor};
use candle::{DType, Device, Tensor};
fn main() -> Result<()> {
let device = Device::new_cuda(0)?;
let x = Tensor::new(&[3f32, 1., 4., 1., 5.], &device)?;
println!("{:?}", x.to_vec1::<f32>()?);
let y = Tensor::new(&[2f32, 7., 1., 8., 2.], &device)?;
let z = (y * 3.)?;
println!("{:?}", z.to_vec1::<f32>()?);
let x = Tensor::new(&[2f32, 7., 1., 8., 2.], &device)?;
let y = (x * 3.)?;
println!("{:?}", y.to_vec1::<f32>()?);
let x = Tensor::ones((3, 2), DType::F32, &device)?;
println!("{:?}", x.to_vec2::<f32>()?);
Ok(())
}