From a3f4f0be8f2261bfdfad050ed8aae83d23309d00 Mon Sep 17 00:00:00 2001 From: Berke Ates Date: Sat, 10 Dec 2022 12:50:57 +0100 Subject: [PATCH 01/14] removed arial --- scripts/single_plot.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/single_plot.py b/scripts/single_plot.py index 2c7adb2..17747ee 100755 --- a/scripts/single_plot.py +++ b/scripts/single_plot.py @@ -38,8 +38,7 @@ def add_median_labels(ax, precision='.2f'): ha='center', va='bottom', fontweight='bold', - color='black', - fontfamily='Arial') + color='black') dt = pd.read_csv(input_file) From d425c409e933921e61bd6debc43b94435d7e25df Mon Sep 17 00:00:00 2001 From: Berke Ates Date: Sat, 10 Dec 2022 12:53:48 +0100 Subject: [PATCH 02/14] better error handling --- scripts/multi_plot.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/multi_plot.py b/scripts/multi_plot.py index 6401095..082be68 100755 --- a/scripts/multi_plot.py +++ b/scripts/multi_plot.py @@ -15,7 +15,7 @@ if len(sys.argv) < 3: print("Multi Benchmark Plotting Tool") print("Arguments:") - print(" Input CSVs: A list of CSV files to plot") + print(" Input CSVs: A list of CSV files to plot (at least 4)") print(" Output File: The filepath of the generated plot") exit(1) @@ -27,6 +27,11 @@ dt = [] num_bench = len(input_files) + +if (num_bench < 4): + print("This plotter requires at least 4 CSV files") + exit(1) + rows = 3 cols = ceil(num_bench / rows) color = ['#4D678D', '#4D678D', '#4D678D', '#4D678D', '#EA7878'] From c2a973e00e8519c4d001d3973005145fe7a7cd72 Mon Sep 17 00:00:00 2001 From: Berke Ates Date: Sat, 10 Dec 2022 12:58:11 +0100 Subject: [PATCH 03/14] comment + formatting --- scripts/snippets/dcir.sh | 41 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/scripts/snippets/dcir.sh b/scripts/snippets/dcir.sh index b7e36c6..9253a99 100755 --- a/scripts/snippets/dcir.sh +++ b/scripts/snippets/dcir.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Desc: Runs a Polybench benchmark using DCIR. The output contains any +# Desc: Runs a snippet benchmark using DCIR. The output contains any # intermediate results and the times in the CSV format # Usage: ./dcir.sh @@ -16,10 +16,10 @@ output_dir=$2 repetitions=$3 # Check tools -check_tool(){ - if ! command -v $1 &> /dev/null; then - echo "$1 could not be found" - exit 1 +check_tool() { + if ! command -v $1 &>/dev/null; then + echo "$1 could not be found" + exit 1 fi } @@ -34,7 +34,7 @@ check_tool icc # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Clear .dacecache @@ -46,13 +46,14 @@ input_dir=$(dirname $input_file) input_chrono="$input_dir/$input_name-chrono.c" current_dir=$(dirname $0) scripts_dir=$(dirname $0)/.. -timings_file=$output_dir/${input_name}_timings.csv; touch $timings_file +timings_file=$output_dir/${input_name}_timings.csv +touch $timings_file # Adds a value to the timings file, jumps to the next row after a write csv_line=1 -add_csv(){ +add_csv() { while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >> $timings_file + echo '' >>$timings_file done if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then @@ -60,7 +61,7 @@ add_csv(){ fi sed -i "${csv_line}s/$/$1/" "$timings_file" - csv_line=$((csv_line+1)) + csv_line=$((csv_line + 1)) } # Flags for the benchmark @@ -70,8 +71,8 @@ opt_lvl_dc=3 # Optimization level for the data-centric optimizations # Dace Settings export DACE_compiler_cpu_executable="$(which clang++)" -export CC=`which clang` -export CXX=`which clang++` +export CC=$(which clang) +export CXX=$(which clang++) export DACE_compiler_cpu_openmp_sections=0 export DACE_instrumentation_report_each_invocation=0 export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" @@ -79,20 +80,20 @@ export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" # Generating MLIR from C using Polygeist cgeist -resource-dir=$(clang-13 -print-resource-dir) -S --memref-fullrank \ -O$opt_lvl_cc --raise-scf-to-affine $flags $input_file \ - > $output_dir/${input_name}_cgeist.mlir + >$output_dir/${input_name}_cgeist.mlir # Optimizing with MLIR -mlir-opt --affine-loop-invariant-code-motion $output_dir/${input_name}_cgeist.mlir | \ -mlir-opt --affine-scalrep | mlir-opt --lower-affine | \ -mlir-opt --cse --inline > $output_dir/${input_name}_opt.mlir +mlir-opt --affine-loop-invariant-code-motion $output_dir/${input_name}_cgeist.mlir | + mlir-opt --affine-scalrep | mlir-opt --lower-affine | + mlir-opt --cse --inline >$output_dir/${input_name}_opt.mlir # Converting to DCIR sdfg-opt --convert-to-sdfg $output_dir/${input_name}_opt.mlir \ - > $output_dir/${input_name}_sdfg.mlir + >$output_dir/${input_name}_sdfg.mlir # Translating to SDFG sdfg-translate --mlir-to-sdfg $output_dir/${input_name}_sdfg.mlir \ - > $output_dir/$input_name.sdfg + >$output_dir/$input_name.sdfg # Optimizing data-centrically with DaCe python3 $scripts_dir/opt_sdfg.py $output_dir/$input_name.sdfg \ @@ -102,7 +103,7 @@ python3 $scripts_dir/opt_sdfg.py $output_dir/$input_name.sdfg \ actual=$(python3 $current_dir/bench_dcir.py $output_dir/${input_name}_opt.sdfg 1 T) clang -O0 $flags -o $output_dir/${input_name}_clang_ref.out $input_chrono -lm -$output_dir/${input_name}_clang_ref.out &> /dev/null +$output_dir/${input_name}_clang_ref.out &>/dev/null reference=$? if [ "$actual" -ne "$reference" ]; then @@ -118,6 +119,6 @@ add_csv "DCIR" for i in $(seq 1 $repetitions); do time=$(python3 $scripts_dir/get_sdfg_times.py \ - $output_dir/${input_name}_opt.sdfg $((i-1)) F) + $output_dir/${input_name}_opt.sdfg $((i - 1)) F) add_csv "$time" done From fbc8f474488439d9efe4254869bed63e2f468483 Mon Sep 17 00:00:00 2001 From: Berke Ates Date: Sat, 10 Dec 2022 13:00:15 +0100 Subject: [PATCH 04/14] formatting --- scripts/Polybench/clang.sh | 23 +++++------ scripts/Polybench/dace.sh | 47 +++++++++++----------- scripts/Polybench/dcir.sh | 57 ++++++++++++++------------- scripts/Polybench/gcc.sh | 23 +++++------ scripts/Polybench/mlir.sh | 39 +++++++++--------- scripts/Polybench/run_all.sh | 50 +++++++++++------------ scripts/pytorch/dcir.sh | 39 +++++++++--------- scripts/pytorch/pytorch.sh | 22 +++++------ scripts/pytorch/run_all.sh | 46 +++++++++++----------- scripts/pytorch/torch-mlir.sh | 21 +++++----- scripts/run_all.sh | 4 +- scripts/snippets/clang.sh | 23 +++++------ scripts/snippets/dace.sh | 26 ++++++------ scripts/snippets/gcc.sh | 23 +++++------ scripts/snippets/mlir.sh | 39 +++++++++--------- scripts/snippets/run_all.sh | 74 +++++++++++++++++------------------ 16 files changed, 283 insertions(+), 273 deletions(-) diff --git a/scripts/Polybench/clang.sh b/scripts/Polybench/clang.sh index 32482d3..1c00bc0 100755 --- a/scripts/Polybench/clang.sh +++ b/scripts/Polybench/clang.sh @@ -16,10 +16,10 @@ output_dir=$2 repetitions=$3 # Check tools -check_tool(){ - if ! command -v $1 &> /dev/null; then - echo "$1 could not be found" - exit 1 +check_tool() { + if ! command -v $1 &>/dev/null; then + echo "$1 could not be found" + exit 1 fi } @@ -29,7 +29,7 @@ check_tool python3 # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Helpers @@ -37,15 +37,16 @@ input_name=$(basename ${input_file%.*}) input_dir=$(dirname $input_file) utils_dir=$input_dir/../utilities scripts_dir=$(dirname $0)/.. -timings_file=$output_dir/${input_name}_timings.csv; touch $timings_file +timings_file=$output_dir/${input_name}_timings.csv +touch $timings_file reference=$output_dir/${input_name}_reference.txt actual=$output_dir/${input_name}_actual_clang.txt # Adds a value to the timings file, jumps to the next row after a write csv_line=1 -add_csv(){ +add_csv() { while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >> $timings_file + echo '' >>$timings_file done if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then @@ -53,7 +54,7 @@ add_csv(){ fi sed -i "${csv_line}s/$/$1/" "$timings_file" - csv_line=$((csv_line+1)) + csv_line=$((csv_line + 1)) } # Flags for the benchmark @@ -76,8 +77,8 @@ clang -I $utils_dir -O$opt_lvl_cc $flags -DPOLYBENCH_DUMP_ARRAYS \ gcc -I $utils_dir -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ -o $output_dir/${input_name}_gcc_ref.out $input_file $utils_dir/polybench.c -lm -$output_dir/${input_name}_clang_dump.out 2> $actual 1> /dev/null -$output_dir/${input_name}_gcc_ref.out 2> $reference 1> /dev/null +$output_dir/${input_name}_clang_dump.out 2>$actual 1>/dev/null +$output_dir/${input_name}_gcc_ref.out 2>$reference 1>/dev/null python3 $scripts_dir/../polybench-comparator/comparator.py $reference $actual diff --git a/scripts/Polybench/dace.sh b/scripts/Polybench/dace.sh index 8f40f69..31ffff9 100755 --- a/scripts/Polybench/dace.sh +++ b/scripts/Polybench/dace.sh @@ -16,10 +16,10 @@ output_dir=$2 repetitions=$3 # Check tools -check_tool(){ - if ! command -v $1 &> /dev/null; then - echo "$1 could not be found" - exit 1 +check_tool() { + if ! command -v $1 &>/dev/null; then + echo "$1 could not be found" + exit 1 fi } @@ -28,7 +28,7 @@ check_tool icc # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Clear .dacecache @@ -40,13 +40,14 @@ input_dir=$(dirname $input_file) utils_dir=$input_dir/../utilities current_dir=$(dirname $0) scripts_dir=$(dirname $0)/.. -timings_file=$output_dir/${input_name}_timings.csv; touch $timings_file +timings_file=$output_dir/${input_name}_timings.csv +touch $timings_file # Adds a value to the timings file, jumps to the next row after a write csv_line=1 -add_csv(){ +add_csv() { while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >> $timings_file + echo '' >>$timings_file done if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then @@ -54,7 +55,7 @@ add_csv(){ fi sed -i "${csv_line}s/$/$1/" "$timings_file" - csv_line=$((csv_line+1)) + csv_line=$((csv_line + 1)) } # Flags for the benchmark @@ -67,27 +68,27 @@ if [[ "$input_name" == "gramschmidt" ]]; then opt_lvl_cc=2 fi -if [[ "$input_name" == "durbin" ]] || \ - [[ "$input_name" == "gemver" ]] || \ - [[ "$input_name" == "doitgen" ]]; then +if [[ "$input_name" == "durbin" ]] || + [[ "$input_name" == "gemver" ]] || + [[ "$input_name" == "doitgen" ]]; then opt_lvl_dc=2 fi -if [[ "$input_name" == "floyd-warshall" ]] || \ - [[ "$input_name" == "3mm" ]] || \ - [[ "$input_name" == "cholesky" ]] || \ - [[ "$input_name" == "gemm" ]] || \ - [[ "$input_name" == "lu" ]] || \ - [[ "$input_name" == "ludcmp" ]] || \ - [[ "$input_name" == "symm" ]] || \ - [[ "$input_name" == "syr2k" ]]; then +if [[ "$input_name" == "floyd-warshall" ]] || + [[ "$input_name" == "3mm" ]] || + [[ "$input_name" == "cholesky" ]] || + [[ "$input_name" == "gemm" ]] || + [[ "$input_name" == "lu" ]] || + [[ "$input_name" == "ludcmp" ]] || + [[ "$input_name" == "symm" ]] || + [[ "$input_name" == "syr2k" ]]; then opt_lvl_dc=1 fi # Dace Settings export DACE_compiler_cpu_executable="$(which clang++)" -export CC=`which clang` -export CXX=`which clang++` +export CC=$(which clang) +export CXX=$(which clang++) export DACE_compiler_cpu_openmp_sections=0 export DACE_instrumentation_report_each_invocation=0 export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" @@ -104,6 +105,6 @@ add_csv "DaCe" for i in $(seq 1 $repetitions); do time=$(python3 $scripts_dir/get_sdfg_times.py \ - $output_dir/${input_name}_c2dace_opt.sdfg $((i-1)) T) + $output_dir/${input_name}_c2dace_opt.sdfg $((i - 1)) T) add_csv "$time" done diff --git a/scripts/Polybench/dcir.sh b/scripts/Polybench/dcir.sh index 206ce05..792a4a6 100755 --- a/scripts/Polybench/dcir.sh +++ b/scripts/Polybench/dcir.sh @@ -16,10 +16,10 @@ output_dir=$2 repetitions=$3 # Check tools -check_tool(){ - if ! command -v $1 &> /dev/null; then - echo "$1 could not be found" - exit 1 +check_tool() { + if ! command -v $1 &>/dev/null; then + echo "$1 could not be found" + exit 1 fi } @@ -35,7 +35,7 @@ check_tool icc # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Clear .dacecache @@ -47,15 +47,16 @@ input_dir=$(dirname $input_file) utils_dir=$input_dir/../utilities current_dir=$(dirname $0) scripts_dir=$(dirname $0)/.. -timings_file=$output_dir/${input_name}_timings.csv; touch $timings_file +timings_file=$output_dir/${input_name}_timings.csv +touch $timings_file reference=$output_dir/${input_name}_reference.txt actual=$output_dir/${input_name}_actual_dcir.txt # Adds a value to the timings file, jumps to the next row after a write csv_line=1 -add_csv(){ +add_csv() { while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >> $timings_file + echo '' >>$timings_file done if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then @@ -63,7 +64,7 @@ add_csv(){ fi sed -i "${csv_line}s/$/$1/" "$timings_file" - csv_line=$((csv_line+1)) + csv_line=$((csv_line + 1)) } # Flags for the benchmark @@ -76,9 +77,9 @@ if [[ "$input_name" == "gramschmidt" ]]; then opt_lvl_cc=2 fi -if [[ "$input_name" == "durbin" ]] || \ - [[ "$input_name" == "gemver" ]] || \ - [[ "$input_name" == "doitgen" ]]; then +if [[ "$input_name" == "durbin" ]] || + [[ "$input_name" == "gemver" ]] || + [[ "$input_name" == "doitgen" ]]; then opt_lvl_dc=2 fi @@ -88,8 +89,8 @@ fi # Dace Settings export DACE_compiler_cpu_executable="$(which clang++)" -export CC=`which clang` -export CXX=`which clang++` +export CC=$(which clang) +export CXX=$(which clang++) export DACE_compiler_cpu_openmp_sections=0 export DACE_instrumentation_report_each_invocation=0 export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" @@ -97,20 +98,20 @@ export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" # Generating MLIR from C using Polygeist cgeist -resource-dir=$(clang-13 -print-resource-dir) -I $utils_dir \ -S --memref-fullrank -O$opt_lvl_cc --raise-scf-to-affine $flags $input_file \ - > $output_dir/${input_name}_cgeist.mlir + >$output_dir/${input_name}_cgeist.mlir # Optimizing with MLIR -mlir-opt --affine-loop-invariant-code-motion $output_dir/${input_name}_cgeist.mlir | \ -mlir-opt --affine-scalrep | mlir-opt --lower-affine | \ -mlir-opt --cse --inline > $output_dir/${input_name}_opt.mlir +mlir-opt --affine-loop-invariant-code-motion $output_dir/${input_name}_cgeist.mlir | + mlir-opt --affine-scalrep | mlir-opt --lower-affine | + mlir-opt --cse --inline >$output_dir/${input_name}_opt.mlir # Converting to DCIR sdfg-opt --convert-to-sdfg $output_dir/${input_name}_opt.mlir \ - > $output_dir/${input_name}_sdfg.mlir + >$output_dir/${input_name}_sdfg.mlir # Translating to SDFG sdfg-translate --mlir-to-sdfg $output_dir/${input_name}_sdfg.mlir \ - > $output_dir/$input_name.sdfg + >$output_dir/$input_name.sdfg # Optimizing data-centrically with DaCe python3 $scripts_dir/opt_sdfg.py $output_dir/$input_name.sdfg \ @@ -120,16 +121,16 @@ python3 $scripts_dir/opt_sdfg.py $output_dir/$input_name.sdfg \ gcc -I $utils_dir -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ -o $output_dir/${input_name}_gcc_ref.out $input_file $utils_dir/polybench.c -lm -python3 $current_dir/bench_dcir.py $output_dir/${input_name}_opt.sdfg 1 T 2> $actual 1> /dev/null -$output_dir/${input_name}_gcc_ref.out 2> $reference 1> /dev/null +python3 $current_dir/bench_dcir.py $output_dir/${input_name}_opt.sdfg 1 T 2>$actual 1>/dev/null +$output_dir/${input_name}_gcc_ref.out 2>$reference 1>/dev/null ## Obtain array names touch $output_dir/arrNames.txt -grep "begin dump:" $reference | while read -r line ; do +grep "begin dump:" $reference | while read -r line; do arrTmp=($line) arrName=${arrTmp[2]} - echo -n "$arrName " >> $output_dir/arrNames.txt + echo -n "$arrName " >>$output_dir/arrNames.txt done arrNames=($(cat $output_dir/arrNames.txt)) @@ -137,16 +138,16 @@ rm $output_dir/arrNames.txt ## Remove Warnings from output sed -i '0,/^==BEGIN DUMP_ARRAYS==$/d' $actual -printf '%s\n%s\n' "==BEGIN DUMP_ARRAYS==" "$(cat $actual)" > $actual +printf '%s\n%s\n' "==BEGIN DUMP_ARRAYS==" "$(cat $actual)" >$actual ## Use original array names idx=0 -grep "begin dump:" $actual | while read -r line ; do +grep "begin dump:" $actual | while read -r line; do arrTmp=($line) arrName=${arrTmp[2]} repArrName=${arrNames[idx]} sed -i -e "s/$arrName/$repArrName/g" $actual - idx=$((idx+1)) + idx=$((idx + 1)) done ## Compare the outputs @@ -165,6 +166,6 @@ add_csv "DCIR" for i in $(seq 1 $repetitions); do time=$(python3 $scripts_dir/get_sdfg_times.py \ - $output_dir/${input_name}_opt.sdfg $((i-1)) T) + $output_dir/${input_name}_opt.sdfg $((i - 1)) T) add_csv "$time" done diff --git a/scripts/Polybench/gcc.sh b/scripts/Polybench/gcc.sh index 8bff2fe..994680d 100755 --- a/scripts/Polybench/gcc.sh +++ b/scripts/Polybench/gcc.sh @@ -16,10 +16,10 @@ output_dir=$2 repetitions=$3 # Check tools -check_tool(){ - if ! command -v $1 &> /dev/null; then - echo "$1 could not be found" - exit 1 +check_tool() { + if ! command -v $1 &>/dev/null; then + echo "$1 could not be found" + exit 1 fi } @@ -29,7 +29,7 @@ check_tool python3 # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Helpers @@ -37,15 +37,16 @@ input_name=$(basename ${input_file%.*}) input_dir=$(dirname $input_file) utils_dir=$input_dir/../utilities scripts_dir=$(dirname $0)/.. -timings_file=$output_dir/${input_name}_timings.csv; touch $timings_file +timings_file=$output_dir/${input_name}_timings.csv +touch $timings_file reference=$output_dir/${input_name}_reference.txt actual=$output_dir/${input_name}_actual_gcc.txt # Adds a value to the timings file, jumps to the next row after a write csv_line=1 -add_csv(){ +add_csv() { while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >> $timings_file + echo '' >>$timings_file done if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then @@ -53,7 +54,7 @@ add_csv(){ fi sed -i "${csv_line}s/$/$1/" "$timings_file" - csv_line=$((csv_line+1)) + csv_line=$((csv_line + 1)) } # Flags for the benchmark @@ -76,8 +77,8 @@ gcc -I $utils_dir -O$opt_lvl_cc $flags -DPOLYBENCH_DUMP_ARRAYS \ clang -I $utils_dir -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ -o $output_dir/${input_name}_clang_ref.out $input_file $utils_dir/polybench.c -lm -$output_dir/${input_name}_gcc_dump.out 2> $actual 1> /dev/null -$output_dir/${input_name}_clang_ref.out 2> $reference 1> /dev/null +$output_dir/${input_name}_gcc_dump.out 2>$actual 1>/dev/null +$output_dir/${input_name}_clang_ref.out 2>$reference 1>/dev/null python3 $scripts_dir/../polybench-comparator/comparator.py $reference $actual diff --git a/scripts/Polybench/mlir.sh b/scripts/Polybench/mlir.sh index e3042d5..f5d2c9a 100755 --- a/scripts/Polybench/mlir.sh +++ b/scripts/Polybench/mlir.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Desc: Runs a Polybench benchmark using Polygeist + MLIR. The output contains +# Desc: Runs a Polybench benchmark using Polygeist + MLIR. The output contains # any intermediate results and the times in the CSV format # Usage: ./mlir.sh @@ -16,10 +16,10 @@ output_dir=$2 repetitions=$3 # Check tools -check_tool(){ - if ! command -v $1 &> /dev/null; then - echo "$1 could not be found" - exit 1 +check_tool() { + if ! command -v $1 &>/dev/null; then + echo "$1 could not be found" + exit 1 fi } @@ -33,7 +33,7 @@ check_tool python3 # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Helpers @@ -41,15 +41,16 @@ input_name=$(basename ${input_file%.*}) input_dir=$(dirname $input_file) utils_dir=$input_dir/../utilities scripts_dir=$(dirname $0)/.. -timings_file=$output_dir/${input_name}_timings.csv; touch $timings_file +timings_file=$output_dir/${input_name}_timings.csv +touch $timings_file reference=$output_dir/${input_name}_reference.txt actual=$output_dir/${input_name}_actual_mlir.txt # Adds a value to the timings file, jumps to the next row after a write csv_line=1 -add_csv(){ +add_csv() { while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >> $timings_file + echo '' >>$timings_file done if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then @@ -57,7 +58,7 @@ add_csv(){ fi sed -i "${csv_line}s/$/$1/" "$timings_file" - csv_line=$((csv_line+1)) + csv_line=$((csv_line + 1)) } # Flags for the benchmark @@ -70,29 +71,29 @@ if [[ "$input_name" == "gramschmidt" ]]; then fi # Compiling with MLIR -compile_with_mlir(){ +compile_with_mlir() { additional_flags=$1 output_name=$2 # Generating MLIR from C using Polygeist cgeist -resource-dir=$(clang-13 -print-resource-dir) -I $utils_dir \ -S --memref-fullrank -O$opt_lvl_cc --raise-scf-to-affine $flags \ - $additional_flags $input_file > $output_dir/${output_name}_cgeist.mlir + $additional_flags $input_file >$output_dir/${output_name}_cgeist.mlir # Optimizing with MLIR mlir-opt --affine-loop-invariant-code-motion \ - $output_dir/${output_name}_cgeist.mlir | \ - mlir-opt --affine-scalrep | mlir-opt --lower-affine | \ - mlir-opt --cse --inline > $output_dir/${output_name}_opt.mlir + $output_dir/${output_name}_cgeist.mlir | + mlir-opt --affine-scalrep | mlir-opt --lower-affine | + mlir-opt --cse --inline >$output_dir/${output_name}_opt.mlir # Lower to LLVM dialect mlir-opt --convert-scf-to-cf --convert-func-to-llvm --convert-cf-to-llvm \ --convert-math-to-llvm --lower-host-to-llvm --reconcile-unrealized-casts \ - $output_dir/${output_name}_opt.mlir > $output_dir/${output_name}_ll.mlir + $output_dir/${output_name}_opt.mlir >$output_dir/${output_name}_ll.mlir # Translate mlir-translate --mlir-to-llvmir $output_dir/${output_name}_ll.mlir \ - > $output_dir/${output_name}.ll + >$output_dir/${output_name}.ll # Compile llc -O$opt_lvl_cc --relocation-model=pic $output_dir/${output_name}.ll \ @@ -112,8 +113,8 @@ compile_with_mlir "-DPOLYBENCH_DUMP_ARRAYS" "${input_name}_mlir_dump" gcc -I $utils_dir -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ -o $output_dir/${input_name}_clang_ref.out $input_file $utils_dir/polybench.c -lm -$output_dir/${input_name}_mlir_dump.out 2> $actual 1> /dev/null -$output_dir/${input_name}_clang_ref.out 2> $reference 1> /dev/null +$output_dir/${input_name}_mlir_dump.out 2>$actual 1>/dev/null +$output_dir/${input_name}_clang_ref.out 2>$reference 1>/dev/null python3 $scripts_dir/../polybench-comparator/comparator.py $reference $actual diff --git a/scripts/Polybench/run_all.sh b/scripts/Polybench/run_all.sh index dfa0cfd..b2347ae 100755 --- a/scripts/Polybench/run_all.sh +++ b/scripts/Polybench/run_all.sh @@ -1,7 +1,7 @@ #!/bin/bash -# Desc: Runs all Polybench benchmarks using GCC, Clang, Polygeist + MLIR, DCIR -# and DaCe. The output contains any intermediate results and the times in the +# Desc: Runs all Polybench benchmarks using GCC, Clang, Polygeist + MLIR, DCIR +# and DaCe. The output contains any intermediate results and the times in the # CSV format as well as a plot with all the benchmarks. # Usage: ./run_all.sh @@ -17,7 +17,7 @@ repetitions=$2 # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Helpers @@ -37,24 +37,24 @@ for runner in $runners; do echo "Running with: $runner" for benchmark in $benchmarks; do - bname="$(basename $benchmark .c)" - count=$((count+1)) - diff=$(($total - $count)) - percent=$(($count * 100 / $total)) - - prog='' - for i in $(seq 1 $count); do - prog="$prog#" - done - - for i in $(seq 1 $diff); do - prog="$prog-" - done - - echo -ne "\033[2K\r" - echo -ne "$prog ($percent%) ($bname) " - - $runner $benchmark $output_dir $repetitions + bname="$(basename $benchmark .c)" + count=$((count + 1)) + diff=$(($total - $count)) + percent=$(($count * 100 / $total)) + + prog='' + for i in $(seq 1 $count); do + prog="$prog#" + done + + for i in $(seq 1 $diff); do + prog="$prog-" + done + + echo -ne "\033[2K\r" + echo -ne "$prog ($percent%) ($bname) " + + $runner $benchmark $output_dir $repetitions done echo "" @@ -63,10 +63,10 @@ done csv_files=() for benchmark in $benchmarks; do - bname="$(basename $benchmark .c)" - mv "$output_dir/${bname}_timings.csv" "$output_dir/${bname}.csv" - csv_files+=("$output_dir/${bname}.csv") - cp "$output_dir/${bname}.csv" "$output_dir/fig6_${bname}.csv" + bname="$(basename $benchmark .c)" + mv "$output_dir/${bname}_timings.csv" "$output_dir/${bname}.csv" + csv_files+=("$output_dir/${bname}.csv") + cp "$output_dir/${bname}.csv" "$output_dir/fig6_${bname}.csv" done python3 $scripts_dir/multi_plot.py ${csv_files[*]} $output_dir/fig6.pdf diff --git a/scripts/pytorch/dcir.sh b/scripts/pytorch/dcir.sh index af2c347..da2d9c5 100755 --- a/scripts/pytorch/dcir.sh +++ b/scripts/pytorch/dcir.sh @@ -16,10 +16,10 @@ output_dir=$2 repetitions=$3 # Check tools -check_tool(){ - if ! command -v $1 &> /dev/null; then - echo "$1 could not be found" - exit 1 +check_tool() { + if ! command -v $1 &>/dev/null; then + echo "$1 could not be found" + exit 1 fi } @@ -33,7 +33,7 @@ check_tool icc # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Clear .dacecache @@ -46,13 +46,14 @@ gen_file=$input_dir/dcir_gen.py bench_file=$input_dir/dcir_bench.py current_dir=$(dirname $0) scripts_dir=$(dirname $0)/.. -timings_file=$output_dir/${input_name}_timings.csv; touch $timings_file +timings_file=$output_dir/${input_name}_timings.csv +touch $timings_file # Adds a value to the timings file, jumps to the next row after a write csv_line=1 -add_csv(){ +add_csv() { while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >> $timings_file + echo '' >>$timings_file done if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then @@ -60,39 +61,39 @@ add_csv(){ fi sed -i "${csv_line}s/$/$1/" "$timings_file" - csv_line=$((csv_line+1)) + csv_line=$((csv_line + 1)) } # Dace Settings export DACE_compiler_cpu_executable="$(which icc)" -export CC=`which icc` -export CXX=`which icc` +export CC=$(which icc) +export CXX=$(which icc) export DACE_compiler_cpu_openmp_sections=0 export DACE_instrumentation_report_each_invocation=0 export DACE_compiler_cpu_args="-fPIC -O3 -march=native" # Generating MLIR using Torch-MLIR -python3 $gen_file > $output_dir/${input_name}_mhlo.mlir +python3 $gen_file >$output_dir/${input_name}_mhlo.mlir # Renaming `forward` to `main` (required by DCIR) sed -i -e "s/forward/main/g" $output_dir/${input_name}_mhlo.mlir # Converting MHLO to standard dialects $scripts_dir/mhlo2std.sh $output_dir/${input_name}_mhlo.mlir \ - > $output_dir/${input_name}_std.mlir + >$output_dir/${input_name}_std.mlir # Optimizing with MLIR -mlir-opt --affine-loop-invariant-code-motion $output_dir/${input_name}_std.mlir | \ -mlir-opt --affine-scalrep | mlir-opt --lower-affine | \ -mlir-opt --cse --inline > $output_dir/${input_name}_opt.mlir +mlir-opt --affine-loop-invariant-code-motion $output_dir/${input_name}_std.mlir | + mlir-opt --affine-scalrep | mlir-opt --lower-affine | + mlir-opt --cse --inline >$output_dir/${input_name}_opt.mlir # Converting to DCIR sdfg-opt --convert-to-sdfg $output_dir/${input_name}_opt.mlir \ - > $output_dir/${input_name}_sdfg.mlir + >$output_dir/${input_name}_sdfg.mlir # Translating to SDFG sdfg-translate --mlir-to-sdfg $output_dir/${input_name}_sdfg.mlir \ - > $output_dir/$input_name.sdfg + >$output_dir/$input_name.sdfg # Optimizing data-centrically with DaCe python3 $scripts_dir/opt_sdfg.py $output_dir/$input_name.sdfg \ @@ -112,6 +113,6 @@ add_csv "DCIR" for i in $(seq 1 $repetitions); do time=$(python3 $scripts_dir/get_sdfg_times.py \ - $output_dir/${input_name}_opt.sdfg $((i-1)) F) + $output_dir/${input_name}_opt.sdfg $((i - 1)) F) add_csv "$time" done diff --git a/scripts/pytorch/pytorch.sh b/scripts/pytorch/pytorch.sh index d35ce68..d7d5bef 100755 --- a/scripts/pytorch/pytorch.sh +++ b/scripts/pytorch/pytorch.sh @@ -16,10 +16,10 @@ output_dir=$2 repetitions=$3 # Check tools -check_tool(){ - if ! command -v $1 &> /dev/null; then - echo "$1 could not be found" - exit 1 +check_tool() { + if ! command -v $1 &>/dev/null; then + echo "$1 could not be found" + exit 1 fi } @@ -27,7 +27,7 @@ check_tool python3 # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Helpers @@ -36,13 +36,14 @@ input_name=$(basename $input_dir) input_file=$input_dir/pytorch.py current_dir=$(dirname $0) scripts_dir=$(dirname $0)/.. -timings_file=$output_dir/${input_name}_timings.csv; touch $timings_file +timings_file=$output_dir/${input_name}_timings.csv +touch $timings_file # Adds a value to the timings file, jumps to the next row after a write csv_line=1 -add_csv(){ +add_csv() { while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >> $timings_file + echo '' >>$timings_file done if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then @@ -50,7 +51,7 @@ add_csv(){ fi sed -i "${csv_line}s/$/$1/" "$timings_file" - csv_line=$((csv_line+1)) + csv_line=$((csv_line + 1)) } # Check output @@ -60,11 +61,10 @@ if ! python3 $input_file 0 T; then fi # Running the benchmark -runtimes=$(OMP_NUM_THREADS=1 taskset -c 0 python3 $input_file $repetitions F) +runtimes=$(OMP_NUM_THREADS=1 taskset -c 0 python3 $input_file $repetitions F) add_csv "PyTorch" for i in $runtimes; do add_csv "$i" done - diff --git a/scripts/pytorch/run_all.sh b/scripts/pytorch/run_all.sh index afb338f..7bfe7d0 100755 --- a/scripts/pytorch/run_all.sh +++ b/scripts/pytorch/run_all.sh @@ -1,7 +1,7 @@ #!/bin/bash -# Desc: Runs all pytorch benchmarks using PyTorch, Torch-MLIR and DCIR. The -# output contains any intermediate results and the times in the CSV format as +# Desc: Runs all pytorch benchmarks using PyTorch, Torch-MLIR and DCIR. The +# output contains any intermediate results and the times in the CSV format as # well as all the plots. # Usage: ./run_all.sh @@ -17,7 +17,7 @@ repetitions=$2 # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Helpers @@ -36,33 +36,33 @@ for runner in $runners; do echo "Running with: $runner" for benchmark in $benchmarks; do - bname="$(basename $benchmark .c)" - count=$((count+1)) - diff=$(($total - $count)) - percent=$(($count * 100 / $total)) + bname="$(basename $benchmark .c)" + count=$((count + 1)) + diff=$(($total - $count)) + percent=$(($count * 100 / $total)) - prog='' - for i in $(seq 1 $count); do - prog="$prog#" - done + prog='' + for i in $(seq 1 $count); do + prog="$prog#" + done - for i in $(seq 1 $diff); do - prog="$prog-" - done + for i in $(seq 1 $diff); do + prog="$prog-" + done - echo -ne "\033[2K\r" - echo -ne "$prog ($percent%) ($bname) " - - $runner $benchmark $output_dir $repetitions + echo -ne "\033[2K\r" + echo -ne "$prog ($percent%) ($bname) " + + $runner $benchmark $output_dir $repetitions done echo "" done for benchmark in $benchmarks; do - bench_dir=$(dirname $benchmark) - bench_name=$(basename $bench_dir) - mv "$output_dir/${bench_name}_timings.csv" "$output_dir/${bench_name}.csv" - python3 $scripts_dir/single_plot.py "$output_dir/${bench_name}.csv" \ - $output_dir/$bench_name.pdf + bench_dir=$(dirname $benchmark) + bench_name=$(basename $bench_dir) + mv "$output_dir/${bench_name}_timings.csv" "$output_dir/${bench_name}.csv" + python3 $scripts_dir/single_plot.py "$output_dir/${bench_name}.csv" \ + $output_dir/$bench_name.pdf done diff --git a/scripts/pytorch/torch-mlir.sh b/scripts/pytorch/torch-mlir.sh index baf7ec0..1e313b4 100755 --- a/scripts/pytorch/torch-mlir.sh +++ b/scripts/pytorch/torch-mlir.sh @@ -16,10 +16,10 @@ output_dir=$2 repetitions=$3 # Check tools -check_tool(){ - if ! command -v $1 &> /dev/null; then - echo "$1 could not be found" - exit 1 +check_tool() { + if ! command -v $1 &>/dev/null; then + echo "$1 could not be found" + exit 1 fi } @@ -27,7 +27,7 @@ check_tool python3 # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Helpers @@ -36,13 +36,14 @@ input_name=$(basename $input_dir) input_file=$input_dir/torch-mlir.py current_dir=$(dirname $0) scripts_dir=$(dirname $0)/.. -timings_file=$output_dir/${input_name}_timings.csv; touch $timings_file +timings_file=$output_dir/${input_name}_timings.csv +touch $timings_file # Adds a value to the timings file, jumps to the next row after a write csv_line=1 -add_csv(){ +add_csv() { while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >> $timings_file + echo '' >>$timings_file done if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then @@ -50,7 +51,7 @@ add_csv(){ fi sed -i "${csv_line}s/$/$1/" "$timings_file" - csv_line=$((csv_line+1)) + csv_line=$((csv_line + 1)) } # Check output @@ -60,7 +61,7 @@ if ! python3 $input_file 0 T; then fi # Running the benchmark -runtimes=$(OMP_NUM_THREADS=1 taskset -c 0 python3 $input_file $repetitions F) +runtimes=$(OMP_NUM_THREADS=1 taskset -c 0 python3 $input_file $repetitions F) add_csv "Torch-MLIR" diff --git a/scripts/run_all.sh b/scripts/run_all.sh index de1bd50..5d7b89a 100755 --- a/scripts/run_all.sh +++ b/scripts/run_all.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Desc: Runs all the benchmarks. The output contains any intermediate results +# Desc: Runs all the benchmarks. The output contains any intermediate results # and the times in the CSV format as well as all the plots. # Usage: ./run_all.sh @@ -16,7 +16,7 @@ repetitions=$2 # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Helpers diff --git a/scripts/snippets/clang.sh b/scripts/snippets/clang.sh index 6e7cb8e..70a16a5 100755 --- a/scripts/snippets/clang.sh +++ b/scripts/snippets/clang.sh @@ -16,10 +16,10 @@ output_dir=$2 repetitions=$3 # Check tools -check_tool(){ - if ! command -v $1 &> /dev/null; then - echo "$1 could not be found" - exit 1 +check_tool() { + if ! command -v $1 &>/dev/null; then + echo "$1 could not be found" + exit 1 fi } @@ -29,7 +29,7 @@ check_tool python3 # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Helpers @@ -37,13 +37,14 @@ input_name=$(basename ${input_file%.*}) input_dir=$(dirname $input_file) input_chrono="$input_dir/$input_name-chrono.c" scripts_dir=$(dirname $0)/.. -timings_file=$output_dir/${input_name}_timings.csv; touch $timings_file +timings_file=$output_dir/${input_name}_timings.csv +touch $timings_file # Adds a value to the timings file, jumps to the next row after a write csv_line=1 -add_csv(){ +add_csv() { while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >> $timings_file + echo '' >>$timings_file done if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then @@ -51,7 +52,7 @@ add_csv(){ fi sed -i "${csv_line}s/$/$1/" "$timings_file" - csv_line=$((csv_line+1)) + csv_line=$((csv_line + 1)) } # Flags for the benchmark @@ -64,9 +65,9 @@ clang -O$opt_lvl_cc $flags -o $output_dir/${input_name}_clang.out $input_chrono # Check output gcc -O0 $flags -o $output_dir/${input_name}_gcc_ref.out $input_chrono -lm -$output_dir/${input_name}_clang.out &> /dev/null +$output_dir/${input_name}_clang.out &>/dev/null actual=$? -$output_dir/${input_name}_gcc_ref.out &> /dev/null +$output_dir/${input_name}_gcc_ref.out &>/dev/null reference=$? if [ "$actual" -ne "$reference" ]; then diff --git a/scripts/snippets/dace.sh b/scripts/snippets/dace.sh index 667dfe5..485a5a6 100755 --- a/scripts/snippets/dace.sh +++ b/scripts/snippets/dace.sh @@ -16,10 +16,10 @@ output_dir=$2 repetitions=$3 # Check tools -check_tool(){ - if ! command -v $1 &> /dev/null; then - echo "$1 could not be found" - exit 1 +check_tool() { + if ! command -v $1 &>/dev/null; then + echo "$1 could not be found" + exit 1 fi } @@ -29,7 +29,7 @@ check_tool icc # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Clear .dacecache @@ -42,13 +42,14 @@ input_chrono="$input_dir/$input_name-chrono.c" input_dace="$input_dir/$input_name.sdfg" current_dir=$(dirname $0) scripts_dir=$(dirname $0)/.. -timings_file=$output_dir/${input_name}_timings.csv; touch $timings_file +timings_file=$output_dir/${input_name}_timings.csv +touch $timings_file # Adds a value to the timings file, jumps to the next row after a write csv_line=1 -add_csv(){ +add_csv() { while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >> $timings_file + echo '' >>$timings_file done if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then @@ -56,7 +57,7 @@ add_csv(){ fi sed -i "${csv_line}s/$/$1/" "$timings_file" - csv_line=$((csv_line+1)) + csv_line=$((csv_line + 1)) } # Flags for the benchmark @@ -74,8 +75,8 @@ fi # Dace Settings export DACE_compiler_cpu_executable="$(which clang++)" -export CC=`which clang` -export CXX=`which clang++` +export CC=$(which clang) +export CXX=$(which clang++) export DACE_compiler_cpu_openmp_sections=0 export DACE_instrumentation_report_each_invocation=0 export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" @@ -92,7 +93,6 @@ add_csv "DaCe" for i in $(seq 1 $repetitions); do time=$(python3 $scripts_dir/get_sdfg_times.py \ - $output_dir/${input_name}_c2dace_opt.sdfg $((i-1)) F) + $output_dir/${input_name}_c2dace_opt.sdfg $((i - 1)) F) add_csv "$time" done - diff --git a/scripts/snippets/gcc.sh b/scripts/snippets/gcc.sh index fd12872..aec7e72 100755 --- a/scripts/snippets/gcc.sh +++ b/scripts/snippets/gcc.sh @@ -16,10 +16,10 @@ output_dir=$2 repetitions=$3 # Check tools -check_tool(){ - if ! command -v $1 &> /dev/null; then - echo "$1 could not be found" - exit 1 +check_tool() { + if ! command -v $1 &>/dev/null; then + echo "$1 could not be found" + exit 1 fi } @@ -29,7 +29,7 @@ check_tool python3 # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Helpers @@ -37,13 +37,14 @@ input_name=$(basename ${input_file%.*}) input_dir=$(dirname $input_file) input_chrono="$input_dir/$input_name-chrono.c" scripts_dir=$(dirname $0)/.. -timings_file=$output_dir/${input_name}_timings.csv; touch $timings_file +timings_file=$output_dir/${input_name}_timings.csv +touch $timings_file # Adds a value to the timings file, jumps to the next row after a write csv_line=1 -add_csv(){ +add_csv() { while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >> $timings_file + echo '' >>$timings_file done if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then @@ -51,7 +52,7 @@ add_csv(){ fi sed -i "${csv_line}s/$/$1/" "$timings_file" - csv_line=$((csv_line+1)) + csv_line=$((csv_line + 1)) } # Flags for the benchmark @@ -64,9 +65,9 @@ gcc -O$opt_lvl_cc $flags -o $output_dir/${input_name}_gcc.out $input_chrono -lm # Check output clang -O0 $flags -o $output_dir/${input_name}_clang_ref.out $input_chrono -lm -$output_dir/${input_name}_gcc.out &> /dev/null +$output_dir/${input_name}_gcc.out &>/dev/null actual=$? -$output_dir/${input_name}_clang_ref.out &> /dev/null +$output_dir/${input_name}_clang_ref.out &>/dev/null reference=$? if [ "$actual" -ne "$reference" ]; then diff --git a/scripts/snippets/mlir.sh b/scripts/snippets/mlir.sh index 72a2b69..08468c1 100755 --- a/scripts/snippets/mlir.sh +++ b/scripts/snippets/mlir.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Desc: Runs a snippet benchmark using Polygeist + MLIR. The output contains +# Desc: Runs a snippet benchmark using Polygeist + MLIR. The output contains # any intermediate results and the times in the CSV format # Usage: ./mlir.sh @@ -16,10 +16,10 @@ output_dir=$2 repetitions=$3 # Check tools -check_tool(){ - if ! command -v $1 &> /dev/null; then - echo "$1 could not be found" - exit 1 +check_tool() { + if ! command -v $1 &>/dev/null; then + echo "$1 could not be found" + exit 1 fi } @@ -33,7 +33,7 @@ check_tool python3 # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Helpers @@ -41,13 +41,14 @@ input_name=$(basename ${input_file%.*}) input_dir=$(dirname $input_file) input_chrono="$input_dir/$input_name-chrono.c" scripts_dir=$(dirname $0)/.. -timings_file=$output_dir/${input_name}_timings.csv; touch $timings_file +timings_file=$output_dir/${input_name}_timings.csv +touch $timings_file # Adds a value to the timings file, jumps to the next row after a write csv_line=1 -add_csv(){ +add_csv() { while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >> $timings_file + echo '' >>$timings_file done if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then @@ -55,7 +56,7 @@ add_csv(){ fi sed -i "${csv_line}s/$/$1/" "$timings_file" - csv_line=$((csv_line+1)) + csv_line=$((csv_line + 1)) } # Flags for the benchmark @@ -63,29 +64,29 @@ flags="-fPIC -march=native" opt_lvl_cc=3 # Optimization level for the control-centric optimizations # Compiling with MLIR -compile_with_mlir(){ +compile_with_mlir() { additional_flags=$1 output_name=$2 # Generating MLIR from C using Polygeist cgeist -resource-dir=$(clang-13 -print-resource-dir) \ -S --memref-fullrank -O$opt_lvl_cc --raise-scf-to-affine $flags \ - $additional_flags $input_chrono > $output_dir/${output_name}_cgeist.mlir + $additional_flags $input_chrono >$output_dir/${output_name}_cgeist.mlir # Optimizing with MLIR mlir-opt --affine-loop-invariant-code-motion \ - $output_dir/${output_name}_cgeist.mlir | \ - mlir-opt --affine-scalrep | mlir-opt --lower-affine | \ - mlir-opt --cse --inline > $output_dir/${output_name}_opt.mlir + $output_dir/${output_name}_cgeist.mlir | + mlir-opt --affine-scalrep | mlir-opt --lower-affine | + mlir-opt --cse --inline >$output_dir/${output_name}_opt.mlir # Lower to LLVM dialect mlir-opt --convert-scf-to-cf --convert-func-to-llvm --convert-cf-to-llvm \ --convert-math-to-llvm --lower-host-to-llvm --reconcile-unrealized-casts \ - $output_dir/${output_name}_opt.mlir > $output_dir/${output_name}_ll.mlir + $output_dir/${output_name}_opt.mlir >$output_dir/${output_name}_ll.mlir # Translate mlir-translate --mlir-to-llvmir $output_dir/${output_name}_ll.mlir \ - > $output_dir/${output_name}.ll + >$output_dir/${output_name}.ll # Compile llc -O$opt_lvl_cc --relocation-model=pic $output_dir/${output_name}.ll \ @@ -102,9 +103,9 @@ compile_with_mlir "" "${input_name}_mlir" # Check output clang -O0 $flags -o $output_dir/${input_name}_clang_ref.out $input_file -lm -$output_dir/${input_name}_mlir.out &> /dev/null +$output_dir/${input_name}_mlir.out &>/dev/null actual=$? -$output_dir/${input_name}_clang_ref.out &> /dev/null +$output_dir/${input_name}_clang_ref.out &>/dev/null reference=$? if [ "$actual" -ne "$reference" ]; then diff --git a/scripts/snippets/run_all.sh b/scripts/snippets/run_all.sh index 0a4a6ab..6f58a07 100755 --- a/scripts/snippets/run_all.sh +++ b/scripts/snippets/run_all.sh @@ -1,7 +1,7 @@ #!/bin/bash -# Desc: Runs all snippet benchmarks using GCC, Clang, Polygeist + MLIR, DCIR -# and DaCe. The output contains any intermediate results and the times in the +# Desc: Runs all snippet benchmarks using GCC, Clang, Polygeist + MLIR, DCIR +# and DaCe. The output contains any intermediate results and the times in the # CSV format as well as all the plots. # Usage: ./run_all.sh @@ -17,7 +17,7 @@ repetitions=$2 # Create output directory if [ ! -d $output_dir ]; then - mkdir -p $output_dir; + mkdir -p $output_dir fi # Helpers @@ -37,49 +37,49 @@ for runner in $runners; do echo "Running with: $runner" for benchmark in $benchmarks; do - bname="$(basename $benchmark .c)" - count=$((count+1)) - diff=$(($total - $count)) - percent=$(($count * 100 / $total)) - - prog='' - for i in $(seq 1 $count); do - prog="$prog#" - done - - for i in $(seq 1 $diff); do - prog="$prog-" - done - - echo -ne "\033[2K\r" - echo -ne "$prog ($percent%) ($bname) " - - $runner $benchmark $output_dir $repetitions + bname="$(basename $benchmark .c)" + count=$((count + 1)) + diff=$(($total - $count)) + percent=$(($count * 100 / $total)) + + prog='' + for i in $(seq 1 $count); do + prog="$prog#" + done + + for i in $(seq 1 $diff); do + prog="$prog-" + done + + echo -ne "\033[2K\r" + echo -ne "$prog ($percent%) ($bname) " + + $runner $benchmark $output_dir $repetitions done echo "" done for benchmark in $benchmarks; do - bname="$(basename $benchmark .c)" + bname="$(basename $benchmark .c)" - if [[ "$bname" == "demo" ]]; then - fig_num=2 - fi + if [[ "$bname" == "demo" ]]; then + fig_num=2 + fi - if [[ "$bname" == "mem_line" ]]; then - fig_num=8 - fi + if [[ "$bname" == "mem_line" ]]; then + fig_num=8 + fi - if [[ "$bname" == "congrad_multi_field" ]]; then - fig_num=9 - fi + if [[ "$bname" == "congrad_multi_field" ]]; then + fig_num=9 + fi - if [[ "$bname" == "memory" ]]; then - fig_num=10 - fi + if [[ "$bname" == "memory" ]]; then + fig_num=10 + fi - mv "$output_dir/${bname}_timings.csv" "$output_dir/fig${fig_num}.csv" - python3 $scripts_dir/single_plot.py "$output_dir/fig${fig_num}.csv" \ - $output_dir/fig$fig_num.pdf + mv "$output_dir/${bname}_timings.csv" "$output_dir/fig${fig_num}.csv" + python3 $scripts_dir/single_plot.py "$output_dir/fig${fig_num}.csv" \ + $output_dir/fig$fig_num.pdf done From 8db314810d4f2468327d6648c92fa1fe37bd4e09 Mon Sep 17 00:00:00 2001 From: Berke Ates Date: Sat, 10 Dec 2022 13:05:02 +0100 Subject: [PATCH 05/14] silenced python --- scripts/Polybench/dace.sh | 1 + scripts/Polybench/dcir.sh | 1 + scripts/Polybench/run_all.sh | 3 +++ scripts/pytorch/dcir.sh | 1 + scripts/pytorch/pytorch.sh | 3 +++ scripts/pytorch/run_all.sh | 3 +++ scripts/pytorch/torch-mlir.sh | 3 +++ scripts/run_all.sh | 3 +++ scripts/snippets/dace.sh | 1 + scripts/snippets/dcir.sh | 1 + scripts/snippets/run_all.sh | 3 +++ 11 files changed, 23 insertions(+) diff --git a/scripts/Polybench/dace.sh b/scripts/Polybench/dace.sh index 31ffff9..a2460fa 100755 --- a/scripts/Polybench/dace.sh +++ b/scripts/Polybench/dace.sh @@ -92,6 +92,7 @@ export CXX=$(which clang++) export DACE_compiler_cpu_openmp_sections=0 export DACE_instrumentation_report_each_invocation=0 export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" +export PYTHONWARNINGS="ignore" # Optimizing data-centrically with DaCe python3 $scripts_dir/opt_sdfg.py $input_dir/${input_name}_c2dace.sdfg \ diff --git a/scripts/Polybench/dcir.sh b/scripts/Polybench/dcir.sh index 792a4a6..ab66675 100755 --- a/scripts/Polybench/dcir.sh +++ b/scripts/Polybench/dcir.sh @@ -94,6 +94,7 @@ export CXX=$(which clang++) export DACE_compiler_cpu_openmp_sections=0 export DACE_instrumentation_report_each_invocation=0 export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" +export PYTHONWARNINGS="ignore" # Generating MLIR from C using Polygeist cgeist -resource-dir=$(clang-13 -print-resource-dir) -I $utils_dir \ diff --git a/scripts/Polybench/run_all.sh b/scripts/Polybench/run_all.sh index b2347ae..99172eb 100755 --- a/scripts/Polybench/run_all.sh +++ b/scripts/Polybench/run_all.sh @@ -20,6 +20,9 @@ if [ ! -d $output_dir ]; then mkdir -p $output_dir fi +# Silence Python warnings +export PYTHONWARNINGS="ignore" + # Helpers runners_dir=$(dirname $0) scripts_dir=$(dirname $0)/.. diff --git a/scripts/pytorch/dcir.sh b/scripts/pytorch/dcir.sh index da2d9c5..a6aac90 100755 --- a/scripts/pytorch/dcir.sh +++ b/scripts/pytorch/dcir.sh @@ -71,6 +71,7 @@ export CXX=$(which icc) export DACE_compiler_cpu_openmp_sections=0 export DACE_instrumentation_report_each_invocation=0 export DACE_compiler_cpu_args="-fPIC -O3 -march=native" +export PYTHONWARNINGS="ignore" # Generating MLIR using Torch-MLIR python3 $gen_file >$output_dir/${input_name}_mhlo.mlir diff --git a/scripts/pytorch/pytorch.sh b/scripts/pytorch/pytorch.sh index d7d5bef..f577dbc 100755 --- a/scripts/pytorch/pytorch.sh +++ b/scripts/pytorch/pytorch.sh @@ -30,6 +30,9 @@ if [ ! -d $output_dir ]; then mkdir -p $output_dir fi +# Silence Python warnings +export PYTHONWARNINGS="ignore" + # Helpers input_dir=$(dirname $input_file) input_name=$(basename $input_dir) diff --git a/scripts/pytorch/run_all.sh b/scripts/pytorch/run_all.sh index 7bfe7d0..14713ab 100755 --- a/scripts/pytorch/run_all.sh +++ b/scripts/pytorch/run_all.sh @@ -20,6 +20,9 @@ if [ ! -d $output_dir ]; then mkdir -p $output_dir fi +# Silence Python warnings +export PYTHONWARNINGS="ignore" + # Helpers runners_dir=$(dirname $0) scripts_dir=$(dirname $0)/.. diff --git a/scripts/pytorch/torch-mlir.sh b/scripts/pytorch/torch-mlir.sh index 1e313b4..160ee98 100755 --- a/scripts/pytorch/torch-mlir.sh +++ b/scripts/pytorch/torch-mlir.sh @@ -30,6 +30,9 @@ if [ ! -d $output_dir ]; then mkdir -p $output_dir fi +# Silence Python warnings +export PYTHONWARNINGS="ignore" + # Helpers input_dir=$(dirname $input_file) input_name=$(basename $input_dir) diff --git a/scripts/run_all.sh b/scripts/run_all.sh index 5d7b89a..e07c561 100755 --- a/scripts/run_all.sh +++ b/scripts/run_all.sh @@ -19,6 +19,9 @@ if [ ! -d $output_dir ]; then mkdir -p $output_dir fi +# Silence Python warnings +export PYTHONWARNINGS="ignore" + # Helpers scripts_dir=$(dirname $0) diff --git a/scripts/snippets/dace.sh b/scripts/snippets/dace.sh index 485a5a6..0cae15f 100755 --- a/scripts/snippets/dace.sh +++ b/scripts/snippets/dace.sh @@ -80,6 +80,7 @@ export CXX=$(which clang++) export DACE_compiler_cpu_openmp_sections=0 export DACE_instrumentation_report_each_invocation=0 export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" +export PYTHONWARNINGS="ignore" # Optimizing data-centrically with DaCe python3 $scripts_dir/opt_sdfg.py $input_dir/${input_name}_c2dace.sdfg \ diff --git a/scripts/snippets/dcir.sh b/scripts/snippets/dcir.sh index 9253a99..786e017 100755 --- a/scripts/snippets/dcir.sh +++ b/scripts/snippets/dcir.sh @@ -76,6 +76,7 @@ export CXX=$(which clang++) export DACE_compiler_cpu_openmp_sections=0 export DACE_instrumentation_report_each_invocation=0 export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" +export PYTHONWARNINGS="ignore" # Generating MLIR from C using Polygeist cgeist -resource-dir=$(clang-13 -print-resource-dir) -S --memref-fullrank \ diff --git a/scripts/snippets/run_all.sh b/scripts/snippets/run_all.sh index 6f58a07..06e26a2 100755 --- a/scripts/snippets/run_all.sh +++ b/scripts/snippets/run_all.sh @@ -20,6 +20,9 @@ if [ ! -d $output_dir ]; then mkdir -p $output_dir fi +# Silence Python warnings +export PYTHONWARNINGS="ignore" + # Helpers runners_dir=$(dirname $0) scripts_dir=$(dirname $0)/.. From 5f656b024463f49d945ba88d22fa46a9432d3807 Mon Sep 17 00:00:00 2001 From: Berke Ates Date: Sat, 10 Dec 2022 14:07:42 +0100 Subject: [PATCH 06/14] applied shellcheck --- scripts/Polybench/clang.sh | 46 +++++++-------- scripts/Polybench/dace.sh | 49 ++++++++-------- scripts/Polybench/dcir.sh | 105 +++++++++++++++++----------------- scripts/Polybench/gcc.sh | 46 +++++++-------- scripts/Polybench/mlir.sh | 62 ++++++++++---------- scripts/Polybench/run_all.sh | 28 ++++----- scripts/mhlo2std.sh | 9 ++- scripts/pytorch/dcir.sh | 68 +++++++++++----------- scripts/pytorch/pytorch.sh | 26 ++++----- scripts/pytorch/run_all.sh | 32 +++++------ scripts/pytorch/torch-mlir.sh | 26 ++++----- scripts/run_all.sh | 12 ++-- scripts/snippets/clang.sh | 33 ++++++----- scripts/snippets/dace.sh | 51 +++++++++-------- scripts/snippets/dcir.sh | 71 ++++++++++++----------- scripts/snippets/gcc.sh | 33 ++++++----- scripts/snippets/mlir.sh | 53 +++++++++-------- scripts/snippets/run_all.sh | 30 +++++----- 18 files changed, 387 insertions(+), 393 deletions(-) diff --git a/scripts/Polybench/clang.sh b/scripts/Polybench/clang.sh index 1c00bc0..4387db4 100755 --- a/scripts/Polybench/clang.sh +++ b/scripts/Polybench/clang.sh @@ -17,7 +17,7 @@ repetitions=$3 # Check tools check_tool() { - if ! command -v $1 &>/dev/null; then + if ! command -v "$1" &>/dev/null; then echo "$1 could not be found" exit 1 fi @@ -28,29 +28,29 @@ check_tool gcc check_tool python3 # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Helpers -input_name=$(basename ${input_file%.*}) -input_dir=$(dirname $input_file) +input_name=$(basename "${input_file%.*}") +input_dir=$(dirname "$input_file") utils_dir=$input_dir/../utilities -scripts_dir=$(dirname $0)/.. +scripts_dir=$(dirname "$0")/.. timings_file=$output_dir/${input_name}_timings.csv -touch $timings_file +touch "$timings_file" reference=$output_dir/${input_name}_reference.txt actual=$output_dir/${input_name}_actual_clang.txt # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >>$timings_file + while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then - sed -i "${csv_line}s/$/,/" $timings_file + if [ -n "$(sed "${csv_line}q;d" "$timings_file")" ]; then + sed -i "${csv_line}s/$/,/" "$timings_file" fi sed -i "${csv_line}s/$/$1/" "$timings_file" @@ -67,22 +67,20 @@ if [[ "$input_name" == "gramschmidt" ]]; then fi # Compile -clang -I $utils_dir -O$opt_lvl_cc $flags -o $output_dir/${input_name}_clang.out \ - $input_file $utils_dir/polybench.c -lm +clang -I "$utils_dir" -O$opt_lvl_cc $flags -o "$output_dir"/"${input_name}"_clang.out \ + "$input_file" "$utils_dir"/polybench.c -lm # Check output -clang -I $utils_dir -O$opt_lvl_cc $flags -DPOLYBENCH_DUMP_ARRAYS \ - -o $output_dir/${input_name}_clang_dump.out $input_file $utils_dir/polybench.c -lm +clang -I "$utils_dir" -O$opt_lvl_cc $flags -DPOLYBENCH_DUMP_ARRAYS \ + -o "$output_dir"/"${input_name}"_clang_dump.out "$input_file" "$utils_dir"/polybench.c -lm -gcc -I $utils_dir -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ - -o $output_dir/${input_name}_gcc_ref.out $input_file $utils_dir/polybench.c -lm +gcc -I "$utils_dir" -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ + -o "$output_dir"/"${input_name}"_gcc_ref.out "$input_file" "$utils_dir"/polybench.c -lm -$output_dir/${input_name}_clang_dump.out 2>$actual 1>/dev/null -$output_dir/${input_name}_gcc_ref.out 2>$reference 1>/dev/null +"$output_dir"/"${input_name}"_clang_dump.out 2>"$actual" 1>/dev/null +"$output_dir"/"${input_name}"_gcc_ref.out 2>"$reference" 1>/dev/null -python3 $scripts_dir/../polybench-comparator/comparator.py $reference $actual - -if [ $? -ne 0 ]; then +if ! python3 "$scripts_dir"/../polybench-comparator/comparator.py "$reference" "$actual"; then echo "Output incorrect!" exit 1 fi @@ -90,7 +88,7 @@ fi # Running the benchmark add_csv "Clang" -for i in $(seq 1 $repetitions); do - time=$(OMP_NUM_THREADS=1 taskset -c 0 ./$output_dir/${input_name}_clang.out) +for _ in $(seq 1 "$repetitions"); do + time=$(OMP_NUM_THREADS=1 taskset -c 0 ./"$output_dir"/"${input_name}"_clang.out) add_csv "$time" done diff --git a/scripts/Polybench/dace.sh b/scripts/Polybench/dace.sh index a2460fa..58e06ee 100755 --- a/scripts/Polybench/dace.sh +++ b/scripts/Polybench/dace.sh @@ -17,7 +17,7 @@ repetitions=$3 # Check tools check_tool() { - if ! command -v $1 &>/dev/null; then + if ! command -v "$1" &>/dev/null; then echo "$1 could not be found" exit 1 fi @@ -27,31 +27,30 @@ check_tool python3 check_tool icc # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Clear .dacecache rm -rf .dacecache # Helpers -input_name=$(basename ${input_file%.*}) -input_dir=$(dirname $input_file) -utils_dir=$input_dir/../utilities -current_dir=$(dirname $0) -scripts_dir=$(dirname $0)/.. +input_name=$(basename "${input_file%.*}") +input_dir=$(dirname "$input_file") +current_dir=$(dirname "$0") +scripts_dir=$(dirname "$0")/.. timings_file=$output_dir/${input_name}_timings.csv -touch $timings_file +touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >>$timings_file + while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then - sed -i "${csv_line}s/$/,/" $timings_file + if [ -n "$(sed "${csv_line}q;d" "$timings_file")" ]; then + sed -i "${csv_line}s/$/,/" "$timings_file" fi sed -i "${csv_line}s/$/$1/" "$timings_file" @@ -59,7 +58,6 @@ add_csv() { } # Flags for the benchmark -flags="-DLARGE_DATASET -DDATA_TYPE_IS_DOUBLE -DPOLYBENCH_TIME -fPIC -march=native" opt_lvl_cc=3 # Optimization level for the control-centric optimizations opt_lvl_dc=3 # Optimization level for the data-centric optimizations @@ -86,26 +84,29 @@ if [[ "$input_name" == "floyd-warshall" ]] || fi # Dace Settings -export DACE_compiler_cpu_executable="$(which clang++)" -export CC=$(which clang) -export CXX=$(which clang++) +DACE_compiler_cpu_executable="$(which clang++)" +export DACE_compiler_cpu_executable +CC=$(which clang) +export CC +CXX=$(which clang++) +export CXX export DACE_compiler_cpu_openmp_sections=0 export DACE_instrumentation_report_each_invocation=0 export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" export PYTHONWARNINGS="ignore" # Optimizing data-centrically with DaCe -python3 $scripts_dir/opt_sdfg.py $input_dir/${input_name}_c2dace.sdfg \ - $output_dir/${input_name}_c2dace_opt.sdfg $opt_lvl_dc T +python3 "$scripts_dir"/opt_sdfg.py "$input_dir"/"${input_name}"_c2dace.sdfg \ + "$output_dir"/"${input_name}"_c2dace_opt.sdfg $opt_lvl_dc T # Running the benchmark -OMP_NUM_THREADS=1 taskset -c 0 python3 $current_dir/bench_dace.py \ - $output_dir/${input_name}_c2dace_opt.sdfg $repetitions +OMP_NUM_THREADS=1 taskset -c 0 python3 "$current_dir"/bench_dace.py \ + "$output_dir"/"${input_name}"_c2dace_opt.sdfg "$repetitions" add_csv "DaCe" -for i in $(seq 1 $repetitions); do - time=$(python3 $scripts_dir/get_sdfg_times.py \ - $output_dir/${input_name}_c2dace_opt.sdfg $((i - 1)) T) +for i in $(seq 1 "$repetitions"); do + time=$(python3 "$scripts_dir"/get_sdfg_times.py \ + "$output_dir"/"${input_name}"_c2dace_opt.sdfg $((i - 1)) T) add_csv "$time" done diff --git a/scripts/Polybench/dcir.sh b/scripts/Polybench/dcir.sh index ab66675..2cfc2c9 100755 --- a/scripts/Polybench/dcir.sh +++ b/scripts/Polybench/dcir.sh @@ -17,7 +17,7 @@ repetitions=$3 # Check tools check_tool() { - if ! command -v $1 &>/dev/null; then + if ! command -v "$1" &>/dev/null; then echo "$1 could not be found" exit 1 fi @@ -34,33 +34,33 @@ check_tool python3 check_tool icc # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Clear .dacecache rm -rf .dacecache # Helpers -input_name=$(basename ${input_file%.*}) -input_dir=$(dirname $input_file) +input_name=$(basename "${input_file%.*}") +input_dir=$(dirname "$input_file") utils_dir=$input_dir/../utilities -current_dir=$(dirname $0) -scripts_dir=$(dirname $0)/.. +current_dir=$(dirname "$0") +scripts_dir=$(dirname "$0")/.. timings_file=$output_dir/${input_name}_timings.csv -touch $timings_file +touch "$timings_file" reference=$output_dir/${input_name}_reference.txt actual=$output_dir/${input_name}_actual_dcir.txt # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >>$timings_file + while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then - sed -i "${csv_line}s/$/,/" $timings_file + if [ ! -z "$(sed "${csv_line}q;d" "$timings_file")" ]; then + sed -i "${csv_line}s/$/,/" "$timings_file" fi sed -i "${csv_line}s/$/$1/" "$timings_file" @@ -88,85 +88,86 @@ if [[ "$input_name" == "floyd-warshall" ]]; then fi # Dace Settings -export DACE_compiler_cpu_executable="$(which clang++)" -export CC=$(which clang) -export CXX=$(which clang++) +DACE_compiler_cpu_executable="$(which clang++)" +export DACE_compiler_cpu_executable +CC=$(which clang) +export CC +CXX=$(which clang++) +export CXX export DACE_compiler_cpu_openmp_sections=0 export DACE_instrumentation_report_each_invocation=0 export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" export PYTHONWARNINGS="ignore" # Generating MLIR from C using Polygeist -cgeist -resource-dir=$(clang-13 -print-resource-dir) -I $utils_dir \ - -S --memref-fullrank -O$opt_lvl_cc --raise-scf-to-affine $flags $input_file \ - >$output_dir/${input_name}_cgeist.mlir +cgeist -resource-dir="$(clang-13 -print-resource-dir)" -I "$utils_dir" \ + -S --memref-fullrank -O$opt_lvl_cc --raise-scf-to-affine $flags "$input_file" \ + >"$output_dir"/"${input_name}"_cgeist.mlir # Optimizing with MLIR -mlir-opt --affine-loop-invariant-code-motion $output_dir/${input_name}_cgeist.mlir | +mlir-opt --affine-loop-invariant-code-motion "$output_dir"/"${input_name}"_cgeist.mlir | mlir-opt --affine-scalrep | mlir-opt --lower-affine | - mlir-opt --cse --inline >$output_dir/${input_name}_opt.mlir + mlir-opt --cse --inline >"$output_dir"/"${input_name}"_opt.mlir # Converting to DCIR -sdfg-opt --convert-to-sdfg $output_dir/${input_name}_opt.mlir \ - >$output_dir/${input_name}_sdfg.mlir +sdfg-opt --convert-to-sdfg "$output_dir"/"${input_name}"_opt.mlir \ + >"$output_dir"/"${input_name}"_sdfg.mlir # Translating to SDFG -sdfg-translate --mlir-to-sdfg $output_dir/${input_name}_sdfg.mlir \ - >$output_dir/$input_name.sdfg +sdfg-translate --mlir-to-sdfg "$output_dir"/"${input_name}"_sdfg.mlir \ + >"$output_dir"/"$input_name".sdfg # Optimizing data-centrically with DaCe -python3 $scripts_dir/opt_sdfg.py $output_dir/$input_name.sdfg \ - $output_dir/${input_name}_opt.sdfg $opt_lvl_dc T +python3 "$scripts_dir"/opt_sdfg.py "$output_dir"/"$input_name".sdfg \ + "$output_dir"/"${input_name}"_opt.sdfg $opt_lvl_dc T # Check output -gcc -I $utils_dir -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ - -o $output_dir/${input_name}_gcc_ref.out $input_file $utils_dir/polybench.c -lm +gcc -I "$utils_dir" -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ + -o "$output_dir"/"${input_name}"_gcc_ref.out "$input_file" "$utils_dir"/polybench.c -lm -python3 $current_dir/bench_dcir.py $output_dir/${input_name}_opt.sdfg 1 T 2>$actual 1>/dev/null -$output_dir/${input_name}_gcc_ref.out 2>$reference 1>/dev/null +python3 "$current_dir"/bench_dcir.py "$output_dir"/"${input_name}"_opt.sdfg 1 T 2>"$actual" 1>/dev/null +"$output_dir"/"${input_name}"_gcc_ref.out 2>"$reference" 1>/dev/null ## Obtain array names -touch $output_dir/arrNames.txt +touch "$output_dir"/arr_names.txt -grep "begin dump:" $reference | while read -r line; do - arrTmp=($line) - arrName=${arrTmp[2]} - echo -n "$arrName " >>$output_dir/arrNames.txt +grep "begin dump:" "$reference" | while read -r line; do + arr_tmp=($line) + arr_name=${arr_tmp[2]} + echo -n "$arr_name " >>"$output_dir"/arr_names.txt done -arrNames=($(cat $output_dir/arrNames.txt)) -rm $output_dir/arrNames.txt +arr_names=($(cat $output_dir/arr_names.txt)) +rm "$output_dir"/arr_names.txt ## Remove Warnings from output -sed -i '0,/^==BEGIN DUMP_ARRAYS==$/d' $actual -printf '%s\n%s\n' "==BEGIN DUMP_ARRAYS==" "$(cat $actual)" >$actual +sed -i '0,/^==BEGIN DUMP_ARRAYS==$/d' "$actual" +printf '%s\n%s\n' "==BEGIN DUMP_ARRAYS==" "$(cat $actual)" >"$actual" ## Use original array names idx=0 -grep "begin dump:" $actual | while read -r line; do - arrTmp=($line) - arrName=${arrTmp[2]} - repArrName=${arrNames[idx]} - sed -i -e "s/$arrName/$repArrName/g" $actual +grep "begin dump:" "$actual" | while read -r line; do + arr_tmp=($line) + arr_name=${arr_tmp[2]} + rep_arr_name=${arr_names[idx]} + sed -i -e "s/$arr_name/$rep_arr_name/g" "$actual" idx=$((idx + 1)) done ## Compare the outputs -python3 $scripts_dir/../polybench-comparator/comparator.py $reference $actual - -if [ $? -ne 0 ]; then +if ! python3 "$scripts_dir"/../polybench-comparator/comparator.py "$reference" "$actual"; then echo "Output incorrect!" exit 1 fi # Running the benchmark -OMP_NUM_THREADS=1 taskset -c 0 python3 $current_dir/bench_dcir.py \ - $output_dir/${input_name}_opt.sdfg $repetitions F +OMP_NUM_THREADS=1 taskset -c 0 python3 "$current_dir"/bench_dcir.py \ + "$output_dir"/"${input_name}"_opt.sdfg "$repetitions" F add_csv "DCIR" -for i in $(seq 1 $repetitions); do - time=$(python3 $scripts_dir/get_sdfg_times.py \ - $output_dir/${input_name}_opt.sdfg $((i - 1)) T) +for i in $(seq 1 "$repetitions"); do + time=$(python3 "$scripts_dir"/get_sdfg_times.py \ + "$output_dir"/"${input_name}"_opt.sdfg $((i - 1)) T) add_csv "$time" done diff --git a/scripts/Polybench/gcc.sh b/scripts/Polybench/gcc.sh index 994680d..afdef44 100755 --- a/scripts/Polybench/gcc.sh +++ b/scripts/Polybench/gcc.sh @@ -17,7 +17,7 @@ repetitions=$3 # Check tools check_tool() { - if ! command -v $1 &>/dev/null; then + if ! command -v "$1" &>/dev/null; then echo "$1 could not be found" exit 1 fi @@ -28,29 +28,29 @@ check_tool clang check_tool python3 # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Helpers -input_name=$(basename ${input_file%.*}) -input_dir=$(dirname $input_file) +input_name=$(basename "${input_file%.*}") +input_dir=$(dirname "$input_file") utils_dir=$input_dir/../utilities -scripts_dir=$(dirname $0)/.. +scripts_dir=$(dirname "$0")/.. timings_file=$output_dir/${input_name}_timings.csv -touch $timings_file +touch "$timings_file" reference=$output_dir/${input_name}_reference.txt actual=$output_dir/${input_name}_actual_gcc.txt # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >>$timings_file + while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then - sed -i "${csv_line}s/$/,/" $timings_file + if [ ! -z "$(sed "${csv_line}q;d" "$timings_file")" ]; then + sed -i "${csv_line}s/$/,/" "$timings_file" fi sed -i "${csv_line}s/$/$1/" "$timings_file" @@ -67,22 +67,20 @@ if [[ "$input_name" == "gramschmidt" ]]; then fi # Compile -gcc -I $utils_dir -O$opt_lvl_cc $flags -o $output_dir/${input_name}_gcc.out \ - $input_file $utils_dir/polybench.c -lm +gcc -I "$utils_dir" -O$opt_lvl_cc $flags -o "$output_dir"/"${input_name}"_gcc.out \ + "$input_file" "$utils_dir"/polybench.c -lm # Check output -gcc -I $utils_dir -O$opt_lvl_cc $flags -DPOLYBENCH_DUMP_ARRAYS \ - -o $output_dir/${input_name}_gcc_dump.out $input_file $utils_dir/polybench.c -lm +gcc -I "$utils_dir" -O$opt_lvl_cc $flags -DPOLYBENCH_DUMP_ARRAYS \ + -o "$output_dir"/"${input_name}"_gcc_dump.out "$input_file" "$utils_dir"/polybench.c -lm -clang -I $utils_dir -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ - -o $output_dir/${input_name}_clang_ref.out $input_file $utils_dir/polybench.c -lm +clang -I "$utils_dir" -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ + -o "$output_dir"/"${input_name}"_clang_ref.out "$input_file" "$utils_dir"/polybench.c -lm -$output_dir/${input_name}_gcc_dump.out 2>$actual 1>/dev/null -$output_dir/${input_name}_clang_ref.out 2>$reference 1>/dev/null +"$output_dir"/"${input_name}"_gcc_dump.out 2>"$actual" 1>/dev/null +"$output_dir"/"${input_name}"_clang_ref.out 2>"$reference" 1>/dev/null -python3 $scripts_dir/../polybench-comparator/comparator.py $reference $actual - -if [ $? -ne 0 ]; then +if ! python3 "$scripts_dir"/../polybench-comparator/comparator.py "$reference" "$actual"; then echo "Output incorrect!" exit 1 fi @@ -90,7 +88,7 @@ fi # Running the benchmark add_csv "GCC" -for i in $(seq 1 $repetitions); do - time=$(OMP_NUM_THREADS=1 taskset -c 0 ./$output_dir/${input_name}_gcc.out) +for _ in $(seq 1 "$repetitions"); do + time=$(OMP_NUM_THREADS=1 taskset -c 0 ./"$output_dir"/"${input_name}"_gcc.out) add_csv "$time" done diff --git a/scripts/Polybench/mlir.sh b/scripts/Polybench/mlir.sh index f5d2c9a..4f43fc3 100755 --- a/scripts/Polybench/mlir.sh +++ b/scripts/Polybench/mlir.sh @@ -17,7 +17,7 @@ repetitions=$3 # Check tools check_tool() { - if ! command -v $1 &>/dev/null; then + if ! command -v "$1" &>/dev/null; then echo "$1 could not be found" exit 1 fi @@ -32,29 +32,29 @@ check_tool mlir-translate check_tool python3 # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Helpers -input_name=$(basename ${input_file%.*}) -input_dir=$(dirname $input_file) +input_name=$(basename "${input_file%.*}") +input_dir=$(dirname "$input_file") utils_dir=$input_dir/../utilities -scripts_dir=$(dirname $0)/.. +scripts_dir=$(dirname "$0")/.. timings_file=$output_dir/${input_name}_timings.csv -touch $timings_file +touch "$timings_file" reference=$output_dir/${input_name}_reference.txt actual=$output_dir/${input_name}_actual_mlir.txt # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >>$timings_file + while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then - sed -i "${csv_line}s/$/,/" $timings_file + if [ -n "$(sed "${csv_line}q;d" "$timings_file")" ]; then + sed -i "${csv_line}s/$/,/" "$timings_file" fi sed -i "${csv_line}s/$/$1/" "$timings_file" @@ -76,32 +76,32 @@ compile_with_mlir() { output_name=$2 # Generating MLIR from C using Polygeist - cgeist -resource-dir=$(clang-13 -print-resource-dir) -I $utils_dir \ - -S --memref-fullrank -O$opt_lvl_cc --raise-scf-to-affine $flags \ - $additional_flags $input_file >$output_dir/${output_name}_cgeist.mlir + cgeist -resource-dir="$(clang-13 -print-resource-dir)" -I "$utils_dir" \ + -S --memref-fullrank -O$opt_lvl_cc --raise-scf-to-affine "$flags" \ + "$additional_flags" "$input_file" >"$output_dir"/"${output_name}"_cgeist.mlir # Optimizing with MLIR mlir-opt --affine-loop-invariant-code-motion \ - $output_dir/${output_name}_cgeist.mlir | + "$output_dir"/"${output_name}"_cgeist.mlir | mlir-opt --affine-scalrep | mlir-opt --lower-affine | - mlir-opt --cse --inline >$output_dir/${output_name}_opt.mlir + mlir-opt --cse --inline >"$output_dir"/"${output_name}"_opt.mlir # Lower to LLVM dialect mlir-opt --convert-scf-to-cf --convert-func-to-llvm --convert-cf-to-llvm \ --convert-math-to-llvm --lower-host-to-llvm --reconcile-unrealized-casts \ - $output_dir/${output_name}_opt.mlir >$output_dir/${output_name}_ll.mlir + "$output_dir"/"${output_name}"_opt.mlir >"$output_dir"/"${output_name}"_ll.mlir # Translate - mlir-translate --mlir-to-llvmir $output_dir/${output_name}_ll.mlir \ - >$output_dir/${output_name}.ll + mlir-translate --mlir-to-llvmir "$output_dir"/"${output_name}"_ll.mlir \ + >"$output_dir"/"${output_name}".ll # Compile - llc -O$opt_lvl_cc --relocation-model=pic $output_dir/${output_name}.ll \ - -o $output_dir/${output_name}.s + llc -O$opt_lvl_cc --relocation-model=pic "$output_dir"/"${output_name}".ll \ + -o "$output_dir"/"${output_name}".s # Assemble - clang -O$opt_lvl_cc $flags $additional_flags $output_dir/${output_name}.s \ - $utils_dir/polybench.c -o $output_dir/${output_name}.out -lm + clang -O$opt_lvl_cc $flags $additional_flags "$output_dir"/"${output_name}".s \ + "$utils_dir"/polybench.c -o "$output_dir"/"${output_name}".out -lm } # Compile @@ -110,15 +110,13 @@ compile_with_mlir "" "${input_name}_mlir" # Check output compile_with_mlir "-DPOLYBENCH_DUMP_ARRAYS" "${input_name}_mlir_dump" -gcc -I $utils_dir -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ - -o $output_dir/${input_name}_clang_ref.out $input_file $utils_dir/polybench.c -lm +gcc -I "$utils_dir" -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ + -o "$output_dir"/"${input_name}"_clang_ref.out "$input_file" "$utils_dir"/polybench.c -lm -$output_dir/${input_name}_mlir_dump.out 2>$actual 1>/dev/null -$output_dir/${input_name}_clang_ref.out 2>$reference 1>/dev/null +"$output_dir"/"${input_name}"_mlir_dump.out 2>"$actual" 1>/dev/null +"$output_dir"/"${input_name}"_clang_ref.out 2>"$reference" 1>/dev/null -python3 $scripts_dir/../polybench-comparator/comparator.py $reference $actual - -if [ $? -ne 0 ]; then +if ! python3 "$scripts_dir"/../polybench-comparator/comparator.py "$reference" "$actual"; then echo "Output incorrect!" exit 1 fi @@ -126,7 +124,7 @@ fi # Running the benchmark add_csv "Polygeist + MLIR" -for i in $(seq 1 $repetitions); do - time=$(OMP_NUM_THREADS=1 taskset -c 0 ./$output_dir/${input_name}_mlir.out) +for _ in $(seq 1 "$repetitions"); do + time=$(OMP_NUM_THREADS=1 taskset -c 0 ./"$output_dir"/"${input_name}"_mlir.out) add_csv "$time" done diff --git a/scripts/Polybench/run_all.sh b/scripts/Polybench/run_all.sh index 99172eb..09fe107 100755 --- a/scripts/Polybench/run_all.sh +++ b/scripts/Polybench/run_all.sh @@ -16,20 +16,20 @@ output_dir=$1 repetitions=$2 # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Silence Python warnings export PYTHONWARNINGS="ignore" # Helpers -runners_dir=$(dirname $0) -scripts_dir=$(dirname $0)/.. -benchmarks_dir=$(dirname $0)/../../benchmarks/Polybench +runners_dir=$(dirname "$0") +scripts_dir=$(dirname "$0")/.. +benchmarks_dir=$(dirname "$0")/../../benchmarks/Polybench # Run benchmarks -benchmarks=$(find $benchmarks_dir/* -name '*.c' -not -path "$benchmarks_dir/utilities/*") +benchmarks=$(find "$benchmarks_dir"/* -name '*.c' -not -path "$benchmarks_dir/utilities/*") total=$(echo "$benchmarks" | wc -l) runners="$runners_dir/gcc.sh $runners_dir/clang.sh $runners_dir/dace.sh \ @@ -40,24 +40,24 @@ for runner in $runners; do echo "Running with: $runner" for benchmark in $benchmarks; do - bname="$(basename $benchmark .c)" + bname="$(basename "$benchmark" .c)" count=$((count + 1)) - diff=$(($total - $count)) - percent=$(($count * 100 / $total)) + diff=$((total - count)) + percent=$((count * 100 / total)) prog='' - for i in $(seq 1 $count); do + for _ in $(seq 1 $count); do prog="$prog#" done - for i in $(seq 1 $diff); do + for _ in $(seq 1 $diff); do prog="$prog-" done echo -ne "\033[2K\r" echo -ne "$prog ($percent%) ($bname) " - $runner $benchmark $output_dir $repetitions + $runner "$benchmark" "$output_dir" "$repetitions" done echo "" @@ -66,10 +66,10 @@ done csv_files=() for benchmark in $benchmarks; do - bname="$(basename $benchmark .c)" + bname="$(basename "$benchmark" .c)" mv "$output_dir/${bname}_timings.csv" "$output_dir/${bname}.csv" csv_files+=("$output_dir/${bname}.csv") cp "$output_dir/${bname}.csv" "$output_dir/fig6_${bname}.csv" done -python3 $scripts_dir/multi_plot.py ${csv_files[*]} $output_dir/fig6.pdf +python3 "$scripts_dir"/multi_plot.py ${csv_files[*]} "$output_dir"/fig6.pdf diff --git a/scripts/mhlo2std.sh b/scripts/mhlo2std.sh index 0c13b7b..769f75f 100755 --- a/scripts/mhlo2std.sh +++ b/scripts/mhlo2std.sh @@ -13,8 +13,7 @@ fi input_file=$1 # Execute conversion -mlir-hlo-opt --hlo-legalize-to-linalg $input_file `# mhli -> linalg` | \ -mlir-hlo-opt --linalg-bufferize `# bufferize linalg` | \ -mlir-hlo-opt --convert-linalg-to-affine-loops `# linalg -> affine` | \ -mlir-hlo-opt --computeop-and-func-bufferize \ - --final-bufferize=alignment=128 # tensor -> memref +mlir-hlo-opt --hlo-legalize-to-linalg "$input_file" | + mlir-hlo-opt --linalg-bufferize | + mlir-hlo-opt --convert-linalg-to-affine-loops | + mlir-hlo-opt --computeop-and-func-bufferize --final-bufferize=alignment=128 diff --git a/scripts/pytorch/dcir.sh b/scripts/pytorch/dcir.sh index a6aac90..845a24f 100755 --- a/scripts/pytorch/dcir.sh +++ b/scripts/pytorch/dcir.sh @@ -17,7 +17,7 @@ repetitions=$3 # Check tools check_tool() { - if ! command -v $1 &>/dev/null; then + if ! command -v "$1" &>/dev/null; then echo "$1 could not be found" exit 1 fi @@ -32,32 +32,31 @@ check_tool python3 check_tool icc # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Clear .dacecache rm -rf .dacecache # Helpers -input_dir=$(dirname $input_file) -input_name=$(basename $input_dir) +input_dir=$(dirname "$input_file") +input_name=$(basename "$input_dir") gen_file=$input_dir/dcir_gen.py bench_file=$input_dir/dcir_bench.py -current_dir=$(dirname $0) -scripts_dir=$(dirname $0)/.. +scripts_dir=$(dirname "$0")/.. timings_file=$output_dir/${input_name}_timings.csv -touch $timings_file +touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >>$timings_file + while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then - sed -i "${csv_line}s/$/,/" $timings_file + if [ -n "$(sed "${csv_line}q;d" "$timings_file")" ]; then + sed -i "${csv_line}s/$/,/" "$timings_file" fi sed -i "${csv_line}s/$/$1/" "$timings_file" @@ -65,55 +64,58 @@ add_csv() { } # Dace Settings -export DACE_compiler_cpu_executable="$(which icc)" -export CC=$(which icc) -export CXX=$(which icc) +DACE_compiler_cpu_executable="$(which icc)" +export DACE_compiler_cpu_executable +CC=$(which icc) +export CC +CXX=$(which icc) +export CXX export DACE_compiler_cpu_openmp_sections=0 export DACE_instrumentation_report_each_invocation=0 export DACE_compiler_cpu_args="-fPIC -O3 -march=native" export PYTHONWARNINGS="ignore" # Generating MLIR using Torch-MLIR -python3 $gen_file >$output_dir/${input_name}_mhlo.mlir +python3 "$gen_file" >"$output_dir"/"${input_name}"_mhlo.mlir # Renaming `forward` to `main` (required by DCIR) -sed -i -e "s/forward/main/g" $output_dir/${input_name}_mhlo.mlir +sed -i -e "s/forward/main/g" "$output_dir"/"${input_name}"_mhlo.mlir # Converting MHLO to standard dialects -$scripts_dir/mhlo2std.sh $output_dir/${input_name}_mhlo.mlir \ - >$output_dir/${input_name}_std.mlir +"$scripts_dir"/mhlo2std.sh "$output_dir"/"${input_name}"_mhlo.mlir \ + >"$output_dir"/"${input_name}"_std.mlir # Optimizing with MLIR -mlir-opt --affine-loop-invariant-code-motion $output_dir/${input_name}_std.mlir | +mlir-opt --affine-loop-invariant-code-motion "$output_dir"/"${input_name}"_std.mlir | mlir-opt --affine-scalrep | mlir-opt --lower-affine | - mlir-opt --cse --inline >$output_dir/${input_name}_opt.mlir + mlir-opt --cse --inline >"$output_dir"/"${input_name}"_opt.mlir # Converting to DCIR -sdfg-opt --convert-to-sdfg $output_dir/${input_name}_opt.mlir \ - >$output_dir/${input_name}_sdfg.mlir +sdfg-opt --convert-to-sdfg "$output_dir"/"${input_name}"_opt.mlir \ + >"$output_dir"/"${input_name}"_sdfg.mlir # Translating to SDFG -sdfg-translate --mlir-to-sdfg $output_dir/${input_name}_sdfg.mlir \ - >$output_dir/$input_name.sdfg +sdfg-translate --mlir-to-sdfg "$output_dir"/"${input_name}"_sdfg.mlir \ + >"$output_dir"/"$input_name".sdfg # Optimizing data-centrically with DaCe -python3 $scripts_dir/opt_sdfg.py $output_dir/$input_name.sdfg \ - $output_dir/${input_name}_opt.sdfg 3 T +python3 "$scripts_dir"/opt_sdfg.py "$output_dir"/"$input_name".sdfg \ + "$output_dir"/"${input_name}"_opt.sdfg 3 T # Check output -if ! python3 $bench_file $output_dir/${input_name}_opt.sdfg 0 T; then +if ! python3 "$bench_file" "$output_dir"/"${input_name}"_opt.sdfg 0 T; then echo "Output incorrect!" exit 1 fi # Running the benchmark -OMP_NUM_THREADS=1 taskset -c 0 python3 $bench_file \ - $output_dir/${input_name}_opt.sdfg $repetitions F +OMP_NUM_THREADS=1 taskset -c 0 python3 "$bench_file" \ + "$output_dir"/"${input_name}"_opt.sdfg "$repetitions" F add_csv "DCIR" -for i in $(seq 1 $repetitions); do - time=$(python3 $scripts_dir/get_sdfg_times.py \ - $output_dir/${input_name}_opt.sdfg $((i - 1)) F) +for i in $(seq 1 "$repetitions"); do + time=$(python3 "$scripts_dir"/get_sdfg_times.py \ + "$output_dir"/"${input_name}"_opt.sdfg $((i - 1)) F) add_csv "$time" done diff --git a/scripts/pytorch/pytorch.sh b/scripts/pytorch/pytorch.sh index f577dbc..6148c39 100755 --- a/scripts/pytorch/pytorch.sh +++ b/scripts/pytorch/pytorch.sh @@ -17,7 +17,7 @@ repetitions=$3 # Check tools check_tool() { - if ! command -v $1 &>/dev/null; then + if ! command -v "$1" &>/dev/null; then echo "$1 could not be found" exit 1 fi @@ -26,31 +26,29 @@ check_tool() { check_tool python3 # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Silence Python warnings export PYTHONWARNINGS="ignore" # Helpers -input_dir=$(dirname $input_file) -input_name=$(basename $input_dir) +input_dir=$(dirname "$input_file") +input_name=$(basename "$input_dir") input_file=$input_dir/pytorch.py -current_dir=$(dirname $0) -scripts_dir=$(dirname $0)/.. timings_file=$output_dir/${input_name}_timings.csv -touch $timings_file +touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >>$timings_file + while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then - sed -i "${csv_line}s/$/,/" $timings_file + if [ -n "$(sed "${csv_line}q;d" "$timings_file")" ]; then + sed -i "${csv_line}s/$/,/" "$timings_file" fi sed -i "${csv_line}s/$/$1/" "$timings_file" @@ -58,13 +56,13 @@ add_csv() { } # Check output -if ! python3 $input_file 0 T; then +if ! python3 "$input_file" 0 T; then echo "Output incorrect!" exit 1 fi # Running the benchmark -runtimes=$(OMP_NUM_THREADS=1 taskset -c 0 python3 $input_file $repetitions F) +runtimes=$(OMP_NUM_THREADS=1 taskset -c 0 python3 "$input_file" "$repetitions" F) add_csv "PyTorch" diff --git a/scripts/pytorch/run_all.sh b/scripts/pytorch/run_all.sh index 14713ab..3df68cf 100755 --- a/scripts/pytorch/run_all.sh +++ b/scripts/pytorch/run_all.sh @@ -16,20 +16,20 @@ output_dir=$1 repetitions=$2 # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Silence Python warnings export PYTHONWARNINGS="ignore" # Helpers -runners_dir=$(dirname $0) -scripts_dir=$(dirname $0)/.. -benchmarks_dir=$(dirname $0)/../../benchmarks/pytorch +runners_dir=$(dirname "$0") +scripts_dir=$(dirname "$0")/.. +benchmarks_dir=$(dirname "$0")/../../benchmarks/pytorch # Run benchmarks -benchmarks=$(find $benchmarks_dir/* -name 'pytorch.py') +benchmarks=$(find "$benchmarks_dir"/* -name 'pytorch.py') total=$(echo "$benchmarks" | wc -l) runners="$runners_dir/pytorch.sh $runners_dir/torch-mlir.sh $runners_dir/dcir.sh" @@ -39,33 +39,33 @@ for runner in $runners; do echo "Running with: $runner" for benchmark in $benchmarks; do - bname="$(basename $benchmark .c)" + bname="$(basename "$benchmark" .c)" count=$((count + 1)) - diff=$(($total - $count)) - percent=$(($count * 100 / $total)) + diff=$((total - count)) + percent=$((count * 100 / total)) prog='' - for i in $(seq 1 $count); do + for _ in $(seq 1 $count); do prog="$prog#" done - for i in $(seq 1 $diff); do + for _ in $(seq 1 $diff); do prog="$prog-" done echo -ne "\033[2K\r" echo -ne "$prog ($percent%) ($bname) " - $runner $benchmark $output_dir $repetitions + $runner "$benchmark" "$output_dir" "$repetitions" done echo "" done for benchmark in $benchmarks; do - bench_dir=$(dirname $benchmark) - bench_name=$(basename $bench_dir) + bench_dir=$(dirname "$benchmark") + bench_name=$(basename "$bench_dir") mv "$output_dir/${bench_name}_timings.csv" "$output_dir/${bench_name}.csv" - python3 $scripts_dir/single_plot.py "$output_dir/${bench_name}.csv" \ - $output_dir/$bench_name.pdf + python3 "$scripts_dir"/single_plot.py "$output_dir/${bench_name}.csv" \ + "$output_dir"/"$bench_name".pdf done diff --git a/scripts/pytorch/torch-mlir.sh b/scripts/pytorch/torch-mlir.sh index 160ee98..8c0d101 100755 --- a/scripts/pytorch/torch-mlir.sh +++ b/scripts/pytorch/torch-mlir.sh @@ -17,7 +17,7 @@ repetitions=$3 # Check tools check_tool() { - if ! command -v $1 &>/dev/null; then + if ! command -v "$1" &>/dev/null; then echo "$1 could not be found" exit 1 fi @@ -26,31 +26,29 @@ check_tool() { check_tool python3 # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Silence Python warnings export PYTHONWARNINGS="ignore" # Helpers -input_dir=$(dirname $input_file) -input_name=$(basename $input_dir) +input_dir=$(dirname "$input_file") +input_name=$(basename "$input_dir") input_file=$input_dir/torch-mlir.py -current_dir=$(dirname $0) -scripts_dir=$(dirname $0)/.. timings_file=$output_dir/${input_name}_timings.csv -touch $timings_file +touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >>$timings_file + while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then - sed -i "${csv_line}s/$/,/" $timings_file + if [ -n "$(sed "${csv_line}q;d" "$timings_file")" ]; then + sed -i "${csv_line}s/$/,/" "$timings_file" fi sed -i "${csv_line}s/$/$1/" "$timings_file" @@ -58,13 +56,13 @@ add_csv() { } # Check output -if ! python3 $input_file 0 T; then +if ! python3 "$input_file" 0 T; then echo "Output incorrect!" exit 1 fi # Running the benchmark -runtimes=$(OMP_NUM_THREADS=1 taskset -c 0 python3 $input_file $repetitions F) +runtimes=$(OMP_NUM_THREADS=1 taskset -c 0 python3 "$input_file" "$repetitions" F) add_csv "Torch-MLIR" diff --git a/scripts/run_all.sh b/scripts/run_all.sh index e07c561..56dff88 100755 --- a/scripts/run_all.sh +++ b/scripts/run_all.sh @@ -15,17 +15,17 @@ output_dir=$1 repetitions=$2 # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Silence Python warnings export PYTHONWARNINGS="ignore" # Helpers -scripts_dir=$(dirname $0) +scripts_dir=$(dirname "$0") # Run benchmarks -./$scripts_dir/Polybench/run_all.sh "$output_dir" "$repetitions" -./$scripts_dir/pytorch/run_all.sh "$output_dir" "$repetitions" -./$scripts_dir/snippets/run_all.sh "$output_dir" "$repetitions" +./"$scripts_dir"/Polybench/run_all.sh "$output_dir" "$repetitions" +./"$scripts_dir"/pytorch/run_all.sh "$output_dir" "$repetitions" +./"$scripts_dir"/snippets/run_all.sh "$output_dir" "$repetitions" diff --git a/scripts/snippets/clang.sh b/scripts/snippets/clang.sh index 70a16a5..b3b8131 100755 --- a/scripts/snippets/clang.sh +++ b/scripts/snippets/clang.sh @@ -17,7 +17,7 @@ repetitions=$3 # Check tools check_tool() { - if ! command -v $1 &>/dev/null; then + if ! command -v "$1" &>/dev/null; then echo "$1 could not be found" exit 1 fi @@ -28,27 +28,26 @@ check_tool gcc check_tool python3 # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Helpers -input_name=$(basename ${input_file%.*}) -input_dir=$(dirname $input_file) +input_name=$(basename "${input_file%.*}") +input_dir=$(dirname "$input_file") input_chrono="$input_dir/$input_name-chrono.c" -scripts_dir=$(dirname $0)/.. timings_file=$output_dir/${input_name}_timings.csv -touch $timings_file +touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >>$timings_file + while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then - sed -i "${csv_line}s/$/,/" $timings_file + if [ -n "$(sed "${csv_line}q;d" "$timings_file")" ]; then + sed -i "${csv_line}s/$/,/" "$timings_file" fi sed -i "${csv_line}s/$/$1/" "$timings_file" @@ -60,14 +59,14 @@ flags="-fPIC -march=native" opt_lvl_cc=3 # Optimization level for the control-centric optimizations # Compile -clang -O$opt_lvl_cc $flags -o $output_dir/${input_name}_clang.out $input_chrono -lm +clang -O$opt_lvl_cc $flags -o "$output_dir"/"${input_name}"_clang.out "$input_chrono" -lm # Check output -gcc -O0 $flags -o $output_dir/${input_name}_gcc_ref.out $input_chrono -lm +gcc -O0 $flags -o "$output_dir"/"${input_name}"_gcc_ref.out "$input_chrono" -lm -$output_dir/${input_name}_clang.out &>/dev/null +"$output_dir"/"${input_name}"_clang.out &>/dev/null actual=$? -$output_dir/${input_name}_gcc_ref.out &>/dev/null +"$output_dir"/"${input_name}"_gcc_ref.out &>/dev/null reference=$? if [ "$actual" -ne "$reference" ]; then @@ -78,7 +77,7 @@ fi # Running the benchmark add_csv "Clang" -for i in $(seq 1 $repetitions); do - time=$(OMP_NUM_THREADS=1 taskset -c 0 ./$output_dir/${input_name}_clang.out) +for _ in $(seq 1 "$repetitions"); do + time=$(OMP_NUM_THREADS=1 taskset -c 0 ./"$output_dir"/"${input_name}"_clang.out) add_csv "$time" done diff --git a/scripts/snippets/dace.sh b/scripts/snippets/dace.sh index 0cae15f..723413d 100755 --- a/scripts/snippets/dace.sh +++ b/scripts/snippets/dace.sh @@ -17,7 +17,7 @@ repetitions=$3 # Check tools check_tool() { - if ! command -v $1 &>/dev/null; then + if ! command -v "$1" &>/dev/null; then echo "$1 could not be found" exit 1 fi @@ -28,32 +28,30 @@ check_tool python3 check_tool icc # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Clear .dacecache rm -rf .dacecache # Helpers -input_name=$(basename ${input_file%.*}) -input_dir=$(dirname $input_file) -input_chrono="$input_dir/$input_name-chrono.c" -input_dace="$input_dir/$input_name.sdfg" -current_dir=$(dirname $0) -scripts_dir=$(dirname $0)/.. +input_name=$(basename "${input_file%.*}") +input_dir=$(dirname "$input_file") +current_dir=$(dirname "$0") +scripts_dir=$(dirname "$0")/.. timings_file=$output_dir/${input_name}_timings.csv -touch $timings_file +touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >>$timings_file + while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then - sed -i "${csv_line}s/$/,/" $timings_file + if [ -n "$(sed "${csv_line}q;d" "$timings_file")" ]; then + sed -i "${csv_line}s/$/,/" "$timings_file" fi sed -i "${csv_line}s/$/$1/" "$timings_file" @@ -61,7 +59,7 @@ add_csv() { } # Flags for the benchmark -flags="-fPIC -march=native" +opt_lvl_cc=3 # Optimization level for the control-centric optimizations opt_lvl_dc=3 # Optimization level for the data-centric optimizations # Lower optimization level for specific benchmarks @@ -74,26 +72,29 @@ if [[ "$input_name" == "demo" ]]; then fi # Dace Settings -export DACE_compiler_cpu_executable="$(which clang++)" -export CC=$(which clang) -export CXX=$(which clang++) +DACE_compiler_cpu_executable="$(which clang++)" +export DACE_compiler_cpu_executable +CC=$(which clang) +export CC +CXX=$(which clang++) +export CXX export DACE_compiler_cpu_openmp_sections=0 export DACE_instrumentation_report_each_invocation=0 export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" export PYTHONWARNINGS="ignore" # Optimizing data-centrically with DaCe -python3 $scripts_dir/opt_sdfg.py $input_dir/${input_name}_c2dace.sdfg \ - $output_dir/${input_name}_c2dace_opt.sdfg $opt_lvl_dc T +python3 "$scripts_dir"/opt_sdfg.py "$input_dir"/"${input_name}"_c2dace.sdfg \ + "$output_dir"/"${input_name}"_c2dace_opt.sdfg $opt_lvl_dc T # Running the benchmark -OMP_NUM_THREADS=1 taskset -c 0 python3 $current_dir/bench_dace.py \ - $output_dir/${input_name}_c2dace_opt.sdfg $repetitions +OMP_NUM_THREADS=1 taskset -c 0 python3 "$current_dir"/bench_dace.py \ + "$output_dir"/"${input_name}"_c2dace_opt.sdfg "$repetitions" add_csv "DaCe" -for i in $(seq 1 $repetitions); do - time=$(python3 $scripts_dir/get_sdfg_times.py \ - $output_dir/${input_name}_c2dace_opt.sdfg $((i - 1)) F) +for i in $(seq 1 "$repetitions"); do + time=$(python3 "$scripts_dir"/get_sdfg_times.py \ + "$output_dir"/"${input_name}"_c2dace_opt.sdfg $((i - 1)) F) add_csv "$time" done diff --git a/scripts/snippets/dcir.sh b/scripts/snippets/dcir.sh index 786e017..2d6710a 100755 --- a/scripts/snippets/dcir.sh +++ b/scripts/snippets/dcir.sh @@ -17,7 +17,7 @@ repetitions=$3 # Check tools check_tool() { - if ! command -v $1 &>/dev/null; then + if ! command -v "$1" &>/dev/null; then echo "$1 could not be found" exit 1 fi @@ -33,31 +33,31 @@ check_tool python3 check_tool icc # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Clear .dacecache rm -rf .dacecache # Helpers -input_name=$(basename ${input_file%.*}) -input_dir=$(dirname $input_file) +input_name=$(basename "${input_file%.*}") +input_dir=$(dirname "$input_file") input_chrono="$input_dir/$input_name-chrono.c" -current_dir=$(dirname $0) -scripts_dir=$(dirname $0)/.. +current_dir=$(dirname "$0") +scripts_dir=$(dirname "$0")/.. timings_file=$output_dir/${input_name}_timings.csv -touch $timings_file +touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >>$timings_file + while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then - sed -i "${csv_line}s/$/,/" $timings_file + if [ -n "$(sed "${csv_line}q;d" "$timings_file")" ]; then + sed -i "${csv_line}s/$/,/" "$timings_file" fi sed -i "${csv_line}s/$/$1/" "$timings_file" @@ -70,41 +70,44 @@ opt_lvl_cc=3 # Optimization level for the control-centric optimizations opt_lvl_dc=3 # Optimization level for the data-centric optimizations # Dace Settings -export DACE_compiler_cpu_executable="$(which clang++)" -export CC=$(which clang) -export CXX=$(which clang++) +DACE_compiler_cpu_executable="$(which clang++)" +export DACE_compiler_cpu_executable +CC=$(which clang) +export CC +CXX=$(which clang++) +export CXX export DACE_compiler_cpu_openmp_sections=0 export DACE_instrumentation_report_each_invocation=0 export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" export PYTHONWARNINGS="ignore" # Generating MLIR from C using Polygeist -cgeist -resource-dir=$(clang-13 -print-resource-dir) -S --memref-fullrank \ - -O$opt_lvl_cc --raise-scf-to-affine $flags $input_file \ - >$output_dir/${input_name}_cgeist.mlir +cgeist -resource-dir="$(clang-13 -print-resource-dir)" -S --memref-fullrank \ + -O$opt_lvl_cc --raise-scf-to-affine $flags "$input_file" \ + >"$output_dir"/"${input_name}"_cgeist.mlir # Optimizing with MLIR -mlir-opt --affine-loop-invariant-code-motion $output_dir/${input_name}_cgeist.mlir | +mlir-opt --affine-loop-invariant-code-motion "$output_dir"/"${input_name}"_cgeist.mlir | mlir-opt --affine-scalrep | mlir-opt --lower-affine | - mlir-opt --cse --inline >$output_dir/${input_name}_opt.mlir + mlir-opt --cse --inline >"$output_dir"/"${input_name}"_opt.mlir # Converting to DCIR -sdfg-opt --convert-to-sdfg $output_dir/${input_name}_opt.mlir \ - >$output_dir/${input_name}_sdfg.mlir +sdfg-opt --convert-to-sdfg "$output_dir"/"${input_name}"_opt.mlir \ + >"$output_dir"/"${input_name}"_sdfg.mlir # Translating to SDFG -sdfg-translate --mlir-to-sdfg $output_dir/${input_name}_sdfg.mlir \ - >$output_dir/$input_name.sdfg +sdfg-translate --mlir-to-sdfg "$output_dir"/"${input_name}"_sdfg.mlir \ + >"$output_dir"/"$input_name".sdfg # Optimizing data-centrically with DaCe -python3 $scripts_dir/opt_sdfg.py $output_dir/$input_name.sdfg \ - $output_dir/${input_name}_opt.sdfg $opt_lvl_dc T +python3 "$scripts_dir"/opt_sdfg.py "$output_dir"/"$input_name".sdfg \ + "$output_dir"/"${input_name}"_opt.sdfg $opt_lvl_dc T # Check output -actual=$(python3 $current_dir/bench_dcir.py $output_dir/${input_name}_opt.sdfg 1 T) +actual=$(python3 "$current_dir"/bench_dcir.py "$output_dir"/"${input_name}"_opt.sdfg 1 T) -clang -O0 $flags -o $output_dir/${input_name}_clang_ref.out $input_chrono -lm -$output_dir/${input_name}_clang_ref.out &>/dev/null +clang -O0 $flags -o "$output_dir"/"${input_name}"_clang_ref.out "$input_chrono" -lm +"$output_dir"/"${input_name}"_clang_ref.out &>/dev/null reference=$? if [ "$actual" -ne "$reference" ]; then @@ -113,13 +116,13 @@ if [ "$actual" -ne "$reference" ]; then fi # Running the benchmark -OMP_NUM_THREADS=1 taskset -c 0 python3 $current_dir/bench_dcir.py \ - $output_dir/${input_name}_opt.sdfg $repetitions F +OMP_NUM_THREADS=1 taskset -c 0 python3 "$current_dir"/bench_dcir.py \ + "$output_dir"/"${input_name}"_opt.sdfg "$repetitions" F add_csv "DCIR" -for i in $(seq 1 $repetitions); do - time=$(python3 $scripts_dir/get_sdfg_times.py \ - $output_dir/${input_name}_opt.sdfg $((i - 1)) F) +for i in $(seq 1 "$repetitions"); do + time=$(python3 "$scripts_dir"/get_sdfg_times.py \ + "$output_dir"/"${input_name}"_opt.sdfg $((i - 1)) F) add_csv "$time" done diff --git a/scripts/snippets/gcc.sh b/scripts/snippets/gcc.sh index aec7e72..c1fd655 100755 --- a/scripts/snippets/gcc.sh +++ b/scripts/snippets/gcc.sh @@ -17,7 +17,7 @@ repetitions=$3 # Check tools check_tool() { - if ! command -v $1 &>/dev/null; then + if ! command -v "$1" &>/dev/null; then echo "$1 could not be found" exit 1 fi @@ -28,27 +28,26 @@ check_tool clang check_tool python3 # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Helpers -input_name=$(basename ${input_file%.*}) -input_dir=$(dirname $input_file) +input_name=$(basename "${input_file%.*}") +input_dir=$(dirname "$input_file") input_chrono="$input_dir/$input_name-chrono.c" -scripts_dir=$(dirname $0)/.. timings_file=$output_dir/${input_name}_timings.csv -touch $timings_file +touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >>$timings_file + while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then - sed -i "${csv_line}s/$/,/" $timings_file + if [ -n "$(sed "${csv_line}q;d" "$timings_file")" ]; then + sed -i "${csv_line}s/$/,/" "$timings_file" fi sed -i "${csv_line}s/$/$1/" "$timings_file" @@ -60,14 +59,14 @@ flags="-fPIC -march=native" opt_lvl_cc=3 # Optimization level for the control-centric optimizations # Compile -gcc -O$opt_lvl_cc $flags -o $output_dir/${input_name}_gcc.out $input_chrono -lm +gcc -O$opt_lvl_cc $flags -o "$output_dir"/"${input_name}"_gcc.out "$input_chrono" -lm # Check output -clang -O0 $flags -o $output_dir/${input_name}_clang_ref.out $input_chrono -lm +clang -O0 $flags -o "$output_dir"/"${input_name}"_clang_ref.out "$input_chrono" -lm -$output_dir/${input_name}_gcc.out &>/dev/null +"$output_dir"/"${input_name}"_gcc.out &>/dev/null actual=$? -$output_dir/${input_name}_clang_ref.out &>/dev/null +"$output_dir"/"${input_name}"_clang_ref.out &>/dev/null reference=$? if [ "$actual" -ne "$reference" ]; then @@ -78,7 +77,7 @@ fi # Running the benchmark add_csv "GCC" -for i in $(seq 1 $repetitions); do - time=$(OMP_NUM_THREADS=1 taskset -c 0 ./$output_dir/${input_name}_gcc.out) +for _ in $(seq 1 "$repetitions"); do + time=$(OMP_NUM_THREADS=1 taskset -c 0 ./"$output_dir"/"${input_name}"_gcc.out) add_csv "$time" done diff --git a/scripts/snippets/mlir.sh b/scripts/snippets/mlir.sh index 08468c1..bd3ec2a 100755 --- a/scripts/snippets/mlir.sh +++ b/scripts/snippets/mlir.sh @@ -17,7 +17,7 @@ repetitions=$3 # Check tools check_tool() { - if ! command -v $1 &>/dev/null; then + if ! command -v "$1" &>/dev/null; then echo "$1 could not be found" exit 1 fi @@ -32,27 +32,26 @@ check_tool mlir-translate check_tool python3 # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Helpers -input_name=$(basename ${input_file%.*}) -input_dir=$(dirname $input_file) +input_name=$(basename "${input_file%.*}") +input_dir=$(dirname "$input_file") input_chrono="$input_dir/$input_name-chrono.c" -scripts_dir=$(dirname $0)/.. timings_file=$output_dir/${input_name}_timings.csv -touch $timings_file +touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ $timings_file) < $csv_line ]]; do - echo '' >>$timings_file + while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" $timings_file)" ]; then - sed -i "${csv_line}s/$/,/" $timings_file + if [ ! -z "$(sed "${csv_line}q;d" "$timings_file")" ]; then + sed -i "${csv_line}s/$/,/" "$timings_file" fi sed -i "${csv_line}s/$/$1/" "$timings_file" @@ -69,43 +68,43 @@ compile_with_mlir() { output_name=$2 # Generating MLIR from C using Polygeist - cgeist -resource-dir=$(clang-13 -print-resource-dir) \ + cgeist -resource-dir="$(clang-13 -print-resource-dir)" \ -S --memref-fullrank -O$opt_lvl_cc --raise-scf-to-affine $flags \ - $additional_flags $input_chrono >$output_dir/${output_name}_cgeist.mlir + "$additional_flags" "$input_chrono" >"$output_dir"/"${output_name}"_cgeist.mlir # Optimizing with MLIR mlir-opt --affine-loop-invariant-code-motion \ - $output_dir/${output_name}_cgeist.mlir | + "$output_dir"/"${output_name}"_cgeist.mlir | mlir-opt --affine-scalrep | mlir-opt --lower-affine | - mlir-opt --cse --inline >$output_dir/${output_name}_opt.mlir + mlir-opt --cse --inline >"$output_dir"/"${output_name}"_opt.mlir # Lower to LLVM dialect mlir-opt --convert-scf-to-cf --convert-func-to-llvm --convert-cf-to-llvm \ --convert-math-to-llvm --lower-host-to-llvm --reconcile-unrealized-casts \ - $output_dir/${output_name}_opt.mlir >$output_dir/${output_name}_ll.mlir + "$output_dir"/"${output_name}"_opt.mlir >"$output_dir"/"${output_name}"_ll.mlir # Translate - mlir-translate --mlir-to-llvmir $output_dir/${output_name}_ll.mlir \ - >$output_dir/${output_name}.ll + mlir-translate --mlir-to-llvmir "$output_dir"/"${output_name}"_ll.mlir \ + >"$output_dir"/"${output_name}".ll # Compile - llc -O$opt_lvl_cc --relocation-model=pic $output_dir/${output_name}.ll \ - -o $output_dir/${output_name}.s + llc -O$opt_lvl_cc --relocation-model=pic "$output_dir"/"${output_name}".ll \ + -o "$output_dir"/"${output_name}".s # Assemble - clang -O$opt_lvl_cc $flags $additional_flags $output_dir/${output_name}.s \ - -o $output_dir/${output_name}.out -lm + clang -O$opt_lvl_cc $flags $additional_flags "$output_dir"/"${output_name}".s \ + -o "$output_dir"/"${output_name}".out -lm } # Compile compile_with_mlir "" "${input_name}_mlir" # Check output -clang -O0 $flags -o $output_dir/${input_name}_clang_ref.out $input_file -lm +clang -O0 $flags -o "$output_dir"/"${input_name}"_clang_ref.out "$input_file" -lm -$output_dir/${input_name}_mlir.out &>/dev/null +"$output_dir"/"${input_name}"_mlir.out &>/dev/null actual=$? -$output_dir/${input_name}_clang_ref.out &>/dev/null +"$output_dir"/"${input_name}"_clang_ref.out &>/dev/null reference=$? if [ "$actual" -ne "$reference" ]; then @@ -116,7 +115,7 @@ fi # Running the benchmark add_csv "Polygeist + MLIR" -for i in $(seq 1 $repetitions); do - time=$(OMP_NUM_THREADS=1 taskset -c 0 ./$output_dir/${input_name}_mlir.out) +for _ in $(seq 1 "$repetitions"); do + time=$(OMP_NUM_THREADS=1 taskset -c 0 ./"$output_dir"/"${input_name}"_mlir.out) add_csv "$time" done diff --git a/scripts/snippets/run_all.sh b/scripts/snippets/run_all.sh index 06e26a2..eb33284 100755 --- a/scripts/snippets/run_all.sh +++ b/scripts/snippets/run_all.sh @@ -16,20 +16,20 @@ output_dir=$1 repetitions=$2 # Create output directory -if [ ! -d $output_dir ]; then - mkdir -p $output_dir +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" fi # Silence Python warnings export PYTHONWARNINGS="ignore" # Helpers -runners_dir=$(dirname $0) -scripts_dir=$(dirname $0)/.. -benchmarks_dir=$(dirname $0)/../../benchmarks/snippets +runners_dir=$(dirname "$0") +scripts_dir=$(dirname "$0")/.. +benchmarks_dir=$(dirname "$0")/../../benchmarks/snippets # Run benchmarks -benchmarks=$(find $benchmarks_dir/* -name '*.c' -not -name '*-chrono.c') +benchmarks=$(find "$benchmarks_dir"/* -name '*.c' -not -name '*-chrono.c') total=$(echo "$benchmarks" | wc -l) runners="$runners_dir/gcc.sh $runners_dir/clang.sh $runners_dir/dace.sh \ @@ -40,31 +40,31 @@ for runner in $runners; do echo "Running with: $runner" for benchmark in $benchmarks; do - bname="$(basename $benchmark .c)" + bname="$(basename "$benchmark" .c)" count=$((count + 1)) - diff=$(($total - $count)) - percent=$(($count * 100 / $total)) + diff=$((total - count)) + percent=$((count * 100 / total)) prog='' - for i in $(seq 1 $count); do + for _ in $(seq 1 $count); do prog="$prog#" done - for i in $(seq 1 $diff); do + for _ in $(seq 1 $diff); do prog="$prog-" done echo -ne "\033[2K\r" echo -ne "$prog ($percent%) ($bname) " - $runner $benchmark $output_dir $repetitions + $runner "$benchmark" "$output_dir" "$repetitions" done echo "" done for benchmark in $benchmarks; do - bname="$(basename $benchmark .c)" + bname="$(basename "$benchmark" .c)" if [[ "$bname" == "demo" ]]; then fig_num=2 @@ -83,6 +83,6 @@ for benchmark in $benchmarks; do fi mv "$output_dir/${bname}_timings.csv" "$output_dir/fig${fig_num}.csv" - python3 $scripts_dir/single_plot.py "$output_dir/fig${fig_num}.csv" \ - $output_dir/fig$fig_num.pdf + python3 "$scripts_dir"/single_plot.py "$output_dir/fig${fig_num}.csv" \ + "$output_dir"/fig$fig_num.pdf done From cb212b0f1e17107d1ac4aa1c4f505891bb265dc2 Mon Sep 17 00:00:00 2001 From: Berke Ates Date: Sat, 10 Dec 2022 14:32:27 +0100 Subject: [PATCH 07/14] fixed version --- Dockerfile | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 84b7175..2b6a708 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ ### GENERAL SETUP ################################################################################ -FROM ubuntu:latest as llvm +FROM ubuntu:22.04 as llvm # User directory ENV USER=user @@ -10,8 +10,8 @@ ENV HOME=/home/user WORKDIR $HOME # Install dependencies -RUN apt update -y && \ - apt install -y \ +RUN apt-get update -y && \ + apt-get install -y --no-install-recommends \ wget \ git \ cmake \ @@ -79,8 +79,7 @@ WORKDIR $HOME ################################################################################ # Install python dependencies -RUN pip install --upgrade pip -RUN pip install --upgrade "jax[cpu]" +RUN pip install --upgrade pip; pip install --upgrade "jax[cpu]" # Get MLIR-HLO RUN git clone --depth 1 --branch cgo23 https://github.com/Berke-Ates/mlir-hlo.git @@ -140,9 +139,9 @@ RUN DESTDIR=$HOME/llvm-polygeist ninja install # Copy binaries WORKDIR $HOME/bin -RUN cp $HOME/llvm-polygeist/usr/local/bin/cgeist . -RUN cp $HOME/llvm-polygeist/usr/local/bin/mlir-opt . -RUN cp $HOME/llvm-polygeist/usr/local/bin/mlir-translate . +RUN cp $HOME/llvm-polygeist/usr/local/bin/cgeist .; \ + cp $HOME/llvm-polygeist/usr/local/bin/mlir-opt .; \ + cp $HOME/llvm-polygeist/usr/local/bin/mlir-translate . # Clean up build folders for space RUN rm -rf $HOME/Polygeist $HOME/llvm-polygeist @@ -155,7 +154,7 @@ WORKDIR $HOME ################################################################################ # Copy binaries -FROM ubuntu:latest +FROM ubuntu:22.04 # User directory ENV USER=user @@ -163,15 +162,14 @@ ENV HOME=/home/user WORKDIR $HOME # Move dotfiles -RUN mv /root/.bashrc . -RUN mv /root/.profile . +RUN mv /root/.bashrc .; mv /root/.profile . # Make terminal colorful ENV TERM=xterm-color # Install dependencies -RUN apt update -y && \ - apt install -y \ +RUN apt-get update -y && \ + apt-get install -y \ wget \ git \ clang-13 \ @@ -182,15 +180,13 @@ RUN apt update -y && \ ENTRYPOINT cd $HOME && bash # Dependencies for plotting -RUN pip install --upgrade pip -RUN pip install --upgrade seaborn +RUN pip install --upgrade pip; pip install --upgrade seaborn # Copy Binaries COPY --from=llvm $HOME/bin $HOME/bin # Add clang copy -RUN cp `which clang-13` $HOME/bin/clang -RUN cp `which clang-13` $HOME/bin/clang++ +RUN cp $(which clang-13) $HOME/bin/clang; cp $(which clang-13) $HOME/bin/clang++ # Add binaries to PATH ENV PATH=$HOME/bin:$PATH @@ -208,8 +204,7 @@ WORKDIR $HOME/torch-mlir RUN git submodule update --init --recursive --depth 1 # Install python dependencies -RUN pip install --upgrade pip -RUN pip install -r requirements.txt +RUN pip install --upgrade pip; pip install -r requirements.txt # Build torch-mlir in-tree WORKDIR $HOME/torch-mlir/build @@ -253,7 +248,7 @@ RUN wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRO RUN echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" \ | tee /etc/apt/sources.list.d/oneAPI.list -RUN apt update -y && apt install -y intel-hpckit +RUN apt-get update -y && apt-get install -y intel-hpckit RUN echo "source /opt/intel/oneapi/compiler/2022.2.1/env/vars.sh" >> $HOME/.bashrc From ad2017389850b8928e7d16c9101da07319ce7b26 Mon Sep 17 00:00:00 2001 From: Berke Ates Date: Sat, 10 Dec 2022 14:42:22 +0100 Subject: [PATCH 08/14] replaced ; with && --- Dockerfile | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2b6a708..b166175 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ ENV HOME=/home/user WORKDIR $HOME # Install dependencies -RUN apt-get update -y && \ +RUN apt-get update -y && \ apt-get install -y --no-install-recommends \ wget \ git \ @@ -79,7 +79,7 @@ WORKDIR $HOME ################################################################################ # Install python dependencies -RUN pip install --upgrade pip; pip install --upgrade "jax[cpu]" +RUN pip install --upgrade pip && pip install --upgrade "jax[cpu]" # Get MLIR-HLO RUN git clone --depth 1 --branch cgo23 https://github.com/Berke-Ates/mlir-hlo.git @@ -139,8 +139,8 @@ RUN DESTDIR=$HOME/llvm-polygeist ninja install # Copy binaries WORKDIR $HOME/bin -RUN cp $HOME/llvm-polygeist/usr/local/bin/cgeist .; \ - cp $HOME/llvm-polygeist/usr/local/bin/mlir-opt .; \ +RUN cp $HOME/llvm-polygeist/usr/local/bin/cgeist . && \ + cp $HOME/llvm-polygeist/usr/local/bin/mlir-opt . && \ cp $HOME/llvm-polygeist/usr/local/bin/mlir-translate . # Clean up build folders for space @@ -162,7 +162,7 @@ ENV HOME=/home/user WORKDIR $HOME # Move dotfiles -RUN mv /root/.bashrc .; mv /root/.profile . +RUN mv /root/.bashrc . && mv /root/.profile . # Make terminal colorful ENV TERM=xterm-color @@ -180,13 +180,14 @@ RUN apt-get update -y && \ ENTRYPOINT cd $HOME && bash # Dependencies for plotting -RUN pip install --upgrade pip; pip install --upgrade seaborn +RUN pip install --upgrade pip && pip install --upgrade seaborn # Copy Binaries COPY --from=llvm $HOME/bin $HOME/bin # Add clang copy -RUN cp $(which clang-13) $HOME/bin/clang; cp $(which clang-13) $HOME/bin/clang++ +RUN cp $(which clang-13) $HOME/bin/clang && \ + cp $(which clang-13) $HOME/bin/clang++ # Add binaries to PATH ENV PATH=$HOME/bin:$PATH @@ -204,7 +205,7 @@ WORKDIR $HOME/torch-mlir RUN git submodule update --init --recursive --depth 1 # Install python dependencies -RUN pip install --upgrade pip; pip install -r requirements.txt +RUN pip install --upgrade pip && pip install -r requirements.txt # Build torch-mlir in-tree WORKDIR $HOME/torch-mlir/build From 58294975a41f3ce947ecc72dd26ce1ec588d84b1 Mon Sep 17 00:00:00 2001 From: Berke-Ates Date: Sun, 11 Dec 2022 17:02:29 +0100 Subject: [PATCH 09/14] bugfixes --- scripts/Polybench/dace.sh | 2 +- scripts/Polybench/mlir.sh | 4 ++-- scripts/pytorch/run_all.sh | 6 ++++-- scripts/snippets/clang.sh | 4 ++-- scripts/snippets/dcir.sh | 2 +- scripts/snippets/gcc.sh | 4 ++-- scripts/snippets/mlir.sh | 4 ++-- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/scripts/Polybench/dace.sh b/scripts/Polybench/dace.sh index 58e06ee..3781fe2 100755 --- a/scripts/Polybench/dace.sh +++ b/scripts/Polybench/dace.sh @@ -101,7 +101,7 @@ python3 "$scripts_dir"/opt_sdfg.py "$input_dir"/"${input_name}"_c2dace.sdfg \ # Running the benchmark OMP_NUM_THREADS=1 taskset -c 0 python3 "$current_dir"/bench_dace.py \ - "$output_dir"/"${input_name}"_c2dace_opt.sdfg "$repetitions" + "$output_dir"/"${input_name}"_c2dace_opt.sdfg "$repetitions" &> /dev/null add_csv "DaCe" diff --git a/scripts/Polybench/mlir.sh b/scripts/Polybench/mlir.sh index 4f43fc3..46c26fe 100755 --- a/scripts/Polybench/mlir.sh +++ b/scripts/Polybench/mlir.sh @@ -77,8 +77,8 @@ compile_with_mlir() { # Generating MLIR from C using Polygeist cgeist -resource-dir="$(clang-13 -print-resource-dir)" -I "$utils_dir" \ - -S --memref-fullrank -O$opt_lvl_cc --raise-scf-to-affine "$flags" \ - "$additional_flags" "$input_file" >"$output_dir"/"${output_name}"_cgeist.mlir + -S --memref-fullrank -O$opt_lvl_cc --raise-scf-to-affine $flags \ + $additional_flags "$input_file" >"$output_dir"/"${output_name}"_cgeist.mlir # Optimizing with MLIR mlir-opt --affine-loop-invariant-code-motion \ diff --git a/scripts/pytorch/run_all.sh b/scripts/pytorch/run_all.sh index 3df68cf..fc3fdbc 100755 --- a/scripts/pytorch/run_all.sh +++ b/scripts/pytorch/run_all.sh @@ -39,7 +39,9 @@ for runner in $runners; do echo "Running with: $runner" for benchmark in $benchmarks; do - bname="$(basename "$benchmark" .c)" + bench_dir=$(dirname "$benchmark") + bench_name=$(basename "$bench_dir") + count=$((count + 1)) diff=$((total - count)) percent=$((count * 100 / total)) @@ -54,7 +56,7 @@ for runner in $runners; do done echo -ne "\033[2K\r" - echo -ne "$prog ($percent%) ($bname) " + echo -ne "$prog ($percent%) ($bench_name) " $runner "$benchmark" "$output_dir" "$repetitions" done diff --git a/scripts/snippets/clang.sh b/scripts/snippets/clang.sh index b3b8131..f72ec8c 100755 --- a/scripts/snippets/clang.sh +++ b/scripts/snippets/clang.sh @@ -59,10 +59,10 @@ flags="-fPIC -march=native" opt_lvl_cc=3 # Optimization level for the control-centric optimizations # Compile -clang -O$opt_lvl_cc $flags -o "$output_dir"/"${input_name}"_clang.out "$input_chrono" -lm +clang -O$opt_lvl_cc $flags -o "$output_dir"/"${input_name}"_clang.out "$input_chrono" -lm &> /dev/null # Check output -gcc -O0 $flags -o "$output_dir"/"${input_name}"_gcc_ref.out "$input_chrono" -lm +gcc -O0 $flags -o "$output_dir"/"${input_name}"_gcc_ref.out "$input_chrono" -lm &> /dev/null "$output_dir"/"${input_name}"_clang.out &>/dev/null actual=$? diff --git a/scripts/snippets/dcir.sh b/scripts/snippets/dcir.sh index 2d6710a..cb6b865 100755 --- a/scripts/snippets/dcir.sh +++ b/scripts/snippets/dcir.sh @@ -106,7 +106,7 @@ python3 "$scripts_dir"/opt_sdfg.py "$output_dir"/"$input_name".sdfg \ # Check output actual=$(python3 "$current_dir"/bench_dcir.py "$output_dir"/"${input_name}"_opt.sdfg 1 T) -clang -O0 $flags -o "$output_dir"/"${input_name}"_clang_ref.out "$input_chrono" -lm +clang -O0 $flags -o "$output_dir"/"${input_name}"_clang_ref.out "$input_chrono" -lm &> /dev/null "$output_dir"/"${input_name}"_clang_ref.out &>/dev/null reference=$? diff --git a/scripts/snippets/gcc.sh b/scripts/snippets/gcc.sh index c1fd655..ab7d470 100755 --- a/scripts/snippets/gcc.sh +++ b/scripts/snippets/gcc.sh @@ -59,10 +59,10 @@ flags="-fPIC -march=native" opt_lvl_cc=3 # Optimization level for the control-centric optimizations # Compile -gcc -O$opt_lvl_cc $flags -o "$output_dir"/"${input_name}"_gcc.out "$input_chrono" -lm +gcc -O$opt_lvl_cc $flags -o "$output_dir"/"${input_name}"_gcc.out "$input_chrono" -lm &> /dev/null # Check output -clang -O0 $flags -o "$output_dir"/"${input_name}"_clang_ref.out "$input_chrono" -lm +clang -O0 $flags -o "$output_dir"/"${input_name}"_clang_ref.out "$input_chrono" -lm &> /dev/null "$output_dir"/"${input_name}"_gcc.out &>/dev/null actual=$? diff --git a/scripts/snippets/mlir.sh b/scripts/snippets/mlir.sh index bd3ec2a..98dfe49 100755 --- a/scripts/snippets/mlir.sh +++ b/scripts/snippets/mlir.sh @@ -70,7 +70,7 @@ compile_with_mlir() { # Generating MLIR from C using Polygeist cgeist -resource-dir="$(clang-13 -print-resource-dir)" \ -S --memref-fullrank -O$opt_lvl_cc --raise-scf-to-affine $flags \ - "$additional_flags" "$input_chrono" >"$output_dir"/"${output_name}"_cgeist.mlir + $additional_flags "$input_chrono" >"$output_dir"/"${output_name}"_cgeist.mlir # Optimizing with MLIR mlir-opt --affine-loop-invariant-code-motion \ @@ -100,7 +100,7 @@ compile_with_mlir() { compile_with_mlir "" "${input_name}_mlir" # Check output -clang -O0 $flags -o "$output_dir"/"${input_name}"_clang_ref.out "$input_file" -lm +clang -O0 $flags -o "$output_dir"/"${input_name}"_clang_ref.out "$input_file" -lm &> /dev/null "$output_dir"/"${input_name}"_mlir.out &>/dev/null actual=$? From 864bd3a7bdd46dc37381d88c4efd2e3c1b0c0d9c Mon Sep 17 00:00:00 2001 From: Berke-Ates Date: Wed, 4 Jan 2023 15:06:57 +0100 Subject: [PATCH 10/14] used hadolint on dockerfile --- Dockerfile | 156 +++++++++++++++++++++++++++-------------------------- 1 file changed, 79 insertions(+), 77 deletions(-) diff --git a/Dockerfile b/Dockerfile index b166175..82a54f1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,13 +12,15 @@ WORKDIR $HOME # Install dependencies RUN apt-get update -y && \ apt-get install -y --no-install-recommends \ - wget \ - git \ - cmake \ - ninja-build \ - clang \ - lld \ - python3-pip + wget=1.21.2-2ubuntu1 \ + git=1:2.34.1-1ubuntu1.5 \ + cmake=3.22.1-1ubuntu1.22.04.1 \ + ninja-build=1.10.1-1 \ + clang=1:14.0-55~exp2 \ + lld=1:14.0-55~exp2 \ + python3-pip=22.0.2+dfsg-1 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* ################################################################################ ### Install mlir-dace @@ -40,36 +42,25 @@ RUN cmake -G Ninja ../llvm \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ \ -DLLVM_ENABLE_LLD=ON \ - -DLLVM_INSTALL_UTILS=ON - -RUN ninja - -# Install and clear build folder -RUN mkdir -p $HOME/llvm-dcir -RUN DESTDIR=$HOME/llvm-dcir ninja install + -DLLVM_INSTALL_UTILS=ON && \ + ninja # Add binaries to PATH -ENV PATH=$HOME/llvm-dcir/usr/local/bin:$PATH +# ENV PATH=$HOME/llvm-dcir/usr/local/bin:$PATH # Build mlir-dace WORKDIR $HOME/mlir-dace/build RUN cmake -G Ninja .. \ - -DMLIR_DIR=$HOME/llvm-dcir/usr/local/lib/cmake/mlir \ - -DLLVM_EXTERNAL_LIT=$HOME/llvm-dcir/usr/local/bin/llvm-lit \ + -DMLIR_DIR=$HOME/mlir-dace/llvm-project/build/lib/cmake/mlir \ + -DLLVM_EXTERNAL_LIT=$HOME/mlir-dace/llvm-project/build/bin/llvm-lit \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ \ - -DCMAKE_BUILD_TYPE=Release - -RUN ninja - -RUN DESTDIR=$HOME/llvm-dcir ninja install - -WORKDIR $HOME/bin -RUN cp $HOME/mlir-dace/build/bin/* . - -# Clean up build folders for space -RUN rm -rf $HOME/mlir-dace $HOME/llvm-dcir + -DCMAKE_BUILD_TYPE=Release && \ + ninja && \ + mkdir -p $HOME/bin && \ + cp $HOME/mlir-dace/build/bin/* $HOME/bin && \ + rm -rf $HOME/mlir-dace # Go home WORKDIR $HOME @@ -79,7 +70,8 @@ WORKDIR $HOME ################################################################################ # Install python dependencies -RUN pip install --upgrade pip && pip install --upgrade "jax[cpu]" +RUN pip install --upgrade --no-cache-dir pip==22.3.1 && \ + pip install --upgrade --no-cache-dir "jax[cpu]"==0.4.1 # Get MLIR-HLO RUN git clone --depth 1 --branch cgo23 https://github.com/Berke-Ates/mlir-hlo.git @@ -89,10 +81,10 @@ WORKDIR $HOME/mlir-hlo RUN git clone https://github.com/llvm/llvm-project.git WORKDIR $HOME/mlir-hlo/llvm-project -RUN git checkout $(cat ../build_tools/llvm_version.txt) +RUN git checkout "$(cat ../build_tools/llvm_version.txt)" WORKDIR $HOME/mlir-hlo -RUN build_tools/build_mlir.sh ${PWD}/llvm-project/ ${PWD}/llvm-build +RUN build_tools/build_mlir.sh "$PWD"/llvm-project/ "$PWD"/llvm-build # Build MLIR-HLO WORKDIR $HOME/mlir-hlo/build @@ -101,16 +93,10 @@ RUN cmake .. -GNinja \ -DLLVM_ENABLE_LLD=ON \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_ENABLE_ASSERTIONS=On \ - -DMLIR_DIR=${PWD}/../llvm-build/lib/cmake/mlir - -RUN DESTDIR=$HOME/llvm-mlir-hlo ninja install - -# Copy binaries -WORKDIR $HOME/bin -RUN cp $HOME/mlir-hlo/build/bin/mlir-hlo-opt . - -# Clean up build folders for space -RUN rm -rf $HOME/mlir-hlo $HOME/llvm-mlir-hlo + -DMLIR_DIR="$PWD"/../llvm-build/lib/cmake/mlir && \ + ninja && \ + cp $HOME/mlir-hlo/build/bin/mlir-hlo-opt $HOME/bin && \ + rm -rf $HOME/mlir-hlo # Go home WORKDIR $HOME @@ -133,18 +119,12 @@ RUN cmake -G Ninja ../llvm-project/llvm \ -DLLVM_EXTERNAL_POLYGEIST_SOURCE_DIR=.. \ -DLLVM_TARGETS_TO_BUILD="host" \ -DLLVM_ENABLE_ASSERTIONS=ON \ - -DCMAKE_BUILD_TYPE=Release - -RUN DESTDIR=$HOME/llvm-polygeist ninja install - -# Copy binaries -WORKDIR $HOME/bin -RUN cp $HOME/llvm-polygeist/usr/local/bin/cgeist . && \ - cp $HOME/llvm-polygeist/usr/local/bin/mlir-opt . && \ - cp $HOME/llvm-polygeist/usr/local/bin/mlir-translate . - -# Clean up build folders for space -RUN rm -rf $HOME/Polygeist $HOME/llvm-polygeist + -DCMAKE_BUILD_TYPE=Release && \ + ninja && \ + cp $HOME/Polygeist/build/bin/cgeist $HOME/bin && \ + cp $HOME/Polygeist/build/bin/mlir-opt $HOME/bin && \ + cp $HOME/Polygeist/build/bin/mlir-translate $HOME/bin && \ + rm -rf $HOME/Polygeist # Go home WORKDIR $HOME @@ -169,32 +149,43 @@ ENV TERM=xterm-color # Install dependencies RUN apt-get update -y && \ - apt-get install -y \ - wget \ - git \ - clang-13 \ - lld \ - python3-pip + apt-get install -y --no-install-recommends \ + wget=1.21.2-2ubuntu1 \ + git=1:2.34.1-1ubuntu1.5 \ + cmake=3.22.1-1ubuntu1.22.04.1 \ + make=4.3-4.1build1 \ + ninja-build=1.10.1-1 \ + clang-13=1:13.0.1-2ubuntu2.1 \ + gcc=4:11.2.0-1ubuntu1 \ + lld=1:14.0-55~exp2 \ + python3-pip=22.0.2+dfsg-1 \ + python3=3.10.6-1~22.04 \ + python3-dev=3.10.6-1~22.04 \ + gpg=2.2.27-3ubuntu2.1 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* # Launch bash shell at home -ENTRYPOINT cd $HOME && bash +ENTRYPOINT ["/bin/bash", "-c"] +CMD ["cd $HOME && bash"] -# Dependencies for plotting -RUN pip install --upgrade pip && pip install --upgrade seaborn +# Python dependencies +RUN pip install --upgrade --no-cache-dir pip==22.3.1 && \ + pip install --upgrade --no-cache-dir seaborn==0.12.2 + +# Get Polybench comparator +RUN git clone --depth 1 --branch cgo23 https://github.com/Berke-Ates/polybench-comparator.git # Copy Binaries COPY --from=llvm $HOME/bin $HOME/bin # Add clang copy -RUN cp $(which clang-13) $HOME/bin/clang && \ - cp $(which clang-13) $HOME/bin/clang++ +RUN cp "$(which clang-13)" $HOME/bin/clang && \ + cp "$(which clang-13)" $HOME/bin/clang++ # Add binaries to PATH ENV PATH=$HOME/bin:$PATH -# Get Polybench comparator -RUN git clone --depth 1 --branch cgo23 https://github.com/Berke-Ates/polybench-comparator.git - ################################################################################ ### Install torch-mlir ################################################################################ @@ -205,7 +196,9 @@ WORKDIR $HOME/torch-mlir RUN git submodule update --init --recursive --depth 1 # Install python dependencies -RUN pip install --upgrade pip && pip install -r requirements.txt +RUN pip install --upgrade --no-cache-dir pip==22.3.1 && \ + sed -i -e 's/1.14.0.dev20221109/2.0.0.dev20221231/g' pytorch-requirements.txt && \ + pip install --no-cache-dir -r requirements.txt # Build torch-mlir in-tree WORKDIR $HOME/torch-mlir/build @@ -226,9 +219,8 @@ RUN cmake -G Ninja ../externals/llvm-project/llvm \ -DCMAKE_SHARED_LINKER_FLAGS_INIT="-fuse-ld=lld" \ -DLLVM_INSTALL_UTILS=ON \ -DLIBTORCH_SRC_BUILD=ON \ - -DLIBTORCH_VARIANT=shared - -RUN ninja + -DLIBTORCH_VARIANT=shared && \ + ninja # Go home WORKDIR $HOME @@ -242,16 +234,25 @@ ENV PYTHONPATH=$HOME/torch-mlir/build/../examples:$PYTHONPATH ### Install ICC ################################################################################ -RUN wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \ +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +RUN wget --progress=dot:giga -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \ | gpg --dearmor \ | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null RUN echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" \ | tee /etc/apt/sources.list.d/oneAPI.list -RUN apt-get update -y && apt-get install -y intel-hpckit +RUN apt-get update -y && \ + apt-get install -y --no-install-recommends \ + intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic=2023.0.0-25370 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +RUN echo "source /opt/intel/oneapi/compiler/latest/env/vars.sh" >> $HOME/.bashrc -RUN echo "source /opt/intel/oneapi/compiler/2022.2.1/env/vars.sh" >> $HOME/.bashrc +# Go home +WORKDIR $HOME ################################################################################ ### Install dace @@ -260,10 +261,11 @@ RUN echo "source /opt/intel/oneapi/compiler/2022.2.1/env/vars.sh" >> $HOME/.bash RUN git clone --depth 1 --branch cgo23 https://github.com/Berke-Ates/dace.git WORKDIR $HOME/dace -RUN git submodule update --init --recursive --depth 1 - -RUN pip install --editable . +RUN git submodule update --init --recursive --depth 1 && \ + pip install --no-cache-dir --editable . && \ + pip install --no-cache-dir mxnet-mkl==1.6.0 numpy==1.23.1 +# Go home WORKDIR $HOME ################################################################################ From 50f0eda7ee188bd9d79859a2fc32688a03f2fdc0 Mon Sep 17 00:00:00 2001 From: Berke-Ates Date: Thu, 5 Jan 2023 00:41:48 +0100 Subject: [PATCH 11/14] more stable scripts --- scripts/Polybench/clang.sh | 10 +++++++++- scripts/Polybench/dace.sh | 12 +++++++++--- scripts/Polybench/dcir.sh | 14 +++++++++++--- scripts/Polybench/gcc.sh | 12 ++++++++++-- scripts/Polybench/mlir.sh | 10 +++++++++- scripts/Polybench/run_all.sh | 6 ++++++ scripts/mhlo2std.sh | 15 +++++++++++++++ scripts/pytorch/dcir.sh | 9 ++++++--- scripts/pytorch/pytorch.sh | 7 ++++++- scripts/pytorch/run_all.sh | 5 +++++ scripts/pytorch/torch-mlir.sh | 7 ++++++- scripts/run_all.sh | 5 +++++ scripts/snippets/clang.sh | 18 ++++++++++++++---- scripts/snippets/dace.sh | 9 +++++++-- scripts/snippets/dcir.sh | 15 ++++++++++++--- scripts/snippets/gcc.sh | 18 ++++++++++++++---- scripts/snippets/mlir.sh | 19 +++++++++++++++---- scripts/snippets/run_all.sh | 7 ++++++- 18 files changed, 165 insertions(+), 33 deletions(-) diff --git a/scripts/Polybench/clang.sh b/scripts/Polybench/clang.sh index 4387db4..0d57611 100755 --- a/scripts/Polybench/clang.sh +++ b/scripts/Polybench/clang.sh @@ -4,6 +4,11 @@ # intermediate results and the times in the CSV format # Usage: ./clang.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 3 ]; then echo "Usage: ./clang.sh " @@ -45,7 +50,7 @@ actual=$output_dir/${input_name}_actual_clang.txt # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + while [[ $(grep -c ^ "$timings_file") -lt $csv_line ]]; do echo '' >>"$timings_file" done @@ -67,13 +72,16 @@ if [[ "$input_name" == "gramschmidt" ]]; then fi # Compile +# shellcheck disable=SC2086 clang -I "$utils_dir" -O$opt_lvl_cc $flags -o "$output_dir"/"${input_name}"_clang.out \ "$input_file" "$utils_dir"/polybench.c -lm # Check output +# shellcheck disable=SC2086 clang -I "$utils_dir" -O$opt_lvl_cc $flags -DPOLYBENCH_DUMP_ARRAYS \ -o "$output_dir"/"${input_name}"_clang_dump.out "$input_file" "$utils_dir"/polybench.c -lm +# shellcheck disable=SC2086 gcc -I "$utils_dir" -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ -o "$output_dir"/"${input_name}"_gcc_ref.out "$input_file" "$utils_dir"/polybench.c -lm diff --git a/scripts/Polybench/dace.sh b/scripts/Polybench/dace.sh index 3781fe2..6cf8a71 100755 --- a/scripts/Polybench/dace.sh +++ b/scripts/Polybench/dace.sh @@ -4,6 +4,11 @@ # intermediate results and the times in the CSV format # Usage: ./dace.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 3 ]; then echo "Usage: ./dace.sh " @@ -24,7 +29,8 @@ check_tool() { } check_tool python3 -check_tool icc +check_tool clang +check_tool clang++ # Create output directory if [ ! -d "$output_dir" ]; then @@ -45,7 +51,7 @@ touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + while [[ $(grep -c ^ "$timings_file") -lt $csv_line ]]; do echo '' >>"$timings_file" done @@ -101,7 +107,7 @@ python3 "$scripts_dir"/opt_sdfg.py "$input_dir"/"${input_name}"_c2dace.sdfg \ # Running the benchmark OMP_NUM_THREADS=1 taskset -c 0 python3 "$current_dir"/bench_dace.py \ - "$output_dir"/"${input_name}"_c2dace_opt.sdfg "$repetitions" &> /dev/null + "$output_dir"/"${input_name}"_c2dace_opt.sdfg "$repetitions" &>/dev/null add_csv "DaCe" diff --git a/scripts/Polybench/dcir.sh b/scripts/Polybench/dcir.sh index 2cfc2c9..b88afb1 100755 --- a/scripts/Polybench/dcir.sh +++ b/scripts/Polybench/dcir.sh @@ -4,6 +4,11 @@ # intermediate results and the times in the CSV format # Usage: ./dcir.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 3 ]; then echo "Usage: ./dcir.sh " @@ -24,6 +29,7 @@ check_tool() { } check_tool clang +check_tool clang++ check_tool clang-13 check_tool gcc check_tool cgeist @@ -31,7 +37,6 @@ check_tool mlir-opt check_tool sdfg-opt check_tool sdfg-translate check_tool python3 -check_tool icc # Create output directory if [ ! -d "$output_dir" ]; then @@ -55,11 +60,11 @@ actual=$output_dir/${input_name}_actual_dcir.txt # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + while [[ $(grep -c ^ "$timings_file") -lt $csv_line ]]; do echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" "$timings_file")" ]; then + if [ -n "$(sed "${csv_line}q;d" "$timings_file")" ]; then sed -i "${csv_line}s/$/,/" "$timings_file" fi @@ -100,6 +105,7 @@ export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" export PYTHONWARNINGS="ignore" # Generating MLIR from C using Polygeist +# shellcheck disable=SC2086 cgeist -resource-dir="$(clang-13 -print-resource-dir)" -I "$utils_dir" \ -S --memref-fullrank -O$opt_lvl_cc --raise-scf-to-affine $flags "$input_file" \ >"$output_dir"/"${input_name}"_cgeist.mlir @@ -155,10 +161,12 @@ grep "begin dump:" "$actual" | while read -r line; do done ## Compare the outputs +set +e if ! python3 "$scripts_dir"/../polybench-comparator/comparator.py "$reference" "$actual"; then echo "Output incorrect!" exit 1 fi +set -e # Running the benchmark OMP_NUM_THREADS=1 taskset -c 0 python3 "$current_dir"/bench_dcir.py \ diff --git a/scripts/Polybench/gcc.sh b/scripts/Polybench/gcc.sh index afdef44..8de67da 100755 --- a/scripts/Polybench/gcc.sh +++ b/scripts/Polybench/gcc.sh @@ -4,6 +4,11 @@ # intermediate results and the times in the CSV format # Usage: ./gcc.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 3 ]; then echo "Usage: ./gcc.sh " @@ -45,11 +50,11 @@ actual=$output_dir/${input_name}_actual_gcc.txt # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + while [[ $(grep -c ^ "$timings_file") -lt $csv_line ]]; do echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" "$timings_file")" ]; then + if [ -n "$(sed "${csv_line}q;d" "$timings_file")" ]; then sed -i "${csv_line}s/$/,/" "$timings_file" fi @@ -67,13 +72,16 @@ if [[ "$input_name" == "gramschmidt" ]]; then fi # Compile +# shellcheck disable=SC2086 gcc -I "$utils_dir" -O$opt_lvl_cc $flags -o "$output_dir"/"${input_name}"_gcc.out \ "$input_file" "$utils_dir"/polybench.c -lm # Check output +# shellcheck disable=SC2086 gcc -I "$utils_dir" -O$opt_lvl_cc $flags -DPOLYBENCH_DUMP_ARRAYS \ -o "$output_dir"/"${input_name}"_gcc_dump.out "$input_file" "$utils_dir"/polybench.c -lm +# shellcheck disable=SC2086 clang -I "$utils_dir" -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ -o "$output_dir"/"${input_name}"_clang_ref.out "$input_file" "$utils_dir"/polybench.c -lm diff --git a/scripts/Polybench/mlir.sh b/scripts/Polybench/mlir.sh index 46c26fe..dc3704f 100755 --- a/scripts/Polybench/mlir.sh +++ b/scripts/Polybench/mlir.sh @@ -4,6 +4,11 @@ # any intermediate results and the times in the CSV format # Usage: ./mlir.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 3 ]; then echo "Usage: ./mlir.sh " @@ -49,7 +54,7 @@ actual=$output_dir/${input_name}_actual_mlir.txt # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + while [[ $(grep -c ^ "$timings_file") -lt $csv_line ]]; do echo '' >>"$timings_file" done @@ -76,6 +81,7 @@ compile_with_mlir() { output_name=$2 # Generating MLIR from C using Polygeist + # shellcheck disable=SC2086 cgeist -resource-dir="$(clang-13 -print-resource-dir)" -I "$utils_dir" \ -S --memref-fullrank -O$opt_lvl_cc --raise-scf-to-affine $flags \ $additional_flags "$input_file" >"$output_dir"/"${output_name}"_cgeist.mlir @@ -100,6 +106,7 @@ compile_with_mlir() { -o "$output_dir"/"${output_name}".s # Assemble + # shellcheck disable=SC2086 clang -O$opt_lvl_cc $flags $additional_flags "$output_dir"/"${output_name}".s \ "$utils_dir"/polybench.c -o "$output_dir"/"${output_name}".out -lm } @@ -110,6 +117,7 @@ compile_with_mlir "" "${input_name}_mlir" # Check output compile_with_mlir "-DPOLYBENCH_DUMP_ARRAYS" "${input_name}_mlir_dump" +# shellcheck disable=SC2086 gcc -I "$utils_dir" -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ -o "$output_dir"/"${input_name}"_clang_ref.out "$input_file" "$utils_dir"/polybench.c -lm diff --git a/scripts/Polybench/run_all.sh b/scripts/Polybench/run_all.sh index 09fe107..d4acac5 100755 --- a/scripts/Polybench/run_all.sh +++ b/scripts/Polybench/run_all.sh @@ -5,6 +5,11 @@ # CSV format as well as a plot with all the benchmarks. # Usage: ./run_all.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 2 ]; then echo "Usage: ./run_all.sh " @@ -72,4 +77,5 @@ for benchmark in $benchmarks; do cp "$output_dir/${bname}.csv" "$output_dir/fig6_${bname}.csv" done +# shellcheck disable=SC2086,SC2048 python3 "$scripts_dir"/multi_plot.py ${csv_files[*]} "$output_dir"/fig6.pdf diff --git a/scripts/mhlo2std.sh b/scripts/mhlo2std.sh index 769f75f..7d5cebb 100755 --- a/scripts/mhlo2std.sh +++ b/scripts/mhlo2std.sh @@ -3,6 +3,11 @@ # Desc: Converts the mhlo dialect to builtin dialect for further conversion # Usage: ./mhlo2std.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 1 ]; then echo "Usage: ./mhlo2std.sh " @@ -12,6 +17,16 @@ fi # Read args input_file=$1 +# Check tools +check_tool() { + if ! command -v "$1" &>/dev/null; then + echo "$1 could not be found" + exit 1 + fi +} + +check_tool mlir-hlo-opt + # Execute conversion mlir-hlo-opt --hlo-legalize-to-linalg "$input_file" | mlir-hlo-opt --linalg-bufferize | diff --git a/scripts/pytorch/dcir.sh b/scripts/pytorch/dcir.sh index 845a24f..5267719 100755 --- a/scripts/pytorch/dcir.sh +++ b/scripts/pytorch/dcir.sh @@ -4,6 +4,11 @@ # intermediate results and the times in the CSV format # Usage: ./dcir.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 3 ]; then echo "Usage: ./dcir.sh " @@ -23,8 +28,6 @@ check_tool() { fi } -check_tool clang -check_tool cgeist check_tool mlir-opt check_tool sdfg-opt check_tool sdfg-translate @@ -51,7 +54,7 @@ touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + while [[ $(grep -c ^ "$timings_file") -lt $csv_line ]]; do echo '' >>"$timings_file" done diff --git a/scripts/pytorch/pytorch.sh b/scripts/pytorch/pytorch.sh index 6148c39..5c81594 100755 --- a/scripts/pytorch/pytorch.sh +++ b/scripts/pytorch/pytorch.sh @@ -4,6 +4,11 @@ # intermediate results and the times in the CSV format # Usage: ./pytorch.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 3 ]; then echo "Usage: ./pytorch.sh " @@ -43,7 +48,7 @@ touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + while [[ $(grep -c ^ "$timings_file") -lt $csv_line ]]; do echo '' >>"$timings_file" done diff --git a/scripts/pytorch/run_all.sh b/scripts/pytorch/run_all.sh index fc3fdbc..ae47d86 100755 --- a/scripts/pytorch/run_all.sh +++ b/scripts/pytorch/run_all.sh @@ -5,6 +5,11 @@ # well as all the plots. # Usage: ./run_all.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 2 ]; then echo "Usage: ./run_all.sh " diff --git a/scripts/pytorch/torch-mlir.sh b/scripts/pytorch/torch-mlir.sh index 8c0d101..fc59c79 100755 --- a/scripts/pytorch/torch-mlir.sh +++ b/scripts/pytorch/torch-mlir.sh @@ -4,6 +4,11 @@ # intermediate results and the times in the CSV format # Usage: ./torch-mlir.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 3 ]; then echo "Usage: ./torch-mlir.sh " @@ -43,7 +48,7 @@ touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + while [[ $(grep -c ^ "$timings_file") -lt $csv_line ]]; do echo '' >>"$timings_file" done diff --git a/scripts/run_all.sh b/scripts/run_all.sh index 56dff88..4afcc7a 100755 --- a/scripts/run_all.sh +++ b/scripts/run_all.sh @@ -4,6 +4,11 @@ # and the times in the CSV format as well as all the plots. # Usage: ./run_all.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 2 ]; then echo "Usage: ./run_all.sh " diff --git a/scripts/snippets/clang.sh b/scripts/snippets/clang.sh index f72ec8c..b0fca29 100755 --- a/scripts/snippets/clang.sh +++ b/scripts/snippets/clang.sh @@ -4,6 +4,11 @@ # intermediate results and the times in the CSV format # Usage: ./clang.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 3 ]; then echo "Usage: ./clang.sh " @@ -25,7 +30,6 @@ check_tool() { check_tool clang check_tool gcc -check_tool python3 # Create output directory if [ ! -d "$output_dir" ]; then @@ -42,7 +46,7 @@ touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + while [[ $(grep -c ^ "$timings_file") -lt $csv_line ]]; do echo '' >>"$timings_file" done @@ -59,15 +63,19 @@ flags="-fPIC -march=native" opt_lvl_cc=3 # Optimization level for the control-centric optimizations # Compile -clang -O$opt_lvl_cc $flags -o "$output_dir"/"${input_name}"_clang.out "$input_chrono" -lm &> /dev/null +# shellcheck disable=SC2086 +clang -O$opt_lvl_cc $flags -o "$output_dir"/"${input_name}"_clang.out "$input_chrono" -lm &>/dev/null # Check output -gcc -O0 $flags -o "$output_dir"/"${input_name}"_gcc_ref.out "$input_chrono" -lm &> /dev/null +# shellcheck disable=SC2086 +gcc -O0 $flags -o "$output_dir"/"${input_name}"_gcc_ref.out "$input_chrono" -lm &>/dev/null +set +e "$output_dir"/"${input_name}"_clang.out &>/dev/null actual=$? "$output_dir"/"${input_name}"_gcc_ref.out &>/dev/null reference=$? +set -e if [ "$actual" -ne "$reference" ]; then echo "Output incorrect!" @@ -78,6 +86,8 @@ fi add_csv "Clang" for _ in $(seq 1 "$repetitions"); do + set +e time=$(OMP_NUM_THREADS=1 taskset -c 0 ./"$output_dir"/"${input_name}"_clang.out) + set -e add_csv "$time" done diff --git a/scripts/snippets/dace.sh b/scripts/snippets/dace.sh index 723413d..296bb94 100755 --- a/scripts/snippets/dace.sh +++ b/scripts/snippets/dace.sh @@ -4,6 +4,11 @@ # intermediate results and the times in the CSV format # Usage: ./dace.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 3 ]; then echo "Usage: ./dace.sh " @@ -24,8 +29,8 @@ check_tool() { } check_tool clang +check_tool clang++ check_tool python3 -check_tool icc # Create output directory if [ ! -d "$output_dir" ]; then @@ -46,7 +51,7 @@ touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + while [[ $(grep -c ^ "$timings_file") -lt $csv_line ]]; do echo '' >>"$timings_file" done diff --git a/scripts/snippets/dcir.sh b/scripts/snippets/dcir.sh index cb6b865..bb8a954 100755 --- a/scripts/snippets/dcir.sh +++ b/scripts/snippets/dcir.sh @@ -4,6 +4,11 @@ # intermediate results and the times in the CSV format # Usage: ./dcir.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 3 ]; then echo "Usage: ./dcir.sh " @@ -24,13 +29,13 @@ check_tool() { } check_tool clang +check_tool clang++ check_tool clang-13 check_tool cgeist check_tool mlir-opt check_tool sdfg-opt check_tool sdfg-translate check_tool python3 -check_tool icc # Create output directory if [ ! -d "$output_dir" ]; then @@ -52,7 +57,7 @@ touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + while [[ $(grep -c ^ "$timings_file") -lt $csv_line ]]; do echo '' >>"$timings_file" done @@ -82,6 +87,7 @@ export DACE_compiler_cpu_args="-fPIC -O$opt_lvl_cc -march=native" export PYTHONWARNINGS="ignore" # Generating MLIR from C using Polygeist +# shellcheck disable=SC2086 cgeist -resource-dir="$(clang-13 -print-resource-dir)" -S --memref-fullrank \ -O$opt_lvl_cc --raise-scf-to-affine $flags "$input_file" \ >"$output_dir"/"${input_name}"_cgeist.mlir @@ -106,9 +112,12 @@ python3 "$scripts_dir"/opt_sdfg.py "$output_dir"/"$input_name".sdfg \ # Check output actual=$(python3 "$current_dir"/bench_dcir.py "$output_dir"/"${input_name}"_opt.sdfg 1 T) -clang -O0 $flags -o "$output_dir"/"${input_name}"_clang_ref.out "$input_chrono" -lm &> /dev/null +# shellcheck disable=SC2086 +clang -O0 $flags -o "$output_dir"/"${input_name}"_clang_ref.out "$input_chrono" -lm &>/dev/null +set +e "$output_dir"/"${input_name}"_clang_ref.out &>/dev/null reference=$? +set -e if [ "$actual" -ne "$reference" ]; then echo "Output incorrect!" diff --git a/scripts/snippets/gcc.sh b/scripts/snippets/gcc.sh index ab7d470..0816a29 100755 --- a/scripts/snippets/gcc.sh +++ b/scripts/snippets/gcc.sh @@ -4,6 +4,11 @@ # intermediate results and the times in the CSV format # Usage: ./gcc.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 3 ]; then echo "Usage: ./gcc.sh " @@ -25,7 +30,6 @@ check_tool() { check_tool gcc check_tool clang -check_tool python3 # Create output directory if [ ! -d "$output_dir" ]; then @@ -42,7 +46,7 @@ touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + while [[ $(grep -c ^ "$timings_file") -lt $csv_line ]]; do echo '' >>"$timings_file" done @@ -59,15 +63,19 @@ flags="-fPIC -march=native" opt_lvl_cc=3 # Optimization level for the control-centric optimizations # Compile -gcc -O$opt_lvl_cc $flags -o "$output_dir"/"${input_name}"_gcc.out "$input_chrono" -lm &> /dev/null +# shellcheck disable=SC2086 +gcc -O$opt_lvl_cc $flags -o "$output_dir"/"${input_name}"_gcc.out "$input_chrono" -lm &>/dev/null # Check output -clang -O0 $flags -o "$output_dir"/"${input_name}"_clang_ref.out "$input_chrono" -lm &> /dev/null +# shellcheck disable=SC2086 +clang -O0 $flags -o "$output_dir"/"${input_name}"_clang_ref.out "$input_chrono" -lm &>/dev/null +set +e "$output_dir"/"${input_name}"_gcc.out &>/dev/null actual=$? "$output_dir"/"${input_name}"_clang_ref.out &>/dev/null reference=$? +set -e if [ "$actual" -ne "$reference" ]; then echo "Output incorrect!" @@ -78,6 +86,8 @@ fi add_csv "GCC" for _ in $(seq 1 "$repetitions"); do + set +e time=$(OMP_NUM_THREADS=1 taskset -c 0 ./"$output_dir"/"${input_name}"_gcc.out) + set -e add_csv "$time" done diff --git a/scripts/snippets/mlir.sh b/scripts/snippets/mlir.sh index 98dfe49..71a5dcd 100755 --- a/scripts/snippets/mlir.sh +++ b/scripts/snippets/mlir.sh @@ -4,6 +4,11 @@ # any intermediate results and the times in the CSV format # Usage: ./mlir.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 3 ]; then echo "Usage: ./mlir.sh " @@ -29,7 +34,6 @@ check_tool clang-13 check_tool cgeist check_tool mlir-opt check_tool mlir-translate -check_tool python3 # Create output directory if [ ! -d "$output_dir" ]; then @@ -46,11 +50,11 @@ touch "$timings_file" # Adds a value to the timings file, jumps to the next row after a write csv_line=1 add_csv() { - while [[ $(grep -c ^ "$timings_file") < $csv_line ]]; do + while [[ $(grep -c ^ "$timings_file") -lt $csv_line ]]; do echo '' >>"$timings_file" done - if [ ! -z "$(sed "${csv_line}q;d" "$timings_file")" ]; then + if [ -n "$(sed "${csv_line}q;d" "$timings_file")" ]; then sed -i "${csv_line}s/$/,/" "$timings_file" fi @@ -68,6 +72,7 @@ compile_with_mlir() { output_name=$2 # Generating MLIR from C using Polygeist + # shellcheck disable=SC2086 cgeist -resource-dir="$(clang-13 -print-resource-dir)" \ -S --memref-fullrank -O$opt_lvl_cc --raise-scf-to-affine $flags \ $additional_flags "$input_chrono" >"$output_dir"/"${output_name}"_cgeist.mlir @@ -92,6 +97,7 @@ compile_with_mlir() { -o "$output_dir"/"${output_name}".s # Assemble + # shellcheck disable=SC2086 clang -O$opt_lvl_cc $flags $additional_flags "$output_dir"/"${output_name}".s \ -o "$output_dir"/"${output_name}".out -lm } @@ -100,12 +106,15 @@ compile_with_mlir() { compile_with_mlir "" "${input_name}_mlir" # Check output -clang -O0 $flags -o "$output_dir"/"${input_name}"_clang_ref.out "$input_file" -lm &> /dev/null +# shellcheck disable=SC2086 +clang -O0 $flags -o "$output_dir"/"${input_name}"_clang_ref.out "$input_file" -lm &>/dev/null +set +e "$output_dir"/"${input_name}"_mlir.out &>/dev/null actual=$? "$output_dir"/"${input_name}"_clang_ref.out &>/dev/null reference=$? +set -e if [ "$actual" -ne "$reference" ]; then echo "Output incorrect!" @@ -116,6 +125,8 @@ fi add_csv "Polygeist + MLIR" for _ in $(seq 1 "$repetitions"); do + set +e time=$(OMP_NUM_THREADS=1 taskset -c 0 ./"$output_dir"/"${input_name}"_mlir.out) + set -e add_csv "$time" done diff --git a/scripts/snippets/run_all.sh b/scripts/snippets/run_all.sh index eb33284..23e4731 100755 --- a/scripts/snippets/run_all.sh +++ b/scripts/snippets/run_all.sh @@ -5,6 +5,11 @@ # CSV format as well as all the plots. # Usage: ./run_all.sh +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + # Check args if [ $# -ne 2 ]; then echo "Usage: ./run_all.sh " @@ -84,5 +89,5 @@ for benchmark in $benchmarks; do mv "$output_dir/${bname}_timings.csv" "$output_dir/fig${fig_num}.csv" python3 "$scripts_dir"/single_plot.py "$output_dir/fig${fig_num}.csv" \ - "$output_dir"/fig$fig_num.pdf + "$output_dir"/fig"$fig_num".pdf done From 55a3328e9e6932583789826cd2768c9640bc6e98 Mon Sep 17 00:00:00 2001 From: Berke-Ates Date: Fri, 6 Jan 2023 15:55:15 +0100 Subject: [PATCH 12/14] dcir shellcheck changes --- scripts/Polybench/dcir.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/Polybench/dcir.sh b/scripts/Polybench/dcir.sh index b88afb1..f1508d6 100755 --- a/scripts/Polybench/dcir.sh +++ b/scripts/Polybench/dcir.sh @@ -128,6 +128,7 @@ python3 "$scripts_dir"/opt_sdfg.py "$output_dir"/"$input_name".sdfg \ "$output_dir"/"${input_name}"_opt.sdfg $opt_lvl_dc T # Check output +# shellcheck disable=SC2086 gcc -I "$utils_dir" -O0 $flags -DPOLYBENCH_DUMP_ARRAYS \ -o "$output_dir"/"${input_name}"_gcc_ref.out "$input_file" "$utils_dir"/polybench.c -lm @@ -138,21 +139,24 @@ python3 "$current_dir"/bench_dcir.py "$output_dir"/"${input_name}"_opt.sdfg 1 T touch "$output_dir"/arr_names.txt grep "begin dump:" "$reference" | while read -r line; do + # shellcheck disable=SC2206 arr_tmp=($line) arr_name=${arr_tmp[2]} echo -n "$arr_name " >>"$output_dir"/arr_names.txt done -arr_names=($(cat $output_dir/arr_names.txt)) +mapfile -t -d " " arr_names < <(cat "$output_dir"/arr_names.txt) rm "$output_dir"/arr_names.txt ## Remove Warnings from output sed -i '0,/^==BEGIN DUMP_ARRAYS==$/d' "$actual" -printf '%s\n%s\n' "==BEGIN DUMP_ARRAYS==" "$(cat $actual)" >"$actual" +content_actual=$(cat "$actual") +printf '%s\n%s\n' "==BEGIN DUMP_ARRAYS==" "$content_actual" >"$actual" ## Use original array names idx=0 grep "begin dump:" "$actual" | while read -r line; do + # shellcheck disable=SC2206 arr_tmp=($line) arr_name=${arr_tmp[2]} rep_arr_name=${arr_names[idx]} From 4fcca0ffd6eb8a2e7bc380a91c64764eec7296f5 Mon Sep 17 00:00:00 2001 From: Berke-Ates Date: Mon, 9 Jan 2023 14:07:02 +0100 Subject: [PATCH 13/14] silenced snippets --- scripts/snippets/dcir.sh | 2 +- scripts/snippets/mlir.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/snippets/dcir.sh b/scripts/snippets/dcir.sh index bb8a954..ed9956e 100755 --- a/scripts/snippets/dcir.sh +++ b/scripts/snippets/dcir.sh @@ -90,7 +90,7 @@ export PYTHONWARNINGS="ignore" # shellcheck disable=SC2086 cgeist -resource-dir="$(clang-13 -print-resource-dir)" -S --memref-fullrank \ -O$opt_lvl_cc --raise-scf-to-affine $flags "$input_file" \ - >"$output_dir"/"${input_name}"_cgeist.mlir + 1>"$output_dir"/"${input_name}"_cgeist.mlir 2>/dev/null # Optimizing with MLIR mlir-opt --affine-loop-invariant-code-motion "$output_dir"/"${input_name}"_cgeist.mlir | diff --git a/scripts/snippets/mlir.sh b/scripts/snippets/mlir.sh index 71a5dcd..0dd7234 100755 --- a/scripts/snippets/mlir.sh +++ b/scripts/snippets/mlir.sh @@ -75,7 +75,8 @@ compile_with_mlir() { # shellcheck disable=SC2086 cgeist -resource-dir="$(clang-13 -print-resource-dir)" \ -S --memref-fullrank -O$opt_lvl_cc --raise-scf-to-affine $flags \ - $additional_flags "$input_chrono" >"$output_dir"/"${output_name}"_cgeist.mlir + $additional_flags "$input_chrono" 1>"$output_dir"/"${output_name}"_cgeist.mlir \ + 2>/dev/null # Optimizing with MLIR mlir-opt --affine-loop-invariant-code-motion \ From e844a32b1fade8a64e6ccf229a5d307f85b5a9db Mon Sep 17 00:00:00 2001 From: Berke-Ates Date: Mon, 9 Jan 2023 15:32:59 +0100 Subject: [PATCH 14/14] added pytorch with jit --- Dockerfile | 3 - benchmarks/pytorch/mish/pytorch_jit.py | 78 ++++++++++++++++++++++++++ scripts/pytorch/pytorch_jit.sh | 76 +++++++++++++++++++++++++ scripts/pytorch/run_all.sh | 3 +- 4 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 benchmarks/pytorch/mish/pytorch_jit.py create mode 100755 scripts/pytorch/pytorch_jit.sh diff --git a/Dockerfile b/Dockerfile index 82a54f1..304c332 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,9 +45,6 @@ RUN cmake -G Ninja ../llvm \ -DLLVM_INSTALL_UTILS=ON && \ ninja -# Add binaries to PATH -# ENV PATH=$HOME/llvm-dcir/usr/local/bin:$PATH - # Build mlir-dace WORKDIR $HOME/mlir-dace/build diff --git a/benchmarks/pytorch/mish/pytorch_jit.py b/benchmarks/pytorch/mish/pytorch_jit.py new file mode 100644 index 0000000..c58e529 --- /dev/null +++ b/benchmarks/pytorch/mish/pytorch_jit.py @@ -0,0 +1,78 @@ +#!/usr/bin/python3 + +# Desc: Runs the Mish benchmark using Pytorch with JIT +# Usage: python3 pytorch_jit.py + +import sys +import numpy as np +import torch +from torch import nn +import time +import torch_mlir + +from torch_mlir_e2e_test.mhlo_backends.linalg_on_tensors import LinalgOnTensorsMhloBackend + +if len(sys.argv) != 3: + print("PyTorch(JIT) Mish Benchmarking Tool") + print("Arguments:") + print(" Repetitions: How many times to run the benchmark") + print(" Test Output (T/F): If 'T', tests the output against Torch-MLIR") + exit(1) + +repetitions = int(sys.argv[1]) +test_output = sys.argv[2] == 'T' + + +# Load model +class Mish(nn.Module): + + def __init__(self): + super().__init__() + + def forward(self, x): + x = torch.log(1 + torch.exp(x)) + return x + + +data = torch.rand(8, 32, 224, 224) +model = torch.jit.trace(Mish(), data).to(torch.device('cpu')) +model.eval() + +# Benchmark +for i in range(repetitions): + data = torch.rand(8, 32, 224, 224) + start = time.time() + model.forward(data) + runtime = time.time() - start + print(runtime * 1000) + +# Test output +if test_output: + data = torch.zeros(8, 32, 224, 224) + + for i in range(8): + for j in range(32): + for k in range(224): + for l in range(224): + data[i, j, k, l] = (i + j + k + l) / (8 + 32 + 224 + 224) + + prediction_pytorch = model.forward(data).numpy() + + # Generate MHLO + backend = LinalgOnTensorsMhloBackend() + + model_mlir = nn.Sequential(Mish()).to(torch.device('cpu')) + model_mlir.eval() + module = torch_mlir.compile(model_mlir, + data, + output_type=torch_mlir.OutputType.MHLO) + + compiled = backend.compile(module) + jit_module = backend.load(compiled) + + prediction_torch_mlir = jit_module.forward(data.numpy()) + + # Compare + if not np.allclose( + prediction_pytorch, prediction_torch_mlir, rtol=1e-5, atol=1e-8): + exit(1) diff --git a/scripts/pytorch/pytorch_jit.sh b/scripts/pytorch/pytorch_jit.sh new file mode 100755 index 0000000..5008ceb --- /dev/null +++ b/scripts/pytorch/pytorch_jit.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +# Desc: Runs a pytorch benchmark using Pytorch with JIT. The output contains any +# intermediate results and the times in the CSV format +# Usage: ./pytorch_jit.sh + +# Be safe +set -e # Fail script when subcommand fails +set -u # Disallow using undefined variables +set -o pipefail # Prevent errors from being masked + +# Check args +if [ $# -ne 3 ]; then + echo "Usage: ./pytorch_jit.sh " + exit 1 +fi + +# Read args +input_file=$1 +output_dir=$2 +repetitions=$3 + +# Check tools +check_tool() { + if ! command -v "$1" &>/dev/null; then + echo "$1 could not be found" + exit 1 + fi +} + +check_tool python3 + +# Create output directory +if [ ! -d "$output_dir" ]; then + mkdir -p "$output_dir" +fi + +# Silence Python warnings +export PYTHONWARNINGS="ignore" + +# Helpers +input_dir=$(dirname "$input_file") +input_name=$(basename "$input_dir") +input_file=$input_dir/pytorch_jit.py +timings_file=$output_dir/${input_name}_timings.csv +touch "$timings_file" + +# Adds a value to the timings file, jumps to the next row after a write +csv_line=1 +add_csv() { + while [[ $(grep -c ^ "$timings_file") -lt $csv_line ]]; do + echo '' >>"$timings_file" + done + + if [ -n "$(sed "${csv_line}q;d" "$timings_file")" ]; then + sed -i "${csv_line}s/$/,/" "$timings_file" + fi + + sed -i "${csv_line}s/$/$1/" "$timings_file" + csv_line=$((csv_line + 1)) +} + +# Check output +if ! python3 "$input_file" 0 T; then + echo "Output incorrect!" + exit 1 +fi + +# Running the benchmark +runtimes=$(OMP_NUM_THREADS=1 taskset -c 0 python3 "$input_file" "$repetitions" F) + +add_csv "PyTorch (JIT)" + +for i in $runtimes; do + add_csv "$i" +done diff --git a/scripts/pytorch/run_all.sh b/scripts/pytorch/run_all.sh index ae47d86..37b694f 100755 --- a/scripts/pytorch/run_all.sh +++ b/scripts/pytorch/run_all.sh @@ -37,7 +37,8 @@ benchmarks_dir=$(dirname "$0")/../../benchmarks/pytorch benchmarks=$(find "$benchmarks_dir"/* -name 'pytorch.py') total=$(echo "$benchmarks" | wc -l) -runners="$runners_dir/pytorch.sh $runners_dir/torch-mlir.sh $runners_dir/dcir.sh" +runners="$runners_dir/pytorch.sh $runners_dir/pytorch_jit.sh \ + $runners_dir/torch-mlir.sh $runners_dir/dcir.sh" for runner in $runners; do count=0