Skip to content

Commit 104c32e

Browse files
hamishunJack L CrawfordEnrico Steffinlongo
committed
Fix threading issue with timers (homenc#350)
Co-Authored-By: Jack L Crawford <[email protected]> Co-Authored-By: Enrico Steffinlongo <[email protected]>
1 parent 559c60c commit 104c32e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+426
-426
lines changed

OLD_INSTALL.txt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,12 @@ library, currently these are:
112112
this may take a significant amount of memory.
113113

114114

115-
-DFHE_THREADS tells HElib to enable generic multithreading capabilities;
116-
must be used with a thread-enabled NTL and the -pthread
117-
flag should be passed to gcc
115+
-DHELIB_THREADS tells HElib to enable generic multithreading capabilities;
116+
must be used with a thread-enabled NTL and the -pthread
117+
flag should be passed to gcc
118118

119-
-DFHE_DCRT_THREADS tells HElib to use a multithreading strategy at the
120-
DoubleCRT level; requires -DFHE_THREADS (see above)
121-
122-
-DFHE_BOOT_THREADS tells HElib to use a multithreading strategy for
123-
bootstrapping; requires -DFHE_THREADS (see above)
119+
-DHELIB_BOOT_THREADS tells HElib to use a multithreading strategy for
120+
bootstrapping; requires -DHELIB_THREADS (see above)
124121

125122

126123
-DDEBUG_PRINTOUT

include/helib/ArgMap.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -537,18 +537,15 @@ ArgMap& ArgMap::arg(const std::string& name, T& value, const std::string& doc)
537537

538538
template <typename T>
539539
ArgMap& ArgMap::arg(const std::string& name,
540-
T& value,
541-
const std::string& doc,
542-
const char* info)
540+
T& value,
541+
const std::string& doc,
542+
const char* info)
543543
{
544544
arg(name, value);
545545

546546
docVec.push_back({name, doc, required_mode});
547547
if (info != nullptr && info[0] != '\0')
548-
std::get<1>(docVec.back())
549-
.append(" [ default=")
550-
.append(info)
551-
.append(" ]");
548+
std::get<1>(docVec.back()).append(" [ default=").append(info).append(" ]");
552549

553550
return *this;
554551
}

include/helib/CModulus.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Cmodulus
7777
void privateInit(const PAlgebra&, long rt);
7878

7979
public:
80-
#ifdef FHE_OPENCL
80+
#ifdef HELIB_OPENCL
8181
SmartPtr<AltFFTPrimeInfo> altFFTInfo;
8282
// We need to allow copying...the underlying object
8383
// is immutable

include/helib/EncryptedArray.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ typedef std::complex<double> cx_double;
3333

3434
// DIRT: we're using undocumented NTL interfaces here
3535
// also...this probably should be defined in NTL, anyway....
36-
#define FHE_MORE_UNWRAPARGS(n) NTL_SEPARATOR_##n NTL_REPEATER_##n(NTL_UNWRAPARG)
36+
#define HELIB_MORE_UNWRAPARGS(n) \
37+
NTL_SEPARATOR_##n NTL_REPEATER_##n(NTL_UNWRAPARG)
3738

3839
// these are used to implement PlaintextArray stuff routines
3940

include/helib/fhe_stats.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* limitations under the License. See accompanying LICENSE file.
1111
*/
1212

13-
#ifndef FHE_STATS_H
14-
#define FHE_STATS_H
13+
#ifndef HELIB_STATS_H
14+
#define HELIB_STATS_H
1515

1616
#include <vector>
1717
#include <iostream>
@@ -35,15 +35,15 @@ struct fhe_stats_record
3535
void save(double val);
3636
};
3737

38-
#define FHE_STATS_UPDATE(name, val) \
38+
#define HELIB_STATS_UPDATE(name, val) \
3939
do { \
4040
if (fhe_stats) { \
4141
static fhe_stats_record _local_stats_record(name); \
4242
_local_stats_record.update(val); \
4343
} \
4444
} while (0)
4545

