Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 5 additions & 7 deletions .github/workflows/run-3pc-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ jobs:
test-all-3pc:
if: github.event.pull_request.draft == false

# ubuntu-latest, for private repos, only gives us 2 cores
# see github docs for more info
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

# Bumping this because apt install is slow (and we need coproto installed)
timeout-minutes: 30
Expand Down Expand Up @@ -64,7 +62,7 @@ jobs:

test-2pc:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

# This should be more than enough time to run tests, but also need enough
# time to install libOTe + save cache, where necessary
Expand Down Expand Up @@ -110,7 +108,7 @@ jobs:
with:
path: |
build/secure-join-install
key: secrecy-securejoin-${{ hashFiles('scripts/_setup_libote.sh', 'scripts/_clone_libote.sh', 'scripts/_setup_securejoin.sh', 'scripts/cmake/FindlibOTe.cmake') }}
key: secrecy-securejoin-${{ hashFiles('scripts/_setup_libote.sh', 'scripts/_clone_libote.sh', 'scripts/_setup_securejoin.sh') }}

# cache miss, so install from scratch
- if: ${{ steps.cache-securejoin.outputs.cache-hit != 'true' }}
Expand Down Expand Up @@ -140,9 +138,9 @@ jobs:
test-others:
if: github.event.pull_request.draft == false

# ubuntu-latest, for private repos, only gives us 2 cores
# for private repos, only gives us 2 cores
# see github docs for more info
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

timeout-minutes: 10

Expand Down
26 changes: 11 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(Orq VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(OPT_LEVEL "2" CACHE STRING "Optimization level (0-3)")
set(CMAKE_CXX_FLAGS "-O${OPT_LEVEL} -pthread -fwrapv")
set(CMAKE_CXX_FLAGS "-O${OPT_LEVEL} -g -pthread -fwrapv")

add_compile_options(-Wno-deprecated-declarations)

Expand All @@ -25,13 +25,7 @@ endif (PERF)

if (NOT NO_X86_SSE)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
# ubuntu-latest runners are a mix of AVX2-only and AVX-512 machines, and
# x86-64-v3 (common ancestor) is sufficient for our purposes.
if(DEFINED ENV{GITHUB_ACTIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mbmi -march=x86-64-v3")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mbmi -march=native")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mbmi -march=native")
endif()
endif (NOT NO_X86_SSE)

Expand Down Expand Up @@ -96,6 +90,10 @@ find_package(Threads REQUIRED)
# Adding Dependencies
# add_subdirectory(src/external-lib/sql-parser)

# Skip MPI C++ bindings: RELIC (via libOTe/SecureJoin) #define's DOUBLE,
# which collides with OpenMPI's MPI::DOUBLE when the CXX headers are pulled in.
add_compile_definitions(OMPI_SKIP_MPICXX MPICH_SKIP_MPICXX)

# Adding MPI Library
find_package(MPI REQUIRED)
if (MPI_FOUND)
Expand Down Expand Up @@ -129,9 +127,7 @@ if (PROTOCOL EQUAL "2" AND LINK_LIBOTE)

find_package(secureJoin REQUIRED HINTS
secure-join-install/lib/cmake/secureJoin/
secure-join-install/lib64/cmake/secureJoin/
build/secure-join-install/lib/cmake/secureJoin/
build/secure-join-install/lib64/cmake/secureJoin/)
build/secure-join-install/lib/cmake/secureJoin/)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/build/secure-join-install/lib)
endif ()

