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
impl CPU
Sourcepub fn new() -> CPU
pub fn new() -> CPU
Creates an CPU with an InternCPU that holds an empty vector of pointers.
Examples found in repository?
More examples
examples/cpu_cache.rs (line 7)
6fn main() {
7 let device = CPU::new();
8
9 let a = Matrix::<i16>::new(&device, (100, 100));
10 let b = Matrix::<i16>::new(&device, (100, 100));
11
12 let out = a + b;
13 let ptr = {
14 let cache = device.cache.borrow();
15 let mut node = Ident::new(100 * 100);
16 node.idx = 0;
17 cache.nodes.get(&node).unwrap().ptr
18 };
19
20 assert!(ptr == out.as_buf().ptr.ptr as *mut u8);
21}Trait Implementations§
Source§impl<T: Float, D: MainMemory, S: Shape> ActivationOps<T, S, D> for CPU
Available on crate feature cpu only.
impl<T: Float, D: MainMemory, S: Shape> ActivationOps<T, S, D> for CPU
Available on crate feature
cpu only.fn sigmoid(&self, x: &Matrix<'_, T, D, S>) -> Matrix<'_, T, Self, S>
fn sigmoid_grad( &self, activated: &Matrix<'_, T, D, S>, ) -> Matrix<'_, T, Self, S>
fn tanh(&self, x: &Matrix<'_, T, D, S>) -> Matrix<'_, T, Self, S>
fn tanh_grad(&self, x: &Matrix<'_, T, D, S>) -> Matrix<'_, T, Self, S>
fn relu(&self, x: &Matrix<'_, T, D, S>) -> Matrix<'_, T, Self, S>
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>)
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
Available on crate feature cpu only.
impl<T: Number, D: MainMemory, S: Shape> AdditionalOps<T, S, D> for CPU
Available on crate feature
cpu only.fn adds(&self, lhs: &Matrix<'_, T, D, S>, rhs: T) -> Matrix<'_, T, Self, S>
fn subs(&self, lhs: &Matrix<'_, T, D, S>, rhs: T) -> Matrix<'_, T, Self, S>
fn muls(&self, lhs: &Matrix<'_, T, D, S>, rhs: T) -> Matrix<'_, T, Self, S>
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,
impl<T, S> Alloc<'_, T, S> for CPUwhere
S: Shape,
Source§fn alloc(&self, len: usize, flag: AllocFlag) -> CPUPtr<T>
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,
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>) -> CPUPtr<T>
fn alloc_with_vec(&self, vec: Vec<T>) -> 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.fn with_array(&'a self, array: <S as Shape>::ARR<T>) -> Self::Ptr<T, S>where
T: Clone,
Source§impl<T: Number, D: MainMemory, S: Shape> AssignOps<T, S, D> for CPU
Available on crate feature cpu only.
impl<T: Number, D: MainMemory, S: Shape> AssignOps<T, S, D> for CPU
Available on crate feature
cpu only.Source§impl<T, S, D> BaseOps<T, S, D> for CPU
Available on crate feature cpu only.
impl<T, S, D> BaseOps<T, S, D> for CPU
Available on crate feature
cpu only.Source§fn add(
&self,
lhs: &Matrix<'_, T, D, S>,
rhs: &Matrix<'_, T, D, S>,
) -> Matrix<'_, T, Self, S>
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>
fn sub( &self, lhs: &Matrix<'_, T, D, S>, rhs: &Matrix<'_, T, D, S>, ) -> Matrix<'_, T, Self, S>
Element-wise subtraction Read more
Source§impl CacheReturn for CPU
impl CacheReturn for CPU
Source§impl<T: Number, D: MainMemory, S: Shape> ClipOp<T, S, D> for CPU
Available on crate feature cpu only.
impl<T: Number, D: MainMemory, S: Shape> ClipOp<T, S, D> for CPU
Available on crate feature
cpu only.Source§impl<T: Default + Copy, D: MainMemory> DiagflatOp<T, D> for CPU
Available on crate feature cpu only.
impl<T: Default + Copy, D: MainMemory> DiagflatOp<T, D> for CPU
Available on crate feature
cpu only.Source§impl<T, D, S> FnsOps<T, S, D> for CPU
Available on crate feature cpu only.
impl<T, D, S> FnsOps<T, S, D> for CPU
Available on crate feature
cpu only.fn exp(&self, x: &Matrix<'_, T, D, S>) -> Matrix<'_, T, Self, S>
fn ln(&self, x: &Matrix<'_, T, D, S>) -> Matrix<'_, T, Self, S>
fn neg(&self, x: &Matrix<'_, T, D, S>) -> Matrix<'_, T, Self, S>
fn powf(&self, x: &Matrix<'_, T, D, S>, rhs: T) -> Matrix<'_, T, Self, S>
fn powi(&self, x: &Matrix<'_, T, D, S>, rhs: i32) -> Matrix<'_, T, Self, S>
Source§impl MainMemory for CPU
impl MainMemory for CPU
Source§impl<T: Copy + PartialOrd, D: MainMemory> MaxOps<T, D> for CPU
Available on crate feature cpu only.
impl<T: Copy + PartialOrd, D: MainMemory> MaxOps<T, D> for CPU
Available on crate feature
cpu only.Source§impl<T, D, S> Read<T, D, S> for CPUwhere
D: MainMemory,
S: Shape,
impl<T, D, S> Read<T, D, S> for CPUwhere
D: MainMemory,
S: Shape,
Source§impl<T: Number, D: MainMemory, LS: Shape, RS: Shape> RowOp<T, LS, RS, D> for CPU
Available on crate feature cpu only.
impl<T: Number, D: MainMemory, LS: Shape, RS: Shape> RowOp<T, LS, RS, D> for CPU
Available on crate feature
cpu only.Source§impl<T, D: MainMemory, S: Shape> ScalarAssign<T, S, D> for CPU
Available on crate feature cpu only.
impl<T, D: MainMemory, S: Shape> ScalarAssign<T, S, D> for CPU
Available on crate feature
cpu only.fn adds_assign(&self, lhs: &mut Matrix<'_, T, D, S>, rhs: T)
fn muls_assign(&self, lhs: &mut Matrix<'_, T, D, S>, rhs: T)
fn divs_assign(&self, lhs: &mut Matrix<'_, T, D, S>, rhs: T)
fn subs_assign(&self, lhs: &mut Matrix<'_, T, D, S>, rhs: T)
Source§impl<T: Float + GenericBlas + MatrixMultiply> SoftmaxOps<T> for CPU
Available on crate feature cpu only.
impl<T: Float + GenericBlas + MatrixMultiply> SoftmaxOps<T> for CPU
Available on crate feature
cpu only.Source§impl<T: Number, D: MainMemory, IS: Shape> SumOps<T, IS, D> for CPU
Available on crate feature cpu only.
impl<T: Number, D: MainMemory, IS: Shape> SumOps<T, IS, D> for CPU
Available on crate feature
cpu only.Source§impl<T: Copy + Default + AddAssign, D: MainMemory, IS: Shape, OS: Shape> SumOverOps<T, IS, OS, D> for CPU
Available on crate feature cpu only.
impl<T: Copy + Default + AddAssign, D: MainMemory, IS: Shape, OS: Shape> SumOverOps<T, IS, OS, D> for CPU
Available on crate feature
cpu only.Source§impl<T: Default + Copy, D: MainMemory, IS: Shape, OS: Shape> TransposeOp<T, IS, OS, D> for CPU
Available on crate feature cpu only.
impl<T: Default + Copy, D: MainMemory, IS: Shape, OS: Shape> TransposeOp<T, IS, OS, D> for CPU
Available on crate feature
cpu only.impl<'a, T> DevicelessAble<'a, T> for CPU
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> 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