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

refactor: Explicitly instantiate Goblin translator relations #3239

Merged
merged 16 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ add_subdirectory(decrypt_bench)
add_subdirectory(pippenger_bench)
add_subdirectory(plonk_bench)
add_subdirectory(honk_bench)
add_subdirectory(relations_bench)
add_subdirectory(relations_bench)
add_subdirectory(widgets_bench)
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
set(BENCHMARK_SOURCES
barycentric.bench.cpp
relations.bench.cpp
widget.bench.cpp
)

# Required libraries for benchmark suites
set(LINKED_LIBRARIES
polynomials
proof_system
benchmark::benchmark
transcript
stdlib_primitives
)

# Add executable and custom target for each suite, e.g. ultra_honk_bench
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
#include "barretenberg/flavor/goblin_translator.hpp"
#include "barretenberg/flavor/goblin_ultra.hpp"
#include "barretenberg/flavor/ultra.hpp"
#include "barretenberg/relations/auxiliary_relation.hpp"
#include "barretenberg/relations/ecc_op_queue_relation.hpp"
#include "barretenberg/relations/elliptic_relation.hpp"
#include "barretenberg/relations/gen_perm_sort_relation.hpp"
#include "barretenberg/relations/lookup_relation.hpp"
#include "barretenberg/relations/permutation_relation.hpp"
#include "barretenberg/relations/relation_parameters.hpp"
#include "barretenberg/relations/ultra_arithmetic_relation.hpp"
#include <benchmark/benchmark.h>

namespace {
Expand Down Expand Up @@ -78,4 +71,40 @@ void ultra_arithmetic_relation(::benchmark::State& state) noexcept
}
BENCHMARK(ultra_arithmetic_relation);

void translator_decomposition_relation(::benchmark::State& state) noexcept
{
execute_relation<honk::flavor::GoblinTranslator, GoblinTranslatorDecompositionRelation<FF>>(state);
}
BENCHMARK(translator_decomposition_relation);

void translator_opcode_constraint_relation(::benchmark::State& state) noexcept
{
execute_relation<honk::flavor::GoblinTranslator, GoblinTranslatorOpcodeConstraintRelation<FF>>(state);
}
BENCHMARK(translator_opcode_constraint_relation);

void translator_accumulator_transfer_relation(::benchmark::State& state) noexcept
{
execute_relation<honk::flavor::GoblinTranslator, GoblinTranslatorAccumulatorTransferRelation<FF>>(state);
}
BENCHMARK(translator_accumulator_transfer_relation);

void translator_gen_perm_sort_relation(::benchmark::State& state) noexcept
{
execute_relation<honk::flavor::GoblinTranslator, GoblinTranslatorGenPermSortRelation<FF>>(state);
}
BENCHMARK(translator_gen_perm_sort_relation);

void translator_non_native_field_relation(::benchmark::State& state) noexcept
{
execute_relation<honk::flavor::GoblinTranslator, GoblinTranslatorNonNativeFieldRelation<FF>>(state);
}
BENCHMARK(translator_non_native_field_relation);

void translator_permutation_relation(::benchmark::State& state) noexcept
{
execute_relation<honk::flavor::GoblinTranslator, GoblinTranslatorPermutationRelation<FF>>(state);
}
BENCHMARK(translator_permutation_relation);

} // namespace proof_system::benchmark::relations
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Each source represents a separate benchmark suite
set(BENCHMARK_SOURCES
widget.bench.cpp
)

# Required libraries for benchmark suites
set(LINKED_LIBRARIES
polynomials
proof_system
benchmark::benchmark
transcript
stdlib_primitives
)

# Add executable and custom target for each suite, e.g. ultra_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,3 @@
#include <benchmark/benchmark.h>

