diff --git a/.gitmodules b/.gitmodules index ac11bb95..ecfa5184 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,8 +1,8 @@ [submodule "extern/ENCRYPTO_utils"] path = extern/ENCRYPTO_utils - url = ../ENCRYPTO_utils.git + url = https://github.com/encryptogroup/ENCRYPTO_utils.git branch = feature-cmake [submodule "extern/OTExtension"] path = extern/OTExtension - url = ../OTExtension.git + url = https://github.com/encryptogroup/OTExtension.git branch = feature-cmake diff --git a/MATRIX/MatrixMeasurement.h b/MATRIX/MatrixMeasurement.h new file mode 100644 index 00000000..9c7ec766 --- /dev/null +++ b/MATRIX/MatrixMeasurement.h @@ -0,0 +1,103 @@ +// +// Created by liork on 8/22/18. +// + +#ifndef ABY_MATRIXMEASUREMENT_H +#define ABY_MATRIXMEASUREMENT_H + +#include +#include +#include +#include + + +using namespace std; +using namespace std::chrono; + +class MatrixMeasurement +{ +private: + string getcwdStr() + { + char* buff;//automatically cleaned when it exits scope + return string(getcwd(buff,255)); + } + + int getTaskIdx(string name) + { + auto it = std::find(m_tasksNames.begin(), m_tasksNames.end(), name); + auto idx = distance(m_tasksNames.begin(), it); + return idx; + } + + vector> m_cpuStartTimes; + vector> m_cpuEndTimes; + string m_arguments = ""; + vector m_tasksNames; + +public: + MatrixMeasurement(size_t argc, char* argv[], vector tasksNames, int numberOfIterations): + m_cpuStartTimes(vector>(tasksNames.size(), vector(numberOfIterations))), + m_cpuEndTimes(vector>(tasksNames.size(), vector(numberOfIterations))) + { + + for(size_t idx = 0; idx < argc; ++idx) + { + string s(argv[idx]); + if (idx < argc - 1) + m_arguments += s + "*"; + else + m_arguments += s; + } + + m_tasksNames = tasksNames; + } + + void startSubTask(string taskName, int currentIterationNumber) + { + int taskIdx = getTaskIdx(taskName); + auto now = system_clock::now(); + + //Cast the time point to ms, then get its duration, then get the duration's count. + auto ms = time_point_cast(now).time_since_epoch().count(); + m_cpuStartTimes[taskIdx][currentIterationNumber] = ms; + } + + void endSubTask(string taskName, int currentIterationNumber) + { + int taskIdx = getTaskIdx(taskName); + auto now = system_clock::now(); + + //Cast the time point to ms, then get its duration, then get the duration's count. + auto ms = time_point_cast(now).time_since_epoch().count(); + m_cpuEndTimes[taskIdx][currentIterationNumber] = ms; + + // if this is the last task and last iteration write the data to file + if (taskIdx == m_tasksNames.size() - 1 && currentIterationNumber == m_cpuEndTimes[0].size() - 1) + { + string logFileName = getcwdStr() + "/../../MATRIX/logs/" + m_arguments + ".log"; + ofstream logFile(logFileName); + if (logFile.is_open()) + { + //write to file + int numberOfIterations = m_cpuEndTimes[0].size(); + for (size_t idx = 0; idx < m_tasksNames.size(); ++idx) + { + logFile << m_tasksNames[idx] + ":"; + cout << "taskName : " << m_tasksNames[idx] << endl; + for (size_t idx2 = 0; idx2 < numberOfIterations; ++idx2) + { + cout << "value : " << m_cpuEndTimes[idx][idx2] << endl; + logFile << to_string(m_cpuEndTimes[idx][idx2]- m_cpuStartTimes[taskIdx][currentIterationNumber]) + + ","; + } + + logFile << "\n"; + } + logFile.close(); + } + } + } +}; + +#endif //ABY_MATRIXMEASUREMENT_H diff --git a/MATRIX/build.sh b/MATRIX/build.sh new file mode 100644 index 00000000..b2eab111 --- /dev/null +++ b/MATRIX/build.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +cd .. +mkdir -p build && cd build +cmake .. -DABY_BUILD_EXE=On +make \ No newline at end of file diff --git a/MATRIX/logs/dummylog b/MATRIX/logs/dummylog new file mode 100644 index 00000000..e69de29b diff --git a/MATRIX/run.sh b/MATRIX/run.sh new file mode 100755 index 00000000..25d14289 --- /dev/null +++ b/MATRIX/run.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# read the arguments without party id + +argc=$# +argv=($@) +values="" + +for (( j=1; j= 8 else if((phase_value != ePreCompRead)||(!std::filesystem::exists(filename))) { +#else + else if((phase_value != ePreCompRead)||(!std::experimental::filesystem::exists(filename))) { +#endif /**Compute the MTs normally*/ ComputeMTs(); /**Check if the mode of precomputation is store. If so store it to respective file.*/ @@ -1668,7 +1692,11 @@ void BoolSharing::StoreMTsToFile(const char *filename) { Condition to check if the file already exists. If so then, the mode of write would be file append. */ +#if _GNUC_ >= 8 if(std::filesystem::exists(filename)) { +#else + if(std::experimental::filesystem::exists(filename)) { +#endif fp = fopen(filename, "a+b"); } else { @@ -1696,7 +1724,11 @@ void BoolSharing::ReadMTsFromFile(const char *filename) { FILE *fp; /**Calculate the file size*/ +#if __GNUC_ >= 8 uint64_t file_size = std::filesystem::file_size(filename); +#else + uint64_t file_size = std::experimental::filesystem::file_size(filename); +#endif /**Variable for the storing the NUMANDSizes value from the file.*/ uint32_t num_and_sizes; @@ -1766,7 +1798,11 @@ void BoolSharing::ReadMTsFromFile(const char *filename) { BOOL BoolSharing::isCircuitSizeLessThanOrEqualWithValueFromFile(char *filename, uint32_t in_circ_size) { /**Check if the file already exists and if the existing is empty. If so, return false.*/ - if(!std::filesystem::exists(filename)||std::filesystem::is_empty(filename)) { +#if __GNUC_ >= 8 + if(!std::experimental::filesystem::exists(filename)||std::filesystem::is_empty(filename)) { +#else + if(!std::experimental::filesystem::exists(filename)||std::experimental::filesystem::is_empty(filename)) { +#endif /**Returning false and reverting the precomputation mode to default.*/ return FALSE; } diff --git a/src/abycore/sharing/sharing.cpp b/src/abycore/sharing/sharing.cpp index 5d1e0068..bc6adc6b 100644 --- a/src/abycore/sharing/sharing.cpp +++ b/src/abycore/sharing/sharing.cpp @@ -21,7 +21,11 @@ #include #include #include +#if _GNUC_ >= 8 #include +#else +#include +#endif #include #include @@ -65,13 +69,17 @@ ePreCompPhase Sharing::GetPreCompPhaseValue() { } void Sharing::PreCompFileDelete() { uint64_t truncation_size; +#if __GNUC_ >= 8 std::filesystem::path filename; +#else + std::experimental::filesystem::path filename; +#endif if(m_eRole == SERVER) { filename = "pre_comp_server.dump"; } else { filename = "pre_comp_client.dump"; } - +#if __GNUC_ >= 8 if((std::filesystem::exists(filename))&&(GetPreCompPhaseValue() == ePreCompRead)) { if(m_nFilePos >= std::filesystem::file_size(filename)) { @@ -86,6 +94,22 @@ void Sharing::PreCompFileDelete() { } } } +#else + if((std::experimental::filesystem::exists(filename))&&(GetPreCompPhaseValue() == ePreCompRead)) { + + if(m_nFilePos >= std::experimental::filesystem::file_size(filename)) { + std::experimental::filesystem::remove(filename); + } + else { + truncation_size = std::experimental::filesystem::file_size(filename) - m_nFilePos; + std::error_code ec; + std::experimental::filesystem::resize_file(filename, truncation_size, ec); + if(ec) { + std::cout << "Error occured in truncate:" << ec.message() << std::endl; + } + } + } +#endif } diff --git a/src/examples/innerproduct/common/innerproduct.cpp b/src/examples/innerproduct/common/innerproduct.cpp index e1cceaa0..6fe3511e 100644 --- a/src/examples/innerproduct/common/innerproduct.cpp +++ b/src/examples/innerproduct/common/innerproduct.cpp @@ -18,11 +18,28 @@ #include "innerproduct.h" #include "../../../abycore/sharing/sharing.h" +#include "../../../../MATRIX/MatrixMeasurement.h" int32_t test_inner_product_circuit(e_role role, const std::string& address, uint16_t port, seclvl seclvl, uint32_t nvals, uint32_t bitlen, uint32_t nthreads, e_mt_gen_alg mt_alg, e_sharing sharing, uint32_t num) { + /** + Step 0: Init logger. + */ + char * argv[4]; + argv[0] = (char*)"innerproduct"; + argv[1] = (char*)malloc(16); + sprintf(argv[1], "%d", role); + argv[2] = (char*)malloc(16); + sprintf(argv[2], "%d", bitlen); + argv[3] = (char*)malloc(16); + sprintf(argv[3], "%d", seclvl.symbits); + + vector subTaskNames{"BuildInnerProductCircuit", "ExecCircuit"}; + + MatrixMeasurement log(4, argv, subTaskNames, 1); + /** Step 1: Create the ABYParty object which defines the basis of all the operations which are happening. Operations performed are on the @@ -31,6 +48,7 @@ int32_t test_inner_product_circuit(e_role role, const std::string& address, uint ABYParty* party = new ABYParty(role, address, port, seclvl, bitlen, nthreads, mt_alg); + /** Step 2: Get to know all the sharing types available in the program. */ @@ -92,8 +110,10 @@ int32_t test_inner_product_circuit(e_role role, const std::string& address, uint problem by passing the shared objects and circuit object. Don't forget to type cast the circuit object to type of share */ + log.startSubTask("BuildInnerProductCircuit", 0); s_out = BuildInnerProductCircuit(s_x_vec, s_y_vec, num, (ArithmeticCircuit*) circ); + log.endSubTask("BuildInnerProductCircuit", 0); /** Step 8: Output the value of s_out (the computation result) to both parties @@ -104,7 +124,9 @@ int32_t test_inner_product_circuit(e_role role, const std::string& address, uint Step 9: Executing the circuit using the ABYParty object evaluate the problem. */ + log.startSubTask("ExecCircuit", 0); party->ExecCircuit(); + log.endSubTask("ExecCircuit", 0); /** Step 10: Type caste the plaintext output to 16 bit unsigned integer.