forked from hasktorch/hasktorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-cabal.sh
executable file
·47 lines (36 loc) · 1.39 KB
/
setup-cabal.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
#!/usr/bin/env bash
set -xe
if ghc --version | grep 9.0.1 ; then
curl https://www.stackage.org/nightly-2021-07-22/cabal.config > cabal.project.freeze
else
curl https://www.stackage.org/lts-17.2/cabal.config > cabal.project.freeze
fi
case "$(uname)" in
"Darwin")
TOTAL_MEM_GB=`sysctl hw.physmem | awk '{print int($2/1024/1024/1024)}'`
NUM_CPU=$(sysctl -n hw.ncpu)
;;
"Linux")
TOTAL_MEM_GB=`grep MemTotal /proc/meminfo | awk '{print int($2/1024/1024)}'`
NUM_CPU=$(nproc --all)
;;
esac
USED_MEM_GB=`echo $TOTAL_MEM_GB | awk '{print int(($1 + 1) / 2)}'`
USED_NUM_CPU=`echo $NUM_CPU | awk '{print int(($1 + 1) / 2)}'`
USED_NUM_CPU=`echo $USED_MEM_GB $USED_NUM_CPU | awk '{if($1<x$2) {print $1} else {print $2}}'`
USED_MEM_GB=`echo $USED_NUM_CPU | awk '{print ($1)"G"}'`
USED_MEMX2_GB=`echo $USED_NUM_CPU | awk '{print ($1 * 2)"G"}'`
cat <<EOF > cabal.project.local
package libtorch-ffi
extra-include-dirs: $(pwd)/deps/libtorch/include/torch/csrc/api/include
extra-include-dirs: $(pwd)/deps/libtorch/include
extra-lib-dirs: $(pwd)/deps/libtorch/lib
package *
extra-lib-dirs: $(pwd)/deps/mklml/lib
extra-lib-dirs: $(pwd)/deps/libtorch/lib
extra-lib-dirs: $(pwd)/deps/tokenizers/lib
package libtorch-ffi
ghc-options: -j${USED_NUM_CPU} +RTS -A128m -n2m -M${USED_MEM_GB} -RTS
package hasktorch
ghc-options: -j${USED_NUM_CPU} +RTS -A128m -n2m -M${USED_MEMX2_GB} -RTS
EOF