Crates.io | custos-macro |
lib.rs | custos-macro |
version | 0.1.1 |
source | src |
created_at | 2023-02-09 12:42:15.118257 |
updated_at | 2023-04-14 19:51:41.478391 |
description | A macro crate for custos. |
homepage | |
repository | https://github.com/elftausend/custos-macro |
max_upload_size | |
id | 780705 |
size | 10,681 |
Adds a Stack
operation based on a CPU
operation.
Expands a CPU
implementation to a Stack
and CPU
implementation.
#[impl_stack]
impl<T, D, S> ElementWise<T, D, S> for CPU
where
T: Number,
D: MainMemory,
S: Shape
{
fn add(&self, lhs: &Buffer<T, D, S>, rhs: &Buffer<T, D, S>) -> Buffer<T, CPU, S> {
let mut out = self.retrieve(lhs.len, (lhs, rhs));
cpu_element_wise(lhs, rhs, &mut out, |o, a, b| *o = a + b);
out
}
fn mul(&self, lhs: &Buffer<T, D, S>, rhs: &Buffer<T, D, S>) -> Buffer<T, CPU, S> {
let mut out = self.retrieve(lhs.len, (lhs, rhs));
cpu_element_wise(lhs, rhs, &mut out, |o, a, b| *o = a * b);
out
}
}
'#[impl_stack]' expands the implementation above to the following 'Stack' implementation:
impl<T, D, S> ElementWise<T, D, S> for Stack
where
T: Number,
D: MainMemory,
S: Shape
{
fn add(&self, lhs: &Buffer<T, D, S>, rhs: &Buffer<T, D, S>) -> Buffer<T, Stack, S> {
let mut out = self.retrieve(lhs.len, (lhs, rhs));
cpu_element_wise(lhs, rhs, &mut out, |o, a, b| *o = a + b);
out
}
fn mul(&self, lhs: &Buffer<T, D, S>, rhs: &Buffer<T, D, S>) -> Buffer<T, Stack, S> {
let mut out = self.retrieve(lhs.len, (lhs, rhs));
cpu_element_wise(lhs, rhs, &mut out, |o, a, b| *o = a * b);
out
}
}
// Now is it possible to execute this operations with a CPU and Stack device.