forked from WvanWoerden/G6K-GPU-Tensor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrebuild.sh
More file actions
executable file
·252 lines (232 loc) · 6.42 KB
/
Copy pathrebuild.sh
File metadata and controls
executable file
·252 lines (232 loc) · 6.42 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/bin/bash
# G6K-GPU-Tensor Rebuild Script (Modernized for PEP 517/518)
# Usage: ./rebuild.sh [OPTIONS]
#
# This script configures and rebuilds G6K with custom parameters using the modern pip-based system.
#
# Key Options:
# -m, --maxsievingdim N Set maximum sieving dimension (default: 128)
# --gpuvecnum N Set GPU vector number (default: 65536)
# -f, --fast Fast build (NDEBUG, templated dimensions)
# -s, --stats Enable statistics collection
# -c, --cpucounters Enable CPU performance counters
# -g, --ggdb Enable debug symbols
# -j, --jobs N Number of parallel jobs (default: 4)
#
# Examples:
# ./rebuild.sh -m 160 # Build for max dimension 160
# ./rebuild.sh -m 256 --fast # Fast build for dimension 256
# ./rebuild.sh -m 160 --gpuvecnum 131072 # Custom GPU vector size
# ./rebuild.sh --onlyconf # Only generate configuration, don't build
echo "Git status: " > .last_build
git log --pretty=short | head -n5 >> .last_build
git status | grep "modified" >> .last_build
echo "=================" >> .last_build
echo "rebuild.sh $*" >> .last_build
echo "=================" >> .last_build
enable_cpucounters=0
enable_stats=0
enable_ndebug=0
maxsievingdim=128
gpuvecnum=65536
enable_ggdb=0
enable_jobs=0
enable_templated_dim=0
enable_popcount=1
enable_yr=1
jobs=4
while [[ $# -gt 0 ]]; do
case "$1" in
-m|--maxsievingdim)
maxsievingdim=$2
shift
;;
--gpuvecnum)
gpuvecnum=$2
shift
;;
-j|--jobs)
jobs=$2
shift
;;
-y|--noyr)
enable_yr=0
enable_popcount=0
;;
-g|--ggdb)
enable_ggdb=1
;;
-c|--cpucounters)
enable_cpucounters=1
;;
-s|--stats)
enable_stats=1
;;
-ss|--extended_stats)
enable_stats=2
;;
-t|--templated_dim)
enable_templated_dim=1
;;
-f|--fast)
enable_ndebug=1
enable_cpucounters=0
enable_stats=0
enable_templated_dim=1
;;
-p|--no_popcount)
enable_popcount=0
;;
--with-cuda)
enable_cuda=$2
shift
;;
--build-threshold)
build_threshold=$2
shift
;;
--sieve-threshold)
sieve_threshold=$2
shift
;;
--onlyconf)
only_conf=1
;;
*)
;;
esac
shift
done
EXTRAFLAGS=""
if [ ${enable_yr} -eq 0 ]; then
EXTRAFLAGS="$EXTRAFLAGS -DNOYR=1"
fi
if [ ${enable_popcount} -eq 0 ]; then
EXTRAFLAGS="$EXTRAFLAGS -DPOPCOUNT=0"
fi
if [ ${enable_ggdb} -eq 1 ]; then
EXTRAFLAGS="$EXTRAFLAGS -g -ggdb"
fi
if [ ${enable_cpucounters} -eq 1 ]; then
EXTRAFLAGS="$EXTRAFLAGS -DPERFORMANCE_COUNTING"
fi
if [ ${enable_stats} -ge 1 ]; then
EXTRAFLAGS="$EXTRAFLAGS -DENABLE_STATS"
fi
if [ ${enable_stats} -ge 2 ]; then
EXTRAFLAGS="$EXTRAFLAGS -DENABLE_EXTENDED_STATS"
fi
if [ ${enable_ndebug} -eq 1 ]; then
EXTRAFLAGS="$EXTRAFLAGS -DNDEBUG"
fi
if [ ${enable_templated_dim} -eq 1 ]; then
EXTRAFLAGS="$EXTRAFLAGS -DTEMPLATED_DIM"
fi
if [ ${maxsievingdim} -gt 0 ]; then
EXTRAFLAGS="$EXTRAFLAGS -DMAX_SIEVING_DIM=${maxsievingdim}"
fi
if [ "$build_threshold" != "" ]; then
EXTRAFLAGS="$EXTRAFLAGS -DXPC_BUCKET_THRESHOLD=${build_threshold}"
fi
if [ "$sieve_threshold" != "" ]; then
EXTRAFLAGS="$EXTRAFLAGS -DXPC_THRESHOLD=${sieve_threshold}"
fi
if [ "$gpuvecnum" != "" ]; then
EXTRAFLAGS="$EXTRAFLAGS -DGPUVECNUM=${gpuvecnum}"
fi
### CUDA: CONFIGURE OPTIONS ###
want_cuda="maybe"
have_nvcc="no"
if [ "$CUDAPATH" = "" ]; then
cuda_path="/usr/local/cuda"
else
cuda_path="$CUDAPATH"
fi
if [ "${enable_cuda}" = "no" ]; then
want_cuda="no"
elif [ "${enable_cuda}" = "yes" ]; then
want_cuda="yes"
elif [ "${enable_cuda}" != "" ]; then
want_cuda="yes"
cuda_path="${enable_cuda}"
fi
echo "want_cuda: ${want_cuda}" #&>> cuda_debug.log
echo "cuda_path: ${cuda_path}" #&>> cuda_debug.log
### CUDA: FIND NVCC
if [ "${want_cuda}" != "no" ]; then
if [ "${cuda_path}" != "" ]; then
PATH=${PATH}:${cuda_path}/bin
fi
NVCC=$(which nvcc)
if [ "${NVCC}" != "" ]; then
have_nvcc="yes"
fi
fi
echo "nvcc_path: ${NVCC}" #&>> cuda_debug.log
if [ "${have_nvcc}" = "yes" ]; then
NVCC_VERSION=`${NVCC} --version | grep release | awk 'gsub(/,/, "") {print $5}'`
echo "nvcc version: ${NVCC_VERSION}" #&>> cuda_debug.log
cuda_libdir=lib
if [ `uname -m` = x86_64 ]; then
cuda_libdir=lib64
fi
if [ `uname -m` = powerpc64le ]; then
cuda_libdir=lib64
fi
CUDA_FLAGS="-lineinfo -I${cuda_path}/include -I../parallel-hashmap"
CUDA_LIBS="-L${cuda_path}/${cuda_libdir} -Wl,-rpath=${cuda_path}/${cuda_libdir} -lcudart -L${cuda_path}/${cuda_libdir}/stubs -Wl,-rpath=${cuda_path}/${cuda_libdir}/stubs -lcuda -lcublas -lcurand"
echo "CUDA_FLAGS: ${CUDA_FLAGS}" #&>> cuda_debug.log
echo "CUDA_LIBS: ${CUDA_LIBS}" #&>> cuda_debug.log
EXTRAFLAGS="$EXTRAFLAGS -DHAVE_CUDA"
CUDA_CXX=""
HAVE_CUDA=1
else
HAVE_CUDA=0
fi
### END CUDA SECTION
# write Makefile.local
cat >Makefile.local <<EOF
EXTRAFLAGS=${EXTRAFLAGS}
HAVE_CUDA=${HAVE_CUDA}
CUDA_PATH=${cuda_path}
NVCC=${NVCC}
CUDA_FLAGS=${CUDA_FLAGS}
CUDA_LIBS=${CUDA_LIBS}
CUDA_CXX=${CUDA_CXX}
EOF
if [ "${only_conf}" = "1" ]; then
exit
fi
[ -d parallel-hashmap ] || git clone https://github.com/cr-marcstevens/parallel-hashmap
# Clean build artifacts
rm -rf build/ *.so g6k/*.so g6k/*.cpp cuda/*.o kernel/*.o *.egg-info/ __pycache__/ g6k/__pycache__/ `find g6k -name "*.pyc"`
# Ensure parallel-hashmap dependency
[ -d parallel-hashmap ] || git clone https://github.com/cr-marcstevens/parallel-hashmap
# Write compile-time configuration for setup.py to use
cat >compile_config.py <<EOF
# Auto-generated configuration from rebuild.sh
REBUILD_CONFIG = {
'MAX_SIEVING_DIM': ${maxsievingdim},
'GPUVECNUM': ${gpuvecnum},
'EXTRAFLAGS': '${EXTRAFLAGS}',
'HAVE_CUDA': ${HAVE_CUDA},
'CUDA_PATH': '${cuda_path}',
'NVCC': '${NVCC}',
'CUDA_FLAGS': '${CUDA_FLAGS}',
'CUDA_LIBS': '${CUDA_LIBS}'
}
EOF
export G6K_COMPILE_CONFIG="$(pwd)/compile_config.py"
echo "Building G6K with MAX_SIEVING_DIM=${maxsievingdim}, GPUVECNUM=${gpuvecnum}"
echo "Extra flags: ${EXTRAFLAGS}"
echo "CUDA enabled: ${HAVE_CUDA}"
# Use modern pip-based build system
if [ -n "${VIRTUAL_ENV}" ]; then
echo "Using virtual environment: ${VIRTUAL_ENV}"
pip install -e . --force-reinstall --no-deps --no-build-isolation || exit 1
else
echo "No virtual environment detected. Installing globally with pip..."
pip install -e . --force-reinstall --no-deps --no-build-isolation || exit 1
fi
echo "Build completed successfully!"
echo "Configuration written to Makefile.local and compile_config.py"