Struct custos_math::custos::devices::cpu::CPU

source ·
pub struct CPU {
    pub cache: RefCell<Cache<CPU>>,
    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, Read, 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<CPU>>§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: Float, D: MainMemory, S: Shape> ActivationOps<T, S, D> for CPU

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

inplace
source§

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

source§

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

inplace
source§

impl<T: Number, D: MainMemory, S: Shape> AdditionalOps<T, S, D> for CPU

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

Allocate memory on the implemented device. Read more
source§

fn with_slice(&self, data: &[T]) -> CPUPtr<T>where T: Clone,

Allocate new memory with data Read more
source§

fn alloc_with_vec(&self, vec: Vec<T, Global>) -> CPUPtr<T>

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§

impl<T: Number, D: MainMemory, S: Shape> AssignOps<T, S, D> for CPU

source§

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

Add assign Read more
source§

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

source§

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

source§

impl<T, S, D> BaseOps<T, S, D> for CPUwhere T: Number, S: Shape, D: MainMemory,

source§

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

Element-wise addition Read more
source§

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

Element-wise subtraction Read more
source§

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

Element-wise multiplication Read more
source§

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

Element-wise division Read more
source§

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

source§

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

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 CPU

§

type CT = RawCpuBuf

source§

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

Returns a device specific Cache.
source§

impl<T, D> ClearBuf<T, D, ()> for CPUwhere T: Default, D: MainMemory,

source§

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

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

impl<T: Number, D: MainMemory, S: Shape> ClipOp<T, S, D> for CPU

source§

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

source§

impl<'a, T, S> CloneBuf<'a, T, S> for CPUwhere T: Clone, S: Shape,

source§

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

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

impl<T: Number, D: MainMemory> ColOp<T, D> for CPU

source§

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

source§

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

source§

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

source§

impl<T, R, D> CopySlice<T, R, D> for CPUwhere T: Copy, R: RangeBounds<usize>, D: MainMemory, [T]: Index<R, Output = [T]>,

source§

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

Copy a slice of the given buffer into a new buffer. Read more
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 Device for CPU

§

type Ptr = CPUPtr<U>

§

type Cache = Cache<CPU>

source§

fn new() -> Result<CPU, 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: Default + Copy, D: MainMemory> DiagflatOp<T, D> for CPU

source§

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

source§

impl<T, D, S> FnsOps<T, S, D> for CPUwhere T: Float, D: MainMemory, S: Shape,

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl<T, D, LS, RS, OS> Gemm<T, LS, RS, OS, D> for CPUwhere T: GenericBlas + Default + Copy, D: MainMemory, LS: Shape, RS: Shape, OS: Shape,

source§

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

source§

impl GraphReturn for CPU

source§

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

source§

impl MainMemory for CPU

source§

fn as_ptr<T, S>(ptr: &<CPU as Device>::Ptr<T, S>) -> *const Twhere S: Shape,

source§

fn as_ptr_mut<T, S>(ptr: &mut <CPU as Device>::Ptr<T, S>) -> *mut Twhere S: Shape,

source§

impl<T: Copy + PartialOrd, D: MainMemory> MaxOps<T, D> for CPU

source§

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

source§

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

source§

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

source§

impl<T: Float, D: MainMemory, S: Shape> RandOp<T, S, D> for CPU

source§

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

source§

impl RawConv for CPU

source§

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

source§

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

source§

impl<T, D, S> Read<T, D, S> for CPUwhere D: MainMemory, S: Shape,

§

type Read = &'a [T]

source§

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

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

fn read_to_vec<'a>(&self, buf: &Buffer<'_, T, D, S>) -> Vec<T, Global>where T: Default + Clone,

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

impl<T: Number, D: MainMemory, LS: Shape, RS: Shape> RowOp<T, LS, RS, D> for CPU

source§

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

source§

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

source§

impl<T, D: MainMemory, S: Shape> ScalarAssign<T, S, D> for CPUwhere T: Copy + AddAssign + MulAssign + DivAssign + SubAssign,

source§

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

source§

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

source§

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

source§

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

source§

impl<T: Float + GenericBlas + MatrixMultiply> SoftmaxOps<T, CPU> for CPUwhere CPU: ColOp<T>,

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: Number, D: MainMemory, IS: Shape> SumOps<T, IS, D> for CPU

source§

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

source§

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

source§

impl<T: Copy + Default + AddAssign, D: MainMemory, IS: Shape, OS: Shape> SumOverOps<T, IS, OS, D> for CPU

source§

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

source§

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

source§

impl<T: Default + Copy, D: MainMemory, IS: Shape, OS: Shape> TransposeOp<T, IS, OS, D> for CPU

source§

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

source§

impl<T, D> WriteBuf<T, D, ()> for CPUwhere T: Copy, D: MainMemory,

source§

fn write(&self, buf: &mut Buffer<'_, T, D, ()>, 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.
source§

impl<'a, T> DevicelessAble<'a, T, ()> for CPU

Auto Trait Implementations§

§

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 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,