2023-08-13 19:53:34 +08:00
|
|
|
#[cfg(feature = "accelerate")]
|
|
|
|
extern crate accelerate_src;
|
|
|
|
|
2023-07-08 19:43:56 +08:00
|
|
|
#[cfg(feature = "mkl")]
|
|
|
|
extern crate intel_mkl_src;
|
|
|
|
|
|
|
|
use anyhow::Result;
|
2023-08-02 15:20:22 +08:00
|
|
|
use candle_core::{Device, Tensor};
|
2023-07-08 19:43:56 +08:00
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
|
|
|
let device = Device::new_cuda(0)?;
|
2023-08-24 19:07:31 +08:00
|
|
|
let in_t = Tensor::rand(-1f32, 1f32, (1, 3, 12, 7), &device)?;
|
|
|
|
let k_t = Tensor::rand(-1f32, 1f32, (6, 3, 1, 1), &device)?;
|
|
|
|
let out_t = in_t.conv2d(&k_t, 0, 1, 1)?;
|
|
|
|
println!("{out_t}");
|
|
|
|
let in_t = in_t.to_device(&Device::Cpu)?;
|
|
|
|
let k_t = k_t.to_device(&Device::Cpu)?;
|
|
|
|
let out_t2 = in_t.conv2d(&k_t, 0, 1, 1)?;
|
|
|
|
let diff = (out_t.to_device(&Device::Cpu)? - out_t2)?
|
|
|
|
.sqr()?
|
|
|
|
.sum_all()?;
|
|
|
|
println!("{diff}");
|
2023-08-24 17:16:37 +08:00
|
|
|
|
2023-08-15 04:30:41 +08:00
|
|
|
let t = Tensor::randn(0f32, 1f32, (2, 4, 96, 96), &device)?;
|
|
|
|
let w = Tensor::randn(0f32, 1f32, (320, 4, 3, 3), &device)?;
|
2023-08-23 19:58:55 +08:00
|
|
|
let res = t.conv2d(&w, 1, 1, 1)?;
|
2023-08-15 04:30:41 +08:00
|
|
|
println!("{res:?}");
|
2023-07-08 19:43:56 +08:00
|
|
|
Ok(())
|
|
|
|
}
|