Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
interaction_builder.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <memory>
4
#include <optional>
5
#include <vector>
6
7
#include "
barretenberg/vm2/generated/columns.hpp
"
8
#include "
barretenberg/vm2/tracegen/lib/shared_index_cache.hpp
"
9
#include "
barretenberg/vm2/tracegen/trace_container.hpp
"
10
11
namespace
bb::avm2::tracegen
{
12
13
// Helper to generate a tuple type with N const FF& elements.
14
namespace
detail {
15
template
<
size_t
N,
typename
= std::make_index_sequence<N>>
struct
RefTupleHelper
;
16
template
<
size_t
N,
size_t
... Is>
struct
RefTupleHelper
<N,
std
::index_sequence<Is...>> {
17
template
<
size_t
>
using
ConstFFRef
=
const
FF
&;
18
using
type
=
flat_tuple::tuple<ConstFFRef<Is>
...>;
19
};
20
}
// namespace detail
21
template
<
size_t
N>
using
RefTuple
=
typename
detail::RefTupleHelper<N>::type
;
22
23
class
InteractionBuilderInterface
{
24
public
:
25
virtual
~InteractionBuilderInterface
() =
default
;
26
virtual
void
process
(
TraceContainer
& trace) = 0;
27
// Fingerprint of the destination columns.
28
// Used to identify jobs that share the same destination columns and prevent them
29
// from building the index at the same time.
30
virtual
size_t
get_destination_columns_fingerprint
()
const
{
return
0; }
31
};
32
33
// A concatenate that works with movable objects.
34
template
<
typename
T>
std::vector<T>
concatenate_jobs
(
std::vector<T>
&& first,
auto
&&... rest)
35
{
36
std::vector<T>
result =
std::move
(first);
37
result.reserve(first.size() + (rest.size() + ...));
38
(
std::move
(rest.begin(), rest.end(),
std::back_inserter
(result)), ...);
39
return
result;
40
}
41
42
// Orders jobs to minimize index building contention.
43
// Jobs with first occurrences of each destination column key come first, followed by jobs that share
44
// destination column keys with previously seen ones.
45
// This ordering helps the SharedIndexCache by ensuring that when multiple jobs share
46
// the same destination, only the first one builds the index while others wait.
47
void
order_jobs_by_destination_columns
(std::vector<
std::unique_ptr<InteractionBuilderInterface>
>& jobs);
48
49
}
// namespace bb::avm2::tracegen
bb::avm2::tracegen::InteractionBuilderInterface
Definition
interaction_builder.hpp:23
bb::avm2::tracegen::InteractionBuilderInterface::get_destination_columns_fingerprint
virtual size_t get_destination_columns_fingerprint() const
Definition
interaction_builder.hpp:30
bb::avm2::tracegen::InteractionBuilderInterface::~InteractionBuilderInterface
virtual ~InteractionBuilderInterface()=default
bb::avm2::tracegen::InteractionBuilderInterface::process
virtual void process(TraceContainer &trace)=0
bb::avm2::tracegen::TraceContainer
Definition
trace_container.hpp:24
columns.hpp
bb::avm2::tracegen
Definition
full_row.hpp:9
bb::avm2::tracegen::RefTuple
typename detail::RefTupleHelper< N >::type RefTuple
Definition
interaction_builder.hpp:21
bb::avm2::tracegen::order_jobs_by_destination_columns
void order_jobs_by_destination_columns(std::vector< std::unique_ptr< InteractionBuilderInterface > > &jobs)
Definition
interaction_builder.cpp:9
bb::avm2::tracegen::concatenate_jobs
std::vector< T > concatenate_jobs(std::vector< T > &&first, auto &&... rest)
Definition
interaction_builder.hpp:34
bb::avm2::FF
AvmFlavorSettings::FF FF
Definition
field.hpp:10
std
STL namespace.
std::get
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition
tuple.hpp:13
shared_index_cache.hpp
bb::avm2::tracegen::detail::RefTupleHelper< N, std::index_sequence< Is... > >::ConstFFRef
const FF & ConstFFRef
Definition
interaction_builder.hpp:17
bb::avm2::tracegen::detail::RefTupleHelper
Definition
interaction_builder.hpp:15
tuplet::tuple
Definition
tuplet.hpp:610
trace_container.hpp
src
barretenberg
vm2
tracegen
lib
interaction_builder.hpp
Generated by
1.9.8