Skip to content

Commit

Permalink
Merge pull request #375 from fboemer/fboemer/hexl-v1.2.0
Browse files Browse the repository at this point in the history
Update to HEXL version 1.2.1
  • Loading branch information
Wei Dai committed Sep 15, 2021
1 parent e966ba1 commit 747b98a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 31 deletions.
32 changes: 17 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ endif()
# Required files and directories
include(GNUInstallDirs)

# Runtime path setup
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Source Tree
set(SEAL_INCLUDES_DIR ${CMAKE_CURRENT_LIST_DIR}/native/src)
set(SEAL_THIRDPARTY_DIR ${CMAKE_CURRENT_LIST_DIR}/thirdparty)
Expand Down Expand Up @@ -219,9 +223,9 @@ if(SEAL_USE_INTEL_HEXL)
message(STATUS "Intel HEXL: download ...")
seal_fetch_thirdparty_content(ExternalIntelHEXL)
else()
find_package(HEXL 1.1.0)
find_package(HEXL 1.2.1)
if (NOT TARGET HEXL::hexl)
FATAL_ERROR("Intel HEXL: not found")
message(FATAL_ERROR "Intel HEXL: not found")
endif()
endif()
endif()
Expand Down Expand Up @@ -412,15 +416,13 @@ if(NOT BUILD_SHARED_LIBS)
if(SEAL_USE_INTEL_HEXL)
if(SEAL_BUILD_DEPS)
add_dependencies(seal HEXL::hexl)
target_include_directories(seal PUBLIC $<BUILD_INTERFACE:${hexl_SOURCE_DIR}/hexl/include>)
target_include_directories(seal PUBLIC
$<BUILD_INTERFACE:$<TARGET_PROPERTY:HEXL::hexl,INTERFACE_INCLUDE_DIRECTORIES>>)
seal_combine_archives(seal HEXL::hexl)
target_compile_options(seal PUBLIC $<TARGET_PROPERTY:HEXL::hexl,INTERFACE_COMPILE_OPTIONS>)
target_link_options(seal PUBLIC $<TARGET_PROPERTY:HEXL::hexl,INTERFACE_LINK_OPTIONS>)
else()
target_link_libraries(seal PRIVATE HEXL::hexl)
get_target_property(
HEXL_INCLUDE_DIR
HEXL::hexl
INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(seal PUBLIC ${HEXL_INCLUDE_DIR})
target_link_libraries(seal PUBLIC HEXL::hexl)
endif()
endif()

Expand Down Expand Up @@ -461,12 +463,12 @@ else()
endif()

if(SEAL_USE_INTEL_HEXL)
get_target_property(
HEXL_INCLUDE_DIR
HEXL::hexl
INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(seal_shared PUBLIC ${HEXL_INCLUDE_DIR})
target_link_libraries(seal_shared PRIVATE HEXL::hexl)
target_link_libraries(seal_shared PUBLIC HEXL::hexl)
# Install shared HEXL library to installation directory
install(DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_LIBRARY_PREFIX}
FILES_MATCHING PATTERN "*hexl*"
)
endif()
endif()

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ The optional dependencies and their tested versions (other versions may work as

| Optional dependency | Tested version | Use |
| ------------------------------------------------------ | -------------- | ------------------------------------------------ |
| [Intel HEXL](https://github.com/intel/hexl) | 1.1.0 | Acceleration of low-level kernels |
| [Intel HEXL](https://github.com/intel/hexl) | 1.2.1 | Acceleration of low-level kernels |
| [Microsoft GSL](https://github.com/microsoft/GSL) | 3.1.0 | API extensions |
| [ZLIB](https://github.com/madler/zlib) | 1.2.11 | Compressed serialization |
| [Zstandard](https://github.com/facebook/zstd) | 1.4.5 | Compressed serialization (much faster than ZLIB) |
Expand Down
8 changes: 2 additions & 6 deletions cmake/ExternalIntelHEXL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@ FetchContent_Declare(
hexl
PREFIX hexl
GIT_REPOSITORY https://github.com/intel/hexl
GIT_TAG 2dc1db # v1.1.0
GIT_TAG df6c26f # 1.2.1
)
FetchContent_GetProperties(hexl)

if(NOT hexl_POPULATED)
FetchContent_Populate(hexl)
set(HEXL_DEBUG OFF) # Set to ON/OFF to toggle debugging

set(CMAKE_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING "" FORCE)
set(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING "" FORCE)
set(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE STRING "" FORCE)
set(HEXL_DEBUG ${HEXL_DEBUG} CACHE BOOL "" FORCE)
set(HEXL_BENCHMARK OFF CACHE BOOL "" FORCE)
set(HEXL_EXPORT OFF CACHE BOOL "" FORCE)
set(HEXL_COVERAGE OFF CACHE BOOL "" FORCE)
set(HEXL_TESTING OFF CACHE BOOL "" FORCE)
set(HEXL_SHARED_LIB OFF CACHE BOOL "" FORCE)
set(HEXL_SHARED_LIB ${BUILD_SHARED_LIBS} CACHE BOOL "" FORCE)
set(EXCLUDE_FROM_ALL TRUE)

mark_as_advanced(BUILD_HEXL)
Expand Down
2 changes: 1 addition & 1 deletion native/src/seal/evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ namespace seal
// x = (x[0] * y[0], x[0] * y[1] + x[1] * y[0], x[1] * y[1])
// with appropriate modular reduction
SEAL_ITERATE(coeff_modulus, coeff_modulus_size, [&](auto I) {
SEAL_ITERATE(iter(size_t(0)), num_tiles, [&](auto J) {
SEAL_ITERATE(iter(size_t(0)), num_tiles, [&](SEAL_MAYBE_UNUSED auto J) {
// Compute third output polynomial, overwriting input
// x[2] = x[1] * y[1]
dyadic_product_coeffmod(
Expand Down
4 changes: 2 additions & 2 deletions native/src/seal/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ namespace seal

streamoff Serialization::Save(
function<void(ostream &)> save_members, streamoff raw_size, ostream &stream, compr_mode_type compr_mode,
bool clear_buffers)
SEAL_MAYBE_UNUSED bool clear_buffers)
{
if (!save_members)
{
Expand Down Expand Up @@ -339,7 +339,7 @@ namespace seal
}

streamoff Serialization::Load(
function<void(istream &, SEALVersion)> load_members, istream &stream, bool clear_buffers)
function<void(istream &, SEALVersion)> load_members, istream &stream, SEAL_MAYBE_UNUSED bool clear_buffers)
{
if (!load_members)
{
Expand Down
2 changes: 1 addition & 1 deletion native/src/seal/util/intel_seal_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace intel
{
namespace seal_ext
{
hexl::NTT get_ntt(size_t N, uint64_t modulus, uint64_t root)
intel::hexl::NTT &get_ntt(size_t N, uint64_t modulus, uint64_t root)
{
static unordered_map<pair<uint64_t, uint64_t>, hexl::NTT, HashPair> ntt_cache_;

Expand Down
8 changes: 3 additions & 5 deletions native/src/seal/util/intel_seal_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ namespace intel
return cache_.back().get();
}

void deallocate_impl(void *p, std::size_t n)
void deallocate_impl(void *p, SEAL_MAYBE_UNUSED std::size_t n)
{
(void)n;
auto it = std::remove_if(
cache_.begin(), cache_.end(),
[p](const seal::util::Pointer<seal::seal_byte> &seal_pointer) { return p == seal_pointer.get(); });
Expand Down Expand Up @@ -97,9 +96,8 @@ namespace intel
}
}

void deallocate_impl(void *p, std::size_t n)
void deallocate_impl(void *p, SEAL_MAYBE_UNUSED std::size_t n)
{
(void)n;
{
// to prevent inline optimization with deadlock
auto accessor = policy_.locker();
Expand Down Expand Up @@ -151,7 +149,7 @@ namespace intel
@param[in] modulus The modulus
@param[in] root The root of unity
*/
hexl::NTT get_ntt(std::size_t N, std::uint64_t modulus, std::uint64_t root);
intel::hexl::NTT &get_ntt(size_t N, uint64_t modulus, uint64_t root);

/**
Computes the forward negacyclic NTT from the given parameters.
Expand Down
3 changes: 3 additions & 0 deletions native/tests/seal/util/rns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,8 @@ namespace sealtest
}

// The size of Bsk is 2. Both values here are multiples of 35 (i.e., q).
// Skip tests exceeding input bound when using HEXL in DEBUG mode
#if !defined(SEAL_DEBUG) || !defined(SEAL_USE_INTEL_HEXL)
in[0] = 35;
in[1] = 70;
in[2] = 35;
Expand All @@ -896,6 +898,7 @@ namespace sealtest
rns_tool->decrypt_scale_and_round(in_iter, out_iter, pool);
ASSERT_EQ(2ULL, out[0]);
ASSERT_EQ(0ULL, out[1]);
#endif
}

TEST(RNSToolTest, DivideAndRoundQLastInplace)
Expand Down

0 comments on commit 747b98a

Please sign in to comment.