2个版本

0.1.1 2023年4月14日
0.1.0 2023年2月9日

45#expand

Download history 4/week @ 2024-03-10 41/week @ 2024-03-31 2/week @ 2024-04-07

96 每月下载
用于 2 个crate(通过 custos

MIT 许可证

10KB

custos-macro

基于CPU操作添加了Stack操作。

示例

CPU实现扩展为StackCPU实现。

#[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.

依赖项

~265–710KB
~17K SLoC