-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
executable file
·189 lines (170 loc) · 6.86 KB
/
configure
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/sh
# Anticonf (tm, Jeroen Ooms) style alternative to autoconf written by Louis
# Aslett based on work by Jeroen Ooms (cf github: jeroen/curl & jeroen/openssl)
PKG_CONFIG_NAME="zlib"
PKG_DEB_NAME="zlib1g-dev"
PKG_RPM_NAME="zlib-devel"
PKG_CSW_NAME="libz_dev"
PKG_TEST_HEADER="<zlib.h>"
PKG_LIBS="-lz $PKG_LIBS"
PKG_CFLAGS="$PKG_CFLAGS"
# Try using pkg-config if it exists
pkg-config --version >/dev/null 2>&1
if [ $? -eq 0 ]; then
PKGCONFIG_CFLAGS=`pkg-config --cflags ${PKG_CONFIG_NAME}`
PKGCONFIG_LIBS=`pkg-config --libs ${PKG_CONFIG_NAME}`
fi
# Include and library directories
if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]; then
echo "Found INCLUDE_DIR and/or LIB_DIR!"
PKG_CFLAGS="-I$INCLUDE_DIR $PKG_CFLAGS"
PKG_LIBS="-L$LIB_DIR $PKG_LIBS"
elif [ "$PKGCONFIG_CFLAGS" ] || [ "$PKGCONFIG_LIBS" ]; then
echo "Found pkg-config cflags and libs!"
PKG_CFLAGS="$PKGCONFIG_CFLAGS $PKG_CFLAGS"
PKG_LIBS="$PKGCONFIG_LIBS $PKG_LIBS"
fi
# Find compiler
CC=`${R_HOME}/bin/R CMD config CC`
CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS`
# Debug info
echo "Using PKG_CFLAGS=$PKG_CFLAGS"
echo "Using PKG_LIBS=$PKG_LIBS"
# Test configuration
echo "#include $PKG_TEST_HEADER" | ${CC} ${PKG_CFLAGS} ${CFLAGS} -Wno-error -E -xc - >/dev/null 2>&1 || R_CONFIG_ERROR=1;
# Customize the error
if [ $R_CONFIG_ERROR ]; then
echo "------------------------- ANTICONF ERROR ---------------------------"
echo "Configuration failed because $PKG_CONFIG_NAME was not found. Try installing:"
echo " * deb: $PKG_DEB_NAME (Debian, Ubuntu, etc)"
echo " * rpm: $PKG_RPM_NAME (Fedora, CentOS, RHEL)"
echo " * csw: $PKG_CSW_NAME (Solaris)"
echo "If $PKG_CONFIG_NAME is already installed, check that 'pkg-config' is in your"
echo "PATH and PKG_CONFIG_PATH contains a $PKG_CONFIG_NAME.pc file. If pkg-config"
echo "is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:"
echo "R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'"
echo "--------------------------------------------------------------------"
exit 1;
fi
# Check combinations of intrinsics flags
counter=0
intrinsics=""
[ -n "${NOASM+isset}" ] && counter=$((counter + 1)) && PKG_CFLAGS="$PKG_CFLAGS -DKALIS_ISA_NOASM" && intrinsics="No special assembly"
[ -n "${AVX512+isset}" ] && counter=$((counter + 1)) && PKG_CFLAGS="$PKG_CFLAGS -DKALIS_ISA_AVX512" && intrinsics="AVX-512 family of"
[ -n "${AVX2+isset}" ] && counter=$((counter + 1)) && PKG_CFLAGS="$PKG_CFLAGS -DKALIS_ISA_AVX2" && intrinsics="AVX2 family of"
[ -n "${NEON+isset}" ] && counter=$((counter + 1)) && PKG_CFLAGS="$PKG_CFLAGS -DKALIS_ISA_NEON" && intrinsics="NEON family of"
# Were zero/one options chosen?
if [ "$counter" -gt 1 ]; then
echo "ERROR: At most one set of instructions can be specified (NOASM, AVX512, AVX2 or NEON)"
exit 1
fi
# Was an option forced?
if [ "$counter" -eq 1 ]; then
echo "$intrinsics instruction set extentions will by used (forced by user)."
fi
# If no option force by user, then attempt to auto-detect
if [ "$counter" -eq 0 ]; then
intrindetected=0
# Check if we're on an x86 system with AVX-512 family ISA
intrin=0
${CC} ${PKG_CFLAGS} ${CFLAGS} -dM -E - < /dev/null | grep "__AVX512F__" > /dev/null
intrin=$((intrin+$?))
${CC} ${PKG_CFLAGS} ${CFLAGS} -dM -E - < /dev/null | grep "__AVX2__" > /dev/null
intrin=$((intrin+$?))
${CC} ${PKG_CFLAGS} ${CFLAGS} -dM -E - < /dev/null | grep "__SSE2__" > /dev/null
intrin=$((intrin+$?))
${CC} ${PKG_CFLAGS} ${CFLAGS} -dM -E - < /dev/null | grep "__BMI2__" > /dev/null
intrin=$((intrin+$?))
echo "#include <immintrin.h>" | ${CC} ${PKG_CFLAGS} ${CFLAGS} -Wno-error -E -xc - >/dev/null 2>&1
intrin=$((intrin+$?))
if [ "$intrindetected" -eq 0 ] && [ "$intrin" -eq 0 ]; then
PKG_CFLAGS="$PKG_CFLAGS -DKALIS_ISA_AVX512"
intrinsics="AVX-512 family of"
intrindetected=1
fi
# Check if we're on an x86 system with AVX2 family ISA
intrin=0
${CC} ${PKG_CFLAGS} ${CFLAGS} -dM -E - < /dev/null | grep "__AVX2__" > /dev/null
intrin=$((intrin+$?))
${CC} ${PKG_CFLAGS} ${CFLAGS} -dM -E - < /dev/null | grep "__AVX__" > /dev/null
intrin=$((intrin+$?))
${CC} ${PKG_CFLAGS} ${CFLAGS} -dM -E - < /dev/null | grep "__SSE4_1__" > /dev/null
intrin=$((intrin+$?))
${CC} ${PKG_CFLAGS} ${CFLAGS} -dM -E - < /dev/null | grep "__SSE2__" > /dev/null
intrin=$((intrin+$?))
${CC} ${PKG_CFLAGS} ${CFLAGS} -dM -E - < /dev/null | grep "__FMA__" > /dev/null
intrin=$((intrin+$?))
${CC} ${PKG_CFLAGS} ${CFLAGS} -dM -E - < /dev/null | grep "__BMI2__" > /dev/null
intrin=$((intrin+$?))
echo "#include <immintrin.h>" | ${CC} ${PKG_CFLAGS} ${CFLAGS} -Wno-error -E -xc - >/dev/null 2>&1
intrin=$((intrin+$?))
if [ "$intrindetected" -eq 0 ] && [ "$intrin" -eq 0 ]; then
PKG_CFLAGS="$PKG_CFLAGS -DKALIS_ISA_AVX2"
intrinsics="AVX2 family of"
intrindetected=1
fi
# Check if we're on an ARM system with NEON intrinsics
intrin=0
${CC} ${PKG_CFLAGS} ${CFLAGS} -dM -E - < /dev/null | grep "__ARM_NEON" > /dev/null
intrin=$((intrin+$?))
${CC} ${PKG_CFLAGS} ${CFLAGS} -dM -E - < /dev/null | grep "__ARM_FEATURE_FMA" > /dev/null
intrin=$((intrin+$?))
echo "#include <arm_neon.h>" | ${CC} ${PKG_CFLAGS} ${CFLAGS} -Wno-error -E -xc - >/dev/null 2>&1
intrin=$((intrin+$?))
if [ "$intrindetected" -eq 0 ] && [ "$intrin" -eq 0 ]; then
PKG_CFLAGS="$PKG_CFLAGS -DKALIS_ISA_NEON"
intrinsics="NEON family of"
intrindetected=1
fi
if [ "$intrindetected" -eq 0 ]; then
PKG_CFLAGS="$PKG_CFLAGS -DKALIS_ISA_NOASM"
intrinsics="No special assembly"
fi
echo "$intrinsics instruction set extentions will by used (auto-detected)."
fi
# Check if we have access to pthreads (checking functions and headers, so no -E on compiler)
echo "#define _GNU_SOURCE
#include <pthread.h>
int main() {
pthread_t threads[2];
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_create(&threads[0], &attr, NULL, NULL);
return 0;
}" | ${CC} ${PKG_CFLAGS} ${CFLAGS} -Wno-error -pthread -xc - >/dev/null 2>&1
if [ "$?" -eq 0 ]; then
PKG_CFLAGS="$PKG_CFLAGS -pthread"
PKG_LIBS="$PKG_LIBS -lpthread -pthread"
echo "Threading support detected."
fi
# NB: MacOS has pthreads but not pthread_setaffinity_np
echo "#define _GNU_SOURCE
#include <pthread.h>
int main() {
cpu_set_t cpus;
CPU_ZERO(&cpus);
CPU_SET(1, &cpus);
pthread_setaffinity_np(0,0,0);
return 0;
}" | ${CC} ${PKG_CFLAGS} ${CFLAGS} -Wno-error -pthread -xc - >/dev/null 2>&1
if [ "$?" -eq 0 ]; then
PKG_CFLAGS="$PKG_CFLAGS -DKALIS_AFFINITY"
echo "Thread affinity support detected."
fi
# To customise unroll depth
if [ ! -z ${UNROLL+isset} ]; then
PKG_CFLAGS="$PKG_CFLAGS -DKALIS_UNROLL=$UNROLL"
echo "Loop unrolling default overridden by UNROLL configure-vars flag to depth $UNROLL"
else
echo "Loop unrolling at default value"
fi
# Gen Makevars
sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars
if [ -f a.out ] ; then
rm a.out
fi
if [ -e a.out.dSYM ] ; then
rm -rf a.out.dSYM
fi
# Success
exit 0