@@ -10,31 +10,61 @@ set -e
1010# ./build.sh breakout --local # Standalone executable (debug, sanitizers)
1111# ./build.sh breakout --fast # Standalone executable (optimized)
1212# ./build.sh breakout --web # Emscripten web build
13+ # # copy build/web/ENV/* to ../docker/puffer.ai/docs/assets/ENV/
1314# ./build.sh breakout --profile # Kernel profiling binary
15+ # ./build.sh breakout --device N # Pin CUDA_VISIBLE_DEVICES during the build
1416# ./build.sh all # Build all envs native and native float32
17+ #
18+ # Native train/eval binaries are written per-env so parallel builds/runs
19+ # do not clobber a shared ./puffer:
20+ # build/puffer_<env> default precision
21+ # build/puffer_<env>_float --float
22+ # Runtime GPU selection: CUDA_VISIBLE_DEVICES=N ./build/puffer_<env> train <env>
23+ # or ./build/puffer_<env> train <env> base.gpu_offset=N
1524
1625if [ -z " $1 " ]; then
17- echo " Usage: ./build.sh ENV_NAME [--gpu] [--float] [--debug] [--local|--fast|--web|--profile|--cpu]"
26+ echo " Usage: ./build.sh ENV_NAME [--gpu] [--float] [--debug] [--local|--fast|--web|--profile|--cpu] [--device N] "
1827 exit 1
1928fi
2029ENV=$1
2130shift
2231
2332USE_GPU_ENV=0
24- for arg in " $@ " ; do
25- case $arg in
33+ DEVICE=" "
34+ SNAKE_RAW=0
35+ while [ $# -gt 0 ]; do
36+ case $1 in
2637 --gpu) USE_GPU_ENV=1 ;;
2738 --float) PRECISION=" -DPRECISION_FLOAT" ;;
39+ --no-onehot) SNAKE_RAW=1 ;;
2840 --debug) DEBUG=1 ;;
2941 --local) MODE=local ;;
3042 --fast) MODE=fast ;;
3143 --web) MODE=web ;;
3244 --profile) MODE=profile ;;
3345 --cpu) MODE=cpu ;;
34- * ) echo " Error: unknown argument '$arg '" && exit 1 ;;
46+ --device)
47+ shift
48+ if [ -z " $1 " ]; then
49+ echo " Error: --device requires a GPU index" && exit 1
50+ fi
51+ DEVICE=$1
52+ ;;
53+ --device=* )
54+ DEVICE=" ${1# --device=} "
55+ if [ -z " $DEVICE " ]; then
56+ echo " Error: --device requires a GPU index" && exit 1
57+ fi
58+ ;;
59+ * ) echo " Error: unknown argument '$1 '" && exit 1 ;;
3560 esac
61+ shift
3662done
3763
64+ if [ -n " $DEVICE " ]; then
65+ export CUDA_VISIBLE_DEVICES=" $DEVICE "
66+ fi
67+
3868if [ " $ENV " = " all" ]; then
3969 FAILED=" "
4070 for env_dir in ocean/* /; do
@@ -197,28 +227,55 @@ if [ "$MODE" = "local" ] || [ "$MODE" = "fast" ]; then
197227 echo " Built: ./$OUTPUT_NAME "
198228 exit 0
199229elif [ " $MODE " = " web" ]; then
230+ ENV_HEADER=" $SRC_DIR /$ENV .h"
231+ if ! grep -q ' typedef[[:space:]].*obs_t' " $ENV_HEADER " 2> /dev/null; then
232+ echo " Error: $ENV_HEADER must typedef obs_t for web eval"
233+ exit 1
234+ fi
200235 mkdir -p " build/web/$ENV "
201236 PRELOAD_ENV=()
202237 if [ -d " resources/$ENV " ]; then
203238 PRELOAD_ENV=(--preload-file " resources/$ENV @resources/$ENV " )
204239 fi
205240 echo " Compiling $ENV for web..."
241+ PRELOAD=(
242+ --preload-file resources/$ENV @resources/$ENV
243+ --preload-file resources/shared@resources/shared
244+ --preload-file config/default.ini@config/default.ini
245+ )
246+ if [ -f " config/$ENV .ini" ]; then
247+ PRELOAD+=(--preload-file " config/$ENV .ini@config/$ENV .ini" )
248+ fi
249+ if [ -f " config/${ENV} _web.ini" ]; then
250+ PRELOAD+=(--preload-file " config/${ENV} _web.ini@config/${ENV} _web.ini" )
251+ fi
206252 emcc \
207253 -o " build/web/$ENV /game.html" \
208- " $SRC_FILE " $EXTRA_SRC \
254+ -x c src/puffercpu.h -x none $EXTRA_SRC \
209255 -O3 -Wall -Wno-narrowing \
210256 " ${LINK_ARCHIVES[@]} " \
211- " ${INCLUDES[@]} " \
257+ -I. -Isrc -I $SRC_DIR -Ivendor " ${INCLUDES[@]} " \
212258 -L. -L./$RAYLIB_NAME /lib \
213259 -sASSERTIONS=2 -gsource-map \
214260 -sUSE_GLFW=3 -sUSE_WEBGL2=1 -sASYNCIFY -sFILESYSTEM -sFORCE_FILESYSTEM=1 \
215261 --shell-file vendor/minshell.html \
216262 -sINITIAL_MEMORY=512MB -sALLOW_MEMORY_GROWTH -sSTACK_SIZE=512KB \
217263 -DPLATFORM_WEB -DGRAPHICS_API_OPENGL_ES3 \
264+ -DPUFFERCPU_EVAL_MAIN \
265+ -DENV_HEADER=\" $ENV_HEADER \" \
266+ -DPUFFER_ENV_NAME=\" $ENV \" \
218267 --preload-file resources/shared@resources/shared \
219268 " ${PRELOAD_ENV[@]} " \
269+ " ${PRELOAD[@]} " \
220270 " ${EXTRA_CFLAGS[@]} "
221271 echo " Built: build/web/$ENV /game.html"
272+ WEBSITE_DIR=" ${PUFFER_WEBSITE_DIR:- ../ docker/ puffer.ai} "
273+ WEBSITE_ASSETS=" $WEBSITE_DIR /docs/assets"
274+ if [ -d " $WEBSITE_ASSETS " ]; then
275+ mkdir -p " $WEBSITE_ASSETS /$ENV "
276+ cp -a " build/web/$ENV /." " $WEBSITE_ASSETS /$ENV /"
277+ echo " Published: $WEBSITE_ASSETS /$ENV /"
278+ fi
222279 exit 0
223280elif [ " $MODE " = " cpu" ]; then
224281 ENV_HEADER=" $SRC_DIR /$ENV .h"
@@ -227,19 +284,21 @@ elif [ "$MODE" = "cpu" ]; then
227284 exit 1
228285 fi
229286
287+ mkdir -p build
230288 echo " Compiling standalone CPU eval for $ENV ..."
231289 ${CC:- clang} " ${CLANG_OPT[@]} " \
232290 -I. -Isrc -I$SRC_DIR -Ivendor " ${INCLUDES[@]} " \
233291 -DPLATFORM_DESKTOP \
234292 -DPUFFERCPU_EVAL_MAIN \
235293 -DENV_HEADER=\" $ENV_HEADER \" \
294+ -DPUFFER_ENV_NAME=\" $ENV \" \
236295 -x c src/puffercpu.h -x none $EXTRA_SRC \
237296 " ${LINK_ARCHIVES[@]} " \
238297 " ${EXTRA_LDFLAGS[@]} " \
239298 " ${STANDALONE_LDFLAGS[@]} " \
240299 -lm -lpthread -fopenmp \
241- -o build_cpu
242- echo " Built: ./build_cpu "
300+ -o " build/cpu_ ${ENV} "
301+ echo " Built: ./build/cpu_ ${ENV} "
243302 exit 0
244303fi
245304
@@ -293,7 +352,15 @@ MODE=${MODE:-native}
293352NVCC_NARROW=(-Xcompiler=-Wno-narrowing --diag-suppress=2361)
294353
295354if [ " $MODE " = " native" ]; then
296- echo " Compiling native train/eval binary ($ARCH )..."
355+ if [ -n " $PRECISION " ]; then
356+ TRAIN_BIN=" build/puffer_${ENV} _float"
357+ elif [ " $SNAKE_RAW " = " 1" ]; then
358+ TRAIN_BIN=" build/puffer_${ENV} _raw"
359+ EXTRA_CFLAGS+=(-DSNAKE_ONEHOT=0)
360+ else
361+ TRAIN_BIN=" build/puffer_${ENV} "
362+ fi
363+ echo " Compiling native train/eval binary ($ARCH ) -> $TRAIN_BIN ..."
297364 $NVCC $NVCC_OPT -arch=$ARCH -std=c++17 \
298365 -I. -Isrc -I$SRC_DIR -Ivendor \
299366 " ${INCLUDES[@]} " \
@@ -314,11 +381,12 @@ if [ "$MODE" = "native" ]; then
314381 " ${EXTRA_LDFLAGS[@]} " \
315382 -lcudart -lnccl -lnvidia-ml -lcublas -lcusolver -lcurand \
316383 -lm -lpthread $OMP_LIB " ${STANDALONE_LDFLAGS[@]} " \
317- -o puffer
318- echo " Built: ./puffer "
384+ -o " $TRAIN_BIN "
385+ echo " Built: ./$TRAIN_BIN "
319386
320387elif [ " $MODE " = " profile" ]; then
321- echo " Compiling profile binary ($ARCH )..."
388+ PROFILE_BIN=" build/profile_${ENV} "
389+ echo " Compiling profile binary ($ARCH ) -> $PROFILE_BIN ..."
322390 $NVCC $NVCC_OPT -arch=$ARCH -std=c++17 \
323391 -I. -Isrc -I$SRC_DIR -Ivendor \
324392 " ${INCLUDES[@]} " \
@@ -336,6 +404,6 @@ elif [ "$MODE" = "profile" ]; then
336404 -L$CUDA_HOME /lib64 \
337405 -lnccl -lnvidia-ml -lcublas -lcusolver -lcurand \
338406 -lGL -lm -lpthread $OMP_LIB \
339- -o profile
340- echo " Built: ./profile "
407+ -o " $PROFILE_BIN "
408+ echo " Built: ./$PROFILE_BIN "
341409fi
0 commit comments