From eb1f5b18422fe5ec396ecf6cbaaaa84e1d30f544 Mon Sep 17 00:00:00 2001 From: rudy Date: Thu, 5 May 2022 08:41:17 +0200 Subject: [PATCH] fix(keysetcache): use a portable hash function will help to make macos faster on the ci --- .github/workflows/continuous-integration.yml | 4 ++-- compiler/Makefile | 3 ++- compiler/lib/ClientLib/ClientParameters.cpp | 11 +++++++---- compiler/lib/ClientLib/KeySetCache.cpp | 3 ++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 7a53be20c..5e943f112 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -136,7 +136,7 @@ jobs: if: ${{ matrix.compiler == 'gcc7' && github.ref == 'refs/heads/master' }} uses: actions/upload-artifact@v3 with: - name: KeySetCache + name: KeySetCacheV1 path: KeySetCache retention-days: 90 @@ -144,7 +144,7 @@ jobs: uses: Remagpie/gha-remove-artifact@v1 if: ${{ matrix.compiler == 'gcc7' && github.ref == 'refs/heads/master' }} with: - only-name: KeySetCache + only-name: KeySetCacheV1 max-count: 1 - name: Build compiler diff --git a/compiler/Makefile b/compiler/Makefile index 382825742..8cb1937ce 100644 --- a/compiler/Makefile +++ b/compiler/Makefile @@ -10,6 +10,7 @@ CONCRETE_OPTIMIZER_BRANCH ?= master KEYSETCACHEDEV=/tmp/KeySetCache KEYSETCACHECI ?= ../KeySetCache +KEYSETCACHENAME ?= KeySetCacheV1 export PATH := $(BUILD_DIR)/bin:$(PATH) @@ -115,7 +116,7 @@ test-dataflow: test-end-to-end-jit-dfr test-end-to-end-jit-auto-parallelization GITHUB_URL=https://api.github.com/repos/zama-ai/concrete-compiler-internal GITHUB_URL_LIST_ARTIFACTS="${GITHUB_URL}/actions/artifacts" CURL=curl -H"Accept: application/vnd.github.v3+json" -H"authorization: Bearer ${GITHUB_TOKEN}" -keysetcache.zip: REDIRECT_URL = $(shell ${CURL} -s ${GITHUB_URL_LIST_ARTIFACTS} | grep -A 10 KeySetCache | grep archive_download_url | head -n 1 | grep -o 'http[^"]\+') +keysetcache.zip: REDIRECT_URL = $(shell ${CURL} -s ${GITHUB_URL_LIST_ARTIFACTS} | grep -A 10 ${KEYSETCACHENAME} | grep archive_download_url | head -n 1 | grep -o 'http[^"]\+') keysetcache.zip: ${CURL} --location -o keysetcache.zip ${REDIRECT_URL} du -h keysetcache.zip diff --git a/compiler/lib/ClientLib/ClientParameters.cpp b/compiler/lib/ClientLib/ClientParameters.cpp index ae59c4833..5210e2ba4 100644 --- a/compiler/lib/ClientLib/ClientParameters.cpp +++ b/compiler/lib/ClientLib/ClientParameters.cpp @@ -6,6 +6,7 @@ #include #include "boost/outcome.h" +#include "llvm/ADT/Hashing.h" #include "concretelang/ClientLib/ClientParameters.h" @@ -20,20 +21,22 @@ template static inline void hash_(std::size_t &seed, const T &v, Rest... rest) { // See https://softwareengineering.stackexchange.com/a/402543 const auto GOLDEN_RATIO = 0x9e3779b97f4a7c15; // pseudo random bits - const std::hash hasher; - seed ^= hasher(v) + GOLDEN_RATIO + (seed << 6) + (seed >> 2); + seed ^= llvm::hash_value(v) + GOLDEN_RATIO + (seed << 6) + (seed >> 2); hash_(seed, rest...); } +static long double_to_bits(double &v) { return *reinterpret_cast(&v); } + void LweSecretKeyParam::hash(size_t &seed) { hash_(seed, dimension); } void BootstrapKeyParam::hash(size_t &seed) { hash_(seed, inputSecretKeyID, outputSecretKeyID, level, baseLog, - glweDimension, variance); + glweDimension, double_to_bits(variance)); } void KeyswitchKeyParam::hash(size_t &seed) { - hash_(seed, inputSecretKeyID, outputSecretKeyID, level, baseLog, variance); + hash_(seed, inputSecretKeyID, outputSecretKeyID, level, baseLog, + double_to_bits(variance)); } std::size_t ClientParameters::hash() { diff --git a/compiler/lib/ClientLib/KeySetCache.cpp b/compiler/lib/ClientLib/KeySetCache.cpp index 9f911ab84..eab7850c1 100644 --- a/compiler/lib/ClientLib/KeySetCache.cpp +++ b/compiler/lib/ClientLib/KeySetCache.cpp @@ -235,7 +235,8 @@ KeySetCache::loadOrGenerateSave(ClientParameters ¶ms, uint64_t seed_msb, } } - std::cerr << "KeySetCache: miss, regenerating\n"; + std::cerr << "KeySetCache: miss, regenerating " << std::string(folderPath) + << "\n"; OUTCOME_TRY(auto key_set, KeySet::generate(params, seed_msb, seed_lsb)); OUTCOME_TRYV(saveKeys(*key_set, folderPath));