Skip to content

Chore/m1 tests without integer #393

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

Merged
merged 11 commits into from
Jul 10, 2023
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
23 changes: 22 additions & 1 deletion .github/workflows/m1_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@ on:
workflow_dispatch:
pull_request:
types: [labeled]
# Have a nightly build for M1 tests
schedule:
# * is a special character in YAML so you have to quote this string
# At 22:00 every day
# Timezone is UTC, so Paris time is +2 during the summer and +1 during winter
- cron: "0 22 * * *"

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-C target-cpu=native"
ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
CARGO_PROFILE: release_lto_off
FAST_TESTS: "TRUE"

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
cargo-builds:
if: "github.event_name != 'pull_request' || contains(github.event.label.name, 'm1_test')"
if: ${{ (github.event_name == 'schedule' && github.repository == 'zama-ai/tfhe-rs') || github.event_name != 'pull_request' || contains(github.event.label.name, 'm1_test') }}
runs-on: ["self-hosted", "m1mac"]

steps:
Expand Down Expand Up @@ -87,6 +95,19 @@ jobs:
run: |
make test_integer_ci

- name: Gen Keys if required
run: |
make GEN_KEY_CACHE_MULTI_BIT_ONLY=TRUE gen_key_cache

- name: Run shortint multi bit tests
run: |
make test_shortint_multi_bit_ci

# # These multi bit integer tests are too slow on M1 with low core count and low RAM
# - name: Run integer multi bit tests
# run: |
# make test_integer_multi_bit_ci

remove_label:
name: Remove m1_test label
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ lto = "fat"
[profile.release]
lto = "fat"

[profile.release_lto_off]
inherits = "release"
lto = "off"

# Compiles much faster for tests and allows reasonable performance for iterating
[profile.devo]
inherits = "dev"
Expand Down
27 changes: 18 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -243,27 +243,33 @@ test_boolean: install_rs_build_toolchain
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
--features=$(TARGET_ARCH_FEATURE),boolean -p tfhe -- boolean::

.PHONY: test_c_api # Run the tests for the C API
test_c_api: install_rs_check_toolchain
.PHONY: test_c_api_rs # Run the rust tests for the C API
test_c_api_rs: install_rs_check_toolchain
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
--features=$(TARGET_ARCH_FEATURE),boolean-c-api,shortint-c-api,high-level-c-api \
-p tfhe \
c_api

"$(MAKE)" build_c_api

.PHONY: test_c_api_c # Run the C tests for the C API
test_c_api_c: build_c_api
./scripts/c_api_tests.sh

.PHONY: test_c_api # Run all the tests for the C API
test_c_api: test_c_api_rs test_c_api_c

.PHONY: test_shortint_ci # Run the tests for shortint ci
test_shortint_ci: install_rs_build_toolchain install_cargo_nextest
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
FAST_TESTS="$(FAST_TESTS)" \
./scripts/shortint-tests.sh --rust-toolchain $(CARGO_RS_BUILD_TOOLCHAIN)
./scripts/shortint-tests.sh --rust-toolchain $(CARGO_RS_BUILD_TOOLCHAIN) \
--cargo-profile "$(CARGO_PROFILE)"

.PHONY: test_shortint_multi_bit_ci # Run the tests for shortint ci running only multibit tests
test_shortint_multi_bit_ci: install_rs_build_toolchain install_cargo_nextest
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
FAST_TESTS="$(FAST_TESTS)" \
./scripts/shortint-tests.sh --rust-toolchain $(CARGO_RS_BUILD_TOOLCHAIN) --multi-bit
./scripts/shortint-tests.sh --rust-toolchain $(CARGO_RS_BUILD_TOOLCHAIN) \
--cargo-profile "$(CARGO_PROFILE)" --multi-bit

