Skip to content

Iyokan NT: Next Generation of Iyokan #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 54 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
135321c
wip
ushitora-anqou Sep 4, 2021
151f4e0
wip
ushitora-anqou Sep 12, 2021
9a79a3a
wip
ushitora-anqou Sep 14, 2021
48cede0
wip
ushitora-anqou Sep 14, 2021
85e2c32
wip
ushitora-anqou Sep 19, 2021
e9e50df
wip
ushitora-anqou Sep 19, 2021
7895376
Add loguru as a submodule
ushitora-anqou Sep 21, 2021
03fdb5a
wip
ushitora-anqou Sep 21, 2021
871a48e
wip
ushitora-anqou Sep 22, 2021
2862388
wip
ushitora-anqou Sep 22, 2021
83302a3
wip
ushitora-anqou Sep 22, 2021
83fb71e
wip
ushitora-anqou Sep 22, 2021
a51aa29
Bump thirdparty/cuFHE from afbd970f37cb2f3d0b658b9dad50462dbfcb8114 t…
ushitora-anqou Sep 22, 2021
cbcbefe
wip
ushitora-anqou Oct 29, 2021
106b93e
wip
ushitora-anqou Oct 30, 2021
6b6ac58
wip
ushitora-anqou Oct 30, 2021
7a756be
wip
ushitora-anqou Oct 31, 2021
de90856
wip
ushitora-anqou Oct 31, 2021
529737d
wip
ushitora-anqou Oct 31, 2021
d66e390
wip
ushitora-anqou Oct 31, 2021
6fce13c
wip
ushitora-anqou Oct 31, 2021
9bd8921
wip
ushitora-anqou Nov 1, 2021
6e5c371
wip
ushitora-anqou Nov 1, 2021
1614444
wip
ushitora-anqou Nov 1, 2021
baedb12
wip
ushitora-anqou Nov 1, 2021
2eeee08
wip
ushitora-anqou Nov 1, 2021
c22b380
wip
ushitora-anqou Nov 1, 2021
9061afe
wip
ushitora-anqou Nov 1, 2021
e75c0ba
wip
ushitora-anqou Nov 2, 2021
7c0c810
wip
ushitora-anqou Nov 2, 2021
3dd5c54
wip
ushitora-anqou Nov 2, 2021
88e2641
wip
ushitora-anqou Nov 2, 2021
0e1addd
wip
ushitora-anqou Nov 2, 2021
92ffee0
wip
ushitora-anqou Nov 3, 2021
46d0426
wip
ushitora-anqou Nov 3, 2021
5850722
wip
ushitora-anqou Nov 3, 2021
264167d
wip
ushitora-anqou Nov 3, 2021
b9b48ef
wip
ushitora-anqou Nov 6, 2021
a24c313
wip
ushitora-anqou Nov 7, 2021
d3dcd03
wip
ushitora-anqou Nov 7, 2021
9481594
wip (fix Snapshot::Snapshot)
ushitora-anqou Nov 9, 2021
bc6a53e
wip
ushitora-anqou Nov 9, 2021
175b721
wip
ushitora-anqou Nov 10, 2021
46911c0
wip
ushitora-anqou Nov 10, 2021
b29b5f8
wip
ushitora-anqou Nov 10, 2021
11a6a1c
wip
ushitora-anqou Nov 11, 2021
1bed0b6
wip
ushitora-anqou Nov 11, 2021
eb869e1
wip
ushitora-anqou Nov 12, 2021
14fe080
plain done
ushitora-anqou Nov 12, 2021
809c541
wip
ushitora-anqou Nov 13, 2021
cbaca2b
wip
ushitora-anqou Nov 13, 2021
9f18067
wip
ushitora-anqou Nov 13, 2021
bc7fd5d
wip
ushitora-anqou Nov 13, 2021
c9ae801
wip
ushitora-anqou Nov 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@
[submodule "fmt"]
path = thirdparty/fmt
url = https://github.com/fmtlib/fmt.git
[submodule "thirdparty/loguru"]
path = thirdparty/loguru
url = https://github.com/emilk/loguru.git
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ if (IYOKAN_ENABLE_CUDA)
else()
add_subdirectory(thirdparty/cuFHE/thirdparties/TFHEpp)
endif(IYOKAN_ENABLE_CUDA)

add_subdirectory(thirdparty/fmt)
add_subdirectory(thirdparty/spdlog)

