-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_features.sh
118 lines (94 loc) · 3.1 KB
/
extract_features.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
CXX_COMPILER=""
KERNEL_DIR=""
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--cxx_compiler=*)
CXX_COMPILER="${1#*=}"
shift
;;
--dir=*)
KERNEL_DIR="${1#*=}"
shift
;;
--include=*)
INCLUDE="${1#*=}"
shift
;;
*)
echo "Invalid argument: $1"
return 1 2>/dev/null
exit 1
;;
esac
done
if [ -z "$CXX_COMPILER" ]
then
echo "Provide the absolute path to the DPC++ compiler as --cxx_compiler argument"
return 1 2>/dev/null
exit 1
fi
if [ -z "$KERNEL_DIR" ]
then
echo "Provide the directory of the kernels as --dir argument"
return 1 2>/dev/null
exit 1
fi
DPCPP_CLANG=$CXX_COMPILER
BIN_DIR=$(dirname $DPCPP_CLANG)
DPCPP_LIB=$BIN_DIR/../lib/
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cmake -S $SCRIPT_DIR/passes -B $SCRIPT_DIR/passes/build
cmake --build $SCRIPT_DIR/passes/build -j
alias sycl="$DPCPP_CLANG -O3 -fsycl -fsycl-targets=nvptx64-nvidia-cuda -fsycl-device-only"
alias opt=opt-15
####### Extract application bitcode
mkdir -p $SCRIPT_DIR/bitcode
for file in $SCRIPT_DIR/$KERNEL_DIR/*.cpp; do
name=`basename ${file%.*}`
if [[ ! -f "$SCRIPT_DIR/bitcode/$name.bc" ]]; then
echo "Generating bitcode for $name"
sycl -Wno-unknown-cuda-version -Wno-deprecated-declarations $file $INCLUDE $SCRIPT_DIR/bitcode/$name.bc
fi
done
mkdir -p $SCRIPT_DIR/features
mkdir -p $SCRIPT_DIR/features-count
mkdir -p $SCRIPT_DIR/features-normalized
# Feature extraction from bitcode
for file in $SCRIPT_DIR/bitcode/*.bc; do
name=`basename ${file%.*}`
opt -load-pass-plugin $SCRIPT_DIR/passes/build/feature-pass/libfeature_pass.so --passes="print<feature>" -disable-output $file 1>> "$SCRIPT_DIR/features/$name.temp" 2> /dev/null
done
# Output parsing
for tempfile in $SCRIPT_DIR/features/*.temp; do
name=`basename ${tempfile%.*}`
features_count="$SCRIPT_DIR/features-count/${name}_features.csv"
features_norm="$SCRIPT_DIR/features-normalized/${name}_features.csv"
echo "kernel_name,mem_gl,int_add,int_bw,flt_mul,int_mul,flt_div,sp_fun,mem_loc,int_div,flt_add" > $features_count
echo "kernel_name,mem_gl,int_add,int_bw,flt_mul,int_mul,flt_div,sp_fun,mem_loc,int_div,flt_add" > $features_norm
lines_number=$(sed -n "/IR-function/=" $tempfile)
for n in $lines_number; do
line_counters=""
line_norm=""
name="$(sed "${n}q;d" $tempfile | awk '{print $2}'),"
line_counters+=$name
line_norm+=$name
counters_line_num=$(($n+6))
counters=$(sed "${counters_line_num}q;d" $tempfile)
let sum=0
for num in $counters; do
sum=$(( $sum + $num ))
done
if [ $sum -eq '0' ]; then
continue
fi
line_counters+=$(echo $counters | sed 's/ /,/g')
normalized_line_num=$(($n+8))
normalized=$(sed "${normalized_line_num}q;d" $tempfile)
line_norm+=$(echo $normalized | sed 's/ /,/g')
echo $line_counters >> $features_count
echo $line_norm >> $features_norm
done
done
rm -r $SCRIPT_DIR/features/