46-
#define FHE_STATS_SAVE(name, val) \
46+
#define HELIB_STATS_SAVE(name, val) \
4747
do { \
4848
if (fhe_stats) { \
4949
static fhe_stats_record _local_stats_record(name); \

include/helib/keySwitching.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ std::ostream& operator<<(std::ostream& str, const KeySwitch& matrix);
134134

135135
//! @brief Constant defining threshold above which a baby-set/giant-step
136136
//! strategy is used
137-
#define FHE_KEYSWITCH_THRESH (50)
137+
#define HELIB_KEYSWITCH_THRESH (50)
138138

139139
//! @brief Constant defining threshold above which a single
140-
//! giant step matrix is added even in FHE_KSS_MIN mode.
140+
//! giant step matrix is added even in HELIB_KSS_MIN mode.
141141
//! This helps in the matmul routines.
142-
#define FHE_KEYSWITCH_MIN_THRESH (8)
142+
#define HELIB_KEYSWITCH_MIN_THRESH (8)
143143

144144
//! @brief Function that returns number of baby steps. Used to keep
145145
//! this and matmul routines "in sync".
@@ -157,7 +157,7 @@ void addFewMatrices(SecKey& sKey, long keyID = 0);
157157
//! For a generator g whose order is larger than bound, generate only enough
158158
//! matrices for the giant-step/baby-step procedures (2*sqrt(ord(g))of them).
159159
void addSome1DMatrices(SecKey& sKey,
160-
long bound = FHE_KEYSWITCH_THRESH,
160+
long bound = HELIB_KEYSWITCH_THRESH,
161161
long keyID = 0);
162162

163163
//! @brief Generate all matrices s(X^{g^i})->s(X) for generators g of
@@ -169,7 +169,7 @@ void addBSGS1DMatrices(SecKey& sKey, long keyID = 0);
169169

170170
//! Generate all/some Frobenius matrices of the form s(X^{p^i})->s(X)
171171
void addSomeFrbMatrices(SecKey& sKey,
172-
long bound = FHE_KEYSWITCH_THRESH,
172+
long bound = HELIB_KEYSWITCH_THRESH,
173173
long keyID = 0);
174174

175175
void addFrbMatrices(SecKey& sKey, long keyID = 0);

include/helib/keys.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424

2525
namespace helib {
2626

27-
#define FHE_KSS_UNKNOWN (0)
27+
#define HELIB_KSS_UNKNOWN (0)
2828
// unknown KS strategy
2929

30-
#define FHE_KSS_FULL (1)
30+
#define HELIB_KSS_FULL (1)
3131
// all KS matrices
3232

33-
#define FHE_KSS_BSGS (2)
33+
#define HELIB_KSS_BSGS (2)
3434
// baby step/giant step strategy
3535

36-
#define FHE_KSS_MIN (3)
36+
#define HELIB_KSS_MIN (3)
3737
// minimal strategy (for g_i, and for g_i^{-ord_i} for bad dims)
3838

3939
void writePubKeyBinary(std::ostream& str, const PubKey& pk);

include/helib/multicore.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,33 @@
1717
#ifndef HELIB_MULTICORE_H
1818
#define HELIB_MULTICORE_H
1919

20-
#ifdef FHE_THREADS
20+
#ifdef HELIB_THREADS
2121

2222
#include <atomic>
2323
#include <mutex>
2424

2525
namespace helib {
2626

27-
#define FHE_atomic_long std::atomic_long
28-
#define FHE_atomic_ulong std::atomic_ulong
27+
#define HELIB_atomic_long std::atomic_long
28+
#define HELIB_atomic_ulong std::atomic_ulong
2929

30-
#define FHE_MUTEX_TYPE std::mutex
31-
#define FHE_MUTEX_GUARD(mx) std::lock_guard<std::mutex> _lock##__LINE__(mx)
30+
#define HELIB_MUTEX_TYPE std::mutex
31+
#define HELIB_MUTEX_GUARD(mx) std::lock_guard<std::mutex> _lock##__LINE__(mx)
32+
33+
} // namespace helib
3234

3335
#else
3436

3537
namespace helib {
3638

37-
#define FHE_atomic_long long
38-
#define FHE_atomic_ulong unsigned long
39+
#define HELIB_atomic_long long
40+
#define HELIB_atomic_ulong unsigned long
41+
42+
#define HELIB_MUTEX_TYPE int
43+
#define HELIB_MUTEX_GUARD(mx) ((void)mx)
3944

40-
#define FHE_MUTEX_TYPE int
41-
#define FHE_MUTEX_GUARD(mx) ((void)mx)
45+
} // namespace helib
4246

43-
#endif
44-
}
47+
#endif // ifdef HELIB_THREADS
4548

4649
#endif // ifndef HELIB_MULTICORE_H

include/helib/recryption.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class ThinRecryptData : public RecryptData
134134
bool minimal = false);
135135
};
136136

