An open API service indexing awesome lists of open source software.

https://github.com/elftausend/custos-macro

A macro crate used for testing purposes. Will be integrated into the custos repo later.
https://github.com/elftausend/custos-macro

Last synced: about 2 months ago
JSON representation

A macro crate used for testing purposes. Will be integrated into the custos repo later.

Awesome Lists containing this project

README

        

# custos-macro

Adds a `Stack` operation based on a `CPU` operation.

# Example

Expands a `CPU` implementation to a `Stack` and `CPU` implementation.

```rust
#[impl_stack]
impl ElementWise for CPU
where
T: Number,
D: MainMemory,
S: Shape
{
fn add(&self, lhs: &Buffer, rhs: &Buffer) -> Buffer {
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, rhs: &Buffer) -> Buffer {
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 ElementWise for Stack
where
T: Number,
D: MainMemory,
S: Shape
{
fn add(&self, lhs: &Buffer, rhs: &Buffer) -> Buffer {
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, rhs: &Buffer) -> Buffer {
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.
```