pub fn cpu_exec<'c, 'a, 'o, T, F>(
    device: &'o CLDevice,
    matrix: &Matrix<'a, T>,
    f: F
) -> Result<Matrix<'o, T>> where
    F: for<'b> Fn(&'b CPU, &Matrix<'_, T>) -> Matrix<'b, T>,
    T: Copy + Default + Debug
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::{CLDevice, VecRead};
use custos_math::{Matrix, opencl::cpu_exec, FnsOps};

fn main() -> custos::Result<()> {
    let device = CLDevice::new(0)?;
    let a = Matrix::<f32>::from((&device, 2, 2, [1., 2., 3., 4.]));
    let res = cpu_exec(&device, &a, |cpu, x| cpu.neg(x))?;
    assert_eq!(device.read(&res), vec![-1., -2., -3., -4.]);
    Ok(())
}