Skip to content

Instantly share code, notes, and snippets.

@danielml3
Created December 5, 2024 11:06
Show Gist options
  • Save danielml3/a58e707927cb2ab177f9e1fe954521cf to your computer and use it in GitHub Desktop.
Save danielml3/a58e707927cb2ab177f9e1fe954521cf to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
matrix=$1
[ -z $matrix ] && exit 1
perf_output_file=perf_output.tmp
events="branches,branch-misses,bus-cycles,cache-misses,cache-references,cpu-cycles,instructions,duration_time"
declare -A crunched_data
declare -A crunched_data_avg
# Iterate over each block size (0 == Naive)
for unroll in 1 2 4 8 16 32; do
echo "#"
echo "# UNROLL = $unroll (${matrix}x${matrix})"
echo "#"
echo "#define UNROLL $unroll" > unroll.h
make
for event in $events; do
repeat=10
if [ $unroll -eq 0 ]; then
perf stat --repeat $repeat -x ";" -o $perf_output_file -e "$event" ../Naive/benchmark $matrix
else
perf stat --repeat $repeat -x ";" -o $perf_output_file -e "$event" ./benchmark $matrix
fi
OLDIFS=$IFS
IFS=$'\n'
perf_output=$(cat $perf_output_file | grep -v "\#")
for line in $perf_output; do
event="$(echo $line | cut -d ';' -f 3)"
event_average="$(echo $line | cut -d ';' -f 1)"
event_desv="$(echo $line | cut -d ';' -f 4)"
if [[ "$event" == "duration_time" ]]; then
event_average=$(python3 -c "print(round(${event_average} / 1e9, 4))")
fi
crunched_data[$event]="${crunched_data[$event]};$event_average±$event_desv"
crunched_data_avg[$event]="${crunched_data_avg[$event]};$event_average"
done
IFS=$OLDIFS
done
done
events=$(echo $events | sed 's/,/\ /g')
echo "Data with deviation: "
for event in $events; do
echo -e "$event${crunched_data[$event]}"
done
echo "Bare data average"
for event in $events; do
echo -e "$event${crunched_data_avg[$event]}" | sed 's/\./,/g'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment