Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
Functions
profile_routing_gadgets.cpp File Reference
#include <algorithm>
#include <libff/common/default_types/ec_pp.hpp>
#include <libff/common/profiling.hpp>
#include <libsnark/gadgetlib1/gadgets/routing/as_waksman_routing_gadget.hpp>
#include <libsnark/gadgetlib1/gadgets/routing/benes_routing_gadget.hpp>
Include dependency graph for profile_routing_gadgets.cpp:

Go to the source code of this file.

Functions

template<typename FieldT >
void get_as_waksman_size (const size_t n, const size_t l, size_t &num_constraints, size_t &num_variables)
 
template<typename FieldT >
void get_benes_size (const size_t n, const size_t l, size_t &num_constraints, size_t &num_variables)
 
template<typename FieldT >
void profile_routing_gadgets (const size_t l)
 
template<typename FieldT >
void profile_num_switches (const size_t l)
 
int main ()
 

Detailed Description

Functions to profile the gadgetlib1 implementations of Benes and AS-Waksman routing networks.

Author
This file is part of libsnark, developed by SCIPR Lab and contributors (see AUTHORS).

Definition in file profile_routing_gadgets.cpp.

Function Documentation

◆ get_as_waksman_size()

template<typename FieldT >
void get_as_waksman_size ( const size_t  n,
const size_t  l,
size_t &  num_constraints,
size_t &  num_variables 
)

Definition at line 22 of file profile_routing_gadgets.cpp.

27 {
29 
30  std::vector<pb_variable_array<FieldT>> randbits(n), outbits(n);
31  for (size_t y = 0; y < n; ++y) {
32  randbits[y].allocate(pb, l, FMT("", "randbits_%zu", y));
33  outbits[y].allocate(pb, l, FMT("", "outbits_%zu", y));
34  }
35 
37  pb, n, randbits, outbits, "main_routing_gadget");
38  r.generate_r1cs_constraints();
39 
40  num_constraints = pb.num_constraints();
41  num_variables = pb.num_variables();
42 }
Here is the call graph for this function:

◆ get_benes_size()

template<typename FieldT >
void get_benes_size ( const size_t  n,
const size_t  l,
size_t &  num_constraints,
size_t &  num_variables 
)

Definition at line 45 of file profile_routing_gadgets.cpp.

50 {
51  const size_t t = libff::log2(n);
52  assert(n == 1ul << t);
53 
55 
56  std::vector<pb_variable_array<FieldT>> randbits(1ul << t),
57  outbits(1ul << t);
58  for (size_t y = 0; y < 1ul << t; ++y) {
59  randbits[y].allocate(pb, l, FMT("", "randbits_%zu", y));
60  outbits[y].allocate(pb, l, FMT("", "outbits_%zu", y));
61  }
62 
64  pb, n, randbits, outbits, n, "main_routing_gadget");
65  r.generate_r1cs_constraints();
66 
67  num_constraints = pb.num_constraints();
68  num_variables = pb.num_variables();
69 }
Here is the call graph for this function:

◆ main()

int main ( )

Definition at line 127 of file profile_routing_gadgets.cpp.

128 {
129  libff::start_profiling();
130  libff::default_ec_pp::init_public_params();
131  profile_routing_gadgets<libff::Fr<libff::default_ec_pp>>(32 + 16 + 3 + 2);
132  profile_num_switches<libff::Fr<libff::default_ec_pp>>(1);
133 }

◆ profile_num_switches()

template<typename FieldT >
void profile_num_switches ( const size_t  l)

Definition at line 98 of file profile_routing_gadgets.cpp.

99 {
100  printf("profiling number of switches in arbitrary size networks (and "
101  "rounded-up for Benes)\n");
102  for (size_t n = 2; n <= 65; ++n) {
103  size_t as_waksman_constr, as_waksman_vars;
104  get_as_waksman_size<FieldT>(n, l, as_waksman_constr, as_waksman_vars);
105 
106  const size_t rounded_n = 1ul << libff::log2(n);
107  size_t benes_constr, benes_vars;
108  get_benes_size<FieldT>(rounded_n, l, benes_constr, benes_vars);
109 
110  const size_t as_waksman_switches =
111  (as_waksman_constr - n * (2 + l)) / 2;
112  const size_t benes_switches = (benes_constr - rounded_n * (2 + l)) / 2;
113  // const size_t benes_expected = libff::log2(rounded_n)*rounded_n; //
114  // switch-Benes has (-rounded_n/2) term
115  printf(
116  "n = %zu (rounded_n = %zu), l = %zu, benes_switches = %zu, "
117  "as_waksman_switches = %zu, ratio = %0.3f\n",
118  n,
119  rounded_n,
120  l,
121  benes_switches,
122  as_waksman_switches,
123  1. * benes_switches / as_waksman_switches);
124  }
125 }

◆ profile_routing_gadgets()

template<typename FieldT >
void profile_routing_gadgets ( const size_t  l)

Definition at line 71 of file profile_routing_gadgets.cpp.

72 {
73  printf("profiling number of constraints for powers-of-2\n");
74  for (size_t n = 2; n <= 65; ++n) {
75  size_t as_waksman_constr, as_waksman_vars;
76  get_as_waksman_size<FieldT>(n, l, as_waksman_constr, as_waksman_vars);
77 
78  const size_t rounded_n = 1ul << libff::log2(n);
79  size_t benes_constr, benes_vars;
80  get_benes_size<FieldT>(rounded_n, l, benes_constr, benes_vars);
81 
82  printf(
83  "n = %zu (rounded = %zu), l = %zu, benes_constr = %zu, benes_vars "
84  "= %zu, as_waksman_constr = %zu, as_waksman_vars = %zu, "
85  "constr_ratio = %0.3f, var_ratio = %0.3f\n",
86  n,
87  rounded_n,
88  l,
89  benes_constr,
90  benes_vars,
91  as_waksman_constr,
92  as_waksman_vars,
93  1. * benes_constr / as_waksman_constr,
94  1. * benes_vars / as_waksman_vars);
95  }
96 }
libsnark::protoboard::num_constraints
size_t num_constraints() const
libsnark::benes_routing_gadget
Definition: benes_routing_gadget.hpp:26
libsnark::protoboard::num_variables
size_t num_variables() const
libsnark::as_waksman_routing_gadget
Definition: as_waksman_routing_gadget.hpp:27
libsnark::protoboard
Definition: pb_variable.hpp:22