Commit 94b0adf6 authored by Gerard Ryan's avatar Gerard Ryan

Merge branch 'v1.1.1' into 'master'

V1.1.1 See merge request !2
parents de794a4c b3a96feb
...@@ -157,6 +157,6 @@ include Makefile.wrapper ...@@ -157,6 +157,6 @@ include Makefile.wrapper
include Makefile.benchmark #builds the benchmark framework include Makefile.benchmark #builds the benchmark framework
include Makefile.docs #populates doxgen documentation include Makefile.docs #populates doxgen documentation
$(BINDIR)/unittest/tests$(EXESUFFIX): $(UNITTESTMAINOBJ) $(COREUNITOBJECTS) $(EXTLIBDIR)/$(PALISADECORELIB) $(PKEUNITOBJECTS) $(EXTLIBDIR)/$(PALISADEPKELIB) $(TRAPDOORUNITOBJECTS) $(EXTLIBDIR)/$(PALISADETRAPDOORLIB) $(NTLLIB) $(GMPLIB) $(BINDIR)/unittest/tests$(EXESUFFIX): $(UNITTESTMAINOBJ) $(COREUNITOBJECTS) $(EXTLIBDIR)/$(PALISADECORELIB) $(PKEUNITOBJECTS) $(EXTLIBDIR)/$(PALISADEPKELIB) $(NTLLIB) $(GMPLIB)
@mkdir -p $(BINDIR)/unittest @mkdir -p $(BINDIR)/unittest
$(CC) -o $@ $(UNITTESTMAINOBJ) $(COREUNITOBJECTS) $(PKEUNITOBJECTS) $(TRAPDOORUNITOBJECTS) $(EXTLIB) -lPALISADEtrapdoor -lPALISADEpke -lPALISADEcore $(TEST_LIB) $(NTLLIB) $(GMPLIB) $(CC) -o $@ $(UNITTESTMAINOBJ) $(COREUNITOBJECTS) $(PKEUNITOBJECTS) $(EXTLIB) -lPALISADEpke -lPALISADEcore $(TEST_LIB) $(NTLLIB) $(GMPLIB)
1/29/2018: PALISADE v1.1.1 is released
PALISADE v1.1.1 includes bug fixes and minor optimizations:
Fixes minor bugs in NativeInteger and multiprecision backends (BigInteger)
Deals properly with a low-probability rounding error in BFVrns
Fixes a compilation error on some CentOS systems
Improves the performance of NativeInteger
Fixes a couple of other minor bugs
12/29/2017: PALISADE v1.1 is released 12/29/2017: PALISADE v1.1 is released
PALISADE v1.1 includes the following new capabilities, library enhancements, and optimizations: PALISADE v1.1 includes the following new capabilities, library enhancements, and optimizations:
...@@ -9,4 +19,4 @@ PALISADE v1.1 includes the following new capabilities, library enhancements, an ...@@ -9,4 +19,4 @@ PALISADE v1.1 includes the following new capabilities, library enhancements, an
* NTL integration as a new option for the multiprecision arithmetic backend * NTL integration as a new option for the multiprecision arithmetic backend
* And more... * And more...
07/15/2017: PALISADE v1.0 is released 07/15/2017: PALISADE v1.0 is released
\ No newline at end of file
...@@ -22,108 +22,47 @@ ...@@ -22,108 +22,47 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 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 #define _USE_MATH_DEFINES
#include "math/backend.h" #include "math/backend.h"
#include "utils/inttypes.h" #include "utils/inttypes.h"
#include "math/nbtheory.h" #include "math/nbtheory.h"
#include "math/distrgen.h"
#include "lattice/elemparams.h" #include "lattice/elemparams.h"
#include "lattice/ilparams.h" #include "lattice/ilparams.h"
#include "lattice/ildcrtparams.h" #include "lattice/ildcrtparams.h"
#include "lattice/ilelement.h" #include "lattice/ilelement.h"
#include "math/distrgen.h"
#include "lattice/poly.h" #include "lattice/poly.h"
#include "../../src/core/lib/lattice/dcrtpoly.h" #include "lattice/dcrtpoly.h"
#include "utils/utilities.h" #include "utils/utilities.h"
#include "vechelper.h"
#include "ElementParmsHelper.h"
using namespace std; using namespace std;
using namespace lbcrypto; using namespace lbcrypto;
// add using BE2Integer = cpu_int::BigInteger<integral_dtype,BigIntegerBitLength>;
static void add_BigVec(benchmark::State& state) { using BE2ILParams = ILParamsImpl<BE2Integer>;
state.PauseTiming(); using BE2ILDCRTParams = ILDCRTParams<BE2Integer>;
BigVector a = makeVector(parmArray[state.range(0)]); using BE2Vector = cpu_int::BigVectorImpl<BE2Integer>;
BigVector b = makeVector(parmArray[state.range(0)]); using BE2Poly = PolyImpl<BE2Integer, BE2Integer, BE2Vector, BE2ILParams>;
state.ResumeTiming(); using BE2DCRTPoly = DCRTPolyImpl<BE2Integer, BE2Integer, BE2Vector, BE2ILDCRTParams>;
a = a+b; using BE4Integer = exp_int::xubint;
} using BE4ILParams = ILParamsImpl<BE4Integer>;
using BE4ILDCRTParams = ILDCRTParams<BE4Integer>;
static void BM_BigVec_Addition(benchmark::State& state) { // benchmark using BE4Vector = exp_int::xmubintvec;
using BE4Poly = PolyImpl<BE4Integer, BE4Integer, BE4Vector, BE4ILParams>;
while (state.KeepRunning()) { using BE4DCRTPoly = DCRTPolyImpl<BE4Integer, BE4Integer, BE4Vector, BE4ILDCRTParams>;
add_BigVec(state);
} using BE6Integer = NTL::myZZ;
} using BE6ILParams = ILParamsImpl<BE6Integer>;
using BE6ILDCRTParams = ILDCRTParams<BE6Integer>;
DO_PARM_BENCHMARK(BM_BigVec_Addition) using BE6Vector = NTL::myVecP<NTL::myZZ>;
using BE6Poly = PolyImpl<BE6Integer, BE6Integer, BE6Vector, BE6ILParams>;
// += using BE6DCRTPoly = DCRTPolyImpl<BE6Integer, BE6Integer, BE6Vector, BE6ILDCRTParams>;
static void addeq_BigVec(benchmark::State& state) {
state.PauseTiming(); #endif /* BENCHMARK_SRC_ALLBACKENDS_H_ */
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()
...@@ -53,29 +53,27 @@ using namespace std; ...@@ -53,29 +53,27 @@ using namespace std;
using namespace lbcrypto; using namespace lbcrypto;
#include "vechelper.h" #include "vechelper.h"
#include "ElementParmsHelper.h"
#include "EncryptHelper.h" #include "EncryptHelper.h"
#include "lattice/elemparamfactory.h"
void BM_keygen(benchmark::State& state) { // benchmark void BM_keygen(benchmark::State& state) { // benchmark
CryptoContext<Poly> cc; CryptoContext<Poly> cc;
if( state.thread_index == 0 ) { if( state.thread_index == 0 ) {
state.PauseTiming();
cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->Enable(ENCRYPTION);
cc->Enable(PRE);
try { try {
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(), cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->GetCyclotomicOrder(), cc->Enable(ENCRYPTION);
cc->GetModulus()); cc->Enable(PRE);
} catch( ... ) {} } catch( std::exception& e ) {
state.SkipWithError( e.what() );
return;
}
try { try {
typename Poly::DggType dgg = Poly::DggType(4); // Create the noise generator ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
cc->GetCyclotomicOrder(),
cc->GetModulus());
} catch( ... ) {} } catch( ... ) {}
state.ResumeTiming();
} }
while (state.KeepRunning()) { while (state.KeepRunning()) {
...@@ -85,27 +83,27 @@ void BM_keygen(benchmark::State& state) { // benchmark ...@@ -85,27 +83,27 @@ void BM_keygen(benchmark::State& state) { // benchmark
BENCHMARK_PARMS(BM_keygen) 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 void BM_encrypt(benchmark::State& state) { // benchmark
CryptoContext<Poly> cc; CryptoContext<Poly> cc;
LPKeyPair<Poly> kp; LPKeyPair<Poly> kp;
Ciphertext<Poly> ciphertext; Ciphertext<Poly> ciphertext;
Plaintext plaintext; 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 ) { if( state.thread_index == 0 ) {
state.PauseTiming(); try {
cc = CryptoContextHelper::getNewContext(parms[state.range(0)]); cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->Enable(ENCRYPTION); cc->Enable(ENCRYPTION);
cc->Enable(PRE); cc->Enable(PRE);
} catch( std::exception& e ) {
state.SkipWithError( e.what() );
return;
}
try { try {
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(), ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
...@@ -113,21 +111,9 @@ void BM_encrypt(benchmark::State& state) { // benchmark ...@@ -113,21 +111,9 @@ void BM_encrypt(benchmark::State& state) { // benchmark
cc->GetModulus()); cc->GetModulus());
} catch( ... ) {} } catch( ... ) {}
try { vector<int64_t> input(cc->GetRingDimension(),0);
typename Poly::DggType dgg = Poly::DggType(4); // Create the noise generator fillrandint(input, cc->GetEncodingParams()->GetPlaintextModulus());
} catch( ... ) {} plaintext = cc->MakeCoefPackedPlaintext(input);
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();
} }
while (state.KeepRunning()) { while (state.KeepRunning()) {
...@@ -148,21 +134,15 @@ void BM_decrypt(benchmark::State& state) { // benchmark ...@@ -148,21 +134,15 @@ void BM_decrypt(benchmark::State& state) { // benchmark
Plaintext plaintext; Plaintext plaintext;
Plaintext plaintextNew; 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 ) { if( state.thread_index == 0 ) {
state.PauseTiming(); try {
cc = CryptoContextHelper::getNewContext(parms[state.range(0)]); cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->Enable(ENCRYPTION); cc->Enable(ENCRYPTION);
cc->Enable(PRE); cc->Enable(PRE);
} catch( std::exception& e ) {
state.SkipWithError( e.what() );
return;
}
try { try {
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(), ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
...@@ -170,21 +150,9 @@ void BM_decrypt(benchmark::State& state) { // benchmark ...@@ -170,21 +150,9 @@ void BM_decrypt(benchmark::State& state) { // benchmark
cc->GetModulus()); cc->GetModulus());
} catch( ... ) {} } catch( ... ) {}
try { vector<int64_t> input(cc->GetRingDimension(),0);
typename Poly::DggType dgg = Poly::DggType(4); // Create the noise generator fillrandint(input, cc->GetEncodingParams()->GetPlaintextModulus());
} catch( ... ) {} plaintext = cc->MakeCoefPackedPlaintext(input);
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();
} }
while (state.KeepRunning()) { while (state.KeepRunning()) {
...@@ -204,11 +172,15 @@ void BM_rekeygen(benchmark::State& state) { // benchmark ...@@ -204,11 +172,15 @@ void BM_rekeygen(benchmark::State& state) { // benchmark
LPKeyPair<Poly> kp; LPKeyPair<Poly> kp;
if( state.thread_index == 0 ) { if( state.thread_index == 0 ) {
state.PauseTiming(); try {
cc = CryptoContextHelper::getNewContext(parms[state.range(0)]); cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->Enable(ENCRYPTION); cc->Enable(ENCRYPTION);
cc->Enable(PRE); cc->Enable(PRE);
cc->Enable(SHE); cc->Enable(SHE);
} catch( std::exception& e ) {
state.SkipWithError( e.what() );
return;
}
try { try {
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(), ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
...@@ -216,13 +188,6 @@ void BM_rekeygen(benchmark::State& state) { // benchmark ...@@ -216,13 +188,6 @@ void BM_rekeygen(benchmark::State& state) { // benchmark
cc->GetModulus()); cc->GetModulus());
} catch( ... ) { } catch( ... ) {
} }
try {
typename Poly::DggType dgg = Poly::DggType(4); // Create the noise generator
} catch( ... ) {
}
state.ResumeTiming();
} }
while (state.KeepRunning()) { while (state.KeepRunning()) {
...@@ -251,21 +216,15 @@ void BM_reencrypt(benchmark::State& state) { // benchmark ...@@ -251,21 +216,15 @@ void BM_reencrypt(benchmark::State& state) { // benchmark
Plaintext plaintext; Plaintext plaintext;
Plaintext plaintextNew; 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 ) { if( state.thread_index == 0 ) {
state.PauseTiming(); try {
cc = CryptoContextHelper::getNewContext(parms[state.range(0)]); cc = CryptoContextHelper::getNewContext(parms[state.range(0)]);
cc->Enable(ENCRYPTION); cc->Enable(ENCRYPTION);
cc->Enable(PRE); cc->Enable(PRE);
} catch( std::exception& e ) {
state.SkipWithError( e.what() );
return;
}
try { try {
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(), ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
...@@ -273,21 +232,9 @@ void BM_reencrypt(benchmark::State& state) { // benchmark ...@@ -273,21 +232,9 @@ void BM_reencrypt(benchmark::State& state) { // benchmark
cc->GetModulus()); cc->GetModulus());
} catch( ... ) {} } catch( ... ) {}
try { vector<int64_t> input(cc->GetRingDimension(),0);
typename Poly::DggType dgg = Poly::DggType(4); // Create the noise generator fillrandint(input, cc->GetEncodingParams()->GetPlaintextModulus());
} catch( ... ) {} plaintext = cc->MakeCoefPackedPlaintext(input);
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();
} }
LPEvalKey<Poly> evalKey; LPEvalKey<Poly> evalKey;
......
/**
* @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);
...@@ -41,22 +41,15 @@ using namespace std; ...@@ -41,22 +41,15 @@ using namespace std;
using namespace lbcrypto; using namespace lbcrypto;
void BM_encoding_Scalar(benchmark::State& state) { void BM_encoding_Scalar(benchmark::State& state) {
usint m = 1024;
PlaintextModulus ptm = 128;
int64_t value = 47;
Plaintext plaintext; Plaintext plaintext;
shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParams>(m);
if( state.thread_index == 0 ) { EncodingParams ep( new EncodingParamsImpl(ptm) );
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();
}
while (state.KeepRunning()) { while (state.KeepRunning()) {
plaintext.reset( new ScalarEncoding(lp, ep, value) );
plaintext->Encode(); plaintext->Encode();
} }
} }
...@@ -65,23 +58,16 @@ BENCHMARK(BM_encoding_Scalar); ...@@ -65,23 +58,16 @@ BENCHMARK(BM_encoding_Scalar);
void BM_encoding_Integer(benchmark::State& state) { // benchmark void BM_encoding_Integer(benchmark::State& state) { // benchmark
CryptoContext<Poly> cc;
Plaintext plaintext; Plaintext plaintext;
usint m = 1024;
PlaintextModulus ptm = 128;
int64_t mv = 58;
if( state.thread_index == 0 ) { shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParams>(m);
state.PauseTiming(); EncodingParams ep( new EncodingParamsImpl(ptm) );
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();
}
while (state.KeepRunning()) { while (state.KeepRunning()) {
plaintext.reset( new IntegerEncoding(lp, ep, mv) );
plaintext->Encode(); plaintext->Encode();
} }
} }
...@@ -90,26 +76,19 @@ BENCHMARK(BM_encoding_Integer); ...@@ -90,26 +76,19 @@ BENCHMARK(BM_encoding_Integer);
void BM_encoding_CoefPacked(benchmark::State& state) { void BM_encoding_CoefPacked(benchmark::State& state) {
Plaintext plaintext; Plaintext plaintext;
usint m = 1024;
PlaintextModulus ptm = 128;
PlaintextModulus half = ptm / 2;
if( state.thread_index == 0 ) { shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParams>(m);
state.PauseTiming(); EncodingParams ep( new EncodingParamsImpl(ptm) );
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); vector<int64_t> intvec;
EncodingParams ep( new EncodingParamsImpl(ptm) ); for( usint ii=0; ii<m/2; ii++)
intvec.push_back( rand() % half );
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();
}
while (state.KeepRunning()) { while (state.KeepRunning()) {
plaintext.reset( new CoefPackedEncoding(lp,ep,intvec) );
plaintext->Encode(); plaintext->Encode();
} }
} }
...@@ -123,29 +102,22 @@ void BM_encoding_PackedIntPlaintext(benchmark::State& state) { ...@@ -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 }; std::vector<uint64_t> vectorOfInts1 = { 1,2,3,4,5,6,7,8,0,0 };