-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_Compigra.sh
executable file
·188 lines (154 loc) · 5.25 KB
/
run_Compigra.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash
# MLIR frontend
POLYGEIST_PATH=`YOUR POLYGEIST PATH` # optional: set the path to the Polygeist repository
CLANG14=`YOUR CLANG PATH`
MLIR_OPT="$POLYGEIST_PATH/llvm-project/build/bin/mlir-opt"
MLIR_TRANSLATE="$POLYGEIST_PATH/llvm-project/build/bin/mlir-translate"
COMPIGRA_OPT="$POLYGEIST_PATH/../build/bin/compigra-opt"
BENCH_BASE="$POLYGEIST_PATH/../benchmarks"
# Plugin for modulo scheduling
MS_PLUGIN=`OPT_PLUGIN_PATH` # optional: set the path to the SAT-MapIt plugin
# compile use C->LLVM->MLIR(LLVM)->MLIR(CGRA)
compile_sat() {
local bench_name="$1"
local config="$2x$2"
local mode=$3
local bench_path="$BENCH_BASE/$bench_name"
local bench_c="$bench_path/$bench_name.c"
local bench_ll="$bench_path/$bench_name.ll"
echo $bench_path
# Check if the benchmark file exists
if [ ! -f "$bench_c" ]; then
echo "Error:$bench_c not found."
exit 1
fi
# remove the old IR files
rm -rf "$bench_path"/IR/*
# Create the directory to store the DAG text files
if [ ! -d "$BENCH_BASE/$benchmark/IR/SatMapDAG" ]; then
mkdir "$BENCH_BASE/$benchmark/IR/SatMapDAG"
fi
# remove the old DAG text files
rm -rf "$bench_path/IR/SatMapDAG"/$bench_name*
# using clang to compile 32-bit system
local f_ll="$bench_path/IR/llvm.ll"
local f_llvm="$bench_path/IR/llvm.mlir"
local f_cgra="$bench_path/IR/cgra.mlir"
local f_dag="$bench_path/IR/SatMapDAG/$bench_name"
local f_hardware="$bench_path/IR/hardware.mlir"
local f_sat="$bench_path/IR/sat.mlir"
# Get llvm IR from clang
$CLANG14 -S -c -emit-llvm -m32 -O3 \
-fno-unroll-loops -fno-vectorize -fno-slp-vectorize \
"$bench_c" -o "$f_ll" 2> /dev/null
# Check whether conversion success
if [ $? -ne 0 ]; then
echo "FAILED ON LLVM IR GENERATION."
return 1
else
echo "Generate LLVM IR."
fi
# Translate llvm to mlir llvm dialect
$MLIR_TRANSLATE --import-llvm "$f_ll" > "$f_llvm" 2> /dev/null
# Check whether conversion success
if [ $? -ne 0 ]; then
echo "FAILED ON LLVM IR GENERATION."
return 1
else
echo "Translate to MLIR with LLVM Dialect."
fi
# convert llvm to cgra operation
$COMPIGRA_OPT --allow-unregistered-dialect \
--convert-llvm-to-cgra="func-name=$bench_name mem-json=${BENCH_BASE}/memory_config.json" \
"$f_llvm" > "$f_cgra" 2> /dev/null
# Check whether conversion success
if [ $? -ne 0 ]; then
echo "FAILED ON CONVERTING LLVM TO CGRA DIALECT."
return 1
else
echo "Conversion success."
fi
# convert cgra operations to fit into hardware ISA
$COMPIGRA_OPT --allow-unregistered-dialect \
--fit-openedge="out-dag=$f_dag" "$f_cgra" > "$f_hardware" 2> /dev/null
# Check whether hardware transformation success
if [ $? -ne 0 ]; then
echo "FAILED ON HARDWARE TRANSFORMATION."
return 1
else
echo "Hardware transformation success."
fi
# folder to place the DAG text files
local sat_text="$bench_path/IR/SatMapDAG/"
if [ ! -d $sat_text ]; then
mkdir -p $sat_text
fi
# if not existed $path/$config, mkdir
if [ ! -d $bench_path/$config ]; then
mkdir -p $bench_path/$config
fi
# Generate the scheduled assembly code
if [ "$mode" -eq 0 ]; then
echo "!Warning: Not using SAT-MapIt results."
$COMPIGRA_OPT --allow-unregistered-dialect \
--gen-openedge-asm="func-name=$bench_name \
grid=$2" "$f_hardware" > $f_sat #2> /dev/null
if [ $? -ne 0 ]; then
echo "Kernel scheduling failed."
return 1
else
echo "Kernel schedule success."
fi
# mv out.sat and out_grid.sat to $bench_path/$config
mv out.sat $bench_path/$config/NoOptim_out.sat
mv out_grid.sat $bench_path/$config/NoOptim_out_grid.sat
else
# Run SAT-MapIt to schedule the loop block
python3 $MS_PLUGIN --path $sat_text --bench $bench_name --unit $2 --seed 13\
> $bench_path/$config/"out_raw.sat" 2> /dev/null
# Check whether loop block scheduling success
if [ $? -ne 0 ]; then
echo "FAILED ON LOOP BLOCK SCHEDULING."
return 1
else
echo "Loop block scheduling success."
fi
$COMPIGRA_OPT --allow-unregistered-dialect \
--gen-openedge-asm="func-name=$bench_name \
map-result=$bench_path/$config/out_raw.sat grid=$2" \
"$f_hardware" > $f_sat 2> /dev/null
if [ $? -ne 0 ]; then
echo "Kernel scheduling failed."
return 1
else
echo "Kernel schedule success."
fi
fi
echo "COMPILATION SUCCESS."
return 0
}
benchmark=$1
config=$2
task=$3
# Check if the second parameter is provided
if [ -z "$2" ]; then
config=4
else
config=$2
fi
# Check if the third parameter is provided
if [ -z "$3" ]; then
task=1
else
if [ "$3" -eq 0 ]; then
task=0
else
echo "Error: Invalid task value. \
Task must be 0, specifying not use sat-mapit results"
exit 1
fi
fi
if [ ! -d "$BENCH_BASE/$benchmark/IR" ]; then
mkdir "$BENCH_BASE/$benchmark/IR"
fi
compile_sat $benchmark $config $task