BENCHMARK_MAIN();
40 changes: 20 additions & 20 deletions barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,28 +1284,28 @@ class ECCVMGrumpkin : public ECCVMBase<barretenberg::g1, curve::Grumpkin, pcs::i
} // namespace flavor
namespace sumcheck {

extern template class ECCVMTranscriptRelationBase<barretenberg::fr>;
extern template class ECCVMWnafRelationBase<barretenberg::fr>;
extern template class ECCVMPointTableRelationBase<barretenberg::fr>;
extern template class ECCVMMSMRelationBase<barretenberg::fr>;
extern template class ECCVMSetRelationBase<barretenberg::fr>;
extern template class ECCVMLookupRelationBase<barretenberg::fr>;
extern template class ECCVMTranscriptRelationImpl<barretenberg::fr>;
extern template class ECCVMWnafRelationImpl<barretenberg::fr>;
extern template class ECCVMPointTableRelationImpl<barretenberg::fr>;
extern template class ECCVMMSMRelationImpl<barretenberg::fr>;
extern template class ECCVMSetRelationImpl<barretenberg::fr>;
extern template class ECCVMLookupRelationImpl<barretenberg::fr>;

DECLARE_SUMCHECK_RELATION_CLASS(ECCVMTranscriptRelationBase, flavor::ECCVM);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMWnafRelationBase, flavor::ECCVM);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMPointTableRelationBase, flavor::ECCVM);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMMSMRelationBase, flavor::ECCVM);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMSetRelationBase, flavor::ECCVM);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationBase, flavor::ECCVM);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMTranscriptRelationImpl, flavor::ECCVM);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMWnafRelationImpl, flavor::ECCVM);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMPointTableRelationImpl, flavor::ECCVM);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMMSMRelationImpl, flavor::ECCVM);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMSetRelationImpl, flavor::ECCVM);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationImpl, flavor::ECCVM);

DECLARE_SUMCHECK_RELATION_CLASS(ECCVMTranscriptRelationBase, flavor::ECCVMGrumpkin);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMWnafRelationBase, flavor::ECCVMGrumpkin);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMPointTableRelationBase, flavor::ECCVMGrumpkin);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMMSMRelationBase, flavor::ECCVMGrumpkin);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMSetRelationBase, flavor::ECCVMGrumpkin);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationBase, flavor::ECCVMGrumpkin);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMTranscriptRelationImpl, flavor::ECCVMGrumpkin);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMWnafRelationImpl, flavor::ECCVMGrumpkin);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMPointTableRelationImpl, flavor::ECCVMGrumpkin);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMMSMRelationImpl, flavor::ECCVMGrumpkin);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMSetRelationImpl, flavor::ECCVMGrumpkin);
DECLARE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationImpl, flavor::ECCVMGrumpkin);

DECLARE_SUMCHECK_PERMUTATION_CLASS(ECCVMSetRelationBase, flavor::ECCVM);
DECLARE_SUMCHECK_PERMUTATION_CLASS(ECCVMSetRelationBase, flavor::ECCVMGrumpkin);
DECLARE_SUMCHECK_PERMUTATION_CLASS(ECCVMSetRelationImpl, flavor::ECCVM);
DECLARE_SUMCHECK_PERMUTATION_CLASS(ECCVMSetRelationImpl, flavor::ECCVMGrumpkin);
} // namespace sumcheck
} // namespace proof_system::honk
22 changes: 21 additions & 1 deletion barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "barretenberg/polynomials/univariate.hpp"
#include "barretenberg/proof_system/arithmetization/arithmetization.hpp"
#include "barretenberg/proof_system/circuit_builder/goblin_translator_circuit_builder.hpp"
#include "barretenberg/relations/relation_parameters.hpp"
#include "barretenberg/relations/translator_vm/translator_decomposition_relation.hpp"
#include "barretenberg/relations/translator_vm/translator_extra_relations.hpp"
#include "barretenberg/relations/translator_vm/translator_gen_perm_sort_relation.hpp"
Expand Down Expand Up @@ -1634,5 +1635,24 @@ template <size_t mini_circuit_size> class GoblinTranslator_ {
};
};

using GoblinTranslatorBasic = GoblinTranslator_<2048>;
using GoblinTranslator = GoblinTranslator_<2048>;

} // namespace proof_system::honk::flavor

namespace proof_system {

extern template class GoblinTranslatorPermutationRelationImpl<barretenberg::fr>;
extern template class GoblinTranslatorGenPermSortRelationImpl<barretenberg::fr>;
extern template class GoblinTranslatorOpcodeConstraintRelationImpl<barretenberg::fr>;
extern template class GoblinTranslatorAccumulatorTransferRelationImpl<barretenberg::fr>;
extern template class GoblinTranslatorDecompositionRelationImpl<barretenberg::fr>;
extern template class GoblinTranslatorNonNativeFieldRelationImpl<barretenberg::fr>;

DECLARE_SUMCHECK_RELATION_CLASS(GoblinTranslatorPermutationRelationImpl, honk::flavor::GoblinTranslator);
DECLARE_SUMCHECK_RELATION_CLASS(GoblinTranslatorGenPermSortRelationImpl, honk::flavor::GoblinTranslator);
DECLARE_SUMCHECK_RELATION_CLASS(GoblinTranslatorOpcodeConstraintRelationImpl, honk::flavor::GoblinTranslator);
DECLARE_SUMCHECK_RELATION_CLASS(GoblinTranslatorAccumulatorTransferRelationImpl, honk::flavor::GoblinTranslator);
DECLARE_SUMCHECK_RELATION_CLASS(GoblinTranslatorDecompositionRelationImpl, honk::flavor::GoblinTranslator);
DECLARE_SUMCHECK_RELATION_CLASS(GoblinTranslatorNonNativeFieldRelationImpl, honk::flavor::GoblinTranslator);

} // namespace proof_system
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@
#define EntityEdge(Flavor) Flavor::AllEntities<Flavor::FF, Flavor::FF>

