Skip to content

Commit

Permalink
fix: remove clone of coefficients in CPU HAL (risc0#1187)
Browse files Browse the repository at this point in the history
Came across this todo, and figured I'd just PR in the change to avoid
the realloc/copy.

> This is safe because the `Ref` guard is kept during the `par_iter`
execution. The code can be made to be more verbose to express this, if
preferred.

---------

Co-authored-by: Frank Laub <[email protected]>
  • Loading branch information
austinabell and flaub authored Dec 8, 2023
1 parent 07072d6 commit d625632
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions risc0/zkp/src/hal/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl<F: Field> Hal for CpuHal<F> {
let eval_count = which.size();
assert_eq!(xs.size(), eval_count);
assert_eq!(out.size(), eval_count);
let coeffs = coeffs.as_slice().to_vec(); // TODO: avoid copy
let coeffs = &*coeffs.as_slice();
let which = which.as_slice();
let xs = xs.as_slice();
let mut out = out.as_slice_mut();
Expand Down Expand Up @@ -553,7 +553,7 @@ impl<F: Field> Hal for CpuHal<F> {
let col_size = matrix.size() / output.size();
assert_eq!(matrix.size(), col_size * row_size);
let mut output = output.as_slice_mut();
let matrix = matrix.as_slice().to_vec(); // TODO: avoid copy
let matrix = &*matrix.as_slice();
let hashfn = self.suite.hashfn.as_ref();
output.par_iter_mut().enumerate().for_each(|(idx, output)| {
let column: Vec<Self::Elem> =
Expand Down

0 comments on commit d625632

Please sign in to comment.