Skip to content

Commit

Permalink
Trying to reduce lookup argument memory consumption.
Browse files Browse the repository at this point in the history
  • Loading branch information
martun committed Dec 22, 2023
1 parent d2962e4 commit 2c0b998
Showing 1 changed file with 39 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,9 @@ namespace nil {
one_polynomial - preprocessed_data.q_last - preprocessed_data.q_blind;

// Prepare lookup value
std::vector<math::polynomial_dfs<typename FieldType::value_type>> lookup_value;
for(std::size_t t_id = 0; t_id < lookup_tables.size(); t_id++){
auto lookup_value_ptr = std::make_unique<std::vector<math::polynomial_dfs<typename FieldType::value_type>>>();
auto& lookup_value = *lookup_value_ptr;
for(std::size_t t_id = 0; t_id < lookup_tables.size(); t_id++) {
const plonk_lookup_table<FieldType> &l_table = lookup_tables[t_id];
const math::polynomial_dfs<typename FieldType::value_type> &lookup_tag = plonk_columns.selector(l_table.tag_index);
for( std::size_t o_id = 0; o_id < l_table.lookup_options.size(); o_id++ ){
Expand All @@ -308,7 +309,8 @@ namespace nil {
}

// Prepare lookup input
std::vector<math::polynomial_dfs<typename FieldType::value_type>> lookup_input;
auto lookup_input_ptr = std::make_unique<std::vector<math::polynomial_dfs<typename FieldType::value_type>>>();
auto& lookup_input = *lookup_input_ptr;
for( const auto &gate:lookup_gates ){
math::expression<DfsVariableType> expr;
math::polynomial_dfs<typename FieldType::value_type> lookup_selector = plonk_columns.selector(gate.tag_index);
Expand All @@ -329,11 +331,14 @@ namespace nil {
// 3. Lookup_input and lookup_value are ready
// Now sort them!
// Reduce value and input:
std::vector<math::polynomial_dfs<typename FieldType::value_type>> reduced_value;
auto reduced_value_ptr = std::make_unique<std::vector<math::polynomial_dfs<typename FieldType::value_type>>>();
auto& reduced_value = *reduced_value_ptr;

for( std::size_t i = 0; i < lookup_value.size(); i++ ){
reduced_value.push_back(reduce_dfs_polynomial_domain(lookup_value[i], basic_domain->m));
}
std::vector<math::polynomial_dfs<typename FieldType::value_type>> reduced_input;
auto reduced_input_ptr = std::make_unique<std::vector<math::polynomial_dfs<typename FieldType::value_type>>>();
auto& reduced_input = *reduced_input_ptr;

for( std::size_t i = 0; i < lookup_input.size(); i++ ){
reduced_input.push_back(reduce_dfs_polynomial_domain(lookup_input[i], basic_domain->m));
Expand Down Expand Up @@ -377,33 +382,47 @@ namespace nil {
}
V_L[k] *= h_tmp.inversed();
}

// We don't use reduced_input and reduced_value after this line.
reduced_input_ptr.reset(nullptr);
reduced_value_ptr.reset(nullptr);

commitment_scheme.append_to_batch(PERMUTATION_BATCH, V_L);

BOOST_CHECK(V_L[preprocessed_data.common_data.usable_rows_amount] == FieldType::value_type::one());

math::polynomial_dfs<typename FieldType::value_type> g = math::polynomial_dfs<typename FieldType::value_type>::one();
g *= (one+beta).pow(lookup_input.size());

std::vector<math::polynomial_dfs<typename FieldType::value_type>> g_multipliers;
for( std::size_t i = 0; i < lookup_input.size(); i++) {
g_multipliers.push_back(gamma + lookup_input[i]);
}
{
std::vector<math::polynomial_dfs<typename FieldType::value_type>> g_multipliers;
for( std::size_t i = 0; i < lookup_input.size(); i++) {
g_multipliers.push_back(gamma + lookup_input[i]);
}
// We don't use lookup_input after this line.
lookup_input_ptr.reset(nullptr);

auto part1 = (one+beta) * gamma;
for( std::size_t i = 0; i < lookup_value.size(); i++ ){
auto lookup_shifted = math::polynomial_shift(lookup_value[i], 1, basic_domain->m);
g_multipliers.push_back( part1 + lookup_value[i] + beta * lookup_shifted);
}
auto part1 = (one+beta) * gamma;
for( std::size_t i = 0; i < lookup_value.size(); i++ ){
auto lookup_shifted = math::polynomial_shift(lookup_value[i], 1, basic_domain->m);
g_multipliers.push_back( part1 + lookup_value[i] + beta * lookup_shifted);
}

// We don't use lookup Value after this line.
lookup_value_ptr.reset(nullptr);

g *= polynomial_product(std::move(g_multipliers));
g *= polynomial_product(std::move(g_multipliers));
}

math::polynomial_dfs<typename FieldType::value_type> h;
std::vector<math::polynomial_dfs<typename FieldType::value_type>> h_multipliers;
for( std::size_t i = 0; i < sorted.size(); i++){
auto sorted_shifted = math::polynomial_shift(sorted[i], 1, basic_domain->m);
h_multipliers.push_back((one+beta) * gamma + sorted[i] + beta * sorted_shifted);
{
std::vector<math::polynomial_dfs<typename FieldType::value_type>> h_multipliers;
for( std::size_t i = 0; i < sorted.size(); i++){
auto sorted_shifted = math::polynomial_shift(sorted[i], 1, basic_domain->m);
h_multipliers.push_back((one+beta) * gamma + sorted[i] + beta * sorted_shifted);
}
h = polynomial_product(h_multipliers);
}
h = polynomial_product(h_multipliers);

math::polynomial_dfs<typename FieldType::value_type> V_L_shifted =
math::polynomial_shift(V_L, 1, basic_domain->m);
Expand Down

0 comments on commit 2c0b998

Please sign in to comment.