forked from hasktorch/hasktorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-cabal.sh
More file actions
executable file
·52 lines (39 loc) · 1.5 KB
/
setup-cabal.sh
File metadata and controls
executable file
·52 lines (39 loc) · 1.5 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
#!/usr/bin/env bash
set -xe
ghc --version
#curl https://www.stackage.org/lts-21.25/cabal.config |\
curl https://www.stackage.org/lts-22.44/cabal.config | \
sed -e 's/with-compiler: .*$//g' |\
sed -e 's/.*inline-c.*//g' > cabal.project.freeze
case "$(uname)" in
"Darwin")
TOTAL_MEM_GB=$(sysctl hw.memsize | awk '{print int($2/1024/1024/1024)}')
NUM_CPU=$(sysctl -n hw.ncpu)
GHC_OPTIONS="-optl-ld_classic"
;;
"Linux")
TOTAL_MEM_GB=$(grep MemTotal /proc/meminfo | awk '{print int($2/1024/1024)}')
NUM_CPU=$(nproc --all)
GHC_OPTIONS=""
;;
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<$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: /opt/homebrew/include
extra-lib-dirs: /opt/homebrew/lib
extra-lib-dirs: /opt/homebrew/opt/libomp/lib
package *
extra-lib-dirs: /opt/homebrew/lib
extra-lib-dirs: /opt/homebrew/opt/libomp/lib
package libtorch-ffi
ghc-options: ${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
package vector
ghc-options: -j${USED_NUM_CPU} +RTS -A128m -n2m -M${USED_MEMX2_GB} -RTS
EOF