Skip to content

Commit

Permalink
Fixed macOS support and Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdulcet committed Feb 15, 2024
1 parent 55c260e commit 9e00890
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
70 changes: 63 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,25 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-11, macos-12, macos-13]
os: [macos-11, macos-12, macos-13, macos-14]
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Install
run: |
brew install hwloc
brew install gmp hwloc
- name: Script
run: |
set -x
set -o pipefail
sysctl -a
for mode in '' NOSIMD SSE2 AVX AVX2 AVX512; do
MODES=( '' NOSIMD )
if [[ ${{ matrix.os }} == macos-14 ]]; then
MODES+=( ASIMD )
else
MODES+=( SSE2 AVX AVX2 AVX512 )
fi
for mode in "${MODES[@]}"; do
echo -e "\n$mode\n"
bash -e -o pipefail -- makemake.sh use_hwloc $mode
(cd obj${mode:+_$mode}; make clean)
Expand All @@ -218,12 +224,12 @@ jobs:
ASan-macOS:
name: AddressSanitizer macOS

runs-on: macos-13
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Install
run: |
brew install hwloc
brew install gmp hwloc
- name: Before script
run: |
sed -i '' 's/-O3/-Og -fsanitize=address,undefined/' makemake.sh
Expand All @@ -239,12 +245,12 @@ jobs:
TSan-macOS:
name: ThreadSanitizer macOS

runs-on: macos-13
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Install
run: |
brew install hwloc
brew install gmp hwloc
- name: Before script
run: |
sed -i '' 's/-O3/-Og -fsanitize=thread/' makemake.sh
Expand All @@ -256,3 +262,53 @@ jobs:
make clean
time ./Mlucas -s m -cpu "0:$(( $(sysctl -n hw.ncpu) - 1 ))"
continue-on-error: true

Windows:
name: Windows

