From 142fb46b2faaf0cca6f7176fb580991d383499ca Mon Sep 17 00:00:00 2001 From: Nikolay Puzanov Date: Sat, 17 Jun 2023 10:56:00 +0300 Subject: [PATCH] Rewrite run.sh script --- README.md | 28 ++++- run.sh | 226 +++++++++++++++++++++++++++--------- scripts/sim_vars.sh | 11 ++ source/testbench.sv | 5 +- test-iverilog/__build.sh | 4 +- test-iverilog/__run.sh | 8 +- test-iverilog/top.sv | 4 +- test-modelsim/__build.sh | 4 +- test-modelsim/__run.sh | 8 +- test-modelsim/top.sv | 4 +- test-verilator/Makefile | 4 +- test-verilator/__build.sh | 4 +- test-verilator/__run.sh | 8 +- test-xcelium/.dir-locals.el | 1 + test-xcelium/__build.sh | 8 +- test-xcelium/__run.sh | 8 +- test-xcelium/top.sv | 4 +- test-xsim/__build.sh | 5 +- test-xsim/__run.sh | 8 +- test-xsim/top.sv | 4 +- 20 files changed, 247 insertions(+), 109 deletions(-) create mode 100644 scripts/sim_vars.sh create mode 100644 test-xcelium/.dir-locals.el diff --git a/README.md b/README.md index b9a2b70..6e9e875 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Простой бенчмарк HDL симуляторов (преранняя версия) +# Простой бенчмарк HDL симуляторов (версия альфа) Для оценки скорости запускается симуляция 1024 софт-процессоров [PicoRV32](https://github.com/YosysHQ/picorv32) с программой вычисления хэш-суммы MD5 @@ -14,9 +14,29 @@ симуляторе. Скрипты называются `__build.sh` (для сборки проекта) и `__run.sh` (для запуска симуляции). -Скрипт `run.sh` запускает бенчмарк из выбранной папки или все тесты, если параметром -указать `all`. В параметрах можно указать сразу несколько папок с тестами. Результаты -бенчмарка записываются в файл `results.txt`. +Скрипт `run.sh` запускает бенчмарк из выбранной папки или все тесты. В параметрах +можно указать количество софт-ядер, размер блока, количество потоков симуляции (пока +только для верилятора) и список бенчмарков: + +``` + $ ./run.sh -h + Usage: ./run.sh [OPTION]... [SIM...] + Run simulator benchmark. Calculates MD5 hash from a block data + on an array of soft-cores PicoRV32. + + Options: + -c [COUNT] Soft CPU count in simulation. Default: 1024 + -s [SIZE] Data block size in bytes. Default: 1024 bytes + -t [COUNT] Simulation threads count. Default: 1 + (so far only for Verilator) + -l List of available benchmarks + -h This help + + The SIM parameter is the name of the simulator from the list of + option -l. If the parameter is not specified, benchmarks for all + simulators will be performed. Be careful, some simulators take + a very long time to benchmark. +``` ## Результаты для 1024 процессоров diff --git a/run.sh b/run.sh index ac3cd8f..8772435 100755 --- a/run.sh +++ b/run.sh @@ -1,65 +1,181 @@ #!/usr/bin/env bash -BUILD=__build.sh -RUN=__run.sh +## Default valies +CPU_COUNT=1024 +BLOCK_SIZE=1 +THREADS=1 -if [ "$1" == "all" ] +BLD_SCRIPT="__build.sh" +RUN_SCRIPT="__run.sh" +TEST_DIR_PREFIX="test-" +LOG_PREFIX="####" + +function sim_dir_valid() +{ + if [ -e "$1/$BLD_SCRIPT" ] && [ -e "$1/$RUN_SCRIPT" ] + then + return 0 + else + return 1 + fi +} + +function sim_list() +{ + for dir in "$TEST_DIR_PREFIX"* + do + if sim_dir_valid "$dir" + then + echo "${dir:5}" + fi + done +} + +function print_help() +{ + echo "Usage: $0 [OPTION]... [SIM...]" + echo "Run simulator benchmark. Calculates MD5 hash from a block data" + echo "on an array of soft-cores PicoRV32." + echo + echo "Options:" + echo " -c [COUNT] Soft CPU count in simulation. Default: 1024" + echo " -s [SIZE] Data block size in bytes. Default: 1024 bytes" + echo " -t [COUNT] Simulation threads count. Default: 1" + echo " (so far only for Verilator)" + echo " -l List of available benchmarks" + echo " -h This help" + echo + echo "The SIM parameter is the name of the simulator from the list of" + echo "option -l. If the parameter is not specified, benchmarks for all" + echo "simulators will be performed. Be careful, some simulators take " + echo "a very long time to benchmark." + echo +} + +function check_arg(){ + if [[ $2 == -* ]] + then + echo "Option $1 requires an argument" >&2 + exit 1 + fi +} + +function parse_param() +{ + while getopts ":c:s:t:lh" opt + do + case $opt in + c) + check_arg "-c" "$OPTARG" + CPU_COUNT=$OPTARG + ;; + s) + check_arg "-s" "$OPTARG" + BLOCK_SIZE=$OPTARG + ;; + t) + check_arg "-t" "$OPTARG" + THREADS=$OPTARG + ;; + l) + sim_list + exit 0 + ;; + h) + print_help + exit 0 + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + print_help + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument" >&2 + exit 1 + ;; + esac + done +} + +function log() +{ + echo -n "$LOG_PREFIX " + echo "$@" +} + +function run_benchmark() +{ + benchmark=$1 + dir=$TEST_DIR_PREFIX$benchmark + + if sim_dir_valid "$dir" + then + local t0 t1 ms + + if cd "$dir" + then + # Build + log "Build $benchmark" + t0=$(date +%s%N | cut -b1-13) + + if ! ./$BLD_SCRIPT "$CPU_COUNT" "$BLOCK_SIZE" "$THREADS" + then + cd .. + log "Build $benchmark FAILED" + return 1 + fi + + t1=$(date +%s%N | cut -b1-13) + ms=$((t1 - t0)) + log "Build $benchmark time (ms): $ms" + + echo + + # Run + log "Run $benchmark" + t0=$(date +%s%N | cut -b1-13) + + if ! ./$RUN_SCRIPT "$CPU_COUNT" "$BLOCK_SIZE" "$THREADS" + then + cd .. + log "RUN $benchmark FAILED" + return 1 + fi + + t1=$(date +%s%N | cut -b1-13) + ms=$((t1 - t0)) + log "Run $benchmark time (ms): $ms" + + cd .. + return 0 + else + log "Can't change dir to $dir" + return 1 + fi + else + log "No run scripts found in $dir" + return 1 + fi +} + +parse_param "$@" +shift $((OPTIND - 1)) + +if [ $# -gt 0 ] then - tests=$(ls -1d test-*) -elif [ -n "$1" ] -then - tests="$@" + benches="$*" else - echo "Usage: $0 " - exit -1 + for b in $(sim_list); do benches="$benches$b "; done fi -## Log header -echo >> results.txt -echo "---------- Simulator's benchmark -----------" >> results.txt -echo $(date) >> results.txt -echo >> results.txt +log "Soft-cores count: $CPU_COUNT" +log "Block size: $BLOCK_SIZE" +log "Threads count: $THREADS" +log "Benchmarks: $benches" -## Run tests -for test_dir in $tests +for bench in $benches do - if [ ! -d "$test_dir" ] - then - echo "Directory $test_dir is not exists" - exit -1 - fi - - if [ -e $test_dir/$BUILD -a -e $test_dir/$RUN ] - then - echo "#### Run benchmark in $test_dir" - - cd $test_dir - - ./$BUILD - if [ $? -eq 0 ] - then - start_ms=$(date +%s%N | cut -b1-13) - - ./$RUN - if [ $? -eq 0 ] - then - stop_ms=$(date +%s%N | cut -b1-13) - ms=$(expr $stop_ms - $start_ms) - echo "#### $test_dir: $ms milliseconds" - else - ms="RUN FAIL" - echo "#### $test_dir: run fail" - fi - else - ms="BUILD FAIL" - echo "#### $test_dir: build fail" - fi - - echo "" - cd .. - - echo "$test_dir: $ms" >> results.txt - else - echo "Skip $test_dir directory" - fi + echo + run_benchmark "$bench" done diff --git a/scripts/sim_vars.sh b/scripts/sim_vars.sh new file mode 100644 index 0000000..62e4627 --- /dev/null +++ b/scripts/sim_vars.sh @@ -0,0 +1,11 @@ +if [ $# -lt 3 ] +then + echo "Usage: $0