Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: native guest macro for kernel functions #1191

Merged
merged 36 commits into from
Jan 15, 2025

Conversation

TlatoaniHJ
Copy link
Contributor

@TlatoaniHJ TlatoaniHJ commented Jan 7, 2025

Revision of #1121. Introduces the openvm_native_guest_macro::kernel! macro. Its current behavior is as follows:

openvm_native_guest_macro::kernel! {
    fn function_name(arg1: RustType1 | EdslType1<F>, ..)-> RustReturnType | EdslReturnType<F> {
        compiler_output.txt
    }
}

Inside the macro, you provide a function declaration. Each type (argument types and return types) should be specified in the form A | B, where A is a Rust type and B is an eDSL type (which will generally have a generic F and possibly EF). Currently, only usize | Felt<F> is supported.

Inside the function body, you should provide a filename. The corresponding file should contain a series of u32s in plaintext format, which should be obtained from compiling an eDSL program. For each argument of the function, there should be one u32 equal to its fp in the eDSL program. Then, there should be a single u32 equal to the same for the return value. The remaining u32s should be the serialization of the compiled program.

The intention is that the eDSL program's inputs and outputs should correspond to the eDSL types specified in the macro invocation. However for now, although only Felt<F> is allowed by the macro, the eDSL program can use either Felt<F> or Usize<F> as their runtime behavior is the same.

An example of a Fibonacci program is provided in benchmarks/programs/test_kernel: benchmarks/programs/test_kernel/src/main.rs is the Rust program containing the macro invocation, and benchmarks/programs/test_kernel/kernel/src/main.rs is the program containing the eDSL code which is run to produce benchmarks/programs/test_kernel/compiler_output.txt. You can run benchmarks/src/bin/test_kernel.rs to compile and execute this program.

This comment has been minimized.

This comment has been minimized.

@jonathanpwang jonathanpwang changed the title Feat/Native guest program macro feat: native guest macro for kernel functions Jan 7, 2025
@lispc
Copy link
Contributor

lispc commented Jan 8, 2025

I would suggest split this pr into multi parts:
first merge the transpiler relared pr, to allow hybrid rv32 instructions and long form instructions.
when other parts.

Cargo.toml Outdated Show resolved Hide resolved

openvm_native_guest_macro::edsl_kernel! {
fn function_name(n: usize | Felt<F>) -> usize | Felt<F> {
compiler_output.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can address later, I would slightly prefer if this was a string with " " to match include_bytes!

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@lispc
Copy link
Contributor

lispc commented Jan 10, 2025

one thing missed i think, is the "castf" extension handling in sdk configs.

and also transpiler

impl SdkVmConfig {
    pub fn transpiler(&self) -> Transpiler<F> {

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link

group app.proof_time_ms app.cycles app.cells_used leaf.proof_time_ms leaf.cycles leaf.cells_used
verify_fibair (-4 [-0.1%]) 3,476 711,443 25,512,535 - - -
fibonacci_program 6,059 1,500,137 51,505,102 - - -
regex_program (+47 [+0.2%]) 19,044 4,190,904 165,028,173 - - -
ecrecover_program (-4 [-0.2%]) 2,634 285,401 15,092,297 - - -

Commit: 8813fbf

Benchmark Workflow

@jonathanpwang jonathanpwang merged commit 7c1bbf6 into main Jan 15, 2025
22 checks passed
@jonathanpwang jonathanpwang deleted the feat/native-guest-macro branch January 15, 2025 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants