forked from JeffersonLab/qdp-jit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpack_libdevice.sh
executable file
·91 lines (64 loc) · 1.54 KB
/
pack_libdevice.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
88
89
90
91
#!/bin/bash
if [ "$#" -ne 1 ] || ! [ -d "$1" ]; then
echo "Usage: $0 DIRECTORY" >&2
exit 1
fi
LIBDEVICE_DIR=$1
QDPJIT_DIR=`pwd`
OUT_HEADER="$QDPJIT_DIR/include/qdp_libdevice.h"
OUT_LIB="$QDPJIT_DIR/lib/qdp_libdevice.cc"
if [ -f $OUT_HEADER ]; then
echo "$OUT_HEADER already exists."
exit 1
fi
if [ -f $OUT_LIB ]; then
echo "$OUT_LIB already exists."
exit 1
fi
if [ ! -f ${LIBDEVICE_DIR}/libdevice.bc ]; then
echo "${LIBDEVICE_DIR}/libdevice.bc not found."
exit 1
fi
if [ ! -d include ]; then
echo "Please call from qdp-jit root dir!"
exit 1
fi
if [ ! -d lib ]; then
echo "Please call from qdp-jit root dir!"
exit 1
fi
cat << 'EOF' > $OUT_HEADER
#ifndef qdp_libdevice
#define qdp_libdevice
namespace QDP {
namespace LIBDEVICE {
EOF
cat << 'EOF' > $OUT_LIB
namespace QDP {
namespace LIBDEVICE {
EOF
if [ -d $LIBDEVICE_DIR ]; then
cd $LIBDEVICE_DIR
echo "ok"
for libdev in `ls libdevice.bc`; do
echo $libdev
head=`xxd -i $libdev | head -n 1| sed -e 's/\[\].*$/\[\];/'`
tail=`xxd -i $libdev | tail -n 1| sed -e 's/_len.*$/_len;/'`
name=`echo $head | sed -e 's/^.*char //'| sed -e 's/\[\]//' | sed -e 's/;//'`
# libdevice.compute_20.10.bc [name] / name_len
echo "extern $head" >> $OUT_HEADER
echo "extern $tail" >> $OUT_HEADER
xxd -i $libdev >> $OUT_LIB
done
fi
cat << 'EOF' >> $OUT_HEADER
} // namespace LIBDEVICE
} // namespace QDP
#endif
EOF
cat << 'EOF' >> $OUT_LIB
} // namespace LIBDEVICE
} // namespace QDP
EOF
cd $QDPJIT_DIR
#unsigned char libdevice_compute_20_10_bc[] = {