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

compiler options and codegen split #1879

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

leonardoalt
Copy link
Member

Extracted from #1790.

This PR:

  • creates the new CompilerOptions that encapsulate precompiles and common options, needed by both cli-rs and tests
  • splits codegen, runtime and bootloader into an outer facing dispatcher based on the compiler options, and internal versions that currently are just copies of the previous implementation that is specific to Goldilocks and larger modulus.

After this PR, the riscv-bb PR will simply add analogous 17-bit codegen, runtime and bootloader files.

use crate::CompilerOptions;

/// Translates a RISC-V program to POWDR ASM
/// with constraints that work for a field >= the Goldilocks modulus.
Copy link
Member Author

Choose a reason for hiding this comment

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

This file contains everything that was "removed" according to GH from the file above code_gen.rs, and I changed the text in this line. Everything else is untouched.

MERKLE_TREE_DEPTH, NUM_PAGES_INDEX, N_LEAVES_LOG, PAGE_INPUTS_OFFSET, PAGE_NUMBER_MASK,
PAGE_SIZE_BYTES, PC_INDEX, REGISTER_NAMES, SHUTDOWN_START, WORDS_PER_HASH, WORDS_PER_PAGE,
};

Copy link
Member Author

Choose a reason for hiding this comment

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

This "new" file contains everything "removed" from file above bootloader.rs that is specific to the 64 bits version of the constraints, unmodified.

use itertools::Itertools;

use crate::code_gen::Register;

Copy link
Member Author

Choose a reason for hiding this comment

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

This file contains everything that was "removed" from file above runtime.rs, with all the 64-bit specific stuff, unmodified.

runtime = runtime.with_arith();
}
runtime
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This type, its constructor and its usage are the only changes.

#[derive(Clone)]
pub struct SyscallImpl(pub Vec<FunctionStatement>);

pub trait Runtime {
Copy link
Member Author

Choose a reason for hiding this comment

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

This trait could even go away potentially, since we don't use it as dyn or Box anymore.

/// Full path to machine (e.g, `path::to::Machine`)
path: SymbolPath,
pub path: SymbolPath,
Copy link
Member Author

Choose a reason for hiding this comment

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

Note to self: these pubs can probably go now too.

use std::{
path::{Path, PathBuf},
process::Command,
};

/// Like compiler::test_util::run_pilcom_asm_string, but also runs RISCV executor.
pub fn verify_riscv_asm_string<S: serde::Serialize + Send + Sync + 'static>(
pub fn verify_riscv_asm_string<T: FieldElement, S: serde::Serialize + Send + Sync + 'static>(
Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately we do need T around here because of Pipeline and inputs.

@leonardoalt leonardoalt force-pushed the extract-codegen branch 3 times, most recently from fbd7196 to 5f2bd16 Compare October 8, 2024 14:06
let libs = coprocessors_to_options(coprocessors)?;
let options = CompilerOptions::new(field, libs, continuations);
powdr_riscv::compile_riscv_elf(input_file, Path::new(input_file), options, output_dir, true)
.ok_or_else(|| vec!["could not translate RISC-V executable".to_string()])?;

Ok(())
}

#[allow(clippy::too_many_arguments)]
fn execute<F: FieldElement>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

execute already takes F, it doesn't need the field: KnownField parameter

Copy link
Member Author

Choose a reason for hiding this comment

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

yea I kept both because they are used in different ways, so didn't want to mix them up. Fine with removing, but want to double check after explaining why. Should I still remove it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, i'd call F::known_field inside

Copy link
Collaborator

Choose a reason for hiding this comment

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

there's a similar situation in another part of the code, but there I think F can be removed, because there you match on the known field to then pick a concrete field

let mut pipeline_bb = make_prepared_pipeline(file_name, inputs_bb, vec![]);
pipeline_bb.compute_witness().unwrap();
let pipeline_bb = make_prepared_pipeline(file_name, inputs_bb, vec![]);
test_plonky3_pipeline(pipeline_bb);
Copy link
Collaborator

@pacheco pacheco Oct 9, 2024

Choose a reason for hiding this comment

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

should this go into this PR? not that I see any particular issue

Copy link
Member Author

Choose a reason for hiding this comment

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

I can remove, it just came with the same patch when I extracted

@@ -24,7 +24,7 @@ fn slice_to_vec<T: FieldElement>(arr: &[i32]) -> Vec<T> {
fn sqrt_asm() {
let f = "asm/sqrt.asm";
let i = [3];
regular_test(f, &i);
regular_test_without_babybear(f, &i);
Copy link
Collaborator

Choose a reason for hiding this comment

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

why without_babybear again?

Copy link
Member Author

Choose a reason for hiding this comment

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

since I added the change in your other comment above to also make proofs with p3, some asm tests fail because they have lookups/permutations inside the machine which we don't support

@@ -216,6 +216,7 @@ pub struct DryRunResult<F: FieldElement> {
/// - The number of rows after which the prover should jump to the shutdown routine.
pub fn rust_continuations_dry_run<F: FieldElement>(
pipeline: &mut Pipeline<F>,
field: KnownField,
Copy link
Collaborator

Choose a reason for hiding this comment

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

can get KnownField from F

Copy link
Member Author

Choose a reason for hiding this comment

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

yea but I wanted to keep them decoupled on purpose, in case we manage to remove F here. But I'll remove it

}

pub fn with_arith(self) -> Self {
Self {
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can do the following:

Self {
    arith: true,
    ..self
}

and it will move all the other fields to the new object

}

pub fn with_continuations(self) -> Self {
Self {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same for these

use test_log::test;

fn run_instruction_test(path: &Path) {
let options_32 = CompilerOptions::new_32();
run_instruction_test_with_options(path, options_32);
Copy link
Collaborator

@pacheco pacheco Oct 9, 2024

Choose a reason for hiding this comment

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

is the extra function needed? function itself is a single statement

Copy link
Member Author

Choose a reason for hiding this comment

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

in the riscv-bb PR we also run for babybear here, then it made sense. I removed it after the extraction to keep this PR GL only

@@ -13,13 +12,12 @@ use test_log::test;

use powdr_riscv::{
continuations::{rust_continuations, rust_continuations_dry_run},
Runtime,
CompilerOptions, RuntimeLibs,
};

/// Compiles and runs a rust program with continuations, runs the full
/// witness generation & verifies it using Pilcom.
pub fn test_continuations(case: &str) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should these tests be _64? or should we also have BB inside here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

or maybe _gl?

Copy link
Member Author

Choose a reason for hiding this comment

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

eventually we should have bb as well, but for now only 64. Do you mean the test name?

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.

2 participants