Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

FastCompute implementation of GPA witness layer low-to-high HAL op#813

Open
djadjka wants to merge 1 commit intomainfrom
adziadziuk/cry-490-fastcompute-implementation-of-gpa-witness-layer-low-to-high
Open

FastCompute implementation of GPA witness layer low-to-high HAL op#813
djadjka wants to merge 1 commit intomainfrom
adziadziuk/cry-490-fastcompute-implementation-of-gpa-witness-layer-low-to-high

Conversation

@djadjka
Copy link
Contributor

@djadjka djadjka commented Jun 18, 2025

TL;DR

Implemented the pairwise_product_reduce function for the FastCpuLayer and added tests for it.

What changed?

  • Implemented the previously unimplemented pairwise_product_reduce function in the ComputeLayerExecutor trait for FastCpuLayer
  • Added input validation to ensure the input length is a power of 2 and greater than or equal to 2
  • Implemented the pairwise product reduction algorithm using parallel chunks processing
  • Removed the unused fill method from SmallOwnedChunk
  • Simplified the fill_constant implementation to use the new slice abstraction
  • Added necessary imports (Itertools and PackedMemorySlice)
  • Added tests for the new functionality with both single round and multi-round reductions

How to test?

Run the new tests:

cargo test -p fast_compute test_pairwise_product_reduce
cargo test -p fast_compute test_pairwise_product_reduce_single_round

Why make this change?

This change implements a previously unimplemented function that is needed for computing pairwise products and reducing them, which is a common operation in cryptographic protocols. The implementation is optimized for CPU execution using parallel processing where possible.

Copy link
Contributor Author

djadjka commented Jun 18, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label merge-ready to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@djadjka djadjka marked this pull request as ready for review June 18, 2025 10:59
Comment on lines +179 to +183
let value = P::broadcast(value);

for element in slice.as_slice_mut() {
*element = value;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!
Can be simplified even further:

slice.as_slice_mut().fill(P::broadcast(value));

Comment on lines +665 to +671
.for_each(|(chunk, output)| {
let scalar_iter = P::iter_slice(chunk)
.tuples()
.map(|(left, right)| left * right);
*output = P::from_scalars(scalar_iter);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Potentially it would be faster to re-use the packed multiplication by interleaving values:

let (lhs, rhs) = PackedField::interleave(chunk[0], chunk[1]);
let mults = lhs*rhs;

PackedField::from_scalars(mults.iter().step_by(2).copied(), mults.iter().skip(1).step_by(2).copied())

@graphite-app graphite-app bot changed the base branch from btrapani/sys-348-add-gpa-partial-product-hal-op-ref-impl to graphite-base/813 June 18, 2025 12:10
@graphite-app graphite-app bot force-pushed the adziadziuk/cry-490-fastcompute-implementation-of-gpa-witness-layer-low-to-high branch from 344ff0b to 1de23a6 Compare June 18, 2025 12:10
@graphite-app graphite-app bot force-pushed the graphite-base/813 branch from e0e8aef to f1b3aa2 Compare June 18, 2025 12:10
@graphite-app graphite-app bot changed the base branch from graphite-base/813 to main June 18, 2025 12:11
@graphite-app graphite-app bot force-pushed the adziadziuk/cry-490-fastcompute-implementation-of-gpa-witness-layer-low-to-high branch from 1de23a6 to 07af836 Compare June 18, 2025 12:11
Some(log_num_inputs) => log_num_inputs,
};
let expected_round_outputs_len = log_num_inputs;
if round_outputs.len() != expected_round_outputs_len as usize {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe move the logic verifying the input and output dimensions to a separate helper function to share between the reference and fast implementations?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants