Skip to content

Commit

Permalink
chore(ci): add a cpu count script to avoid crashing on macOS on make -j
Browse files Browse the repository at this point in the history
  • Loading branch information
IceTDrinker committed Apr 8, 2024
1 parent d457c1f commit 3f53cca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion scripts/c_api_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ done
CURR_DIR="$(dirname "$0")"
REPO_ROOT="${CURR_DIR}/.."
TFHE_BUILD_DIR="${REPO_ROOT}/tfhe/build/"
CPU_COUNT="$(./cpu_count.sh)"

mkdir -p "${TFHE_BUILD_DIR}"

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
Expand Down
10 changes: 10 additions & 0 deletions scripts/cpu_count.sh
Original file line number Diff line number Diff line change
@@ -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}
9 changes: 1 addition & 8 deletions scripts/integer-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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="$(./cpu_count.sh)"

if uname -a | grep "arm64"; then
if [[ $(uname) == "Darwin" ]]; then
Expand Down

0 comments on commit 3f53cca

Please sign in to comment.