Expand All @@ -143,10 +139,10 @@ find_package(cryptoTools REQUIRED HINTS
list(APPEND LINK_LIBRARIES "oc::cryptoTools")

function(add_secure_join target_name)
if(PROTOCOL EQUAL "2" AND LINK_LIBOTE)
target_link_libraries(${target_name} secureJoin)
target_include_directories(${target_name} SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/build/secure-join-install/include/secureJoin/)
endif()
if(PROTOCOL EQUAL "2" AND LINK_LIBOTE)
target_link_libraries(${target_name} secureJoin)
target_include_directories(${target_name} SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/build/secure-join-install/include/secureJoin/)
endif()
endfunction()

# Option: switch between custom 4PC and original Dalskov et al. protocol
Expand Down
2 changes: 1 addition & 1 deletion bench/micro/micro_comm_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main(int argc, char** argv) {
comm_suffix = "NoCopyComm (" + std::to_string(NOCOPY_COMMUNICATOR_THREADS) + ")";

single_cout(
"Vector: " << test_size << " x " << std::numeric_limits<std::make_unsigned_t<T>>::digits
"Vector: " << test_size << " x " << std::numeric_limits<orq::make_unsigned_t<T>>::digits
<< "b | Sample count: " << SAMPLE_COUNT << " | Communicator: " << comm_suffix);

orq::Vector<T> send_batch(test_size), recv_batch(test_size);
Expand Down
2 changes: 1 addition & 1 deletion bench/micro/micro_comm_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main(int argc, char** argv) {
comm_suffix = "NoCopyComm (" + std::to_string(NOCOPY_COMMUNICATOR_THREADS) + ")";

single_cout(
"Vector: " << test_size << " x " << std::numeric_limits<std::make_unsigned_t<T>>::digits
"Vector: " << test_size << " x " << std::numeric_limits<orq::make_unsigned_t<T>>::digits
<< "b | Sample count: " << SAMPLE_COUNT << " | Communicator: " << comm_suffix);

#ifdef CORRECTNESS_CHECK
Expand Down
2 changes: 1 addition & 1 deletion bench/micro/micro_primitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main(int argc, char** argv) {
ASharedVector<T> x(test_size), y(test_size);

single_cout("Vector " << test_size << " x "
<< std::numeric_limits<std::make_unsigned_t<T>>::digits << "b");
<< std::numeric_limits<orq::make_unsigned_t<T>>::digits << "b");

stopwatch::timepoint("Start");

Expand Down
2 changes: 1 addition & 1 deletion bench/micro/thread_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main(int argc, char** argv) {

BSharedVector<T> a(test_size), b(test_size);

const int bw = std::numeric_limits<std::make_unsigned_t<T>>::digits;
const int bw = std::numeric_limits<orq::make_unsigned_t<T>>::digits;

single_cout("Test " << test_size << " x " << bw << " " << op << "\n");

Expand Down
2 changes: 1 addition & 1 deletion bench/queries/other/comorbidity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ using sec = duration<float, seconds::period>;
#endif

using T = int64_t;
using uT = std::make_unsigned_t<T>;
using uT = orq::make_unsigned_t<T>;

// Setting these up to be roughly similar in size to TPCH, SF 1 -> ~5M rows
// Update later based on dataset if required
Expand Down
2 changes: 1 addition & 1 deletion bench/queries/other/distinct_patients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ using sec = duration<float, seconds::period>;
#endif

using T = int64_t;
using uT = std::make_unsigned_t<T>;
using uT = orq::make_unsigned_t<T>;

// Setting these up to be roughly similar in size to TPCH, SF 1 -> ~5M rows
// Update later based on dataset if required
Expand Down
2 changes: 1 addition & 1 deletion bench/queries/tpch/tpch_dbgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class TPCDatabase {
* @return Vector<T>
*/
Vector<T> randomColumn(size_t size, T min_val, T max_val) {
using uT = std::make_unsigned_t<T>;
using uT = orq::make_unsigned_t<T>;

Vector<uT> uvec(size);
runTime->populateLocalRandom(uvec);
Expand Down
2 changes: 1 addition & 1 deletion examples/ex4_wagegap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int main(int argc, char **argv) {
auto pID = runTime->getPartyID();

using D = int32_t;
using uD = std::make_unsigned_t<D>;
using uD = orq::make_unsigned_t<D>;

std::vector<std::string> schema = {
"Salary", // in USD
Expand Down
70 changes: 66 additions & 4 deletions include/backend/common/util.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,77 @@
#pragma once

#include <bit>
#include <concepts>
#include <cstdint>
#include <type_traits>

template <typename U,
bool UseUnsigned = (std::integral<U> && !std::is_same_v<std::remove_cv_t<U>, bool>)>
// GCC 15's libstdc++ does not treat __int128 as an integral type, so
// std::integral, std::make_unsigned, and std::is_signed reject it. Clang
// still accepts it. __int128 and unsigned __int128 are __int128_t and
// __uint128_t.
template <typename T>
concept extended_integral = std::same_as<std::remove_cv_t<T>, __int128> ||
std::same_as<std::remove_cv_t<T>, unsigned __int128>;

namespace orq {

template <typename T>
struct make_unsigned {
using type = std::make_unsigned_t<T>;
};

template <extended_integral T>
struct make_unsigned<T> {
using type = unsigned __int128;
};

template <typename T>
using make_unsigned_t = typename make_unsigned<T>::type;

template <typename T>
inline constexpr bool is_signed_v =
std::is_signed_v<T> || std::same_as<std::remove_cv_t<T>, __int128>;

template <typename T>
inline constexpr bool is_unsigned_v =
std::is_unsigned_v<T> || std::same_as<std::remove_cv_t<T>, unsigned __int128>;

// std::popcount and std::bit_width require __unsigned_integer, which also
// excludes unsigned __int128 on GCC 15.
constexpr int popcount(unsigned __int128 x) {
return std::popcount(static_cast<std::uint64_t>(x)) +
std::popcount(static_cast<std::uint64_t>(x >> 64));
}

template <typename T>
requires(!extended_integral<T>)
constexpr int popcount(T x) {
return std::popcount(x);
}

constexpr int bit_width(unsigned __int128 x) {
auto hi = static_cast<std::uint64_t>(x >> 64);
if (hi != 0) {
return 64 + std::bit_width(hi);
}
return std::bit_width(static_cast<std::uint64_t>(x));
}

template <typename T>
requires(!extended_integral<T>)
constexpr int bit_width(T x) {
return std::bit_width(x);
}

} // namespace orq

template <typename U, bool UseUnsigned = ((std::integral<U> || extended_integral<U>) &&
!std::is_same_v<std::remove_cv_t<U>, bool>)>
struct UnsignedTypeSelector {
using type = U;
};

template <typename U>
struct UnsignedTypeSelector<U, true> {
using type = std::make_unsigned_t<U>;
};
using type = orq::make_unsigned_t<U>;
};
2 changes: 1 addition & 1 deletion include/core/containers/b_shared_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ using unique_B = std::unique_ptr<BSharedVector<S, E>>;
*/
template <typename Share, typename EVector>
class BSharedVector : public SharedVector<Share, EVector> {
static const uint MAX_BITS_NUMBER = std::numeric_limits<std::make_unsigned_t<Share>>::digits;
static const uint MAX_BITS_NUMBER = std::numeric_limits<orq::make_unsigned_t<Share>>::digits;
static const uint LOG_MAX_BITS_NUMBER = std::bit_width(MAX_BITS_NUMBER - 1);

using unique_B = std::unique_ptr<BSharedVector>;
Expand Down
8 changes: 4 additions & 4 deletions include/core/containers/dummy_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ namespace service {
*/
template <typename T>
class Vector {
template <typename U,
bool UseUnsigned = (std::integral<U> && !std::is_same_v<std::remove_cv_t<U>, bool>)>
template <typename U, bool UseUnsigned = ((std::integral<U> || extended_integral<U>) &&
!std::is_same_v<std::remove_cv_t<U>, bool>)>
struct UnsignedTypeSelector {
using type = U;
};

template <typename U>
struct UnsignedTypeSelector<U, true> {
using type = std::make_unsigned_t<U>;
using type = orq::make_unsigned_t<U>;
};

/**
Expand Down Expand Up @@ -161,7 +161,7 @@ class Vector {
* conversion. Default is 16.
*/
template <std::floating_point FP>
requires std::integral<T>
requires std::integral<T> || extended_integral<T>
Vector(const std::vector<FP>& _other, int fixed_point_precision = 16)
: Vector(static_cast<VectorSizeType>(_other.size())) {
precision = fixed_point_precision;
Expand Down
21 changes: 11 additions & 10 deletions include/core/containers/mapping_access_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ struct is_ntl_gf2e<NTL::GF2E> : std::true_type {};
} // namespace orq

template <typename T>
concept arithmetic = std::integral<T> or std::floating_point<T> or orq::is_ntl_gf2e<T>::value;
concept arithmetic = std::integral<T> or extended_integral<T> or std::floating_point<T> or
orq::is_ntl_gf2e<T>::value;

/**
* @brief Define a binary operation between two vectors, such as `a - b`.
Expand Down Expand Up @@ -180,7 +181,7 @@ static inline T getBit(const T& share, int bitIndex) {
if constexpr (_use_bmi && std::numeric_limits<T>::digits <= 64) {
return _bextr_u64(share, bitIndex, 1);
} else {
using Unsigned_type = typename std::make_unsigned<T>::type;
using Unsigned_type = orq::make_unsigned_t<T>;
return ((Unsigned_type)share >> bitIndex) & (Unsigned_type)1;
}
}
Expand All @@ -194,7 +195,7 @@ static inline T getBit(const T& share, int bitIndex) {
*/
template <typename T>
static inline void setBit(T& share, const T& bit, int bitIndex) {
using Unsigned_type = typename std::make_unsigned<T>::type;
using Unsigned_type = orq::make_unsigned_t<T>;
share = (share & ~(((Unsigned_type)1 << bitIndex))) | (bit << bitIndex);
}

Expand All @@ -207,7 +208,7 @@ static inline void setBit(T& share, const T& bit, int bitIndex) {
*/
template <typename T>
static inline void clrBit(T& share, int bitIndex) {
using Unsigned_type = typename std::make_unsigned<T>::type;
using Unsigned_type = orq::make_unsigned_t<T>;
share &= ~((Unsigned_type)1 << bitIndex);
}

Expand Down Expand Up @@ -238,7 +239,7 @@ static inline void setBitValue(T& share, const T& value, int bitIndex) {
* @param mask which bits to modify
*/
template <typename T>
static inline void setBitMask(T& share, const bool& value, const std::make_unsigned_t<T>& mask) {
static inline void setBitMask(T& share, const bool& value, const orq::make_unsigned_t<T>& mask) {
share = (share & ~mask) | (-value & mask);
}

Expand All @@ -248,15 +249,15 @@ static inline void setBitMask(T& share, const bool& value, const std::make_unsig
*/
template <typename T>
class Vector {
template <typename U,
bool UseUnsigned = (std::integral<U> && !std::is_same_v<std::remove_cv_t<U>, bool>)>
template <typename U, bool UseUnsigned = ((std::integral<U> || extended_integral<U>) &&
!std::is_same_v<std::remove_cv_t<U>, bool>)>
struct UnsignedTypeSelector {
using type = U;
};

template <typename U>
struct UnsignedTypeSelector<U, true> {
using type = std::make_unsigned_t<U>;
using type = orq::make_unsigned_t<U>;
};

/**
Expand Down Expand Up @@ -418,7 +419,7 @@ class Vector {
* conversion. Default is 16.
*/
template <std::floating_point FP>
requires std::integral<T>
requires std::integral<T> || extended_integral<T>
Vector(const std::vector<FP>& _other, int fixed_point_precision = 16)
: Vector(static_cast<VectorSizeType>(_other.size())) {
precision = fixed_point_precision;
Expand Down Expand Up @@ -508,7 +509,7 @@ class Vector {
Vector res = this->construct_like();

for (VectorSizeType i = 0; i < size; ++i) {
res[i] = std::popcount(static_cast<Unsigned_type>((*this)[i])) & 1;
res[i] = orq::popcount(static_cast<Unsigned_type>((*this)[i])) & 1;
}

return res;
Expand Down
2 changes: 1 addition & 1 deletion include/core/containers/permutation.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ElementwisePermutation {
ElementwisePermutation(const SharedVector<Share, argEVector> &v)
: sharedVector(v.vector, v.encoding) {
// ensure we're not discarding data when converting to 32 bits
const int bit_length = std::numeric_limits<std::make_unsigned_t<Share>>::digits;
const int bit_length = std::numeric_limits<orq::make_unsigned_t<Share>>::digits;
static_assert(bit_length <= 32);
}

Expand Down
Loading