137-
#define FHE_MIN_CAP_FRAC (2.0 / 3.0)
137+
#define HELIB_MIN_CAP_FRAC (2.0 / 3.0)
138138
// Used in calculation of "min capacity".
139139
// This could be set to 1.0, but just to be on the safe side,
140140
// it is set to 2/3. If we did set it to 1, the min capacity

include/helib/timing.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*
1616
* This module contains some utility functions for measuring the time that
1717
* various methods take to execute. To use it, we insert the macro
18-
* FHE_TIMER_START at the beginning of the method(s) that we want to time and
19-
* FHE_TIMER_STOP at the end, then the main program needs to call the function
18+
* HELIB_TIMER_START at the beginning of the method(s) that we want to time and
19+
* HELIB_TIMER_STOP at the end, then the main program needs to call the function
2020
* setTimersOn() to activate the timers and setTimersOff() to pause them.
2121
* To obtain the value of a given timer (in seconds), the application can
2222
* use the function getTime4func(const char *fncName), and the function
@@ -48,8 +48,8 @@ class FHEtimer
4848
const char* loc;
4949

5050
// THREADS: these need to be atomic
51-
FHE_atomic_ulong counter;
52-
FHE_atomic_long numCalls;
51+
HELIB_atomic_ulong counter;
52+
HELIB_atomic_long numCalls;
5353

5454
FHEtimer(const char* _name, const char* _loc) :
5555
name(_name), loc(_loc), counter(0), numCalls(0)
@@ -108,24 +108,24 @@ class auto_timer
108108
// NOTE: the STOP functions below are not really needed,
109109
// but are provided for backward compatibility
110110

111-
#define FHE_STRINGIFY(x) #x
112-
#define FHE_TOSTRING(x) FHE_STRINGIFY(x)
113-
#define FHE_AT __FILE__ ":" FHE_TOSTRING(__LINE__)
111+
#define HELIB_STRINGIFY(x) #x
112+
#define HELIB_TOSTRING(x) HELIB_STRINGIFY(x)
113+
#define HELIB_AT __FILE__ ":" HELIB_TOSTRING(__LINE__)
114114

115-
#define FHE_stringify_aux(s) #s
116-
#define FHE_stringify(s) FHE_stringify_aux(s)
115+
#define HELIB_stringify_aux(s) #s
116+
#define HELIB_stringify(s) HELIB_stringify_aux(s)
117117

118-
#define FHE_TIMER_START \
119-
static helib::FHEtimer _local_timer(__func__, FHE_AT); \
118+
#define HELIB_TIMER_START \
119+
static helib::FHEtimer _local_timer(__func__, HELIB_AT); \
120120
helib::auto_timer _local_auto_timer(&_local_timer)
121121

122-
#define FHE_TIMER_STOP _local_auto_timer.stop()
122+
#define HELIB_TIMER_STOP _local_auto_timer.stop()
123123

124-
#define FHE_NTIMER_START(n) \
125-
static helib::FHEtimer _named_local_timer##n(#n, FHE_AT); \
124+
#define HELIB_NTIMER_START(n) \
125+
static helib::FHEtimer _named_local_timer##n(#n, HELIB_AT); \
126126
helib::auto_timer _named_local_auto_timer##n(&_named_local_timer##n)
127127

128-
#define FHE_NTIMER_STOP(n) _named_local_auto_timer##n.stop();
128+
#define HELIB_NTIMER_STOP(n) _named_local_auto_timer##n.stop();
129129

130130
} // namespace helib
131131

0 commit comments

Comments
 (0)