pub fn cpu_exec<'a, 'o, T, F>(
device: &'o OpenCL,
matrix: &Matrix<'a, T, OpenCL>,
f: F,
) -> Result<Matrix<'o, T, OpenCL>>Expand description
Compute operations on the CPU even though the matrix was created with an OpenCL device. There were some optimizations implemented regarding unified memory architectures.
ยงExample
use custos::{OpenCL, Read};
use custos_math::{Matrix, opencl::cpu_exec, FnsOps};
fn main() -> custos::Result<()> {
let device = OpenCL::new(0)?;
let a = Matrix::from((&device, 2, 2, [1f32, 2., 3., 4.]));
let res = cpu_exec(&device, &a, |cpu, x| cpu.neg(x))?;
assert_eq!(res.read(), vec![-1., -2., -3., -4.]);
Ok(())
}