custos 0.1.5

A minimal OpenCL, CUDA and host CPU array manipulation engine / framework.
Documentation

custos

Crates.io version Docs

A minimal OpenCL, CUDA and host CPU array manipulation engine / framework. It provides the tools needed to execute array operations with the CPU, as well as with CUDA and OpenCL devices. This library demonstrates how the operations can be implemented for the compute devices: custos-math

Installation

Add "custos" as a dependency:

[dependencies]
custos = "0.1.5"

# to disable the default features (cuda, opencl) and use an own set of features:
#custos = {version = "0.1.5", default-features=false, features=["opencl", "safe"]}

Available features:

  • "opencl" ... adds OpenCL features, where the CLDevice (feature) is the most important one.
  • "cuda" ... adds CUDA features. (CudaDevice)
  • "safe" ... non-copy matrix and buffer. (safer)

Examples

Using the host CPU as the compute device:

cpu_readme.rs

use custos::{CPU, AsDev, VecRead, Buffer, ClearBuf};

fn main() {
    let device = CPU::new();
    let mut a = Buffer::from(( &device, [1, 2, 3, 4, 5, 6]));
    
    // specify device for operation
    device.clear(&mut a);
    assert_eq!(device.read(&a), [0; 6]);

    // select() ... sets CPU as 'global device' 
    // -> when device is not specified in an operation, the 'global device' is used
    let device = CPU::new().select();

    let mut a = Buffer::from(( &device, [1, 2, 3, 4, 5, 6]));

    // no need to specify the device
    a.clear();
    assert_eq!(a.read(), vec![0; 6]);
}

Using an OpenCL device as the compute device:

cl_readme.rs

use custos::{AsDev, Buffer, CLDevice};

fn main() -> custos::Result<()> {
    let device = CLDevice::new(0)?.select();
    
    let mut a = Buffer::from((&device, [5, 3, 2, 4, 6, 2]));
    a.clear();

    assert_eq!(a.read(), [0; 6]);
    
    Ok(())
}

Using a CUDA device as the compute device:

cuda_readme.rs

use custos::{CudaDevice, AsDev, Buffer};

fn main() -> custos::Result<()> {
    let device = CudaDevice::new(0)?.select();
    
    let mut a = Buffer::from((&device, [5, 3, 2, 4, 6, 2]));
    a.clear();

    assert_eq!(a.read(), [0; 6]);
    
    Ok(())
}