diff --git a/Makefile b/Makefile index b5e78cf001..852be71718 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ OS:=$(shell uname) RS_CHECK_TOOLCHAIN:=$(shell cat toolchain.txt | tr -d '\n') CARGO_RS_CHECK_TOOLCHAIN:=+$(RS_CHECK_TOOLCHAIN) TARGET_ARCH_FEATURE:=$(shell ./scripts/get_arch_feature.sh) +CPU_COUNT=$(shell ./scripts/cpu_count.sh) RS_BUILD_TOOLCHAIN:=stable CARGO_RS_BUILD_TOOLCHAIN:=+$(RS_BUILD_TOOLCHAIN) CARGO_PROFILE?=release @@ -423,7 +424,7 @@ test_cuda_backend: mkdir -p "$(TFHECUDA_BUILD)" && \ cd "$(TFHECUDA_BUILD)" && \ cmake .. -DCMAKE_BUILD_TYPE=Release -DTFHE_CUDA_BACKEND_BUILD_TESTS=ON && \ - make -j && \ + make -j "$(CPU_COUNT)" && \ make test .PHONY: test_gpu # Run the tests of the core_crypto module including experimental on the gpu backend @@ -682,7 +683,7 @@ check_compile_tests_benches_gpu: install_rs_build_toolchain mkdir -p "$(TFHECUDA_BUILD)" && \ cd "$(TFHECUDA_BUILD)" && \ cmake .. -DCMAKE_BUILD_TYPE=Debug -DTFHE_CUDA_BACKEND_BUILD_TESTS=ON -DTFHE_CUDA_BACKEND_BUILD_BENCHMARKS=ON && \ - make -j + make -j "$(CPU_COUNT)" .PHONY: build_nodejs_test_docker # Build a docker image with tools to run nodejs tests for wasm API build_nodejs_test_docker: diff --git a/scripts/c_api_tests.sh b/scripts/c_api_tests.sh index 4534b57cc7..88167a4324 100755 --- a/scripts/c_api_tests.sh +++ b/scripts/c_api_tests.sh @@ -39,6 +39,7 @@ done CURR_DIR="$(dirname "$0")" REPO_ROOT="${CURR_DIR}/.." TFHE_BUILD_DIR="${REPO_ROOT}/tfhe/build/" +CPU_COUNT="$("${CURR_DIR}"/cpu_count.sh)" mkdir -p "${TFHE_BUILD_DIR}" @@ -46,7 +47,7 @@ cd "${TFHE_BUILD_DIR}" cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DCARGO_PROFILE="${CARGO_PROFILE}" -DWITH_FEATURE_GPU="${WITH_FEATURE_GPU}" -make -j +make -j "${CPU_COUNT}" if [[ "${BUILD_ONLY}" == "1" ]]; then exit 0 diff --git a/scripts/cpu_count.sh b/scripts/cpu_count.sh new file mode 100755 index 0000000000..335a2fbed7 --- /dev/null +++ b/scripts/cpu_count.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +nproc_bin=nproc + +# macOS detects CPUs differently +if [[ $(uname) == "Darwin" ]]; then + nproc_bin="sysctl -n hw.logicalcpu" +fi + +${nproc_bin} diff --git a/scripts/integer-tests.sh b/scripts/integer-tests.sh index 22d15efce9..5945b1529d 100755 --- a/scripts/integer-tests.sh +++ b/scripts/integer-tests.sh @@ -86,15 +86,8 @@ fi CURR_DIR="$(dirname "$0")" ARCH_FEATURE="$("${CURR_DIR}/get_arch_feature.sh")" -nproc_bin=nproc - -# macOS detects CPUs differently -if [[ $(uname) == "Darwin" ]]; then - nproc_bin="sysctl -n hw.logicalcpu" -fi - # TODO autodetect/have a finer CPU count depending on memory -num_cpu_threads="$(${nproc_bin})" +num_cpu_threads="$("${CURR_DIR}"/cpu_count.sh)" if uname -a | grep "arm64"; then if [[ $(uname) == "Darwin" ]]; then