.PHONY: test_shortint # Run all the tests for shortint
test_shortint: install_rs_build_toolchain
Expand All @@ -274,13 +280,15 @@ test_shortint: install_rs_build_toolchain
test_integer_ci: install_rs_build_toolchain install_cargo_nextest
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
FAST_TESTS="$(FAST_TESTS)" \
./scripts/integer-tests.sh --rust-toolchain $(CARGO_RS_BUILD_TOOLCHAIN)
./scripts/integer-tests.sh --rust-toolchain $(CARGO_RS_BUILD_TOOLCHAIN) \
--cargo-profile "$(CARGO_PROFILE)"

.PHONY: test_integer_multi_bit_ci # Run the tests for integer ci running only multibit tests
test_integer_multi_bit_ci: install_rs_build_toolchain install_cargo_nextest
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
FAST_TESTS="$(FAST_TESTS)" \
./scripts/integer-tests.sh --rust-toolchain $(CARGO_RS_BUILD_TOOLCHAIN) --multi-bit
./scripts/integer-tests.sh --rust-toolchain $(CARGO_RS_BUILD_TOOLCHAIN) \
--cargo-profile "$(CARGO_PROFILE)" --multi-bit

.PHONY: test_integer # Run all the tests for integer
test_integer: install_rs_build_toolchain
Expand All @@ -290,7 +298,8 @@ test_integer: install_rs_build_toolchain
.PHONY: test_high_level_api # Run all the tests for high_level_api
test_high_level_api: install_rs_build_toolchain
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache -p tfhe -- high_level_api::
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache -p tfhe \
-- high_level_api::

.PHONY: test_user_doc # Run tests from the .md documentation
test_user_doc: install_rs_build_toolchain
Expand Down
4 changes: 2 additions & 2 deletions scripts/c_api_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mkdir -p "${TFHE_BUILD_DIR}"

cd "${TFHE_BUILD_DIR}"

cmake .. -DCMAKE_BUILD_TYPE=RELEASE
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DCARGO_PROFILE="${CARGO_PROFILE}"

make -j

Expand All @@ -56,4 +56,4 @@ if [[ $(uname) == "Darwin" ]]; then
fi

# Let's go parallel
ARGS="-j$("${nproc_bin}")" make test
ARGS="-j$(${nproc_bin})" make test
19 changes: 13 additions & 6 deletions scripts/integer-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ function usage() {
echo "--help Print this message"
echo "--rust-toolchain The toolchain to run the tests with default: stable"
echo "--multi-bit Run multi-bit tests only: default off"
echo "--cargo-profile The cargo profile used to build tests"
echo
}

RUST_TOOLCHAIN="+stable"
multi_bit=""
not_multi_bit="_multi_bit"
cargo_profile="release"

while [ -n "$1" ]
do
Expand All @@ -33,6 +35,11 @@ do
not_multi_bit=""
;;

"--cargo-profile" )
shift
cargo_profile="$1"
;;

