Struct custos_math::custos::OpenCL

source ·
pub struct OpenCL {
    pub kernel_cache: RefCell<KernelCacheCL>,
    pub cache: RefCell<Cache<OpenCL>>,
    pub inner: RefCell<CLDevice>,
    pub graph: RefCell<Graph>,
    pub cpu: CPU,
}
Expand description

Used to perform calculations with an OpenCL capable device. To make new calculations invocable, a trait providing new operations should be implemented for CLDevice.

Example

use custos::{OpenCL, Read, Buffer, Error};

fn main() -> Result<(), Error> {
    let device = OpenCL::new(0)?;
     
    let a = Buffer::from((&device, [1.3; 25]));
    let out = device.read(&a);
     
    assert_eq!(out, vec![1.3; 5*5]);
    Ok(())
}

Fields§

§kernel_cache: RefCell<KernelCacheCL>§cache: RefCell<Cache<OpenCL>>§inner: RefCell<CLDevice>§graph: RefCell<Graph>§cpu: CPU

Implementations§

source§

impl OpenCL

source

pub fn new( device_idx: usize ) -> Result<OpenCL, Box<dyn Error + Sync + Send + 'static, Global>>

Returns an OpenCL at the specified device index.

Errors
  • No device is found at the given device index
  • some other OpenCL related errors
source