#define ACCUMULATE(...) _ACCUMULATE(__VA_ARGS__)
#define _ACCUMULATE(Preface, RelationBase, Flavor, AccumulatorType, EdgeType) \
#define _ACCUMULATE(Preface, RelationImpl, Flavor, AccumulatorType, EdgeType) \
Preface template void \
RelationBase<Flavor::FF>::accumulate<proof_system::Relation<RelationBase<Flavor::FF>>::AccumulatorType, \
RelationImpl<Flavor::FF>::accumulate<proof_system::Relation<RelationImpl<Flavor::FF>>::AccumulatorType, \
EdgeType(Flavor)>( \
proof_system::Relation<RelationBase<Flavor::FF>>::AccumulatorType&, \
proof_system::Relation<RelationImpl<Flavor::FF>>::AccumulatorType&, \
EdgeType(Flavor) const&, \
RelationParameters<Flavor::FF> const&, \
Flavor::FF const&);

#define PERMUTATION_METHOD(...) _PERMUTATION_METHOD(__VA_ARGS__)
#define _PERMUTATION_METHOD(Preface, MethodName, RelationBase, Flavor, AccumulatorType, EdgeType) \
Preface template typename proof_system::Relation<RelationBase<Flavor::FF>>::AccumulatorType \
RelationBase<Flavor::FF>::MethodName<proof_system::Relation<RelationBase<Flavor::FF>>::AccumulatorType, \
#define _PERMUTATION_METHOD(Preface, MethodName, RelationImpl, Flavor, AccumulatorType, EdgeType) \
Preface template typename proof_system::Relation<RelationImpl<Flavor::FF>>::AccumulatorType \
RelationImpl<Flavor::FF>::MethodName<proof_system::Relation<RelationImpl<Flavor::FF>>::AccumulatorType, \
EdgeType(Flavor)>(EdgeType(Flavor) const&, \
RelationParameters<Flavor::FF> const&);

#define SUMCHECK_RELATION_CLASS(...) _SUMCHECK_RELATION_CLASS(__VA_ARGS__)
#define _SUMCHECK_RELATION_CLASS(Preface, RelationBase, Flavor) \
ACCUMULATE(Preface, RelationBase, Flavor, SumcheckTupleOfUnivariatesOverSubrelations, ExtendedEdge) \
ACCUMULATE(Preface, RelationBase, Flavor, SumcheckArrayOfValuesOverSubrelations, EvaluationEdge) \
ACCUMULATE(Preface, RelationBase, Flavor, SumcheckArrayOfValuesOverSubrelations, EntityEdge)
#define _SUMCHECK_RELATION_CLASS(Preface, RelationImpl, Flavor) \
ACCUMULATE(Preface, RelationImpl, Flavor, SumcheckTupleOfUnivariatesOverSubrelations, ExtendedEdge) \
ACCUMULATE(Preface, RelationImpl, Flavor, SumcheckArrayOfValuesOverSubrelations, EvaluationEdge) \
ACCUMULATE(Preface, RelationImpl, Flavor, SumcheckArrayOfValuesOverSubrelations, EntityEdge)

#define DECLARE_SUMCHECK_RELATION_CLASS(RelationBase, Flavor) SUMCHECK_RELATION_CLASS(extern, RelationBase, Flavor)
#define DEFINE_SUMCHECK_RELATION_CLASS(RelationBase, Flavor) SUMCHECK_RELATION_CLASS(, RelationBase, Flavor)
#define DECLARE_SUMCHECK_RELATION_CLASS(RelationImpl, Flavor) SUMCHECK_RELATION_CLASS(extern, RelationImpl, Flavor)
#define DEFINE_SUMCHECK_RELATION_CLASS(RelationImpl, Flavor) SUMCHECK_RELATION_CLASS(, RelationImpl, Flavor)