*)
echo "Unknown param : $1"
exit 1
Expand Down Expand Up @@ -94,7 +101,7 @@ and not test(/.*default_add_sequence_multi_thread_param_message_3_carry_3_ks_pbs

cargo "${RUST_TOOLCHAIN}" nextest run \
--tests \
--release \
--cargo-profile "${cargo_profile}" \
--package tfhe \
--profile ci \
--features="${ARCH_FEATURE}",integer,internal-keycache \
Expand All @@ -103,11 +110,11 @@ and not test(/.*default_add_sequence_multi_thread_param_message_3_carry_3_ks_pbs

if [[ "${multi_bit}" == "" ]]; then
cargo "${RUST_TOOLCHAIN}" test \
--release \
--profile "${cargo_profile}" \
--package tfhe \
--features="${ARCH_FEATURE}",integer,internal-keycache \
--doc \
integer::
-- integer::
fi
else
if [[ "${FAST_TESTS}" != TRUE ]]; then
Expand Down Expand Up @@ -138,7 +145,7 @@ and not test(/.*default_add_sequence_multi_thread_param_message_3_carry_3_ks_pbs
num_threads=$((num_cpu_threads * 2 / 3))
cargo "${RUST_TOOLCHAIN}" nextest run \
--tests \
--release \
--cargo-profile "${cargo_profile}" \
--package tfhe \
--profile ci \
--features="${ARCH_FEATURE}",integer,internal-keycache \
Expand All @@ -147,11 +154,11 @@ and not test(/.*default_add_sequence_multi_thread_param_message_3_carry_3_ks_pbs

if [[ "${multi_bit}" == "" ]]; then
cargo "${RUST_TOOLCHAIN}" test \
--release \
--profile "${cargo_profile}" \
--package tfhe \
--features="${ARCH_FEATURE}",integer,internal-keycache \
--doc \
integer:: -- --test-threads="$(${nproc_bin})"
-- --test-threads="$(${nproc_bin})" integer::
fi
fi

Expand Down
21 changes: 14 additions & 7 deletions scripts/shortint-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ function usage() {
echo "--help Print this message"
echo "--rust-toolchain The toolchain to run the tests with default: stable"
echo "--multi-bit Run multi-bit tests only: default off"
echo "--cargo-profile The cargo profile used to build tests"
echo
}

RUST_TOOLCHAIN="+stable"
multi_bit=""
cargo_profile="release"

while [ -n "$1" ]
do
Expand All @@ -31,6 +33,11 @@ do
multi_bit="_multi_bit"
;;

"--cargo-profile" )
shift
cargo_profile="$1"
;;

*)
echo "Unknown param : $1"
exit 1
Expand Down Expand Up @@ -102,7 +109,7 @@ and not test(~smart_add_and_mul)""" # This test is too slow
# Run tests only no examples or benches with small params and more threads
cargo "${RUST_TOOLCHAIN}" nextest run \
--tests \
--release \
--cargo-profile "${cargo_profile}" \
--package tfhe \
--profile ci \
--features="${ARCH_FEATURE}",shortint,internal-keycache \
Expand All @@ -119,7 +126,7 @@ and not test(~smart_add_and_mul)"""
# Run tests only no examples or benches with big params and less threads
cargo "${RUST_TOOLCHAIN}" nextest run \
--tests \
--release \
--cargo-profile "${cargo_profile}" \
--package tfhe \
--profile ci \
--features="${ARCH_FEATURE}",shortint,internal-keycache \
Expand All @@ -128,11 +135,11 @@ and not test(~smart_add_and_mul)"""

if [[ "${multi_bit}" == "" ]]; then
cargo "${RUST_TOOLCHAIN}" test \
--release \
--profile "${cargo_profile}" \
--package tfhe \
--features="${ARCH_FEATURE}",shortint,internal-keycache \
--doc \
shortint::
-- shortint::
fi
fi
else
Expand Down Expand Up @@ -167,7 +174,7 @@ and not test(~smart_add_and_mul)""" # This test is too slow
# Run tests only no examples or benches with small params and more threads
cargo "${RUST_TOOLCHAIN}" nextest run \
--tests \
--release \
--cargo-profile "${cargo_profile}" \
--package tfhe \
--profile ci \
--features="${ARCH_FEATURE}",shortint,internal-keycache \
Expand All @@ -176,11 +183,11 @@ and not test(~smart_add_and_mul)""" # This test is too slow

if [[ "${multi_bit}" == "" ]]; then
cargo "${RUST_TOOLCHAIN}" test \
--release \
--profile "${cargo_profile}" \
--package tfhe \
--features="${ARCH_FEATURE}",shortint,internal-keycache \
--doc \
shortint:: -- --test-threads="$(${nproc_bin})"
-- --test-threads="$(${nproc_bin})" shortint::
fi
fi

Expand Down
15 changes: 14 additions & 1 deletion tfhe/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,27 @@ fn gen_c_api() {
return;
}

fn get_build_profile_name() -> String {
// The profile name is always the 3rd last part of the path (with 1 based indexing).
// e.g. /code/core/target/cli/build/my-build-info-9f91ba6f99d7a061/out
let out_dir = std::env::var("OUT_DIR")
.expect("OUT_DIR is not set, cannot determine build profile, aborting");
out_dir
.split(std::path::MAIN_SEPARATOR)
.nth_back(3)
.expect("Cannot determine build profile, aborting")
.to_string()
}

/// Find the location of the `target/` directory. Note that this may be
/// overridden by `cmake`, so we also need to check the `CARGO_TARGET_DIR`
/// variable.
fn target_dir() -> PathBuf {
if let Ok(target) = env::var("CARGO_TARGET_DIR") {
PathBuf::from(target)
} else {
PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("../target/release")
PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
.join(format!("../target/{}", get_build_profile_name()))
}
}

Expand Down
5 changes: 4 additions & 1 deletion tfhe/c_api_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ project(tfhe-c-api-tests)

cmake_minimum_required(VERSION 3.16)

set(TFHE_C_API_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../../target/release/")
if(NOT CARGO_PROFILE)
set(CARGO_PROFILE release)
endif()
set(TFHE_C_API_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../../target/${CARGO_PROFILE}")

include_directories(${TFHE_C_API_RELEASE})
add_library(Tfhe STATIC IMPORTED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ pub fn generate_lwe_private_functional_packing_keyswitch_key<
);
assert!(
lwe_pfpksk.ciphertext_modulus().is_native_modulus(),
"This operation currently only supports native moduli"
"This operation currently only supports native moduli, got modulus {:?}",
lwe_pfpksk.ciphertext_modulus()
);

// We instantiate a buffer
Expand Down Expand Up @@ -182,7 +183,8 @@ pub fn par_generate_lwe_private_functional_packing_keyswitch_key<
);
assert!(
lwe_pfpksk.ciphertext_modulus().is_native_modulus(),
"This operation currently only supports native moduli"
"This operation currently only supports native moduli, got modulus {:?}",
lwe_pfpksk.ciphertext_modulus()
);

// We retrieve decomposition arguments
Expand Down
12 changes: 8 additions & 4 deletions tfhe/src/core_crypto/algorithms/lwe_wopbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ where
{
assert!(
ciphertext_modulus.is_native_modulus(),
"This operation currently only supports native moduli"
"This operation currently only supports native moduli, got modulus {:?}",
ciphertext_modulus
);

let mut cbs_pfpksk_list = LwePrivateFunctionalPackingKeyswitchKeyListOwned::new(
Expand Down Expand Up @@ -109,7 +110,8 @@ pub fn generate_circuit_bootstrap_lwe_pfpksk_list<
output_cbs_pfpksk_list
.ciphertext_modulus()
.is_native_modulus(),
"This operation currently only supports native moduli"
"This operation currently only supports native moduli, got modulus {:?}",
output_cbs_pfpksk_list.ciphertext_modulus()
);

let decomp_level_count = output_cbs_pfpksk_list.decomposition_level_count();
Expand Down Expand Up @@ -183,7 +185,8 @@ where
{
assert!(
ciphertext_modulus.is_native_modulus(),
"This operation currently only supports native moduli"
"This operation currently only supports native moduli, got modulus {:?}",
ciphertext_modulus
);

let mut cbs_pfpksk_list = LwePrivateFunctionalPackingKeyswitchKeyListOwned::new(
Expand Down Expand Up @@ -244,7 +247,8 @@ pub fn par_generate_circuit_bootstrap_lwe_pfpksk_list<
output_cbs_pfpksk_list
.ciphertext_modulus()
.is_native_modulus(),
"This operation currently only supports native moduli"
"This operation currently only supports native moduli, got modulus {:?}",
output_cbs_pfpksk_list.ciphertext_modulus()
);

let decomp_level_count = output_cbs_pfpksk_list.decomposition_level_count();
Expand Down
Loading