From 9f2fff66b7ae3f4d4c641959b8815b5fa764c581 Mon Sep 17 00:00:00 2001 From: Djordje Antic Date: Tue, 28 Jan 2025 10:50:55 -0600 Subject: [PATCH 1/2] Implement performance checking script Signed-off-by: Djordje Antic --- .../utils/performance/performance-checking.sh | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 mlir/utils/performance/performance-checking.sh diff --git a/mlir/utils/performance/performance-checking.sh b/mlir/utils/performance/performance-checking.sh new file mode 100644 index 000000000000..5b7d6d11d54b --- /dev/null +++ b/mlir/utils/performance/performance-checking.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +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 + ;; + *) + echo "Option $1 doesn't exist" + exit 1 + ;; + esac +done + +#if [ -z "$MODEL_NAME" ]; then +# echo "Provide model: $0 --m " +# exit 1 +#fi + +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" + +#while read testcase +#do +# MIGRAPHX_DISABLE_PASSES=auto_contiguous migraphx-driver time $testcase --mlir > results.out +# awk -F'[/ ]' -v t="$testcase" '/Total time/{k=$3}END{print t "," substr(k, 1, length(k)-2)}' results.out >> times +#done < "$MODEL_NAME/results.out" +# awk -F'[/ ]' -v t="$test_name" '/Total time/{k=$3}END{print t "," substr(k, 1, length(k)-2)}' "$MODEL_NAME/results.out" >> "$MODEL_NAME/times" +#done + +#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 + + +# < Date: Tue, 28 Jan 2025 11:36:55 -0600 Subject: [PATCH 2/2] Implement performance checking script Signed-off-by: Djordje Antic --- .../utils/performance/performance-checking.sh | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/mlir/utils/performance/performance-checking.sh b/mlir/utils/performance/performance-checking.sh index 5b7d6d11d54b..956733ba9096 100644 --- a/mlir/utils/performance/performance-checking.sh +++ b/mlir/utils/performance/performance-checking.sh @@ -1,5 +1,12 @@ #!/bin/bash +# Shell script that captures the performance difference between data types to validate expected kernel performance. +# Usage: /performance-checking --d --p [--r ]" +# Arguments: +# --d Used model, will be the name for the directory with kernels (default: 'resnet50-fp16'). +# --p Path to .onnx file (default: '/models/mlperf/resnet50_v1.onnx'). +# --r Number of times to run each testcase (default: 5). + MODEL_NAME="resnet50-fp16" MODEL_PATH="/models/mlperf/resnet50_v1.onnx" RUNS=5 @@ -18,6 +25,10 @@ while [[ $# -gt 0 ]]; do RUNS="$2" shift 2 ;; + --help) + echo "Usage: $0 --d --p [--r ]" + exit + ;; *) echo "Option $1 doesn't exist" exit 1 @@ -25,10 +36,6 @@ while [[ $# -gt 0 ]]; do esac done -#if [ -z "$MODEL_NAME" ]; then -# echo "Provide model: $0 --m " -# exit 1 -#fi mkdir "$MODEL_NAME" @@ -40,20 +47,9 @@ sed -i -e 's/half_type/int8_type/' -e 's/convolution/quant_convolution/' "$MODEL echo "NEW RUN" >> "$MODEL_NAME/times" -#while read testcase -#do -# MIGRAPHX_DISABLE_PASSES=auto_contiguous migraphx-driver time $testcase --mlir > results.out -# awk -F'[/ ]' -v t="$testcase" '/Total time/{k=$3}END{print t "," substr(k, 1, length(k)-2)}' results.out >> times -#done < "$MODEL_NAME/results.out" -# awk -F'[/ ]' -v t="$test_name" '/Total time/{k=$3}END{print t "," substr(k, 1, length(k)-2)}' "$MODEL_NAME/results.out" >> "$MODEL_NAME/times" -#done - -#test_name=$(basename "$testcase") total_time=0 for ((i = 1; i <= RUNS; i++)) @@ -70,7 +66,3 @@ do done - -# <