Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement performance checking script #1727

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions mlir/utils/performance/performance-checking.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

# Shell script that captures the performance difference between data types to validate expected kernel performance.
# Usage: /performance-checking --d <model> --p <model_path> [--r <number_of_iterations>]"
# Arguments:
# --d <model> Used model, will be the name for the directory with kernels (default: 'resnet50-fp16').
# --p <model_path> Path to .onnx file (default: '/models/mlperf/resnet50_v1.onnx').
# --r <number_of_iterations> Number of times to run each testcase (default: 5).

MODEL_NAME="resnet50-fp16"
MODEL_PATH="/models/mlperf/resnet50_v1.onnx"
RUNS=5

while [[ $# -gt 0 ]]; do
case "$1" in
--d)
MODEL_NAME="$2"
shift 2
;;
--p)
MODEL_PATH="$2"
shift 2
;;
--r)
RUNS="$2"
shift 2
;;
--help)
echo "Usage: $0 --d <model> --p <model_path> [--r <number_of_iterations>]"
exit
;;
*)
echo "Option $1 doesn't exist"
exit 1
;;
esac
done


mkdir "$MODEL_NAME"

MIGRAPHX_MLIR_DUMP_TO_MXR="$MODEL_NAME" MIGRAPHX_ENABLE_NHWC=1 MIGRAPHX_ENABLE_HIPBLASLT_GEMM=1 MIGRAPHX_MLIR_USE_SPECIFIC_OPS="convolution,~fused,~dot" migraphx-driver compile "$MODEL_PATH" --fp16 --exhaustive-tune

ls "$MODEL_NAME"/*.mxr |xargs -I {} -n 1 migraphx-driver read "{}" --py -o "{}".py

sed -i -e 's/half_type/int8_type/' -e 's/convolution/quant_convolution/' "$MODEL_NAME"/*.py

echo "NEW RUN" >> "$MODEL_NAME/times"

for testcase in "$MODEL_NAME"/*.py
do
test_name=$(basename "$testcase")
total_time=0

for ((i = 1; i <= RUNS; i++))
do
MIGRAPHX_DISABLE_PASSES=auto_contiguous migraphx-driver time $testcase --mlir > "$MODEL_NAME/results.out"
#run_time=$(awk -F'[/ ]' -v t="$testcase" '/Total time/{k=$3}END{print t "," substr(k, 1, length(k)-2)}' "$MODEL_NAME/results.out")
run_time=$(awk -F'[/ ]' '/Total time/{print substr($3, 1, length($3)-2)}' "$MODEL_NAME/results.out")
echo $run_time
total_time=$(awk -v total="$total_time" -v run="$run_time" 'BEGIN {print total + run}')
done

avg_time=$(awk -v total="$total_time" -v runs="$RUNS" 'BEGIN {print total / runs}')
echo "$test_name,$avg_time" >> "$MODEL_NAME/times"

done