Struct CPU

Source
pub struct CPU {
    pub cache: RefCell<Cache<RawCpuBuf>>,
    pub graph: RefCell<Graph>,
}
Expand description

A CPU is used to perform calculations on the host CPU. To make new operations invocable, a trait providing new functions should be implemented for CPU.

§Example

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

let device = CPU::new();
let a = Buffer::from((&device, [1, 2, 3]));

let out = device.read(&a);

assert_eq!(out, vec![1, 2, 3]);

Fields§

§cache: RefCell<Cache<RawCpuBuf>>§graph: RefCell<Graph>

Implementations§

Source§

impl CPU

Source

pub fn new() -> CPU

Creates an CPU with an InternCPU that holds an empty vector of pointers.

Trait Implementations§

Source§

impl<T> ActivationOps<T> for CPU
where T: Float,

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<'a, T: CDatatype + Float> AdamOp<'a, T> for CPU

Source§

fn step(&'a self, adam: &mut Adam<'a, T>, params: Vec<Param<'a, T>>)

Source§

impl<T> AdditionalOps<T> for CPU
where T: Number,

Source§

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

Source§

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

Source§

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

Source§

impl<T> Alloc<T> for CPU

Source§

fn alloc(&self, len: usize) -> (*mut T, *mut c_void, u64)

Allocate memory on the implemented device. Read more
Source§

fn with_data(&self, data: &[T]) -> (*mut T, *mut c_void, u64)
where T: Clone,

Allocate new memory with data Read more
Source§

fn alloc_with_vec(&self, vec: Vec<T>) -> (*mut T, *mut c_void, u64)

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.
Source§

fn as_dev(&self) -> Device

Creates a generic representation of the device
Source§

impl AsDev for CPU

Source§

fn dev(&self) -> Device
where Self: Sized + Alloc<u8>,

Source§

impl<T> AssignOps<T> for CPU
where T: Number,

Source§

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

Add assign Read more
Source§

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

Source§

impl<T> BaseOps<T> for CPU
where T: Number,

Source§

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

Element-wise addition Read more
Source§

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

Element-wise subtraction Read more
Source§

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

Element-wise multiplication Read more
Source§

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

Element-wise division Read more
Source§

impl<'a, T> CacheBuf<'a, T> for CPU

Source§

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

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<RawCpuBuf> for CPU

Source§

fn cache(&self) -> RefMut<'_, Cache<RawCpuBuf>>

Returns a device specific Cache.
Source§

impl<T> ClearBuf<T> for CPU
where T: Default,

Source§

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

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

impl<T> ClipOp<T> for CPU
where T: Number,

Source§

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

Source§

impl<'a, T> CloneBuf<'a, T> for CPU
where T: Clone,

Source§

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

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

impl<T> ColOp<T> for CPU
where T: Number,

Source§

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

Source§

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

Source§

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

Source§

impl Debug for CPU

Source§

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

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

impl Default for CPU

Source§

fn default() -> CPU

Returns the “default value” for a type. Read more
Source§

impl<T> DiagflatOp<T> for CPU
where T: Default + Copy,

Source§

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

Source§

impl<T> FnsOps<T> for CPU
where T: Float,

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<T> Gemm<T> for CPU
where T: GenericBlas + Default + Copy,

Source§

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

Source§

impl GraphReturn for CPU

Source§

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

Source§

impl<T> MaxOps<T> for CPU
where T: Number,

Source§

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

Source§

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

Source§

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

Source§

impl<T: Number> OnehotOp<T> for CPU

Source§

fn onehot(&self, matrix: &Matrix<'_, T>) -> Matrix<'_, T>

Source§

impl<T> RandOp<T> for CPU
where T: Float,

Source§

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

Source§

impl<T> RowOp<T> for CPU
where T: Number,

Source§

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

Source§

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

Source§

impl<T: CDatatype> SGDOp<T> for CPU

Source§

fn step_momentum(&self, sgd: &mut SGD<'_, T>, params: Vec<Param<'_, T>>)

Source§

fn step(&self, sgd: &mut SGD<'_, T>, params: Vec<Param<'_, T>>)

Source§

impl<T> ScalarAssign<T> for CPU

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<T> SoftmaxOps<T> for CPU
where T: Float + GenericBlas,

Source§

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

Source§

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

Source§

impl<T> SumOps<T> for CPU
where T: Number,

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<T> TransposeOp<T> for CPU
where T: Default + Copy,

Source§

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

Source§

impl<T> VecRead<T> for CPU
where T: Clone,

Source§

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

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

impl<T> WriteBuf<T> for CPU
where T: Copy,

Source§

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

Write data to the buffer. Read more
Source§

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

Writes data from Buffer to other Buffer.
Source§

impl<T> CCEOp<T> for CPU
where T: Float + CDatatype,

Auto Trait Implementations§

§

impl !Freeze for CPU

§

impl !RefUnwindSafe for CPU

§

impl !Send for CPU

§

impl !Sync for CPU

§

impl Unpin for CPU

§

impl UnwindSafe for CPU

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V