hotg-ai / rune

Rune provides containers to encapsulate and deploy edgeML pipelines and applications
Apache License 2.0
134 stars 15 forks source link

Create a standardised way to declare proc blocks #175

Closed Michael-F-Bryan closed 3 years ago

Michael-F-Bryan commented 3 years ago

At the moment, a proc block is just a normal Rust crate and we use a couple conventions to make sure it is "well formed". These aren't really checked when analysing a Runefile and constructing a pipeline graph, meaning the only way you'll find out that you've written your Runefile incorrectly is when rustc spits out an ugly type error.

My thoughts are to create a macro which expands to a bunch of functions that can be compiled to WebAssembly and called during rune build to discover more about the proc block. Almost like a poor man's reflection mechanism.

proc_block! {
    /// A proc block which applies the Short Time Fourier Transform to a piece of audio,
    /// generating a spectrum.
    type: FFT,
    properties {
        /// The sample rate in hertz.
        hz: i32,
        /// How large each bin should be.
        bin_size: u32,
    },
    inputs {
        f32[_] => u8[_],
    }
}

struct FFT { ... }

impl runic_types::Transform<Tensor<f32>> for FFT {  
    type Output = Tensor<u8>;  

    ...
}
Michael-F-Bryan commented 3 years ago

In https://github.com/hotg-ai/rune/pull/160#pullrequestreview-668065863, @Mi1ind mentioned running into an issue where we'd updated rune-codegen from using proc_block.with_foo() to proc_block.set_foo() for setting proc block parameters (#158).

@Michael-F-Bryan Tried building mobilenet_non_quantized with the proc_block. I am getting the following error when running rune build Runefile:

error[E0599]: no method named `set_count` found for struct `MostConfidentIndices` in the current scope
  --> lib.rs:23:20
   |
23 |     most_confident.set_count(3i32);
   |                    ^^^^^^^^^ help: there is an associated function with a similar name: `with_count`

error[E0599]: no method named `set_labels` found for struct `Label` in the current scope
  --> lib.rs:25:13
   |
25 |     label . set_labels (["background" , "tench/Tinca_tinca" , "goldfish/Carassius_auratus" , "great_white_shark/white_shark/man_eater/man...
   |             ^^^^^^^^^^ help: there is an associated function with a similar name: `with_labels`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0599`.
error: could not compile `mobilenet_non_quantized`

To learn more, run the command again with --verbose.
Error: Rune compilation failed

Caused by:
    0: Compilation failed
    1: Compilation failed
    2: Cargo exited with a return code of 101

Rune version:

rune 0.2.1 (574b452 2021-05-23)

If we had a way for rune build to figure out which parameters a proc block has, we would have been able to emit a much better error message.

Michael-F-Bryan commented 3 years ago

There is still some work to be done to improve our ProcBlock custom derive (see #197), but the bulk of this is complete.