forked from bristolcrypto/SPDZ-2
-
Notifications
You must be signed in to change notification settings - Fork 272
/
Machine.hpp
113 lines (95 loc) · 2.35 KB
/
Machine.hpp
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
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Machine.cpp
*
*/
#ifndef GC_MACHINE_HPP_
#define GC_MACHINE_HPP_
#include <GC/Machine.h>
#include "GC/Program.h"
#include "ThreadMaster.h"
#include "Program.hpp"
namespace GC
{
template <class T>
Machine<T>::Machine()
{
use_encryption = false;
more_comm_less_comp = false;
start_timer();
}
template<class T>
Machine<T>::~Machine()
{
#ifdef VERBOSE
for (auto it = timer.begin(); it != timer.end(); it++)
cerr << T::phase_name() << " timer " << it->first << " at end: "
<< it->second.elapsed() << " seconds" << endl;
#endif
}
template<class T>
size_t Machine<T>::load_program(const string& threadname,
const string& filename)
{
(void)threadname;
progs.push_back({});
progs.back().parse_file(filename);
reset(progs.back());
return progs.back().size();
}
template<class T>
void Machine<T>::load_schedule(const string& progname)
{
BaseMachine::load_schedule(progname);
print_compiler();
}
template <class T>
template <class U>
void Memories<T>::reset(const U& program)
{
MS.resize_min(program.direct_mem(SBIT), "memory");
MC.resize_min(program.direct_mem(CBIT), "memory");
}
template <class T>
template <class U>
void Machine<T>::reset(const U& program)
{
Memories<T>::reset(program);
MI.resize_min(program.direct_mem(INT), "memory");
}
template <class T>
template <class U, class V>
void Machine<T>::reset(const U& program, V& MD)
{
reset(program);
MD.resize_min(program.direct_mem(DYN_SBIT), "dynamic memory");
#ifdef DEBUG_MEMORY
cerr << "reset dynamic mem to " << program.direct_mem(DYN_SBIT) << endl;
#endif
}
template<class T>
void Machine<T>::run_tapes(const vector<int>& args)
{
assert(args.size() % 3 == 0);
for (unsigned i = 0; i < args.size(); i += 3)
run_tape(args[i], args[i + 1], args[i + 2]);
}
template<class T>
void Machine<T>::run_tape(int thread_number, int tape_number, int arg)
{
ThreadMaster<T>::s().run_tape(thread_number, tape_number, arg);
}
template<class T>
void Machine<T>::join_tape(int thread_number)
{
ThreadMaster<T>::s().join_tape(thread_number);
}
template<class T>
void Memories<T>::write_memory(int my_num)
{
ofstream outf(BaseMachine::memory_filename("B", my_num));
outf << 0 << endl;
outf << MC.size() << endl << MC;
outf << 0 << endl << 0 << endl << 0 << endl << 0 << endl;
}
} /* namespace GC */
#endif