forked from CoderLSF/fast-llama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
61 lines (49 loc) · 1.58 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
workdir=$(dirname "$0")
if ! cd $workdir; then
echo "Failed to enter program directory" 1>& 2
exit 1
fi
CC=g++
build_flags=${1:-"-O3"}
DEFINES=""
if (uname -a | grep -q arm64); then
ARCH_FLAGS='-march=armv8-a+simd -mcpu=native -mfpu=neon'
ARCH_LIBS="-lpthread -lm"
DEFINES="$DEFINES -DDISABLE_NUMA"
elif (uname -a | grep -q x86_64); then
DEFINES="$DEFINES -D_GNU_SOURCE"
if egrep -qi '^flags.*\<avx512f\>' /proc/cpuinfo; then
ARCH_FLAGS="-march=native -mavx512f -mavx512bw -mavx512vl -mavx512dq"
elif egrep -qi '^flags.*\<avx2\>' /proc/cpuinfo; then
ARCH_FLAGS="-mavx2"
elif egrep -qi '^flags.*\<sse4_2' /proc/cpuinfo; then
ARCH_FLAGS="-march=native -msse4.2"
else
ARCH_FLAGS=""
fi
ARCH_LIBS="-lpthread -lm"
num_numa_sockets=$(grep '^physical id' /proc/cpuinfo | sort | uniq | wc -l)
if ((num_numa_sockets > 1)); then
ARCH_LIBS="$ARCH_LIBS -lnuma"
else
DEFINES="$DEFINES -DDISABLE_NUMA"
fi
fi
CFLAGS="$ARCH_FLAGS $DEFINES -Wall"
CXXFLAGS="-std=c++20"
LIBS="$ARCH_LIBS"
TARGET=./main
srcs=$(find ./src | egrep '\.cpp$' | tr -s $'\n' ' ')
includes=$(find ./src | egrep '\.(h|hpp)$' | while read HEADER_PATH; do
HEADER_DIR=$(dirname "$HEADER_PATH")
echo "-I$HEADER_DIR"
done | sort | uniq | awk '{printf("%s ", $0);}')
rm -f $TARGET
echo "$CC -o $TARGET $srcs $CXXFLAGS $CFLAGS $LIBS $includes $build_flags"
$CC -o $TARGET $srcs $CXXFLAGS $CFLAGS $LIBS $includes $build_flags
if [ -e $TARGET ]; then
echo -e $'\x1b[32mDone\x1b[0m'
else
echo -e $'\x1b[31mFailed\x1b[0m'
fi