set(IYOKAN_CXXFLAGS -Wall -Wextra -Wno-sign-compare)
Expand All @@ -47,13 +49,13 @@ set(IYOKAN_INCLUDE_DIRS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ELFIO>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/toml11>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/spdlog/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/fmt/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/cuFHE/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/loguru>
)
if (IYOKAN_ENABLE_CUDA)
list(APPEND IYOKAN_INCLUDE_DIRS ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
endif(IYOKAN_ENABLE_CUDA)
set(IYOKAN_LIBS tfhe++ Threads::Threads OpenMP::OpenMP_CXX Backward::Backward stdc++fs)
set(IYOKAN_LIBS tfhe++ Threads::Threads OpenMP::OpenMP_CXX Backward::Backward stdc++fs fmt::fmt)
if (IYOKAN_80BIT_SECURITY)
# For TFHEpp headers
list(APPEND IYOKAN_COMPILE_DEFINITIONS USE_80BIT_SECURITY)
Expand Down
15 changes: 9 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ endif(IYOKAN_ENABLE_CUDA)

##### test0
add_executable(test0
test0.cpp iyokan.cpp iyokan_plain.cpp iyokan_tfhepp.cpp error.cpp
test0.cpp
iyokan_nt.cpp iyokan_nt_plain.cpp iyokan_nt_tfhepp.cpp
error_nt.cpp packet_nt.cpp dataholder_nt.cpp
network_reader.cpp blueprint.cpp label.cpp allocator.cpp snapshot.cpp
${CMAKE_CURRENT_BINARY_DIR}/mux-ram-8-8-8.o
${CMAKE_CURRENT_BINARY_DIR}/mux-ram-8-16-16.o
${CMAKE_CURRENT_BINARY_DIR}/mux-ram-9-16-16.o)
Expand All @@ -41,11 +44,11 @@ target_compile_options(test0 PUBLIC "$<$<CONFIG:RELEASE>:${IYOKAN_CXXFLAGS_RELEA
target_link_libraries(test0 ${IYOKAN_LIBS})
target_include_directories(test0 PRIVATE ${IYOKAN_INCLUDE_DIRS})
target_compile_definitions(test0 PRIVATE ${IYOKAN_COMPILE_DEFINITIONS})
if (IYOKAN_ENABLE_CUDA)
target_sources(test0 PRIVATE iyokan_cufhe.cpp)
target_link_libraries(test0 cufhe_gpu ${CUDA_LIBRARIES})
target_compile_definitions(test0 PRIVATE IYOKAN_CUDA_ENABLED)
endif(IYOKAN_ENABLE_CUDA)
#if (IYOKAN_ENABLE_CUDA)
# target_sources(test0 PRIVATE iyokan_cufhe.cpp)
# target_link_libraries(test0 cufhe_gpu ${CUDA_LIBRARIES})
# target_compile_definitions(test0 PRIVATE IYOKAN_CUDA_ENABLED)
#endif(IYOKAN_ENABLE_CUDA)

##### iyokan-packet
add_executable(iyokan-packet iyokan-packet.cpp error.cpp)
Expand Down
120 changes: 120 additions & 0 deletions src/allocator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#include "dataholder_nt.hpp"
#include "iyokan_nt.hpp"
#include "packet_nt.hpp"

#include <cereal/archives/portable_binary.hpp>
#include <cereal/cereal.hpp>
#include <cereal/types/variant.hpp>

#include <functional>
#include <typeindex>
#include <variant>

namespace {

using namespace nt;

template <class Archive>
void save(Archive& ar, const Bit& b, const std::uint32_t version)
{
assert(version == 1);

ar(static_cast<bool>(b));
}

template <class Archive>
void load(Archive& ar, Bit& b, const std::uint32_t version)
{
assert(version == 1);

bool bl;
ar(bl);
b = static_cast<Bit>(b);
}

struct Serializable {
std::variant<Bit, TLWELvl0> data;

template <class Archive>
void serialize(Archive& ar, const std::uint32_t version)
{
assert(version == 1);

ar(data);
}
};

} // namespace

CEREAL_CLASS_VERSION(Serializable, 1);

namespace nt {

/* class Allocator */

Allocator::Allocator()
: hasLoadedFromIStream_(false), indexToBeMade_(0), data_()
{
}

Allocator::Allocator(cereal::PortableBinaryInputArchive& ar)
: hasLoadedFromIStream_(true), indexToBeMade_(0), data_()
{
// Read and de-serialize data from the snapshot file
size_t size;
Serializable buf;

ar(size);
for (size_t i = 0; i < size; i++) {
ar(buf);
switch (buf.data.index()) {
case 0: { // Bit
Bit b = std::get<0>(buf.data);
data_.emplace_back(b);
break;
}

case 1: { // TLWELvl0
const TLWELvl0& tlwe = std::get<1>(buf.data);
data_.emplace_back(tlwe);
break;
}

default:
ERR_UNREACHABLE;
}
}
}

void Allocator::dumpAllocatedData(cereal::PortableBinaryOutputArchive& ar) const
{
// FIXME: WE KNOW the code in this function is TREMENDOUSLY UGLY (and
// inefficient). We need to find some more sophisticated ways to do this.

Serializable buf;

// Serialization process for each type
std::unordered_map<std::type_index, std::function<void(const std::any&)>>
tyHandlers;
tyHandlers[typeid(Bit)] = [&](const std::any& any) {
const Bit* src = std::any_cast<Bit>(&any);
buf.data = *src;
ar(buf);
};
tyHandlers[typeid(TLWELvl0)] = [&](const std::any& any) {
const TLWELvl0* src = std::any_cast<TLWELvl0>(&any);
buf.data = *src;
ar(buf);
};

// First serialize the size of the entries
ar(static_cast<size_t>(data_.size()));

// Dispatch
for (size_t i = 0; i < data_.size(); i++) {
const std::any& src = data_.at(i);
tyHandlers.at(src.type())(src);
}
}

} // namespace nt
Loading