#define SUMCHECK_PERMUTATION_CLASS(...) _SUMCHECK_PERMUTATION_CLASS(__VA_ARGS__)
#define _SUMCHECK_PERMUTATION_CLASS(Preface, RelationBase, Flavor) \
#define _SUMCHECK_PERMUTATION_CLASS(Preface, RelationImpl, Flavor) \
PERMUTATION_METHOD( \
Preface, compute_permutation_numerator, RelationBase, Flavor, UnivariateAccumulator0, ExtendedEdge) \
Preface, compute_permutation_numerator, RelationImpl, Flavor, UnivariateAccumulator0, ExtendedEdge) \
PERMUTATION_METHOD( \
Preface, compute_permutation_numerator, RelationBase, Flavor, ValueAccumulator0, EvaluationEdge) \
PERMUTATION_METHOD(Preface, compute_permutation_numerator, RelationBase, Flavor, ValueAccumulator0, EntityEdge) \
Preface, compute_permutation_numerator, RelationImpl, Flavor, ValueAccumulator0, EvaluationEdge) \
PERMUTATION_METHOD(Preface, compute_permutation_numerator, RelationImpl, Flavor, ValueAccumulator0, EntityEdge) \
PERMUTATION_METHOD( \
Preface, compute_permutation_denominator, RelationBase, Flavor, UnivariateAccumulator0, ExtendedEdge) \
Preface, compute_permutation_denominator, RelationImpl, Flavor, UnivariateAccumulator0, ExtendedEdge) \
PERMUTATION_METHOD( \
Preface, compute_permutation_denominator, RelationBase, Flavor, ValueAccumulator0, EvaluationEdge) \
PERMUTATION_METHOD(Preface, compute_permutation_denominator, RelationBase, Flavor, ValueAccumulator0, EntityEdge)
Preface, compute_permutation_denominator, RelationImpl, Flavor, ValueAccumulator0, EvaluationEdge) \
PERMUTATION_METHOD(Preface, compute_permutation_denominator, RelationImpl, Flavor, ValueAccumulator0, EntityEdge)

#define DECLARE_SUMCHECK_PERMUTATION_CLASS(RelationBase, Flavor) \
SUMCHECK_PERMUTATION_CLASS(extern, RelationBase, Flavor)
#define DEFINE_SUMCHECK_PERMUTATION_CLASS(RelationBase, Flavor) SUMCHECK_PERMUTATION_CLASS(, RelationBase, Flavor)
#define DECLARE_SUMCHECK_PERMUTATION_CLASS(RelationImpl, Flavor) \
SUMCHECK_PERMUTATION_CLASS(extern, RelationImpl, Flavor)
#define DEFINE_SUMCHECK_PERMUTATION_CLASS(RelationImpl, Flavor) SUMCHECK_PERMUTATION_CLASS(, RelationImpl, Flavor)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(proof_system relations polynomials crypto_pedersen_commitment crypto_pedersen_hash)
barretenberg_module(proof_system relations crypto_pedersen_commitment crypto_pedersen_hash)
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/relations/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(relations proof_system)
barretenberg_module(relations polynomials)
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ namespace proof_system::honk::sumcheck {
*/
template <typename FF>
template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
void ECCVMLookupRelationBase<FF>::accumulate(ContainerOverSubrelations& accumulator,
void ECCVMLookupRelationImpl<FF>::accumulate(ContainerOverSubrelations& accumulator,
const AllEntities& in,
const Parameters& params,
[[maybe_unused]] const FF& scaling_factor)
{
lookup_library::accumulate_logderivative_lookup_subrelation_contributions<FF, ECCVMLookupRelationBase<FF>>(
lookup_library::accumulate_logderivative_lookup_subrelation_contributions<FF, ECCVMLookupRelationImpl<FF>>(
accumulator, in, params, scaling_factor);
}

template class ECCVMLookupRelationBase<barretenberg::fr>;
template class ECCVMLookupRelationBase<grumpkin::fr>;
DEFINE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationBase, flavor::ECCVM);
DEFINE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationBase, flavor::ECCVMGrumpkin);
template class ECCVMLookupRelationImpl<barretenberg::fr>;
template class ECCVMLookupRelationImpl<grumpkin::fr>;
DEFINE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationImpl, flavor::ECCVM);
DEFINE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationImpl, flavor::ECCVMGrumpkin);

} // namespace proof_system::honk::sumcheck
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace proof_system::honk::sumcheck {

template <typename FF_> class ECCVMLookupRelationBase {
template <typename FF_> class ECCVMLookupRelationImpl {
public:
using FF = FF_;
static constexpr size_t READ_TERMS = 4;
Expand Down Expand Up @@ -222,6 +222,6 @@ template <typename FF_> class ECCVMLookupRelationBase {
const FF& scaling_factor);
};

template <typename FF> using ECCVMLookupRelation = Relation<ECCVMLookupRelationBase<FF>>;
template <typename FF> using ECCVMLookupRelation = Relation<ECCVMLookupRelationImpl<FF>>;

} // namespace proof_system::honk::sumcheck
Loading