Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
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
f91bedc3
Commit
f91bedc3
authored
Jan 25, 2018
by
Gerard Ryan
Browse files
more benchmarks, in fewer files. done for now!
parent
4a3e86c5
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
209 additions
and
236 deletions
+209
-236
benchmark/src/Crypto.cpp
benchmark/src/Crypto.cpp
+1
-1
benchmark/src/ElementParmsHelper.h
benchmark/src/ElementParmsHelper.h
+0
-91
benchmark/src/Lattice.cpp
benchmark/src/Lattice.cpp
+3
-3
benchmark/src/NativeVectorMath.cpp
benchmark/src/NativeVectorMath.cpp
+0
-128
benchmark/src/SHE.cpp
benchmark/src/SHE.cpp
+3
-3
benchmark/src/VectorMath.cpp
benchmark/src/VectorMath.cpp
+161
-0
benchmark/src/vechelper.h
benchmark/src/vechelper.h
+9
-9
src/core/lib/math/interface.h
src/core/lib/math/interface.h
+3
-1
src/pke/demo/Temp-smalldemo.cpp
src/pke/demo/Temp-smalldemo.cpp
+29
-0
No files found.
benchmark/src/Crypto.cpp
View file @
f91bedc3
...
...
@@ -53,8 +53,8 @@ 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
;
...
...
benchmark/src/ElementParmsHelper.h
deleted
100644 → 0
View file @
4a3e86c5
/**
* @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
>
(
M16
);
shared_ptr
<
ILParams
>
parm_1024
=
ElemParamFactory
::
GenElemParams
<
ILParams
>
(
M1024
);
shared_ptr
<
ILParams
>
parm_2048
=
ElemParamFactory
::
GenElemParams
<
ILParams
>
(
M2048
);
shared_ptr
<
ILParams
>
parm_4096
=
ElemParamFactory
::
GenElemParams
<
ILParams
>
(
M4096
);
shared_ptr
<
ILParams
>
parm_8192
=
ElemParamFactory
::
GenElemParams
<
ILParams
>
(
M8192
);
shared_ptr
<
ILParams
>
parm_16384
=
ElemParamFactory
::
GenElemParams
<
ILParams
>
(
M16384
);
shared_ptr
<
ILParams
>
parm_32768
=
ElemParamFactory
::
GenElemParams
<
ILParams
>
(
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
>
(
M16
);
shared_ptr
<
ILNativeParams
>
nparm_1024
=
ElemParamFactory
::
GenElemParams
<
ILNativeParams
>
(
M1024
);
shared_ptr
<
ILNativeParams
>
nparm_2048
=
ElemParamFactory
::
GenElemParams
<
ILNativeParams
>
(
M2048
);
shared_ptr
<
ILNativeParams
>
nparm_4096
=
ElemParamFactory
::
GenElemParams
<
ILNativeParams
>
(
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/Lattice.cpp
View file @
f91bedc3
...
...
@@ -36,7 +36,6 @@
#include <vector>
#include "vechelper.h"
#include "ElementParmsHelper.h"
#include "lattice/elemparams.cpp"
#include "lattice/ilparams.cpp"
...
...
@@ -47,13 +46,14 @@
#include "math/transfrm.cpp"
#include "math/discreteuniformgenerator.cpp"
#include "math/discretegaussiangenerator.cpp"
#include "lattice/elemparamfactory.h"
using
namespace
std
;
using
namespace
lbcrypto
;
template
<
typename
E
>
static
E
makeElement
(
shared_ptr
<
lbcrypto
::
ILParamsImpl
<
typename
E
::
Integer
>>
params
)
{
typename
E
::
Vector
vec
=
makeVector
<
E
>
(
params
);
typename
E
::
Vector
vec
=
makeVector
<
typename
E
::
Vector
>
(
params
->
GetRingDimension
(),
params
->
GetModulus
()
);
E
elem
(
params
);
elem
.
SetValues
(
vec
,
elem
.
GetFormat
());
...
...
@@ -63,7 +63,7 @@ static E makeElement(shared_ptr<lbcrypto::ILParamsImpl<typename E::Integer>> par
template
<
typename
E
>
static
E
makeElement
(
shared_ptr
<
lbcrypto
::
ILDCRTParams
<
typename
E
::
Integer
>>
p
)
{
shared_ptr
<
ILParamsImpl
<
typename
E
::
Integer
>>
params
(
new
ILParamsImpl
<
typename
E
::
Integer
>
(
p
->
GetCyclotomicOrder
(),
p
->
GetModulus
(),
1
)
);
typename
E
::
Vector
vec
=
makeVector
<
typename
E
::
PolyLargeType
>
(
params
);
typename
E
::
Vector
vec
=
makeVector
<
typename
E
::
Vector
>
(
params
->
GetRingDimension
(),
params
->
GetModulus
()
);
typename
E
::
PolyLargeType
bigE
(
params
);
bigE
.
SetValues
(
vec
,
bigE
.
GetFormat
());
...
...
benchmark/src/NativeVectorMath.cpp
deleted
100755 → 0
View file @
4a3e86c5
/*
* @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.
*
*/
/*
This code benchmarks functions of the math directory of the PALISADE lattice encryption library.
*/
#include "benchmark/benchmark_api.h"
#include <iostream>
#define _USE_MATH_DEFINES
#include "math/backend.h"
#include "utils/inttypes.h"
#include "math/nbtheory.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 "utils/utilities.h"
#include "vechelper.h"
#include "ElementParmsHelper.h"
using
namespace
std
;
using
namespace
lbcrypto
;
// add
static
void
add_BBVNative
(
benchmark
::
State
&
state
)
{
state
.
PauseTiming
();
NativeVector
a
=
makeNativeVector
(
nparmArray
[
state
.
range
(
0
)]);
NativeVector
b
=
makeNativeVector
(
nparmArray
[
state
.
range
(
0
)]);
state
.
ResumeTiming
();
a
=
a
+
b
;
}
static
void
BM_BBVNative_Addition
(
benchmark
::
State
&
state
)
{
// benchmark
while
(
state
.
KeepRunning
())
{
add_BBVNative
(
state
);
}
}
DO_NATIVEPARM_BENCHMARK
(
BM_BBVNative_Addition
)
// +=
static
void
addeq_BBVNative
(
benchmark
::
State
&
state
)
{
state
.
PauseTiming
();
NativeVector
a
=
makeNativeVector
(
nparmArray
[
state
.
range
(
0
)]);
NativeVector
b
=
makeNativeVector
(
nparmArray
[
state
.
range
(
0
)]);
state
.
ResumeTiming
();
a
+=
b
;
}
static
void
BM_BBVNative_AddEq
(
benchmark
::
State
&
state
)
{
// benchmark
while
(
state
.
KeepRunning
())
{
addeq_BBVNative
(
state
);
}
}
DO_NATIVEPARM_BENCHMARK
(
BM_BBVNative_AddEq
)
// mult
static
void
mult_BBVNative
(
benchmark
::
State
&
state
)
{
// function
state
.
PauseTiming
();
NativeVector
a
=
makeNativeVector
(
nparmArray
[
state
.
range
(
0
)]);
NativeVector
b
=
makeNativeVector
(
nparmArray
[
state
.
range
(
0
)]);
state
.
ResumeTiming
();
a
=
a
*
b
;
}
static
void
BM_BBVNative_Multiplication
(
benchmark
::
State
&
state
)
{
// benchmark
while
(
state
.
KeepRunning
())
{
mult_BBVNative
(
state
);
}
}
DO_NATIVEPARM_BENCHMARK
(
BM_BBVNative_Multiplication
)
// *=
static
void
multeq_BBVNative
(
benchmark
::
State
&
state
)
{
// function
state
.
PauseTiming
();
NativeVector
a
=
makeNativeVector
(
nparmArray
[
state
.
range
(
0
)]);
NativeVector
b
=
makeNativeVector
(
nparmArray
[
state
.
range
(
0
)]);
state
.
ResumeTiming
();
a
*=
b
;
}
static
void
BM_BBVNative_MultEq
(
benchmark
::
State
&
state
)
{
// benchmark
while
(
state
.
KeepRunning
())
{
multeq_BBVNative
(
state
);
}
}
DO_NATIVEPARM_BENCHMARK
(
BM_BBVNative_MultEq
)
//execute the benchmarks
BENCHMARK_MAIN
()
benchmark/src/SHE.cpp
View file @
f91bedc3
...
...
@@ -41,7 +41,7 @@
using
namespace
std
;
using
namespace
lbcrypto
;
static
std
::
vector
<
int64_t
>
makeVector
(
int
siz
,
const
PlaintextModulus
&
ptmi
)
{
static
std
::
vector
<
int64_t
>
make
Int
Vector
(
int
siz
,
const
PlaintextModulus
&
ptmi
)
{
std
::
vector
<
int64_t
>
elem
;
PlaintextModulus
half
=
ptmi
/
2
;
...
...
@@ -57,8 +57,8 @@ static bool setup_SHE(CryptoContext<Poly> cc, Ciphertext<Poly>& ct1, Ciphertext<
LPKeyPair
<
Poly
>
kp
=
cc
->
KeyGen
();
Plaintext
p1
=
cc
->
MakeCoefPackedPlaintext
(
makeVector
(
nel
,
ptm
)
);
Plaintext
p2
=
cc
->
MakeCoefPackedPlaintext
(
makeVector
(
nel
,
ptm
)
);
Plaintext
p1
=
cc
->
MakeCoefPackedPlaintext
(
make
Int
Vector
(
nel
,
ptm
)
);
Plaintext
p2
=
cc
->
MakeCoefPackedPlaintext
(
make
Int
Vector
(
nel
,
ptm
)
);
ct1
=
cc
->
Encrypt
(
kp
.
publicKey
,
p1
);
ct2
=
cc
->
Encrypt
(
kp
.
publicKey
,
p2
);
...
...
benchmark/src/
Big
VectorMath.cpp
→
benchmark/src/VectorMath.cpp
View file @
f91bedc3
...
...
@@ -32,86 +32,130 @@
#include <iostream>
#include "vechelper.h"
#include "ElementParmsHelper.h"
#include "lattice/elemparams.cpp"
#include "lattice/ilparams.cpp"
#include "lattice/ildcrtparams.cpp"
#include "lattice/poly.cpp"
#include "lattice/dcrtpoly.cpp"
#include "math/nbtheory.cpp"
#include "math/transfrm.cpp"
#include "math/discreteuniformgenerator.cpp"
#include "math/discretegaussiangenerator.cpp"
#include "lattice/elemparamfactory.h"
using
namespace
std
;
using
namespace
lbcrypto
;
// add
static
void
add_BigVec
(
benchmark
::
State
&
state
)
{
state
.
PauseTiming
();
BigVector
a
=
makeVector
<
Poly
>
(
parmArray
[
state
.
range
(
0
)]);
BigVector
b
=
makeVector
<
Poly
>
(
parmArray
[
state
.
range
(
0
)]);
state
.
ResumeTiming
();
#define DO_NATIVEVECTOR_BENCHMARK(X) \
BENCHMARK_TEMPLATE(X,NativeVector)->Unit(benchmark::kMicrosecond)->ArgName("parm_16")->Arg(16); \
BENCHMARK_TEMPLATE(X,NativeVector)->Unit(benchmark::kMicrosecond)->ArgName("parm_1024")->Arg(1024); \
BENCHMARK_TEMPLATE(X,NativeVector)->Unit(benchmark::kMicrosecond)->ArgName("parm_2048")->Arg(2048);
a
=
a
+
b
;
#define DO_VECTOR_BENCHMARK_TEMPLATE(X,Y) \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_16")->Arg(16); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_1024")->Arg(1024); \
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_2048")->Arg(2048); \
/*BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_4096")->Arg(4096);*/
\
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_8192")->Arg(8192); \
/*BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_16384")->Arg(16384);*/
\
BENCHMARK_TEMPLATE(X,Y)->Unit(benchmark::kMicrosecond)->ArgName("parm_32768")->Arg(32768);
// add
template
<
typename
V
>
static
void
add_BigVec
(
const
V
&
a
,
const
V
&
b
)
{
V
c
=
a
+
b
;
}
static
void
BM_BigVec_Addition
(
benchmark
::
State
&
state
)
{
// benchmark
template
<
typename
V
>
static
void
BM_BigVec_Add
(
benchmark
::
State
&
state
)
{
// benchmark
auto
p
=
state
.
range
(
0
);
size_t
idx
=
ElemParamFactory
::
GetNearestIndex
(
p
);
typename
V
::
Integer
q
(
ElemParamFactory
::
DefaultSet
[
idx
].
q
);
V
a
=
makeVector
<
V
>
(
p
,
q
);
V
b
=
makeVector
<
V
>
(
p
,
q
);
while
(
state
.
KeepRunning
())
{
add_BigVec
(
state
);
add_BigVec
<
V
>
(
a
,
b
);
}
}
DO_PARM_BENCHMARK
(
BM_BigVec_Addition
)
DO_NATIVEVECTOR_BENCHMARK
(
BM_BigVec_Add
)
DO_VECTOR_BENCHMARK_TEMPLATE
(
BM_BigVec_Add
,
BE2Vector
)
DO_VECTOR_BENCHMARK_TEMPLATE
(
BM_BigVec_Add
,
BE4Vector
)
DO_VECTOR_BENCHMARK_TEMPLATE
(
BM_BigVec_Add
,
BE6Vector
)
// +=
static
void
addeq_BigVec
(
benchmark
::
State
&
state
)
{
state
.
PauseTiming
();
BigVector
a
=
makeVector
<
Poly
>
(
parmArray
[
state
.
range
(
0
)]);
BigVector
b
=
makeVector
<
Poly
>
(
parmArray
[
state
.
range
(
0
)]);
state
.
ResumeTiming
();
template
<
typename
V
>
static
void
addeq_BigVec
(
V
&
a
,
const
V
&
b
)
{
a
+=
b
;
}
template
<
typename
V
>
static
void
BM_BigVec_Addeq
(
benchmark
::
State
&
state
)
{
// benchmark
auto
p
=
state
.
range
(
0
);
size_t
idx
=
ElemParamFactory
::
GetNearestIndex
(
p
);
typename
V
::
Integer
q
(
ElemParamFactory
::
DefaultSet
[
idx
].
q
);
V
b
=
makeVector
<
V
>
(
p
,
q
);
while
(
state
.
KeepRunning
())
{
addeq_BigVec
(
state
);
V
a
=
makeVector
<
V
>
(
p
,
q
);
addeq_BigVec
<
V
>
(
a
,
b
);
}
}
DO_PARM_BENCHMARK
(
BM_BigVec_Addeq
)
DO_NATIVEVECTOR_BENCHMARK
(
BM_BigVec_Addeq
)
DO_VECTOR_BENCHMARK_TEMPLATE
(
BM_BigVec_Addeq
,
BE2Vector
)
DO_VECTOR_BENCHMARK_TEMPLATE
(
BM_BigVec_Addeq
,
BE4Vector
)
DO_VECTOR_BENCHMARK_TEMPLATE
(
BM_BigVec_Addeq
,
BE6Vector
)
// mult
static
void
mult_BigVec
(
benchmark
::
State
&
state
)
{
// function
state
.
PauseTiming
();
BigVector
a
=
makeVector
<
Poly
>
(
parmArray
[
state
.
range
(
0
)]);
BigVector
b
=
makeVector
<
Poly
>
(
parmArray
[
state
.
range
(
0
)]);
state
.
ResumeTiming
();
a
=
a
*
b
;
template
<
typename
V
>
static
void
mult_BigVec
(
const
V
&
a
,
const
V
&
b
)
{
// function
V
c
=
a
*
b
;
}
static
void
BM_BigVec_Multiplication
(
benchmark
::
State
&
state
)
{
// benchmark
template
<
typename
V
>
static
void
BM_BigVec_Mult
(
benchmark
::
State
&
state
)
{
// benchmark
auto
p
=
state
.
range
(
0
);
size_t
idx
=
ElemParamFactory
::
GetNearestIndex
(
p
);
typename
V
::
Integer
q
(
ElemParamFactory
::
DefaultSet
[
idx
].
q
);
V
a
=
makeVector
<
V
>
(
p
,
q
);
V
b
=
makeVector
<
V
>
(
p
,
q
);
while
(
state
.
KeepRunning
())
{
mult_BigVec
(
state
);
mult_BigVec
<
V
>
(
a
,
b
);
}
}
DO_PARM_BENCHMARK
(
BM_BigVec_Multiplication
)
DO_NATIVEVECTOR_BENCHMARK
(
BM_BigVec_Mult
)
DO_VECTOR_BENCHMARK_TEMPLATE
(
BM_BigVec_Mult
,
BE2Vector
)
DO_VECTOR_BENCHMARK_TEMPLATE
(
BM_BigVec_Mult
,
BE4Vector
)
DO_VECTOR_BENCHMARK_TEMPLATE
(
BM_BigVec_Mult
,
BE6Vector
)
// mult
static
void
multeq_BigVec
(
benchmark
::
State
&
state
)
{
// function
state
.
PauseTiming
();
BigVector
a
=
makeVector
<
Poly
>
(
parmArray
[
state
.
range
(
0
)]);
BigVector
b
=
makeVector
<
Poly
>
(
parmArray
[
state
.
range
(
0
)]);
state
.
ResumeTiming
();
template
<
typename
V
>
static
void
multeq_BigVec
(
V
&
a
,
const
V
&
b
)
{
a
*=
b
;
}
template
<
typename
V
>
static
void
BM_BigVec_Multeq
(
benchmark
::
State
&
state
)
{
// benchmark
auto
p
=
state
.
range
(
0
);
size_t
idx
=
ElemParamFactory
::
GetNearestIndex
(
p
);
typename
V
::
Integer
q
(
ElemParamFactory
::
DefaultSet
[
idx
].
q
);
V
b
=
makeVector
<
V
>
(
p
,
q
);
while
(
state
.
KeepRunning
())
{
multeq_BigVec
(
state
);
V
a
=
makeVector
<
V
>
(
p
,
q
);
multeq_BigVec
<
V
>
(
a
,
b
);
}
}
DO_PARM_BENCHMARK
(
BM_BigVec_Multeq
)
DO_NATIVEVECTOR_BENCHMARK
(
BM_BigVec_Multeq
)
DO_VECTOR_BENCHMARK_TEMPLATE
(
BM_BigVec_Multeq
,
BE2Vector
)
DO_VECTOR_BENCHMARK_TEMPLATE
(
BM_BigVec_Multeq
,
BE4Vector
)
DO_VECTOR_BENCHMARK_TEMPLATE
(
BM_BigVec_Multeq
,
BE6Vector
)
//execute the benchmarks
BENCHMARK_MAIN
()
benchmark/src/vechelper.h
View file @
f91bedc3
...
...
@@ -32,19 +32,19 @@
#include "math/backend.h"
using
namespace
lbcrypto
;
template
<
typename
P
>
inline
typename
P
::
Vector
makeVector
(
shared_ptr
<
typename
P
::
Params
>
p
)
{
typename
P
::
DugType
dug
;
dug
.
SetModulus
(
p
->
GetModulus
()
);
template
<
typename
V
>
inline
V
makeVector
(
usint
ringdim
,
const
typename
V
::
Integer
&
mod
)
{
DiscreteUniformGeneratorImpl
<
typename
V
::
Integer
,
V
>
dug
;
dug
.
SetModulus
(
mod
);
return
dug
.
GenerateVector
(
p
->
GetCyclotomicOrder
()
/
2
);
return
dug
.
GenerateVector
(
ringdim
);
}
inline
NativeVector
makeNativeVector
(
shared_ptr
<
ILNativeParams
>
p
)
{
NativePoly
::
DugType
dug
;
dug
.
SetModulus
(
p
->
GetModulus
()
);
inline
NativeVector
makeNativeVector
(
usint
ringdim
,
const
NativeInteger
&
mod
)
{
DiscreteUniformGeneratorImpl
<
NativeInteger
,
NativeVector
>
dug
;
dug
.
SetModulus
(
mod
);
return
dug
.
GenerateVector
(
p
->
GetR
ing
D
im
ension
()
);
return
dug
.
GenerateVector
(
r
ing
d
im
);
}
#endif
src/core/lib/math/interface.h
View file @
f91bedc3
...
...
@@ -379,7 +379,9 @@ namespace lbcrypto {
template
<
typename
T
,
typename
I
>
class
BigVectorInterface
{
public:
public:
typedef
I
Integer
;
// CONSTRUCTORS
// Constructors should be implemented in the derived classes
...
...
src/pke/demo/Temp-smalldemo.cpp
0 → 100644
View file @
f91bedc3
/*
* Temp-smalldemo.cpp
*
* Created on: Jan 4, 2018
* Author: gerardryan
*/
#include "palisade.h"
int
main
()
{
NativeInteger
a
(
100
);
NativeInteger
b
(
100
);
cout
<<
sizeof
(
a
)
<<
endl
;
NativeInteger
c
=
a
.
Plus
(
b
);
// uint64_t x;
//unsigned __int128 y;
a
+=
b
;
cout
<<
a
<<
" "
<<
b
<<
" "
<<
c
;
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment