Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
9
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
PALISADE
PALISADE Development
Commits
1ef72cb6
Commit
1ef72cb6
authored
Jan 25, 2018
by
Jerry Ryan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue-800-benchmark' into v1.1.1-work-branch
parents
b0301dff
f91bedc3
Changes
36
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
36 changed files
with
1153 additions
and
1713 deletions
+1153
-1713
Makefile.common
Makefile.common
+1
-1
benchmark/src/AllBackends.h
benchmark/src/AllBackends.h
+68
-0
benchmark/src/Crypto.cpp
benchmark/src/Crypto.cpp
+59
-112
benchmark/src/ElementParmsHelper.h
benchmark/src/ElementParmsHelper.h
+0
-91
benchmark/src/Encoding.cpp
benchmark/src/Encoding.cpp
+47
-84
benchmark/src/EncryptHelper.h
benchmark/src/EncryptHelper.h
+7
-3
benchmark/src/IntegerMath.cpp
benchmark/src/IntegerMath.cpp
+200
-0
benchmark/src/Lattice.cpp
benchmark/src/Lattice.cpp
+318
-231
benchmark/src/LatticeCompare.cpp
benchmark/src/LatticeCompare.cpp
+0
-169
benchmark/src/LatticeNative.cpp
benchmark/src/LatticeNative.cpp
+0
-204
benchmark/src/NativeIntegerMath.cpp
benchmark/src/NativeIntegerMath.cpp
+0
-180
benchmark/src/SHE.cpp
benchmark/src/SHE.cpp
+31
-21
benchmark/src/Source_presim_bm.cpp
benchmark/src/Source_presim_bm.cpp
+0
-528
benchmark/src/VectorMath.cpp
benchmark/src/VectorMath.cpp
+161
-0
benchmark/src/vechelper.h
benchmark/src/vechelper.h
+9
-9
src/core/lib/lattice/dcrtpoly.cpp
src/core/lib/lattice/dcrtpoly.cpp
+17
-17
src/core/lib/lattice/dcrtpoly.h
src/core/lib/lattice/dcrtpoly.h
+6
-8
src/core/lib/lattice/elemparamfactory.h
src/core/lib/lattice/elemparamfactory.h
+26
-20
src/core/lib/lattice/ildcrtparams.cpp
src/core/lib/lattice/ildcrtparams.cpp
+1
-1
src/core/lib/lattice/ildcrtparams.h
src/core/lib/lattice/ildcrtparams.h
+2
-1
src/core/lib/lattice/ilparams.h
src/core/lib/lattice/ilparams.h
+1
-0
src/core/lib/math/cpu_int/binint.cpp
src/core/lib/math/cpu_int/binint.cpp
+34
-0
src/core/lib/math/cpu_int/binint.h
src/core/lib/math/cpu_int/binint.h
+27
-0
src/core/lib/math/exp_int/ubint.cpp
src/core/lib/math/exp_int/ubint.cpp
+40
-0
src/core/lib/math/exp_int/ubint.h
src/core/lib/math/exp_int/ubint.h
+6
-0
src/core/lib/math/interface.h
src/core/lib/math/interface.h
+30
-1
src/core/lib/utils/parmfactory.h
src/core/lib/utils/parmfactory.h
+5
-4
src/core/unittest/UnitTestEncoding.cpp
src/core/unittest/UnitTestEncoding.cpp
+5
-5
src/core/unittest/UnitTestLatticeElements.cpp
src/core/unittest/UnitTestLatticeElements.cpp
+5
-5
src/core/unittest/UnitTestSerialize.cpp
src/core/unittest/UnitTestSerialize.cpp
+4
-4
src/pke/demo/Temp-smalldemo.cpp
src/pke/demo/Temp-smalldemo.cpp
+29
-0
src/pke/lib/cryptocontextgen.h
src/pke/lib/cryptocontextgen.h
+4
-4
src/pke/lib/cryptocontexthelper-impl.cpp
src/pke/lib/cryptocontexthelper-impl.cpp
+1
-1
src/pke/unittest/UnitTestBVDCRT.cpp
src/pke/unittest/UnitTestBVDCRT.cpp
+1
-1
src/pke/unittest/UnitTestSHE.cpp
src/pke/unittest/UnitTestSHE.cpp
+5
-5
src/pke/unittest/UnitTestSHEAdvanced.cpp
src/pke/unittest/UnitTestSHEAdvanced.cpp
+3
-3
No files found.
Makefile.common
View file @
1ef72cb6
...
...
@@ -113,7 +113,7 @@ PALISADEPYLIB := pycrypto$(LIBSUFFIX)
all
:
$(MAKE)
gmp_all
$(MAKE)
ntl_all
$(MAKE)
allcore allpke alltrapdoor allcircuit utall
$(MAKE)
allcore allpke alltrapdoor allcircuit utall
docs
:
apidocs
...
...
benchmark/src/
BigVectorMath.cpp
→
benchmark/src/
AllBackends.h
100755 → 100644
View file @
1ef72cb6
...
...
@@ -22,108 +22,47 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
This code benchmarks functions of the math directory of the PALISADE lattice encryption library.
*/
#include "benchmark/benchmark_api.h"
// this file contains the magic needed to compile and benchmark all backends in the same executable
#ifndef BENCHMARK_SRC_ALLBACKENDS_H_
#define BENCHMARK_SRC_ALLBACKENDS_H_
#include <iostream>
#define _USE_MATH_DEFINES
#include "math/backend.h"
#include "utils/inttypes.h"
#include "math/nbtheory.h"
#include "math/distrgen.h"
#include "lattice/elemparams.h"
#include "lattice/ilparams.h"
#include "lattice/ildcrtparams.h"
#include "lattice/ilelement.h"
#include "math/distrgen.h"
#include "lattice/poly.h"
#include "
../../src/core/lib/
lattice/dcrtpoly.h"
#include "lattice/dcrtpoly.h"
#include "utils/utilities.h"
#include "vechelper.h"
#include "ElementParmsHelper.h"
using
namespace
std
;
using
namespace
lbcrypto
;
// add
static
void
add_BigVec
(
benchmark
::
State
&
state
)
{
state
.
PauseTiming
();
BigVector
a
=
makeVector
(
parmArray
[
state
.
range
(
0
)]);
BigVector
b
=
makeVector
(
parmArray
[
state
.
range
(
0
)]);
state
.
ResumeTiming
();
a
=
a
+
b
;
}
static
void
BM_BigVec_Addition
(
benchmark
::
State
&
state
)
{
// benchmark
while
(
state
.
KeepRunning
())
{
add_BigVec
(
state
);
}
}
DO_PARM_BENCHMARK
(
BM_BigVec_Addition
)
// +=
static
void
addeq_BigVec
(
benchmark
::
State
&
state
)
{
state
.
PauseTiming
();
BigVector
a
=
makeVector
(
parmArray
[
state
.
range
(
0
)]);
BigVector
b
=
makeVector
(
parmArray
[
state
.
range
(
0
)]);
state
.
ResumeTiming
();
a
+=
b
;
}
static
void
BM_BigVec_Addeq
(
benchmark
::
State
&
state
)
{
// benchmark
while
(
state
.
KeepRunning
())
{
addeq_BigVec
(
state
);
}
}
DO_PARM_BENCHMARK
(
BM_BigVec_Addeq
)
// mult
static
void
mult_BigVec
(
benchmark
::
State
&
state
)
{
// function
state
.
PauseTiming
();
BigVector
a
=
makeVector
(
parmArray
[
state
.
range
(
0
)]);
BigVector
b
=
makeVector
(
parmArray
[
state
.
range
(
0
)]);
state
.
ResumeTiming
();
a
=
a
*
b
;
}
static
void
BM_BigVec_Multiplication
(
benchmark
::
State
&
state
)
{
// benchmark
while
(
state
.
KeepRunning
())
{
mult_BigVec
(
state
);
}
}
DO_PARM_BENCHMARK
(
BM_BigVec_Multiplication
)
// mult
static
void
multeq_BigVec
(
benchmark
::
State
&
state
)
{
// function
state
.
PauseTiming
();
BigVector
a
=
makeVector
(
parmArray
[
state
.
range
(
0
)]);
BigVector
b
=
makeVector
(
parmArray
[
state
.
range
(
0
)]);
state
.
ResumeTiming
();
a
*=
b
;
}
static
void
BM_BigVec_Multeq
(
benchmark
::
State
&
state
)
{
// benchmark
while
(
state
.
KeepRunning
())
{
multeq_BigVec
(
state
);
}
}
DO_PARM_BENCHMARK
(
BM_BigVec_Multeq
)
//execute the benchmarks
BENCHMARK_MAIN
()
using
BE2Integer
=
cpu_int
::
BigInteger
<
integral_dtype
,
BigIntegerBitLength
>
;
using
BE2ILParams
=
ILParamsImpl
<
BE2Integer
>
;
using
BE2ILDCRTParams
=
ILDCRTParams
<
BE2Integer
>
;
using
BE2Vector
=
cpu_int
::
BigVectorImpl
<
BE2Integer
>
;
using
BE2Poly
=
PolyImpl
<
BE2Integer
,
BE2Integer
,
BE2Vector
,
BE2ILParams
>
;
using
BE2DCRTPoly
=
DCRTPolyImpl
<
BE2Integer
,
BE2Integer
,
BE2Vector
,
BE2ILDCRTParams
>
;
using
BE4Integer
=
exp_int
::
xubint
;
using
BE4ILParams
=
ILParamsImpl
<
BE4Integer
>
;
using
BE4ILDCRTParams
=
ILDCRTParams
<
BE4Integer
>
;
using
BE4Vector
=
exp_int
::
xmubintvec
;
using
BE4Poly
=
PolyImpl
<
BE4Integer
,
BE4Integer
,
BE4Vector
,
BE4ILParams
>
;
using
BE4DCRTPoly
=
DCRTPolyImpl
<
BE4Integer
,
BE4Integer
,
BE4Vector
,
BE4ILDCRTParams
>
;
using
BE6Integer
=
NTL
::
myZZ
;
using
BE6ILParams
=
ILParamsImpl
<
BE6Integer
>
;
using
BE6ILDCRTParams
=
ILDCRTParams
<
BE6Integer
>
;
using
BE6Vector
=
NTL
::
myVecP
<
NTL
::
myZZ
>
;
using
BE6Poly
=
PolyImpl
<
BE6Integer
,
BE6Integer
,
BE6Vector
,
BE6ILParams
>
;
using
BE6DCRTPoly
=
DCRTPolyImpl
<
BE6Integer
,
BE6Integer
,
BE6Vector
,
BE6ILDCRTParams
>
;
#endif
/* BENCHMARK_SRC_ALLBACKENDS_H_ */
benchmark/src/Crypto.cpp
View file @
1ef72cb6
...
...
@@ -53,29 +53,27 @@ using namespace std;
using
namespace
lbcrypto
;
#include "vechelper.h"
#include "ElementParmsHelper.h"
#include "EncryptHelper.h"
#include "lattice/elemparamfactory.h"
void
BM_keygen
(
benchmark
::
State
&
state
)
{
// benchmark
CryptoContext
<
Poly
>
cc
;
if
(
state
.
thread_index
==
0
)
{
state
.
PauseTiming
();
cc
=
CryptoContextHelper
::
getNewContext
(
parms
[
state
.
range
(
0
)]);
cc
->
Enable
(
ENCRYPTION
);
cc
->
Enable
(
PRE
);
try
{
ChineseRemainderTransformFTT
<
BigInteger
,
BigVector
>::
PreCompute
(
cc
->
GetRootOfUnity
(),
cc
->
GetCyclotomicOrder
(),
cc
->
GetModulus
());
}
catch
(
...
)
{}
cc
=
CryptoContextHelper
::
getNewContext
(
parms
[
state
.
range
(
0
)]);
cc
->
Enable
(
ENCRYPTION
);
cc
->
Enable
(
PRE
);
}
catch
(
std
::
exception
&
e
)
{
state
.
SkipWithError
(
e
.
what
()
);
return
;
}
try
{
typename
Poly
::
DggType
dgg
=
Poly
::
DggType
(
4
);
// Create the noise generator
ChineseRemainderTransformFTT
<
BigInteger
,
BigVector
>::
PreCompute
(
cc
->
GetRootOfUnity
(),
cc
->
GetCyclotomicOrder
(),
cc
->
GetModulus
());
}
catch
(
...
)
{}
state
.
ResumeTiming
();
}
while
(
state
.
KeepRunning
())
{
...
...
@@ -85,27 +83,27 @@ void BM_keygen(benchmark::State& state) { // benchmark
BENCHMARK_PARMS
(
BM_keygen
)
static
void
fillrandint
(
vector
<
int64_t
>&
vec
,
PlaintextModulus
mod
)
{
mod
/=
2
;
for
(
size_t
ii
=
0
;
ii
<
vec
.
size
();
ii
++
)
vec
[
ii
]
=
rand
()
%
mod
;
};
void
BM_encrypt
(
benchmark
::
State
&
state
)
{
// benchmark
CryptoContext
<
Poly
>
cc
;
LPKeyPair
<
Poly
>
kp
;
Ciphertext
<
Poly
>
ciphertext
;
Plaintext
plaintext
;
auto
randchar
=
[]()
->
char
{
const
char
charset
[]
=
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
;
const
size_t
max_index
=
(
sizeof
(
charset
)
-
1
);
return
charset
[
rand
()
%
max_index
];
};
if
(
state
.
thread_index
==
0
)
{
state
.
PauseTiming
();
cc
=
CryptoContextHelper
::
getNewContext
(
parms
[
state
.
range
(
0
)]);
cc
->
Enable
(
ENCRYPTION
);
cc
->
Enable
(
PRE
);
try
{
cc
=
CryptoContextHelper
::
getNewContext
(
parms
[
state
.
range
(
0
)]);
cc
->
Enable
(
ENCRYPTION
);
cc
->
Enable
(
PRE
);
}
catch
(
std
::
exception
&
e
)
{
state
.
SkipWithError
(
e
.
what
()
);
return
;
}
try
{
ChineseRemainderTransformFTT
<
BigInteger
,
BigVector
>::
PreCompute
(
cc
->
GetRootOfUnity
(),
...
...
@@ -113,21 +111,9 @@ void BM_encrypt(benchmark::State& state) { // benchmark
cc
->
GetModulus
());
}
catch
(
...
)
{}
try
{
typename
Poly
::
DggType
dgg
=
Poly
::
DggType
(
4
);
// Create the noise generator
}
catch
(
...
)
{}
size_t
strSize
=
cc
->
GetRingDimension
();
if
(
strSize
==
0
)
{
state
.
SkipWithError
(
"Chunk size is 0"
);
}
string
shortStr
(
strSize
,
0
);
std
::
generate_n
(
shortStr
.
begin
(),
strSize
,
randchar
);
plaintext
=
cc
->
MakeStringPlaintext
(
shortStr
);
state
.
ResumeTiming
();
vector
<
int64_t
>
input
(
cc
->
GetRingDimension
(),
0
);
fillrandint
(
input
,
cc
->
GetEncodingParams
()
->
GetPlaintextModulus
());
plaintext
=
cc
->
MakeCoefPackedPlaintext
(
input
);
}
while
(
state
.
KeepRunning
())
{
...
...
@@ -148,21 +134,15 @@ void BM_decrypt(benchmark::State& state) { // benchmark
Plaintext
plaintext
;
Plaintext
plaintextNew
;
auto
randchar
=
[]()
->
char
{
const
char
charset
[]
=
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
;
const
size_t
max_index
=
(
sizeof
(
charset
)
-
1
);
return
charset
[
rand
()
%
max_index
];
};
if
(
state
.
thread_index
==
0
)
{
state
.
PauseTiming
();
cc
=
CryptoContextHelper
::
getNewContext
(
parms
[
state
.
range
(
0
)]);
cc
->
Enable
(
ENCRYPTION
);
cc
->
Enable
(
PRE
);
try
{
cc
=
CryptoContextHelper
::
getNewContext
(
parms
[
state
.
range
(
0
)]);
cc
->
Enable
(
ENCRYPTION
);
cc
->
Enable
(
PRE
);
}
catch
(
std
::
exception
&
e
)
{
state
.
SkipWithError
(
e
.
what
()
);
return
;
}
try
{
ChineseRemainderTransformFTT
<
BigInteger
,
BigVector
>::
PreCompute
(
cc
->
GetRootOfUnity
(),
...
...
@@ -170,21 +150,9 @@ void BM_decrypt(benchmark::State& state) { // benchmark
cc
->
GetModulus
());
}
catch
(
...
)
{}
try
{
typename
Poly
::
DggType
dgg
=
Poly
::
DggType
(
4
);
// Create the noise generator
}
catch
(
...
)
{}
size_t
strSize
=
cc
->
GetRingDimension
();
if
(
strSize
==
0
)
{
state
.
SkipWithError
(
"Chunk size is 0"
);
}
string
shortStr
(
strSize
,
0
);
std
::
generate_n
(
shortStr
.
begin
(),
strSize
,
randchar
);
plaintext
=
cc
->
MakeStringPlaintext
(
shortStr
);
state
.
ResumeTiming
();
vector
<
int64_t
>
input
(
cc
->
GetRingDimension
(),
0
);
fillrandint
(
input
,
cc
->
GetEncodingParams
()
->
GetPlaintextModulus
());
plaintext
=
cc
->
MakeCoefPackedPlaintext
(
input
);
}
while
(
state
.
KeepRunning
())
{
...
...
@@ -204,11 +172,15 @@ void BM_rekeygen(benchmark::State& state) { // benchmark
LPKeyPair
<
Poly
>
kp
;
if
(
state
.
thread_index
==
0
)
{
state
.
PauseTiming
();
cc
=
CryptoContextHelper
::
getNewContext
(
parms
[
state
.
range
(
0
)]);
cc
->
Enable
(
ENCRYPTION
);
cc
->
Enable
(
PRE
);
cc
->
Enable
(
SHE
);
try
{
cc
=
CryptoContextHelper
::
getNewContext
(
parms
[
state
.
range
(
0
)]);
cc
->
Enable
(
ENCRYPTION
);
cc
->
Enable
(
PRE
);
cc
->
Enable
(
SHE
);
}
catch
(
std
::
exception
&
e
)
{
state
.
SkipWithError
(
e
.
what
()
);
return
;
}
try
{
ChineseRemainderTransformFTT
<
BigInteger
,
BigVector
>::
PreCompute
(
cc
->
GetRootOfUnity
(),
...
...
@@ -216,13 +188,6 @@ void BM_rekeygen(benchmark::State& state) { // benchmark
cc
->
GetModulus
());
}
catch
(
...
)
{
}
try
{
typename
Poly
::
DggType
dgg
=
Poly
::
DggType
(
4
);
// Create the noise generator
}
catch
(
...
)
{
}
state
.
ResumeTiming
();
}
while
(
state
.
KeepRunning
())
{
...
...
@@ -251,21 +216,15 @@ void BM_reencrypt(benchmark::State& state) { // benchmark
Plaintext
plaintext
;
Plaintext
plaintextNew
;
auto
randchar
=
[]()
->
char
{
const
char
charset
[]
=
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
;
const
size_t
max_index
=
(
sizeof
(
charset
)
-
1
);
return
charset
[
rand
()
%
max_index
];
};
if
(
state
.
thread_index
==
0
)
{
state
.
PauseTiming
();
cc
=
CryptoContextHelper
::
getNewContext
(
parms
[
state
.
range
(
0
)]);
cc
->
Enable
(
ENCRYPTION
);
cc
->
Enable
(
PRE
);
try
{
cc
=
CryptoContextHelper
::
getNewContext
(
parms
[
state
.
range
(
0
)]);
cc
->
Enable
(
ENCRYPTION
);
cc
->
Enable
(
PRE
);
}
catch
(
std
::
exception
&
e
)
{
state
.
SkipWithError
(
e
.
what
()
);
return
;
}
try
{
ChineseRemainderTransformFTT
<
BigInteger
,
BigVector
>::
PreCompute
(
cc
->
GetRootOfUnity
(),
...
...
@@ -273,21 +232,9 @@ void BM_reencrypt(benchmark::State& state) { // benchmark
cc
->
GetModulus
());
}
catch
(
...
)
{}
try
{
typename
Poly
::
DggType
dgg
=
Poly
::
DggType
(
4
);
// Create the noise generator
}
catch
(
...
)
{}
size_t
strSize
=
cc
->
GetRingDimension
();
if
(
strSize
==
0
)
{
state
.
SkipWithError
(
"Chunk size is 0"
);
}
string
shortStr
(
strSize
,
0
);
std
::
generate_n
(
shortStr
.
begin
(),
strSize
,
randchar
);
plaintext
=
cc
->
MakeStringPlaintext
(
shortStr
);
state
.
ResumeTiming
();
vector
<
int64_t
>
input
(
cc
->
GetRingDimension
(),
0
);
fillrandint
(
input
,
cc
->
GetEncodingParams
()
->
GetPlaintextModulus
());
plaintext
=
cc
->
MakeCoefPackedPlaintext
(
input
);
}
LPEvalKey
<
Poly
>
evalKey
;
...
...
benchmark/src/ElementParmsHelper.h
deleted
100644 → 0
View file @
b0301dff
/**
* @author TPOC: palisade@njit.edu
*
* @copyright Copyright (c) 2017, New Jersey Institute of Technology (NJIT)
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "lattice/elemparamfactory.h"
shared_ptr
<
ILParams
>
parm_16
=
ElemParamFactory
::
GenElemParams
<
ILParams
,
BigInteger
>
(
M16
);
shared_ptr
<
ILParams
>
parm_1024
=
ElemParamFactory
::
GenElemParams
<
ILParams
,
BigInteger
>
(
M1024
);
shared_ptr
<
ILParams
>
parm_2048
=
ElemParamFactory
::
GenElemParams
<
ILParams
,
BigInteger
>
(
M2048
);
shared_ptr
<
ILParams
>
parm_4096
=
ElemParamFactory
::
GenElemParams
<
ILParams
,
BigInteger
>
(
M4096
);
shared_ptr
<
ILParams
>
parm_8192
=
ElemParamFactory
::
GenElemParams
<
ILParams
,
BigInteger
>
(
M8192
);
shared_ptr
<
ILParams
>
parm_16384
=
ElemParamFactory
::
GenElemParams
<
ILParams
,
BigInteger
>
(
M16384
);
shared_ptr
<
ILParams
>
parm_32768
=
ElemParamFactory
::
GenElemParams
<
ILParams
,
BigInteger
>
(
M32768
);
shared_ptr
<
ILParams
>
parmArray
[]
=
{
parm_16
,
parm_1024
,
parm_2048
,
parm_4096
,
parm_8192
,
parm_16384
,
parm_32768
,
};
shared_ptr
<
ILNativeParams
>
nparm_16
=
ElemParamFactory
::
GenElemParams
<
ILNativeParams
,
NativeInteger
>
(
M16
);
shared_ptr
<
ILNativeParams
>
nparm_1024
=
ElemParamFactory
::
GenElemParams
<
ILNativeParams
,
NativeInteger
>
(
M1024
);
shared_ptr
<
ILNativeParams
>
nparm_2048
=
ElemParamFactory
::
GenElemParams
<
ILNativeParams
,
NativeInteger
>
(
M2048
);
shared_ptr
<
ILNativeParams
>
nparm_4096
=
ElemParamFactory
::
GenElemParams
<
ILNativeParams
,
NativeInteger
>
(
M4096
);
shared_ptr
<
ILNativeParams
>
nparmArray
[]
=
{
nparm_16
,
nparm_1024
,
nparm_2048
,
nparm_4096
,
//nparm_8192,
//nparm_16384,
//nparm_32768,
};
#define DO_PARM_BENCHMARK(X) \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("parm_16")->Arg(0); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("parm_1024")->Arg(1); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("parm_2048")->Arg(2); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("parm_4096")->Arg(3); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("parm_8192")->Arg(4); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("parm_16384")->Arg(5); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("parm_32768")->Arg(6);
#define DO_NATIVEPARM_BENCHMARK(X) \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("nparm_16")->Arg(0); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("nparm_1024")->Arg(1); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("nparm_2048")->Arg(2); \
BENCHMARK(X)->Unit(benchmark::kMicrosecond)->ArgName("nparm_4096")->Arg(3);
#define DO_PARM_BENCHMARK_TEMPLATE(X,Y) \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_16")->Arg(0); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_1024")->Arg(1); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_2048")->Arg(2); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_4096")->Arg(3); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_8192")->Arg(4); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_16384")->Arg(5); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_32768")->Arg(6);
#define DO_NATIVEPARM_BENCHMARK_TEMPLATE(X,Y) \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("nparm_16")->Arg(0); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("nparm_1024")->Arg(1); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("nparm_2048")->Arg(2); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("nparm_4096")->Arg(3);
benchmark/src/Encoding.cpp
View file @
1ef72cb6
...
...
@@ -41,22 +41,15 @@ using namespace std;
using
namespace
lbcrypto
;
void
BM_encoding_Scalar
(
benchmark
::
State
&
state
)
{
usint
m
=
1024
;
PlaintextModulus
ptm
=
128
;
int64_t
value
=
47
;
Plaintext
plaintext
;
if
(
state
.
thread_index
==
0
)
{
state
.
PauseTiming
();
int64_t
value
=
47
;
usint
m
=
1024
;
PlaintextModulus
ptm
=
128
;
shared_ptr
<
ILParams
>
lp
=
ElemParamFactory
::
GenElemParams
<
ILParams
,
BigInteger
>
(
m
);
EncodingParams
ep
(
new
EncodingParamsImpl
(
ptm
)
);
plaintext
.
reset
(
new
ScalarEncoding
(
lp
,
ep
,
value
)
);
state
.
ResumeTiming
();
}
shared_ptr
<
ILParams
>
lp
=
ElemParamFactory
::
GenElemParams
<
ILParams
>
(
m
);
EncodingParams
ep
(
new
EncodingParamsImpl
(
ptm
)
);
while
(
state
.
KeepRunning
())
{
plaintext
.
reset
(
new
ScalarEncoding
(
lp
,
ep
,
value
)
);
plaintext
->
Encode
();
}
}
...
...
@@ -65,23 +58,16 @@ BENCHMARK(BM_encoding_Scalar);
void
BM_encoding_Integer
(
benchmark
::
State
&
state
)
{
// benchmark
CryptoContext
<
Poly
>
cc
;
Plaintext
plaintext
;
usint
m
=
1024
;
PlaintextModulus
ptm
=
128
;
int64_t
mv
=
58
;
if
(
state
.
thread_index
==
0
)
{
state
.
PauseTiming
();
usint
m
=
1024
;
PlaintextModulus
ptm
=
128
;
int64_t
mv
=
((
int64_t
)
1
<<
33
)
+
(
int64_t
)
1
;
shared_ptr
<
ILParams
>
lp
=
ElemParamFactory
::
GenElemParams
<
ILParams
,
BigInteger
>
(
m
);
EncodingParams
ep
(
new
EncodingParamsImpl
(
ptm
)
);
plaintext
.
reset
(
new
IntegerEncoding
(
lp
,
ep
,
mv
)
);
state
.
ResumeTiming
();
}
shared_ptr
<
ILParams
>
lp
=
ElemParamFactory
::
GenElemParams
<
ILParams
>
(
m
);
EncodingParams
ep
(
new
EncodingParamsImpl
(
ptm
)
);
while
(
state
.
KeepRunning
())
{
plaintext
.
reset
(
new
IntegerEncoding
(
lp
,
ep
,
mv
)
);
plaintext
->
Encode
();
}
}
...
...
@@ -90,26 +76,19 @@ BENCHMARK(BM_encoding_Integer);
void
BM_encoding_CoefPacked
(
benchmark
::
State
&
state
)
{
Plaintext
plaintext
;
usint
m
=
1024
;
PlaintextModulus
ptm
=
128
;
PlaintextModulus
half
=
ptm
/
2
;
if
(
state
.
thread_index
==
0
)
{
state
.
PauseTiming
();
usint
m
=
1024
;
PlaintextModulus
ptm
=
128
;
int64_t
mv
=
((
int64_t
)
1
<<
33
)
+
(
int64_t
)
1
;
shared_ptr
<
ILParams
>
lp
=
ElemParamFactory
::
GenElemParams
<
ILParams
>
(
m
);
EncodingParams
ep
(
new
EncodingParamsImpl
(
ptm
)
);
shared_ptr
<
ILParams
>
lp
=
ElemParamFactory
::
GenElemParams
<
ILParams
,
BigInteger
>
(
m
);
EncodingParams
ep
(
new
EncodingParamsImpl
(
ptm
)
);
vector
<
int64_t
>
intvec
;
for
(
usint
ii
=
0
;
ii
<
m
/
2
;
ii
++
)
intvec
.
push_back
(
rand
()
%
ptm
);
plaintext
.
reset
(
new
CoefPackedEncoding
(
lp
,
ep
,
intvec
)
);
state
.
ResumeTiming
();
}
vector
<
int64_t
>
intvec
;
for
(
usint
ii
=
0
;
ii
<
m
/
2
;
ii
++
)
intvec
.
push_back
(
rand
()
%
half
);
while
(
state
.
KeepRunning
())
{
plaintext
.
reset
(
new
CoefPackedEncoding
(
lp
,
ep
,
intvec
)
);
plaintext
->
Encode
();
}
}
...
...
@@ -123,29 +102,22 @@ void BM_encoding_PackedIntPlaintext(benchmark::State& state) {
std
::
vector
<
uint64_t
>
vectorOfInts1
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
0
,
0
};
if
(
state
.
thread_index
==
0
)
{
state
.
PauseTiming
();
usint
m
=
22
;
PlaintextModulus
p
=
89
;