Skip to content

Instantly share code, notes, and snippets.

@danielml3
Last active November 17, 2024 09:12
Show Gist options
  • Save danielml3/8d9ea968a400b4718ee739e738abf373 to your computer and use it in GitHub Desktop.
Save danielml3/8d9ea968a400b4718ee739e738abf373 to your computer and use it in GitHub Desktop.
Crunches perf-stat data for comparing dgemm block sizes
#!/bin/bash
set -e
matrix=$1
[ -z $matrix ] && exit 1
perf_output_file=perf_output.tmp
events="L1-dcache-loads,L1-dcache-stores,L1-dcache-load-misses,LLC-loads,LLC-stores LLC-load-misses,LLC-store-misses,duration_time"
declare -A crunched_data
declare -A crunched_data_avg
# Iterate over each block size (0 == Naive)
for blocksize in 1 2 4 8 16 32; do
echo "#"
echo "# BLOCKSIZE = $blocksize (${matrix}x${matrix})"
echo "#"
echo "#define BLOCKSIZE $blocksize" > blocksize.h
make
for event in $events; do
repeat=10
if [ $blocksize -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