runs-on: windows-latest
continue-on-error: true
strategy:
matrix:
cc: [gcc, clang]
fail-fast: false
env:
CC: ${{ matrix.cc }}
steps:
- uses: actions/checkout@v4
- name: Before Install
run: |
echo "C:\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "C:\msys64\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "CPPFLAGS=-IC:\msys64\mingw64\include" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "LIBPATH=-LC:\msys64\mingw64\lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Install
run: |
pacman -S --noconfirm mingw-w64-x86_64-gmp mingw-w64-x86_64-hwloc
& $env:CC --version
- name: Install Clang
if: ${{ matrix.cc == 'clang' }}
run: |
pacman -S --noconfirm mingw-w64-x86_64-clang
& $env:CC --version
- name: Script
shell: bash
run: |
set -x
for mode in '' NOSIMD SSE2 AVX AVX2 AVX512; do
echo -e "\n$mode\n"
bash -e -o pipefail -- makemake.sh use_hwloc $mode
(cd obj${mode:+_$mode}; make clean)
for word in '' 1word 2word 3word 4word nword; do
echo -e "\nMfactor $word\n"
bash -e -o pipefail -- makemake.sh mfac $word use_hwloc $mode
(cd obj_mfac${mode:+_$mode}; make clean)
done
done
cd obj
for s in tt t s m l; do time ./Mlucas -s $s -cpu "0:$(( $NUMBER_OF_PROCESSORS - 1 ))" |& tee -a test.log; done
- uses: actions/upload-artifact@v4
if: always()
with:
name: windows_${{ matrix.cc }}_mlucas
path: ${{ github.workspace }}
69 changes: 60 additions & 9 deletions makemake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ HWLOC=0
if echo "$OSTYPE" | grep -iq 'darwin'; then
echo -e "MacOS detected for build host.\n"
CPU_THREADS=$(sysctl -n hw.ncpu)
elif echo "$OSTYPE" | grep -iq 'msys'; then
echo -e "Windows detected for build host.\n"
CPU_THREADS=$NUMBER_OF_PROCESSORS
else # echo "$OSTYPE" | grep -iq 'linux'
echo -e "Assuming OS = Linux for build host.\n"
CPU_THREADS=$(nproc --all)
Expand Down Expand Up @@ -213,28 +216,28 @@ if [[ ${#MODES[*]} -eq 1 ]]; then
elif echo "$OSTYPE" | grep -iq 'darwin'; then

# MacOS:
if sysctl -a | grep machdep.cpu.features | grep -iq 'avx512'; then
if (($(sysctl -n hw.optional.avx512f))); then
echo -e "The CPU supports the AVX512 SIMD build mode.\n"
ARGS+=(-DUSE_AVX512 -march=native)
elif sysctl -a | grep machdep.cpu.features | grep -iq 'avx2'; then
elif (($(sysctl -n hw.optional.avx2_0))); then
echo -e "The CPU supports the AVX2 SIMD build mode.\n"
ARGS+=(-DUSE_AVX2 -march=native -mavx2)
elif sysctl -a | grep machdep.cpu.features | grep -iq 'avx'; then
elif (($(sysctl -n hw.optional.avx1_0))); then
echo -e "The CPU supports the AVX SIMD build mode.\n"
ARGS+=(-DUSE_AVX -march=native -mavx)
elif sysctl -a | grep machdep.cpu.features | grep -iq 'sse2'; then
elif (($(sysctl -n hw.optional.sse2))); then
echo -e "The CPU supports the SSE2 SIMD build mode.\n"
# On my Core2Duo Mac, 'native' gives "error: bad value for -march= switch":
ARGS+=(-DUSE_SSE2 -march=core2)
elif sysctl -a | grep machdep.cpu.features | grep -iq 'asimd'; then
elif (($(sysctl -n hw.optional.AdvSIMD))); then
echo -e "The CPU supports the ASIMD build mode.\n"
ARGS+=(-DUSE_ARM_V8_SIMD -march=native)
else
echo -e "The CPU supports no Mlucas-recognized ASIMD build mode ... building in scalar-double mode.\n"
echo -e "The CPU supports no Mlucas-recognized SIMD build mode ... building in scalar-double mode.\n"
ARGS+=(-march=native)
fi

else
elif echo "$OSTYPE" | grep -iq 'linux'; then

# Linux:
if grep -iq 'avx512' /proc/cpuinfo; then
Expand All @@ -253,10 +256,58 @@ else
echo -e "The CPU supports the ASIMD build mode.\n"
ARGS+=(-DUSE_ARM_V8_SIMD -march=native)
else
echo -e "The CPU supports no Mlucas-recognized ASIMD build mode ... building in scalar-double mode.\n"
echo -e "The CPU supports no Mlucas-recognized SIMD build mode ... building in scalar-double mode.\n"
ARGS+=(-march=native)
fi

else

# Adapted from: https://stackoverflow.com/a/28939692
cat <<EOF >/tmp/simd.c
#include <stdio.h>
int main()
{
#ifdef __x86_64__
#ifdef __AVX512F__
fputs("The CPU supports the AVX512 SIMD build mode.\n\n", stderr);
puts("-DUSE_AVX512 -march=native");
#elif defined __AVX2__
fputs("The CPU supports the AVX2 SIMD build mode.\n\n", stderr);
puts("-DUSE_AVX2 -march=native -mavx2");
#elif defined __AVX__
fputs("The CPU supports the AVX SIMD build mode.\n\n", stderr);
puts("-DUSE_AVX -march=native -mavx");
#elif defined __SSE2__
fputs("The CPU supports the SSE2 SIMD build mode.\n\n", stderr);
puts("-DUSE_SSE2 -march=native");
#else
fputs("The CPU supports no Mlucas-recognized SIMD build mode ... building in scalar-double mode.\n\n", stderr);
puts("-march=native");
#endif
#elif defined __aarch64__
#ifdef __ARM_NEON
fputs("The CPU supports the ASIMD build mode.\n\n", stderr);
puts("-DUSE_ARM_V8_SIMD -march=native");
#else
fputs("The CPU supports no Mlucas-recognized SIMD build mode ... building in scalar-double mode.\n\n", stderr);
puts("-march=native");
#endif
#else
fputs("The CPU supports no Mlucas-recognized SIMD build mode ... building in scalar-double mode.\n\n", stderr);
puts("-march=native");
#endif
return 0;
}
EOF

trap 'rm /tmp/simd{.c,}' EXIT
"${CC:-gcc}" -Wall -g -O3 -march=native -o /tmp/simd /tmp/simd.c
if ! args=$(/tmp/simd); then
echo "$args"
echo "Error: Unable to detect the SIMD build mode" >&2
exit 1
fi
ARGS+=($args)
fi

if [[ -d $DIR ]]; then
Expand All @@ -281,7 +332,7 @@ fi
cat <<EOF >Makefile
CC?=gcc
CFLAGS=-fdiagnostics-color -Wall -g -O3 # -flto=auto
CPPFLAGS=-I/usr/local/include
CPPFLAGS=-I/usr/local/include -I/opt/homebrew/include
LDLIBS=$(echo "$OSTYPE" | grep -iq 'darwin' || echo "-lm -lpthread -lrt") ${LARG[@]}
OBJS=br.o dft_macro.o fermat_mod_square.o fgt_m61.o get_cpuid.o get_fft_radices.o get_fp_rnd_const.o get_preferred_fft_radix.o getRealTime.o imul_macro.o mers_mod_square.o mi64.o Mlucas.o pairFFT_mul.o pair_square.o pm1.o qfloat.o radix1008_ditN_cy_dif1.o radix1024_ditN_cy_dif1.o radix104_ditN_cy_dif1.o radix10_ditN_cy_dif1.o radix112_ditN_cy_dif1.o radix11_ditN_cy_dif1.o radix120_ditN_cy_dif1.o radix128_ditN_cy_dif1.o radix12_ditN_cy_dif1.o radix13_ditN_cy_dif1.o radix144_ditN_cy_dif1.o radix14_ditN_cy_dif1.o radix15_ditN_cy_dif1.o radix160_ditN_cy_dif1.o radix16_dif_dit_pass.o radix16_ditN_cy_dif1.o radix16_dyadic_square.o radix16_pairFFT_mul.o radix16_wrapper_ini.o radix16_wrapper_square.o radix176_ditN_cy_dif1.o radix17_ditN_cy_dif1.o radix18_ditN_cy_dif1.o radix192_ditN_cy_dif1.o radix208_ditN_cy_dif1.o radix20_ditN_cy_dif1.o radix224_ditN_cy_dif1.o radix22_ditN_cy_dif1.o radix240_ditN_cy_dif1.o radix24_ditN_cy_dif1.o radix256_ditN_cy_dif1.o radix26_ditN_cy_dif1.o radix288_ditN_cy_dif1.o radix28_ditN_cy_dif1.o radix30_ditN_cy_dif1.o radix31_ditN_cy_dif1.o radix320_ditN_cy_dif1.o radix32_dif_dit_pass.o radix32_ditN_cy_dif1.o radix32_dyadic_square.o radix32_wrapper_ini.o radix32_wrapper_square.o radix352_ditN_cy_dif1.o radix36_ditN_cy_dif1.o radix384_ditN_cy_dif1.o radix4032_ditN_cy_dif1.o radix40_ditN_cy_dif1.o radix44_ditN_cy_dif1.o radix48_ditN_cy_dif1.o radix512_ditN_cy_dif1.o radix52_ditN_cy_dif1.o radix56_ditN_cy_dif1.o radix5_ditN_cy_dif1.o radix60_ditN_cy_dif1.o radix63_ditN_cy_dif1.o radix64_ditN_cy_dif1.o radix6_ditN_cy_dif1.o radix72_ditN_cy_dif1.o radix768_ditN_cy_dif1.o radix7_ditN_cy_dif1.o radix80_ditN_cy_dif1.o radix88_ditN_cy_dif1.o radix8_dif_dit_pass.o radix8_ditN_cy_dif1.o radix960_ditN_cy_dif1.o radix96_ditN_cy_dif1.o radix992_ditN_cy_dif1.o radix9_ditN_cy_dif1.o rng_isaac.o threadpool.o twopmodq100.o twopmodq128_96.o twopmodq128.o twopmodq160.o twopmodq192.o twopmodq256.o twopmodq64_test.o twopmodq80.o twopmodq96.o twopmodq.o types.o util.o
Expand Down
2 changes: 1 addition & 1 deletion src/platform.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ extern int NTHREADS;
// Nov 2020: Under MacOS, use of sysctlbyname call in util.c::print_host_info needs this moved outside #ifdef USE_THREADS.
// Feb 2021: Under Linux, per this [url=https://github.com/open5gs/open5gs/issues/600]Github discussion[/url],
// "sysctl() is deprecated and may break build with glibc >= 2.30", so add an appropriate GLIBC-version clause:
#if defined(OS_TYPE_MACOSX) || !defined(OS_TYPE_GNU_HURD) && ((__GLIBC__ < 2) || (__GLIBC_MINOR__ < 30))
#if defined(OS_TYPE_MACOSX) || !defined(OS_TYPE_GNU_HURD) && !defined(OS_TYPE_WINDOWS) && ((__GLIBC__ < 2) || (__GLIBC_MINOR__ < 30))
#ifdef OS_TYPE_LINUX
#warning GLIBC either not defined or version < 2.30 ... including <sys/sysctl.h> header.
#endif
Expand Down

0 comments on commit 9e00890

Please sign in to comment.