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: CPUImplementations§
Source§impl OpenCL
impl OpenCL
Sourcepub fn new(device_idx: usize) -> Result<OpenCL, Box<dyn Error + Sync + Send>>
pub fn new(device_idx: usize) -> Result<OpenCL, Box<dyn Error + Sync + Send>>
Sourcepub fn reset(&'static mut self)
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.
pub fn ctx(&self) -> Ref<'_, Context>
pub fn queue(&self) -> Ref<'_, CommandQueue>
pub fn device(&self) -> CLIntDevice
pub fn global_mem_size_in_gb(&self) -> Result<f64, Box<dyn Error + Sync + Send>>
pub fn max_mem_alloc_in_gb(&self) -> Result<f64, Box<dyn Error + Sync + Send>>
pub fn name(&self) -> Result<String, Box<dyn Error + Sync + Send>>
pub fn version(&self) -> Result<String, Box<dyn Error + Sync + Send>>
Sourcepub fn unified_mem(&self) -> bool
pub fn unified_mem(&self) -> bool
Checks whether the device supports unified memory.
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> for OpenCL
Available on crate feature opencl only.
impl<T: CDatatype + Float> ActivationOps<T> for OpenCL
Available on crate feature
opencl only.fn sigmoid(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>
fn sigmoid_grad(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>
fn tanh(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>
fn tanh_grad(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>
fn relu(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>
fn relu_grad(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>
Source§fn relu_grad_mut(&self, x: &mut Matrix<'_, T, Self, ()>)
fn relu_grad_mut(&self, x: &mut Matrix<'_, T, Self, ()>)
inplace
Source§impl<T: CDatatype> AdditionalOps<T> for OpenCL
Available on crate feature opencl only.
impl<T: CDatatype> AdditionalOps<T> for OpenCL
Available on crate feature
opencl only.fn adds(&self, lhs: &Matrix<'_, T, Self>, rhs: T) -> Matrix<'_, T, Self>
fn subs(&self, lhs: &Matrix<'_, T, Self, ()>, rhs: T) -> Matrix<'_, T, Self, ()>
fn muls(&self, lhs: &Matrix<'_, T, Self>, rhs: T) -> Matrix<'_, T, Self>
fn divs(&self, lhs: &Matrix<'_, T, Self>, rhs: T) -> Matrix<'_, T, Self>
Source§impl<T, S> Alloc<'_, T, S> for OpenCLwhere
S: Shape,
impl<T, S> Alloc<'_, T, S> for OpenCLwhere
S: Shape,
Source§fn alloc(&self, len: usize, flag: AllocFlag) -> CLPtr<T>
fn alloc(&self, len: usize, flag: AllocFlag) -> CLPtr<T>
Allocate memory on the implemented device. Read more
Source§fn alloc_with_vec(&'a self, vec: Vec<T>) -> Self::Ptr<T, S>where
T: Clone,
fn alloc_with_vec(&'a self, vec: Vec<T>) -> Self::Ptr<T, S>where
T: Clone,
If the vector
vec was allocated previously, this function can be used in order to reduce the amount of allocations, which may be faster than using a slice of vec.fn with_array(&'a self, array: <S as Shape>::ARR<T>) -> Self::Ptr<T, S>where
T: Clone,
Source§impl<T: CDatatype> AssignOps<T> for OpenCL
Available on crate feature opencl only.
impl<T: CDatatype> AssignOps<T> for OpenCL
Available on crate feature
opencl only.Source§fn add_assign(
&self,
lhs: &mut Buffer<'_, T, OpenCL>,
rhs: &Buffer<'_, T, OpenCL>,
)
fn add_assign( &self, lhs: &mut Buffer<'_, T, OpenCL>, rhs: &Buffer<'_, T, OpenCL>, )
Add assign Read more
fn sub_assign( &self, lhs: &mut Buffer<'_, T, OpenCL>, rhs: &Buffer<'_, T, OpenCL>, )
fn mul_assign( &self, lhs: &mut Buffer<'_, T, Self, ()>, rhs: &Buffer<'_, T, Self, ()>, )
Source§impl<T: CDatatype> BaseOps<T> for OpenCL
Available on crate feature opencl only.
impl<T: CDatatype> BaseOps<T> for OpenCL
Available on crate feature
opencl only.Source§fn add(
&self,
lhs: &Matrix<'_, T, Self>,
rhs: &Matrix<'_, T, Self>,
) -> Matrix<'_, T, Self>
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>
fn sub( &self, lhs: &Matrix<'_, T, Self>, rhs: &Matrix<'_, T, Self>, ) -> Matrix<'_, T, Self>
Element-wise subtraction Read more
Source§impl CacheReturn for OpenCL
impl CacheReturn for OpenCL
Source§impl<T: CDatatype> ColOp<T> for OpenCL
Available on crate feature opencl only.
impl<T: CDatatype> ColOp<T> for OpenCL
Available on crate feature
opencl only.fn add_col( &self, lhs: &Matrix<'_, T, Self>, rhs: &Matrix<'_, T, Self>, ) -> Matrix<'_, T, Self>
fn sub_col( &self, lhs: &Matrix<'_, T, Self>, rhs: &Matrix<'_, T, Self>, ) -> Matrix<'_, T, Self>
fn div_col( &self, lhs: &Matrix<'_, T, Self>, rhs: &Matrix<'_, T, Self>, ) -> Matrix<'_, T, Self>
Source§impl<T: CDatatype> DiagflatOp<T> for OpenCL
Available on crate feature opencl only.
impl<T: CDatatype> DiagflatOp<T> for OpenCL
Available on crate feature
opencl only.Source§impl<T: CDatatype> FnsOps<T> for OpenCL
Available on crate feature opencl only.
impl<T: CDatatype> FnsOps<T> for OpenCL
Available on crate feature
opencl only.fn exp(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>
fn ln(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>
fn neg(&self, x: &Matrix<'_, T, Self>) -> Matrix<'_, T, Self>
fn powf(&self, x: &Matrix<'_, T, Self>, rhs: T) -> Matrix<'_, T, Self>
fn powi(&self, x: &Matrix<'_, T, Self>, rhs: i32) -> Matrix<'_, T, Self>
Source§impl<T> Read<T> for OpenCL
impl<T> Read<T> for OpenCL
Source§impl<T: CDatatype> ScalarAssign<T> for OpenCL
Available on crate feature opencl only.
impl<T: CDatatype> ScalarAssign<T> for OpenCL
Available on crate feature
opencl only.fn adds_assign(&self, lhs: &mut Matrix<'_, T, Self>, rhs: T)
fn muls_assign(&self, lhs: &mut Matrix<'_, T, Self>, rhs: T)
fn divs_assign(&self, lhs: &mut Matrix<'_, T, Self>, rhs: T)
fn subs_assign(&self, lhs: &mut Matrix<'_, T, Self>, rhs: T)
Source§impl<T: GenericBlas + MatrixMultiply + Float> SoftmaxOps<T> for OpenCL
Available on crate feature opencl only.
impl<T: GenericBlas + MatrixMultiply + Float> SoftmaxOps<T> for OpenCL
Available on crate feature
opencl only.Source§impl<T: CDatatype> SumOverOps<T> for OpenCL
Available on crate feature opencl only.
impl<T: CDatatype> SumOverOps<T> for OpenCL
Available on crate feature
opencl only.Source§impl<T: CDatatype> TransposeOp<T> for OpenCL
Available on crate feature opencl only.
impl<T: CDatatype> TransposeOp<T> for OpenCL
Available on crate feature
opencl only.Auto Trait Implementations§
impl !Freeze for OpenCL
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more