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

(WIP) Refactor row major matrix #624

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

mcalancea
Copy link
Collaborator

No description provided.

@naure naure linked an issue Nov 22, 2024 that may be closed by this pull request
@hero78119
Copy link
Collaborator

hero78119 commented Nov 22, 2024

This is a great effort! As some moment I am also curious what would be the impact if we remove MaybeUint feature and use raw vector as we only have one implementation.

I just do a very quick tried on this branch against master branch on riscv_add benchmark with command on remote ceno benchmark machine, with command

### on master branch
cargo bench --bench riscv_add --package ceno_zkvm -- --save-baseline baseline

### on this branch
cargo bench --bench riscv_add --package ceno_zkvm -- --baseline baseline

and the result turns out to be ~+6% slower on e2e latency.

## master branch
add_op_20/prove_add/prove_add_log2_20
                        time:   [1.5172 s 1.5615 s 1.6110 s]

### this branch
add_op_20/prove_add/prove_add_log2_20
                        time:   [1.6454 s 1.6695 s 1.6898 s]
                        change: [+4.1692% +6.3642% +8.4701%] (p = 0.00 < 0.05)

I believed with fibonacchi example it might be even much slower. So it's still nessesary to this feature for keeping high performance.

@hero78119
Copy link
Collaborator

If we just talked about capture this unssignment error, I think we can achieve it from different path: in unittest we support init vector into 2 different default value with same execution trance, and then compare 2 witnesses which should be identical. An unequality indicate there are some unassigment bug. And with that, we can capture the unassignment error in early stage.

@mcalancea mcalancea changed the title Refactor row major matrix (WIP) Refactor row major matrix Nov 22, 2024
@mcalancea
Copy link
Collaborator Author

mcalancea commented Nov 22, 2024

@hero78119

Thank you! This is still work in progress; I'm examining some ways to make it faster while keeping it clean/safe. My bench results are a bit better for some reason:

add_op_20/prove_add/prove_add_log2_20
                        time:   [4.7420 s 4.7740 s 4.8031 s]
                        change: [+1.3563% +2.2286% +3.0911%] (p = 0.00 < 0.05)
                        Performance has regressed.
add_op_21/prove_add/prove_add_log2_21
                        time:   [9.9516 s 10.189 s 10.450 s]
                        change: [-1.7437% +0.5352% +2.8403%] (p = 0.70 > 0.05)
                        No change in performance detected.

What regression % (evaluated at yours) would you consider acceptable?

Copy link
Collaborator

@naure naure left a comment

Choose a reason for hiding this comment

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

Looking nice so far 👍

pub fn num_instances(&self) -> usize {
self.values.len() / self.num_col - self.num_padding_rows
pub fn len(&self) -> usize {
self.values.len()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Confusing name. Maybe total_len, num_cells, …?

let start = Instant::now();
let padding_row = match self.padding_strategy {
InstancePaddingStrategy::RepeatLast => {
self.values[self.values.len() - self.num_col..].to_vec()
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if empty?

There was a special case if steps.is_empty() somewhere:

                InstancePaddingStrategy::RepeatLast if steps.is_empty() => {
                    tracing::debug!("No {} steps to repeat, using zero padding", Self::name());
                    vec![MaybeUninit::new(E::BaseField::ZERO); num_witin]
                }

although that was not completely correct either; better than crashing.

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.

Refactor RowMajorMatrix with a safe API
3 participants