pub fn reset(&'static mut self)

Sets the values of the attributes cache, kernel cache, graph and CPU to their default. This cleans up any accumulated allocations.

source

pub fn ctx(&self) -> Ref<'_, Context>

source

pub fn queue(&self) -> Ref<'_, CommandQueue>

source

pub fn device(&self) -> CLIntDevice

source

pub fn global_mem_size_in_gb( &self ) -> Result<f64, Box<dyn Error + Sync + Send + 'static, Global>>

source

pub fn max_mem_alloc_in_gb( &self ) -> Result<f64, Box<dyn Error + Sync + Send + 'static, Global>>

source

pub fn name( &self ) -> Result<String, Box<dyn Error + Sync + Send + 'static, Global>>

source

pub fn version( &self ) -> Result<String, Box<dyn Error + Sync + Send + 'static, Global>>

source

pub fn unified_mem(&self) -> bool

Checks whether the device supports unified memory.

source

pub fn set_unified_mem(&self, unified_mem: bool)

👎Deprecated since 0.6.0: Use the environment variable ‘CUSTOS_USE_UNIFIED’ set to ‘true’, ‘false’ or ‘default’[=hardware dependent] instead.

Trait Implementations§

source§

impl<T: CDatatype + Float> ActivationOps<T, (), OpenCL> for OpenCL

source§

fn sigmoid(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>

source§

fn sigmoid_grad(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>

source§

fn tanh(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>

source§

fn tanh_grad(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>

source§

fn relu(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>

source§

fn relu_mut(&self, x: &mut Matrix<'_, T, Self, ()>)

inplace
source§

fn relu_grad(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>

source§

fn relu_grad_mut(&self, x: &mut Matrix<'_, T, Self, ()>)

inplace
source§

impl<T: CDatatype> AdditionalOps<T, (), OpenCL> for OpenCL

source§

fn adds(&self, lhs: &Matrix<'_, T, Self>, rhs: T) -> Matrix<'_, T, Self>

source§

fn subs(&self, lhs: &Matrix<'_, T, Self, ()>, rhs: T) -> Matrix<'_, T, Self, ()>

source§

fn muls(&self, lhs: &Matrix<'_, T, Self>, rhs: T) -> Matrix<'_, T, Self>

source§

fn divs(&self, lhs: &Matrix<'_, T, Self>, rhs: T) -> Matrix<'_, T, Self>

source§

impl<T, S> Alloc<'_, T, S> for OpenCLwhere S: Shape,

source§

fn alloc(&self, len: usize, flag: AllocFlag) -> CLPtr<T>

Allocate memory on the implemented device. Read more
source§

fn with_slice(&self, data: &[T]) -> CLPtr<T>

Allocate new memory with data Read more
source§

impl<T: CDatatype> AssignOps<T, (), OpenCL> for OpenCL

source§

fn add_assign(&self, lhs: &mut Buffer<'_, T, OpenCL>, rhs: &Buffer<'_, T, OpenCL>)

Add assign Read more
source§

fn sub_assign(&self, lhs: &mut Buffer<'_, T, OpenCL>, rhs: &Buffer<'_, T, OpenCL>)

source§

fn mul_assign( &self, lhs: &mut Buffer<'_, T, Self, ()>, rhs: &Buffer<'_, T, Self, ()> )

source§

impl<T: CDatatype> BaseOps<T, (), OpenCL> for OpenCL

source§

fn add( &self, lhs: &Matrix<'_, T, Self>, rhs: &Matrix<'_, T, Self> ) -> Matrix<'_, T, Self>

Element-wise addition Read more
source§

fn sub( &self, lhs: &Matrix<'_, T, Self>, rhs: &Matrix<'_, T, Self> ) -> Matrix<'_, T, Self>

Element-wise subtraction Read more
source§

fn mul( &self, lhs: &Matrix<'_, T, Self>, rhs: &Matrix<'_, T, Self> ) -> Matrix<'_, T, Self>

Element-wise multiplication Read more
source§

fn div( &self, lhs: &Matrix<'_, T, Self>, rhs: &Matrix<'_, T, Self> ) -> Matrix<'_, T, Self>

Element-wise division Read more
source§

impl<'a, T> CacheBuf<'a, T, ()> for OpenCL

source§

fn cached(&'a self, len: usize) -> Buffer<'a, T, OpenCL, ()>

Adds a buffer to the cache. Following calls will return this buffer, if the corresponding internal count matches with the id used in the cache. Read more
source§

impl CacheReturn for OpenCL

§

type CT = RawCL

source§

fn cache(&self) -> RefMut<'_, Cache<OpenCL>>where OpenCL: RawConv,

Returns a device specific Cache.
source§

impl<T> ClearBuf<T, OpenCL, ()> for OpenCLwhere T: CDatatype,

source§

fn clear(&self, buf: &mut Buffer<'_, T, OpenCL, ()>)

Sets all elements of the matrix to zero. Read more
source§

impl<T: CDatatype> ClipOp<T, (), OpenCL> for OpenCL

source§

fn clip(&self, x: &Matrix<'_, T, Self>, min: T, max: T) -> Matrix<'_, T, Self>

source§

impl<'a, T> CloneBuf<'a, T, ()> for OpenCL

source§

fn clone_buf( &'a self, buf: &Buffer<'a, T, OpenCL, ()> ) -> Buffer<'a, T, OpenCL, ()>

Creates a deep copy of the specified buffer. Read more
source§

impl<T: CDatatype> ColOp<T, OpenCL> for OpenCL

source§

fn add_col( &self, lhs: &Matrix<'_, T, Self>, rhs: &Matrix<'_, T, Self> ) -> Matrix<'_, T, Self>

source§

fn sub_col( &self, lhs: &Matrix<'_, T, Self>, rhs: &Matrix<'_, T, Self> ) -> Matrix<'_, T, Self>

source§

fn div_col( &self, lhs: &Matrix<'_, T, Self>, rhs: &Matrix<'_, T, Self> ) -> Matrix<'_, T, Self>

source§

impl<T, R> CopySlice<T, R, OpenCL> for OpenCLwhere R: RangeBounds<usize>,

source§

fn copy_slice( &self, buf: &Buffer<'_, T, OpenCL, ()>, range: R ) -> Buffer<'_, T, OpenCL, ()>

Copy a slice of the given buffer into a new buffer. Read more
source§

impl Debug for OpenCL

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Device for OpenCL

§

type Ptr = CLPtr<U>

§

type Cache = Cache<OpenCL>

source§

fn new() -> Result<OpenCL, Box<dyn Error + Sync + Send + 'static, Global>>

source§

fn retrieve<T, S>( &self, len: usize, add_node: impl AddGraph ) -> Buffer<'_, T, Self, S>where S: Shape, Self: for<'a> Alloc<'a, T, S>,

source§

impl<T: CDatatype> DiagflatOp<T, OpenCL> for OpenCL

source§

fn diagflat(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>

source§

impl<T: CDatatype> FnsOps<T, (), OpenCL> for OpenCL

source§

fn exp(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>

source§

fn ln(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>

source§

fn neg(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>

source§

fn powf(&self, x: &Matrix<'_, T, Self>, rhs: T) -> Matrix<'_, T, Self>

source§

fn powi(&self, x: &Matrix<'_, T, Self>, rhs: i32) -> Matrix<'_, T, Self>

source§

impl<T: CDatatype> Gemm<T, (), (), (), OpenCL> for OpenCL

source§

fn gemm( &self, lhs: &Matrix<'_, T, Self>, rhs: &Matrix<'_, T, Self> ) -> Matrix<'_, T, Self>

source§

impl GraphReturn for OpenCL

source§

fn graph(&self) -> RefMut<'_, Graph>

source§

impl<T: CDatatype> MaxOps<T, OpenCL> for OpenCL

source§

fn max(&self, x: &Matrix<'_, T, Self>) -> T

source§

fn max_rows(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>

source§

fn max_cols(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>

source§

impl<T: Float> RandOp<T, (), OpenCL> for OpenCL

source§

fn rand(&self, x: &mut Buffer<'_, T, OpenCL>, lo: T, hi: T)

source§

impl RawConv for OpenCL

source§

fn construct<T, S>( ptr: &<OpenCL as Device>::Ptr<T, S>, len: usize, node: Node ) -> <OpenCL as CacheReturn>::CTwhere S: Shape,

source§

fn destruct<T, S>( ct: &<OpenCL as CacheReturn>::CT, flag: AllocFlag ) -> (<OpenCL as Device>::Ptr<T, S>, Node)where S: Shape,

source§

impl<T> Read<T, OpenCL, ()> for OpenCLwhere T: Clone + Default,

§

type Read = Vec<T, Global>

source§

fn read<'a>( &self, buf: &'a Buffer<'_, T, OpenCL, ()> ) -> <OpenCL as Read<T, OpenCL, ()>>::Read<'a>

Read the data of the Buffer as type Read. Read more
source§

fn read_to_vec(&self, buf: &Buffer<'_, T, OpenCL, ()>) -> Vec<T, Global>

Read the data of a buffer into a vector Read more
source§

impl<T: CDatatype> RowOp<T, (), (), OpenCL> for OpenCL

source§

fn add_row( &self, lhs: &Matrix<'_, T, Self>, rhs: &Matrix<'_, T, Self> ) -> Matrix<'_, T, Self>

source§

fn add_row_mut(&self, lhs: &mut Matrix<'_, T, Self>, rhs: &Matrix<'_, T, Self>)

source§

impl<T: CDatatype> ScalarAssign<T, (), OpenCL> for OpenCL

source§

fn adds_assign(&self, lhs: &mut Matrix<'_, T, Self>, rhs: T)

source§

fn muls_assign(&self, lhs: &mut Matrix<'_, T, Self>, rhs: T)

source§

fn divs_assign(&self, lhs: &mut Matrix<'_, T, Self>, rhs: T)

source§

fn subs_assign(&self, lhs: &mut Matrix<'_, T, Self>, rhs: T)

source§

impl<T: GenericBlas + MatrixMultiply + Float> SoftmaxOps<T, OpenCL> for OpenCL

source§

fn softmax(&self, inputs: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>

source§

fn softmax_grad( &self, activated: &Matrix<'_, T, Self>, grads: &Matrix<'_, T, Self> ) -> Matrix<'_, T, Self>

source§

impl StaticGPU for OpenCL

source§

fn as_static() -> &'static OpenCL

source§

impl<T: Number> SumOps<T, (), OpenCL> for OpenCL

source§

fn sum(&self, x: &Matrix<'_, T, Self>) -> T

source§

fn mean(&self, x: &Matrix<'_, T, Self>) -> T

source§

impl<T: CDatatype> SumOverOps<T, (), (), OpenCL> for OpenCL

source§

fn sum_rows<'a>(&'a self, x: &Matrix<'_, T, Self>) -> Matrix<'a, T, Self>

source§

fn sum_cols(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>

source§

impl<T: CDatatype> TransposeOp<T, (), (), OpenCL> for OpenCL

source§

fn transpose(&self, x: &Matrix<'_, T, OpenCL>) -> Matrix<'_, T, OpenCL>

source§

impl<T> WriteBuf<T, OpenCL, ()> for OpenCL

source§

fn write(&self, buf: &mut Buffer<'_, T, OpenCL, ()>, data: &[T])

Write data to the buffer. Read more
source§

fn write_buf( &self, _dst: &mut Buffer<'_, T, Self, S>, _src: &Buffer<'_, T, Self, S> )

Writes data from Buffer to other Buffer.

Auto Trait Implementations§

§

impl !RefUnwindSafe for OpenCL

§

impl !Send for OpenCL

§

impl !Sync for OpenCL

§

impl Unpin for OpenCL

§

impl UnwindSafe for OpenCL

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<D> IsShapeIndep for Dwhere D: RawConv,