build_benchmark.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/bin/env bash
  2. simulation=${simulation:-1}
  3. simu=${simu:-xlspike}
  4. silent=${silent:-1}
  5. parallel=${parallel:-"-j"}
  6. SCRIPTDIR=$(dirname $(readlink -f $BASH_SOURCE))
  7. SCRIPTDIR=$(readlink -f $SCRIPTDIR)
  8. COMMON_ENV=$(readlink -f $SCRIPTDIR/env.sh)
  9. source $COMMON_ENV
  10. gen_logdir benchmark
  11. describe_env
  12. function do_bench {
  13. local bench=$1
  14. local core=$2
  15. local series=$3
  16. local stdclib=$4
  17. local bench_rstloc=$5
  18. if [[ "x$bench_rstloc" != "x" ]] ; then
  19. bench_rstloc=$(readlink -f $bench_rstloc)
  20. fi
  21. pushd $bench
  22. export CORE=$core CPU_SERIES=$series STDCLIB=$stdclib SIMULATION=$simulation SILENT=$silent SIMU=$simu
  23. echo "Build $bench for CORE=$core CPU_SERIES=$series STDCLIB=$stdclib SIMULATION=$simulation SIMU=$simu SILENT=$silent"
  24. if [ "x$DRYRUN" == "x0" ] ; then
  25. make clean
  26. echo "record build log in $bench_rstloc/build.log"
  27. make $parallel info showflags dasm > $bench_rstloc/build.log 2>&1
  28. if [ $? == 0 ] && [[ "x$bench_rstloc" != "x" ]] ; then
  29. cp -f $bench.verilog $bench_rstloc
  30. cp -f $bench.dump $bench_rstloc
  31. cp -f $bench.elf $bench_rstloc
  32. fi
  33. fi
  34. unset CORE CPU_SERIES STDCLIB SIMULATION SILENT SIMU
  35. popd
  36. }
  37. function do_all_benches {
  38. local genloc=${1:-$gen_elf_loc}
  39. for core_series in n203-200 n300-300 n300fd-300 n600-600 n600fd-600 n900-900 n900fd-900 nx600-600 nx600fd-600 nx900-900 nx900fd-900 ux1000fd-1000
  40. do
  41. for stdclib in newlib_small libncrt_small
  42. do
  43. for bench in coremark whetstone dhrystone
  44. do
  45. tmparr=(${core_series//-/ })
  46. core=${tmparr[0]} series=${tmparr[1]}
  47. if [[ "$core" == *"x"* ]] && [[ "$stdclib" == "libncrt"* ]] ; then
  48. echo "Ignore build for $bench: CORE=$core CPU_SERIES=$series STDCLIB=$stdclib"
  49. else
  50. echo "Do build for $bench: CORE=$core CPU_SERIES=$series STDCLIB=$stdclib"
  51. bench_rstloc=$genloc/$bench/${core}_${stdclib}
  52. mkdir -p $bench_rstloc
  53. pushd application/baremetal/benchmark
  54. if [[ "$bench" == "dhrystone" ]] ; then
  55. for dhry_mode in ground inline best
  56. do
  57. export DHRY_MODE=$dhry_mode
  58. echo "Do build for dhrystone DHRY_MODE=$dhry_mode"
  59. dhry_bench_rstloc=${bench_rstloc}/${dhry_mode}
  60. mkdir -p $dhry_bench_rstloc
  61. do_bench $bench $core $series $stdclib $dhry_bench_rstloc
  62. unset DHRY_MODE
  63. done
  64. else
  65. do_bench $bench $core $series $stdclib $bench_rstloc
  66. fi
  67. popd
  68. fi
  69. done
  70. done
  71. done
  72. }
  73. function dobench_for_runmode {
  74. local genloc=${1:-$gen_elf_loc}
  75. for runmode in "" lm icdlm dcilm cache bus clm
  76. do
  77. echo "Generate RUNMODE=$runmode"
  78. export RUNMODE=$runmode
  79. if [ "x$RUNMODE" == "x" ] ; then
  80. runmode=default
  81. fi
  82. # for runmode=cache, need to run on sram area
  83. if [ "x$RUNMODE" == "xcache" ] ; then
  84. export DOWNLOAD=sram
  85. fi
  86. do_all_benches $genloc/$runmode
  87. unset RUNMODE DOWNLOAD
  88. done
  89. }
  90. function collect_buildinfo {
  91. local benchbuild=$1
  92. date -u +"Build time: %Y-%m-%d, %H:%M:%S" >> $benchbuild
  93. echo "Nuclei SDK Version: on $(git rev-parse --abbrev-ref HEAD) branch, $(git describe --always --abbrev=10 --dirty --tags 2>&1)" >> $benchbuild
  94. echo -n "GCC Version: " >> $benchbuild
  95. riscv-nuclei-elf-gcc -v >> $benchbuild 2>&1
  96. riscv64-unknown-elf-gcc -v >> $benchbuild 2>&1
  97. }
  98. gen_elf_loc=${LOGDIR}
  99. gen_elf_loc=$(readlink -f $gen_elf_loc)
  100. benchbuild=$gen_elf_loc/build.txt
  101. benchlog=$gen_elf_loc/build.log
  102. pushd $NSDK_ROOT
  103. #echo "Do all benchmarks and generate bench to folder ${gen_elf_loc}"
  104. #do_all_benches | tee ${benchlog}
  105. echo "Do all benchmarks and generate bench for various RUNMODE to folder ${gen_elf_loc}"
  106. dobench_for_runmode | tee ${benchlog}
  107. echo "Collect bench build information"
  108. collect_buildinfo $benchbuild
  109. popd
  110. echo "collect all generated elf and verilog files to $LOGZIP"
  111. zip_logdir