-
Notifications
You must be signed in to change notification settings - Fork 283
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
refactor: protogalaxy relations #1897
Changes from 47 commits
021adfc
868227b
06a796b
9e44ce5
e027cb4
cfad8ad
f707120
2f2def3
0ee5f81
e28045c
6fc8b26
6688556
0b545df
ce06bee
b148b49
9daf7d7
8ef4655
4e6be56
8e9118f
25c4440
3a9307f
72cad4c
defab37
7a803aa
69ab878
b4d11c2
9929cbc
77bf2ad
784e2c5
65da597
3b09315
8459d7d
8917f09
cd71cb9
b808419
5d68b6e
11c3aa6
a669bc1
91dd3d4
fa1f8ad
a37913b
ce3a6c3
45f726b
733ae6a
3d73f64
cc33504
70dec35
ec2a4c8
7ddecb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
add_subdirectory(decrypt_bench) | ||
add_subdirectory(pippenger_bench) | ||
add_subdirectory(plonk_bench) | ||
add_subdirectory(honk_bench) | ||
add_subdirectory(honk_bench) | ||
add_subdirectory(relations_bench) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Each source represents a separate benchmark suite | ||
set(BENCHMARK_SOURCES | ||
barycentric.bench.cpp | ||
relations.bench.cpp | ||
) | ||
|
||
# Required libraries for benchmark suites | ||
set(LINKED_LIBRARIES | ||
polynomials | ||
benchmark::benchmark | ||
) | ||
|
||
# Add executable and custom target for each suite, e.g. standard_honk_bench | ||
foreach(BENCHMARK_SOURCE ${BENCHMARK_SOURCES}) | ||
get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension | ||
add_executable(${BENCHMARK_NAME}_bench main.bench.cpp ${BENCHMARK_SOURCE}) | ||
target_link_libraries(${BENCHMARK_NAME}_bench ${LINKED_LIBRARIES}) | ||
add_custom_target(run_${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) | ||
endforeach() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "barretenberg/ecc/curves/bn254/fr.hpp" | ||
#include "barretenberg/polynomials/barycentric.hpp" | ||
#include <benchmark/benchmark.h> | ||
|
||
using namespace benchmark; | ||
|
||
namespace { | ||
auto& engine = numeric::random::get_debug_engine(); | ||
} | ||
|
||
using FF = barretenberg::fr; | ||
using barretenberg::Univariate; | ||
using barretenberg::BarycentricData; | ||
|
||
|
||
namespace proof_system::benchmark { | ||
|
||
void extend_2_to_6(State& state) noexcept | ||
{ | ||
auto univariate = Univariate<FF, 2>::get_random(); | ||
BarycentricData<FF, 2, 6> barycentric_2_to_6; | ||
for (auto _ : state) | ||
{ | ||
DoNotOptimize(barycentric_2_to_6.extend(univariate)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the purpose of this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From https://github.com/google/benchmark/blob/main/docs/user_guide.md#preventing-optimization
Since the result of |
||
} | ||
} | ||
BENCHMARK(extend_2_to_6); | ||
|
||
} // namespace proof_system::benchmark |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <benchmark/benchmark.h> | ||
|
||
BENCHMARK_MAIN(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include "barretenberg/honk/flavor/goblin_ultra.hpp" | ||
#include "barretenberg/honk/flavor/standard.hpp" | ||
#include "barretenberg/honk/flavor/ultra.hpp" | ||
#include "barretenberg/proof_system/relations/arithmetic_relation.hpp" | ||
#include "barretenberg/proof_system/relations/auxiliary_relation.hpp" | ||
#include "barretenberg/proof_system/relations/ecc_op_queue_relation.hpp" | ||
#include "barretenberg/proof_system/relations/elliptic_relation.hpp" | ||
#include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp" | ||
#include "barretenberg/proof_system/relations/lookup_relation.hpp" | ||
#include "barretenberg/proof_system/relations/permutation_relation.hpp" | ||
#include "barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp" | ||
#include <benchmark/benchmark.h> | ||
|
||
namespace { | ||
auto& engine = numeric::random::get_debug_engine(); | ||
} | ||
|
||
namespace proof_system::benchmark::relations { | ||
|
||
using FF = barretenberg::fr; | ||
|
||
template <typename Flavor, typename Relation> void execute_relation(::benchmark::State& state) | ||
{ | ||
// Generate beta and gamma | ||
auto beta = FF::random_element(); | ||
auto gamma = FF::random_element(); | ||
auto public_input_delta = FF::random_element(); | ||
|
||
RelationParameters<FF> params{ | ||
.beta = beta, | ||
.gamma = gamma, | ||
.public_input_delta = public_input_delta, | ||
}; | ||
|
||
using ClaimedEvaluations = typename Flavor::ClaimedEvaluations; | ||
using RelationValues = typename Relation::RelationValues; | ||
|
||
// Extract an array containing all the polynomial evaluations at a given row i | ||
ClaimedEvaluations new_value; | ||
// Define the appropriate RelationValues type for this relation and initialize to zero | ||
RelationValues accumulator; | ||
// Evaluate each constraint in the relation and check that each is satisfied | ||
|
||
Relation relation; | ||
for (auto _ : state) { | ||
relation.add_full_relation_value_contribution(accumulator, new_value, params); | ||
} | ||
} | ||
|
||
void arithmetic_relation(::benchmark::State& state) noexcept | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll want to measure how the relations improve as we optimize. |
||
{ | ||
execute_relation<honk::flavor::Standard, ArithmeticRelation<FF>>(state); | ||
} | ||
BENCHMARK(arithmetic_relation); | ||
|
||
void auxiliary_relation(::benchmark::State& state) noexcept | ||
{ | ||
execute_relation<honk::flavor::Ultra, AuxiliaryRelation<FF>>(state); | ||
} | ||
BENCHMARK(auxiliary_relation); | ||
|
||
void elliptic_relation(::benchmark::State& state) noexcept | ||
{ | ||
execute_relation<honk::flavor::Ultra, EllipticRelation<FF>>(state); | ||
} | ||
BENCHMARK(elliptic_relation); | ||
|
||
void ecc_op_queue_relation(::benchmark::State& state) noexcept | ||
{ | ||
execute_relation<honk::flavor::GoblinUltra, EccOpQueueRelation<FF>>(state); | ||
} | ||
BENCHMARK(ecc_op_queue_relation); | ||
|
||
void gen_perm_sort_relation(::benchmark::State& state) noexcept | ||
{ | ||
execute_relation<honk::flavor::Ultra, GenPermSortRelation<FF>>(state); | ||
} | ||
BENCHMARK(gen_perm_sort_relation); | ||
|
||
void lookup_relation(::benchmark::State& state) noexcept | ||
{ | ||
execute_relation<honk::flavor::Ultra, LookupRelation<FF>>(state); | ||
} | ||
BENCHMARK(lookup_relation); | ||
|
||
void permutation_relation(::benchmark::State& state) noexcept | ||
{ | ||
execute_relation<honk::flavor::Standard, PermutationRelation<FF>>(state); | ||
} | ||
BENCHMARK(permutation_relation); | ||
|
||
void ultra_arithmetic_relation(::benchmark::State& state) noexcept | ||
{ | ||
execute_relation<honk::flavor::Ultra, UltraArithmeticRelation<FF>>(state); | ||
} | ||
BENCHMARK(ultra_arithmetic_relation); | ||
|
||
} // namespace proof_system::benchmark::relations |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ | |
|
||
#include "barretenberg/honk/composer/standard_composer.hpp" | ||
#include "barretenberg/honk/proof_system/prover.hpp" | ||
#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" | ||
#include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp" | ||
#include "barretenberg/proof_system/relations/permutation_relation.hpp" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved the relations to the |
||
#include "barretenberg/proof_system/relations/relation_parameters.hpp" | ||
#include "barretenberg/honk/sumcheck/sumcheck_round.hpp" | ||
#include "barretenberg/honk/utils/grand_product_delta.hpp" | ||
#include "barretenberg/numeric/uint256/uint256.hpp" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,16 @@ | ||
#pragma once | ||
#include "barretenberg/ecc/curves/bn254/g1.hpp" | ||
#include "barretenberg/honk/pcs/kzg/kzg.hpp" | ||
#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" | ||
#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" | ||
#include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp" | ||
#include "barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp" | ||
#include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp" | ||
#include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp" | ||
#include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp" | ||
#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp" | ||
#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp" | ||
#include "barretenberg/proof_system/relations/auxiliary_relation.hpp" | ||
#include "barretenberg/proof_system/relations/ecc_op_queue_relation.hpp" | ||
#include "barretenberg/proof_system/relations/elliptic_relation.hpp" | ||
#include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp" | ||
#include "barretenberg/proof_system/relations/lookup_relation.hpp" | ||
#include "barretenberg/proof_system/relations/permutation_relation.hpp" | ||
#include "barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp" | ||
#include "barretenberg/honk/transcript/transcript.hpp" | ||
#include "barretenberg/polynomials/evaluation_domain.hpp" | ||
#include "barretenberg/polynomials/polynomial.hpp" | ||
#include "barretenberg/polynomials/univariate.hpp" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved barycentric evaluation/extension and univariate polynomials out of the honk module and into the polynomials module. My motivation (other than cleanliness) was to make it quicker to work on the barycentric class; previously you had to build the entire Honk module. |
||
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" | ||
#include "barretenberg/proof_system/flavor/flavor.hpp" | ||
#include "barretenberg/srs/factories/crs_factory.hpp" | ||
#include <array> | ||
#include <concepts> | ||
#include <span> | ||
#include <string> | ||
#include <type_traits> | ||
#include <vector> | ||
|
||
namespace proof_system::honk::flavor { | ||
|
||
|
@@ -50,16 +39,17 @@ class GoblinUltra { | |
// The total number of witness entities not including shifts. | ||
static constexpr size_t NUM_WITNESS_ENTITIES = 15; // 11 (UH) + 4 op wires | ||
|
||
using GrandProductRelations = std::tuple<sumcheck::UltraPermutationRelation<FF>, sumcheck::LookupRelation<FF>>; | ||
using GrandProductRelations = | ||
std::tuple<proof_system::UltraPermutationRelation<FF>, proof_system::LookupRelation<FF>>; | ||
|
||
// define the tuple of Relations that comprise the Sumcheck relation | ||
using Relations = std::tuple<sumcheck::UltraArithmeticRelation<FF>, | ||
sumcheck::UltraPermutationRelation<FF>, | ||
sumcheck::LookupRelation<FF>, | ||
sumcheck::GenPermSortRelation<FF>, | ||
sumcheck::EllipticRelation<FF>, | ||
sumcheck::AuxiliaryRelation<FF>, | ||
sumcheck::EccOpQueueRelation<FF>>; | ||
using Relations = std::tuple<proof_system::UltraArithmeticRelation<FF>, | ||
proof_system::UltraPermutationRelation<FF>, | ||
proof_system::LookupRelation<FF>, | ||
proof_system::GenPermSortRelation<FF>, | ||
proof_system::EllipticRelation<FF>, | ||
proof_system::AuxiliaryRelation<FF>, | ||
proof_system::EccOpQueueRelation<FF>>; | ||
|
||
static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length<Relations>(); | ||
|
||
|
@@ -338,8 +328,8 @@ class GoblinUltra { | |
* @todo TODO(#390): Simplify this by moving MAX_RELATION_LENGTH? | ||
*/ | ||
template <size_t MAX_RELATION_LENGTH> | ||
using ExtendedEdges = | ||
AllEntities<sumcheck::Univariate<FF, MAX_RELATION_LENGTH>, sumcheck::Univariate<FF, MAX_RELATION_LENGTH>>; | ||
using ExtendedEdges = AllEntities<barretenberg::Univariate<FF, MAX_RELATION_LENGTH>, | ||
barretenberg::Univariate<FF, MAX_RELATION_LENGTH>>; | ||
|
||
/** | ||
* @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used this to compare the optimization I put in
BarycentricData
to make extension from degree 2 very efficient. It gives approximately a 10x improvement, in one measurement, 417ns to 40ns.