Skip to content

Commit

Permalink
chore(avm): migrate lookups and permutations (#7335)
Browse files Browse the repository at this point in the history
  • Loading branch information
fcarreiro authored Jul 4, 2024
1 parent c0c9144 commit 56fe4fe
Show file tree
Hide file tree
Showing 59 changed files with 252 additions and 4,839 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#pragma once

#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp"
Expand All @@ -25,81 +23,20 @@ namespace bb {
*/
class incl_main_tag_err_lookup_settings {
public:
/**
* @brief The number of read terms (how many lookups we perform) in each row
*
*/
static constexpr size_t READ_TERMS = 1;
/**
* @brief The number of write terms (how many additions to the lookup table we make) in each row
*
*/
static constexpr size_t WRITE_TERMS = 1;

/**
* @brief The type of READ_TERM used for each read index (basic and scaled)
*
*/
static constexpr size_t READ_TERM_TYPES[READ_TERMS] = { 0 };

/**
* @brief They type of WRITE_TERM used for each write index
*
*/
static constexpr size_t WRITE_TERM_TYPES[WRITE_TERMS] = { 0 };

/**
* @brief How many values represent a single lookup object. This value is used by the automatic read term
* implementation in the relation in case the lookup is a basic or scaled tuple and in the write term if it's a
* basic tuple
*
*/
static constexpr size_t LOOKUP_TUPLE_SIZE = 1;

/**
* @brief The polynomial degree of the relation telling us if the inverse polynomial value needs to be computed
*
*/
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4;

/**
* @brief The degree of the read term if implemented arbitrarily. This value is not used by basic and scaled read
* terms, but will cause compilation error if not defined
*
*/
static constexpr size_t READ_TERM_DEGREE = 0;

/**
* @brief The degree of the write term if implemented arbitrarily. This value is not used by the basic write
* term, but will cause compilation error if not defined
*
*/

static constexpr size_t WRITE_TERM_DEGREE = 0;

/**
* @brief If this method returns true on a row of values, then the inverse polynomial exists at this index.
* Otherwise the value needs to be set to zero.
*
* @details If this is true then the lookup takes place in this row
*
*/

template <typename AllEntities> static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in)
{
return (in.mem_tag_err == 1 || in.main_tag_err == 1);
}

/**
* @brief Subprocedure for computing the value deciding if the inverse polynomial value needs to be checked in this
* row
*
* @tparam Accumulator Type specified by the lookup relation
* @tparam AllEntities Values/Univariates of all entities row
* @param in Value/Univariate of all entities at row/edge
* @return Accumulator
*/

template <typename Accumulator, typename AllEntities>
static inline auto compute_inverse_exists(const AllEntities& in)
{
Expand All @@ -109,30 +46,8 @@ class incl_main_tag_err_lookup_settings {
return (is_operation + is_table_entry - is_operation * is_table_entry);
}

/**
* @brief Get all the entities for the lookup when need to update them
*
* @details The generic structure of this tuple is described in ./generic_lookup_relation.hpp . The following is
description for the current case:
The entities are returned as a tuple of references in the following order (this is for ):
* - The entity/polynomial used to store the product of the inverse values
* - The entity/polynomial that specifies how many times the lookup table entry at this row has been looked up
* - READ_TERMS entities/polynomials that enable individual lookup operations
* - The entity/polynomial that enables adding an entry to the lookup table in this row
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the basic tuple being looked up as the first read term
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the previous accumulators in the second read term
(scaled tuple)
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the shifts in the second read term (scaled tuple)
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the current accumulators in the second read term
(scaled tuple)
* - LOOKUP_TUPLE_SIZE entities/polynomials representing basic tuples added to the table
*
* @return All the entities needed for the lookup
*/

template <typename AllEntities> static inline auto get_const_entities(const AllEntities& in)
{

return std::forward_as_tuple(in.incl_main_tag_err,
in.incl_main_tag_err_counts,
in.mem_tag_err,
Expand All @@ -141,16 +56,8 @@ class incl_main_tag_err_lookup_settings {
in.main_clk);
}

/**
* @brief Get all the entities for the lookup when we only need to read them
* @details Same as in get_const_entities, but nonconst
*
* @return All the entities needed for the lookup
*/

template <typename AllEntities> static inline auto get_nonconst_entities(AllEntities& in)
{

return std::forward_as_tuple(in.incl_main_tag_err,
in.incl_main_tag_err_counts,
in.mem_tag_err,
Expand All @@ -164,4 +71,4 @@ template <typename FF_>
using incl_main_tag_err_relation = GenericLookupRelation<incl_main_tag_err_lookup_settings, FF_>;
template <typename FF_> using incl_main_tag_err = GenericLookup<incl_main_tag_err_lookup_settings, FF_>;

} // namespace bb
} // namespace bb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#pragma once

#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp"
Expand All @@ -25,81 +23,20 @@ namespace bb {
*/
class incl_mem_tag_err_lookup_settings {
public:
/**
* @brief The number of read terms (how many lookups we perform) in each row
*
*/
static constexpr size_t READ_TERMS = 1;
/**
* @brief The number of write terms (how many additions to the lookup table we make) in each row
*
*/
static constexpr size_t WRITE_TERMS = 1;

/**
* @brief The type of READ_TERM used for each read index (basic and scaled)
*
*/
static constexpr size_t READ_TERM_TYPES[READ_TERMS] = { 0 };

/**
* @brief They type of WRITE_TERM used for each write index
*
*/
static constexpr size_t WRITE_TERM_TYPES[WRITE_TERMS] = { 0 };

/**
* @brief How many values represent a single lookup object. This value is used by the automatic read term
* implementation in the relation in case the lookup is a basic or scaled tuple and in the write term if it's a
* basic tuple
*
*/
static constexpr size_t LOOKUP_TUPLE_SIZE = 1;

/**
* @brief The polynomial degree of the relation telling us if the inverse polynomial value needs to be computed
*
*/
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4;

/**
* @brief The degree of the read term if implemented arbitrarily. This value is not used by basic and scaled read
* terms, but will cause compilation error if not defined
*
*/
static constexpr size_t READ_TERM_DEGREE = 0;

/**
* @brief The degree of the write term if implemented arbitrarily. This value is not used by the basic write
* term, but will cause compilation error if not defined
*
*/

static constexpr size_t WRITE_TERM_DEGREE = 0;

/**
* @brief If this method returns true on a row of values, then the inverse polynomial exists at this index.
* Otherwise the value needs to be set to zero.
*
* @details If this is true then the lookup takes place in this row
*
*/

template <typename AllEntities> static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in)
{
return (in.main_tag_err == 1 || in.mem_tag_err == 1);
}

/**
* @brief Subprocedure for computing the value deciding if the inverse polynomial value needs to be checked in this
* row
*
* @tparam Accumulator Type specified by the lookup relation
* @tparam AllEntities Values/Univariates of all entities row
* @param in Value/Univariate of all entities at row/edge
* @return Accumulator
*/

template <typename Accumulator, typename AllEntities>
static inline auto compute_inverse_exists(const AllEntities& in)
{
Expand All @@ -109,44 +46,14 @@ class incl_mem_tag_err_lookup_settings {
return (is_operation + is_table_entry - is_operation * is_table_entry);
}

/**
* @brief Get all the entities for the lookup when need to update them
*
* @details The generic structure of this tuple is described in ./generic_lookup_relation.hpp . The following is
description for the current case:
The entities are returned as a tuple of references in the following order (this is for ):
* - The entity/polynomial used to store the product of the inverse values
* - The entity/polynomial that specifies how many times the lookup table entry at this row has been looked up
* - READ_TERMS entities/polynomials that enable individual lookup operations
* - The entity/polynomial that enables adding an entry to the lookup table in this row
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the basic tuple being looked up as the first read term
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the previous accumulators in the second read term
(scaled tuple)
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the shifts in the second read term (scaled tuple)
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the current accumulators in the second read term
(scaled tuple)
* - LOOKUP_TUPLE_SIZE entities/polynomials representing basic tuples added to the table
*
* @return All the entities needed for the lookup
*/

template <typename AllEntities> static inline auto get_const_entities(const AllEntities& in)
{

return std::forward_as_tuple(
in.incl_mem_tag_err, in.incl_mem_tag_err_counts, in.main_tag_err, in.mem_tag_err, in.main_clk, in.mem_clk);
}

/**
* @brief Get all the entities for the lookup when we only need to read them
* @details Same as in get_const_entities, but nonconst
*
* @return All the entities needed for the lookup
*/

template <typename AllEntities> static inline auto get_nonconst_entities(AllEntities& in)
{

return std::forward_as_tuple(
in.incl_mem_tag_err, in.incl_mem_tag_err_counts, in.main_tag_err, in.mem_tag_err, in.main_clk, in.mem_clk);
}
Expand All @@ -155,4 +62,4 @@ class incl_mem_tag_err_lookup_settings {
template <typename FF_> using incl_mem_tag_err_relation = GenericLookupRelation<incl_mem_tag_err_lookup_settings, FF_>;
template <typename FF_> using incl_mem_tag_err = GenericLookup<incl_mem_tag_err_lookup_settings, FF_>;

} // namespace bb
} // namespace bb
Loading

1 comment on commit 56fe4fe

@AztecBot
Copy link
Collaborator

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'C++ Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.05.

Benchmark suite Current: 56fe4fe Previous: 34d6b8c Ratio
nativeClientIVCBench/Full/6 14968.921465999983 ms/iter 14121.747173000018 ms/iter 1.06
nativeconstruct_proof_ultrahonk_power_of_2/20 5638.221430000001 ms/iter 4740.092910999991 ms/iter 1.19
wasmconstruct_proof_ultrahonk_power_of_2/20 15316.458028000001 ms/iter 14488.878971999999 ms/iter 1.06

This comment was automatically generated by workflow using github-action-benchmark.

CC: @ludamad @codygunton

Please sign in to comment.