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.
- Host: GitHub
- URL: https://github.com/elftausend/custos-macro
- Owner: elftausend
- License: mit
- Created: 2022-10-12T19:36:44.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-12T18:26:08.000Z (over 1 year ago)
- Last Synced: 2024-09-17T15:19:07.194Z (8 months ago)
- Language: Rust
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.
```