This repository has been archived by the owner on May 30, 2023. It is now read-only.
forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleGenerator.cpp
101 lines (92 loc) · 3.36 KB
/
SimpleGenerator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* SimpleThread.cpp
*
*/
#include <FHEOffline/SimpleGenerator.h>
#include "FHEOffline/SimpleMachine.h"
#include "FHEOffline/Sacrificing.h"
#include "Protocols/MAC_Check.h"
#include "Protocols/MAC_Check.hpp"
template <template <class> class T, class FD>
SimpleGenerator<T,FD>::SimpleGenerator(const Names& N, const PartSetup<FD>& setup,
const MultiplicativeMachineParams& machine,
int thread_num, Dtype data_type, Player* player) :
GeneratorBase(thread_num, N, player),
setup(setup), machine(machine),
volatile_memory(0), dd(P, setup),
EC(P, setup.pk, setup.FieldD, timers, machine, thread_num)
{
string prep_dir = machine.get_prep_dir<FD>(P);
if (machine.produce_inputs)
producer = new InputProducer<FD>(P, thread_num, machine.output, prep_dir);
else
switch (data_type)
{
case DATA_TRIPLE:
producer = new TripleProducer_<FD>(setup.FieldD, P.my_num(),
thread_num, machine.output, prep_dir);
break;
case DATA_SQUARE:
producer = new SquareProducer<FD>(setup.FieldD, P.my_num(),
thread_num, machine.output, prep_dir);
break;
case DATA_BIT:
producer = new_bit_producer(setup.FieldD, P, setup.pk, machine.get_covert(), true,
thread_num, machine.output, prep_dir);
break;
case DATA_INVERSE:
producer = new InverseProducer<FD>(setup.FieldD, P.my_num(),
thread_num, machine.output, true, prep_dir);
break;
default:
throw runtime_error("data type not implemented");
}
}
template <template <class> class T, class FD>
SimpleGenerator<T,FD>::~SimpleGenerator()
{
delete producer;
}
template <template <class> class T, class FD>
void SimpleGenerator<T,FD>::run(bool exhaust)
{
Timer timer(CLOCK_THREAD_CPUTIME_ID);
timer.start();
timers["MC init"].start();
MAC_Check<typename FD::T> MC(setup.alphai);
timers["MC init"].stop();
producer->clear();
total = 0;
while (total < machine.nTriplesPerThread or (exhaust and EC.has_left()))
{
producer->run(P, setup.pk, setup.calpha, EC, dd, setup.alphai);
producer->sacrifice(P, MC);
total += producer->num_slots();
}
MC.Check(P);
timer.stop();
timers["Thread"] = timer;
timers.insert(producer->timers.begin(), producer->timers.end());
timers["Networking"] = P.timer;
}
template <template <class> class T, class FD>
size_t SimpleGenerator<T,FD>::report_size(ReportType type)
{
return EC.report_size(type) + EC.get_volatile()
+ producer->report_size(type) + dd.report_size(type)
+ volatile_memory;
}
template <template <class> class T, class FD>
void SimpleGenerator<T,FD>::report_size(ReportType type, MemoryUsage& res)
{
EC.report_size(type, res);
res.add("producer", producer->report_size(type));
res.add("generator volatile", volatile_memory);
res.add("distributed decryption", dd.report_size(type));
}
template class SimpleGenerator<SimpleEncCommit_, FFT_Data>;
template class SimpleGenerator<SummingEncCommit, FFT_Data>;
template class SimpleGenerator<EncCommit_, FFT_Data>;
template class SimpleGenerator<SimpleEncCommit_, P2Data>;
template class SimpleGenerator<SummingEncCommit, P2Data>;
template class SimpleGenerator<EncCommit_, P2Data>;