forked from bristolcrypto/SPDZ-2
-
Notifications
You must be signed in to change notification settings - Fork 272
/
YaoCommon.h
79 lines (61 loc) · 1.5 KB
/
YaoCommon.h
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
/*
* YaoCommon.h
*
*/
#ifndef YAO_YAOCOMMON_H_
#define YAO_YAOCOMMON_H_
#include <stdexcept>
#include <math.h>
#include <vector>
#include <array>
#include "Tools/Exceptions.h"
#include "GC/RuntimeBranching.h"
#include "GC/ThreadMaster.h"
#include "YaoAndJob.h"
#include <thread>
template<class T>
class YaoCommon : public GC::RuntimeBranching
{
int log_n_threads;
GC::ThreadMaster<GC::Secret<T>>& master;
public:
static const int DONE = -1;
static const int MORE = -2;
long counter;
vector<YaoAndJob<T>*> jobs;
YaoCommon(GC::ThreadMaster<GC::Secret<T>>& master) :
log_n_threads(8), master(master), counter(0)
{
}
~YaoCommon()
{
for (auto& job : jobs)
delete job;
}
void init(typename T::Party& party)
{
jobs.resize(get_n_worker_threads());
for (auto& job : jobs)
job = new YaoAndJob<T>(party);
}
void set_n_program_threads(int n_threads)
{
log_n_threads = floor(log2(n_threads));
}
long gate_id(long thread_num)
{
return counter + (thread_num << (64 - log_n_threads));
}
int get_n_worker_threads()
{
return max(1u, thread::hardware_concurrency() / master.machine.nthreads);
}
vector<array<size_t, 2>> get_splits(const vector<int>& args, int threshold,
int total);
void wait(int n_threads)
{
for (int i = 0; i < n_threads; i++)
jobs[i]->worker.done();
}
};
#endif /* YAO_YAOCOMMON_H_ */