-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-bindings.sh
executable file
·87 lines (76 loc) · 2.44 KB
/
build-bindings.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
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
#!/usr/bin/env bash
# set -eu
# build structs
function build_structs {
local FILENAME="$1"
local LIB="$2"
case "$(uname -s)" in
# Treat FreeBSD the same as OSX for now
"Darwin"|"FreeBSD")
sed -i '' 's/<bindings.dsl.h>/"bindings.dsl.h"/g' ${FILENAME}.hsc
sed -i '' 's/^#synonym_t.*//g' ${FILENAME}.hsc
hsc2hs ${FILENAME}.hsc -o ${FILENAME}.hs
sed -i '' '/.*LINE.*/d' ${FILENAME}.hs
sed -i '' "s/${FILENAME}/Structs/" ${FILENAME}.hs
mkdir -p Torch/Types/${LIB}
mv ${FILENAME}.hs Torch/Types/${LIB}/Structs.hs
rm ./${FILENAME}.hsc
;;
"Linux")
sed -i 's/<bindings.dsl.h>/"bindings.dsl.h"/g' ${FILENAME}.hsc
sed -i 's/^#synonym_t.*//g' ${FILENAME}.hsc
hsc2hs ${FILENAME}.hsc -o ${FILENAME}.hs
sed -i '/.*LINE.*/d' ${FILENAME}.hs
sed -i -e "s/${FILENAME}/${LIB}.Structs/" ${FILENAME}.hs
mkdir -p Torch/Types/${LIB}
mv ${FILENAME}.hs Torch/Types/${LIB}/Structs.hs
rm ./${FILENAME}.hsc
;;
*)
echo "Unknown OS"
;;
esac
}
function build_thc {
# Build Cuda structs
if command -v nvcc &> /dev/null; then
cd thc/src
c2hsc --gcc $(command -v gcc) --prefix Torch.Types --verbose thc_cuda_runtime_types.h
build_structs ThcCudaRuntimeTypes Cuda
c2hsc --gcc $(command -v gcc) --prefix Torch.Types --verbose thc_curand_types.h
build_structs ThcCurandTypes CuRand
c2hsc --gcc $(command -v gcc) --prefix Torch.Types --verbose thc_structs.h
build_structs ThcStructs THC
else
echo "can't find nvcc -- please make sure cuda is installed"
exit 1
fi
}
function build_th {
cd th/src
c2hsc --gcc $(command -v gcc) --prefix Torch.Types --verbose th_structs.h
build_structs ThStructs TH
}
if [[ "${0:-}" != "${BASH_SOURCE:-}" ]]; then
printf 'this script is not meant to be sourced.'
printf ' Please run `./built-structs.sh` instead or'
printf '`chmod u+x ./built-structs.sh && ./built-structs.sh`\n'
else
# Build TorchStructs.hsc
case "${1:-}" in
"all")
build_th
build_thc
;;
"thc") build_thc ;;
"th") build_th ;;
"--help"|"-h"|"help"|*)
echo "./build-bindings.sh -- build torch structs from the hasktorch/types subdirectory."
echo ""
echo "USAGE:"
echo " ./build-bindings.sh {all|thc|th} build structs for types/th, types/thc, or both projects"
echo " ./build-bindings.sh {--help|-h|help} short this prompt"
echo ""
;;
esac
fi