Skip to content

Commit

Permalink
Merge pull request openhwgroup#2244 from pascalgouedo/cv32e40p/dev_dd…
Browse files Browse the repository at this point in the history
…_pgo-embench

Updates to be able to run Embench on multiple configurations
  • Loading branch information
MikeOpenHWGroup authored Oct 16, 2023
2 parents 775230b + 57b7a73 commit 9ad9083
Show file tree
Hide file tree
Showing 17 changed files with 1,390 additions and 18 deletions.
101 changes: 88 additions & 13 deletions bin/run_embench.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def main():

parser = build_parser()
args = parser.parse_args()
paths = build_paths(args.core)

if args.debug == 'YES':
logger.setLevel(logging.DEBUG)
Expand All @@ -61,6 +60,14 @@ def main():
logger.info('Must specify a core to benchmark')
sys.exit(1)

if args.cfg == 'default':
core_config = 'corev32'
elif args.cfg == 'pulp':
core_config = 'corev32_pulp'
else:
logger.info(f"Invalid config selected: {args.cfg}, must be 'default' or 'pulp'")
sys.exit(1)

if args.ccomp == 'notset':
logger.info('Must specify a c compiler to benchmark')
sys.exit(1)
Expand All @@ -77,6 +84,14 @@ def main():
logger.info(f"Invalid 'parallel' option: {args.parallel}, must be 'YES' or 'NO'")
sys.exit(1)

if args.absolute == 'YES':
absolute = True
elif args.absolute == 'NO':
absolute = False
else:
logger.info(f"Invalid 'absolute' option: {args.absolute}, must be 'YES' or 'NO'")
sys.exit(1)

if args.build_only == 'YES':
build_only = True
elif args.build_only == 'NO':
Expand All @@ -85,6 +100,8 @@ def main():
logger.info(f"Invalid 'build_only' option: {args.build_only}, must be 'YES' or 'NO'")
sys.exit(1)

paths = build_paths(args.core, core_config, args.logdir, args.builddir)

logger.info("Starting EMBench for core-v-verif")
logger.info(f"Benchmarking core: {args.core}")
logger.info(f"Type of benchmark to run: {args.type}\n\n")
Expand Down Expand Up @@ -142,18 +159,37 @@ def main():
except:
logger.fatal('EMBench python module copy failed')

# copy python module
logger.info(f"Copying {paths['libpy']}/benchmark_speed.py to {paths['embench']}/benchmark_speed.py")
try:
subprocess.run(
['cp', '-pf', f"{paths['libpy']}/benchmark_speed.py", f"{paths['embench']}/benchmark_speed.py"]
)
except:
logger.fatal('EMBench benchmark_speed python script copy failed')

logger.info(f"Copying {paths['libpy']}/benchmark_size.py to {paths['embench']}/benchmark_size.py")
try:
subprocess.run(
['cp', '-pf', f"{paths['libpy']}/benchmark_size.py", f"{paths['embench']}/benchmark_size.py"]
)
except:
logger.fatal('EMBench benchmark_speed python script copy failed')

# ----------------------------------------------------------------------------------------------
# build benchmark object files (build_all.py)
# ----------------------------------------------------------------------------------------------
cmd = [f"{paths['embench']}/build_all.py",
'--arch=corev32',
'--board=corev32',
f'--arch={core_config}',
f'--board={core_config}',
f'--cflags=-I{paths["bsp"]}',
f'--chip={args.type}',
f'--cc={args.ccomp}',
f'--warmup-heat=0',
f'--cpu-mhz={args.cpu_mhz}',
f'--ldflags=-T{paths["bsp"]}/link.ld',
f'--builddir={args.builddir}',
f'--logdir={args.logdir}',
'--clean']
logger.info(f"Calling build script: {' '.join(cmd)}")
try:
Expand Down Expand Up @@ -219,14 +255,24 @@ def main():
logger.info(f"Starting benchmarking of {args.type}")

if args.type == 'speed':
arglist = [f"{paths['embench']}/benchmark_speed.py", '--target-module=run_corev32',
f'--cpu-mhz={args.cpu_mhz}', f'--make-path={paths["make"]}',
arglist = [f"{paths['embench']}/benchmark_speed.py",
f'--target-module=run_corev32',
f'-cfg={args.cfg}',
f'--cpu-mhz={args.cpu_mhz}',
f'--make-path={paths["make"]}',
f'--builddir={args.builddir}',
f'--logdir={args.logdir}',
f'--timeout={args.timeout}',
f'--simulator={args.simulator}']
if parallel:
arglist.append(f'--sim-parallel')
arglist.append(f'--sim-parallel')
else:
arglist = [f"{paths['embench']}/benchmark_size.py"]
arglist = [f"{paths['embench']}/benchmark_size.py",
f'--builddir={args.builddir}',
f'--logdir={args.logdir}']

if absolute:
arglist.append(f'--absolute')

try:
logger.info(f"Running: {' '.join(arglist)}")
Expand Down Expand Up @@ -279,13 +325,28 @@ def build_parser():
help='Core to benchmark'
)

parser.add_argument(
'-cfg',
default='default',
help='Core configuration to benchmark'
)

parser.add_argument(
'-cc',
'--ccomp',
default='notset',
help='C compiler for benchmark'
)

parser.add_argument(
'--absolute',
default='NO',
help=(
'Set this option to "YES" to report absolute numbers\n'+
'makefile alias: EMB_ABSOLUTE'
)
)

parser.add_argument(
'--parallel',
default='NO',
Expand All @@ -307,6 +368,20 @@ def build_parser():
)
)

parser.add_argument(
'--builddir',
type=str,
default='bd',
help='Directory holding all the binaries',
)

parser.add_argument(
'--logdir',
type=str,
default='logs',
help='Directory in which to store logs',
)

parser.add_argument(
'-b',
'--build-only',
Expand Down Expand Up @@ -373,21 +448,21 @@ def build_parser():

return parser

def build_paths(core):
def build_paths(core, core_config, logdir, builddir):
"""map out necessary paths"""
paths = dict()
paths['cver'] = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
paths['core'] = paths['cver'] + '/' + core
paths['libcfg'] = paths['core'] + '/tests/embench/config/corev32'
paths['libcfg'] = paths['core'] + '/tests/embench/config/' + core_config
paths['libpy'] = paths['core'] + '/tests/embench/pylib'
paths['vlib'] = paths['core'] + '/vendor_lib'
paths['emb_logs'] = paths['core'] + '/vendor_lib/embench/logs'
paths['emb_logs'] = logdir
paths['make'] = paths['core'] + '/sim/uvmt'
paths['embench'] = paths['vlib'] + '/embench'
paths['emcfg'] = paths['embench'] + '/config/corev32'
paths['emcfg'] = paths['embench'] + '/config/' + core_config
paths['empy'] = paths['embench'] + '/pylib'
paths['embrd'] = paths['emcfg'] + '/boards/corev32'
paths['emres'] = paths['embench'] + '/bd/src'
paths['embrd'] = paths['emcfg'] + '/boards/' + core_config
paths['emres'] = builddir + '/src'
paths['bsp'] = paths['core'] + '/bsp'
paths['testsem'] = paths['core'] + '/tests/programs/embench'

Expand Down
4 changes: 2 additions & 2 deletions cv32e40p/tests/embench/config/corev32/chips/size/chip.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@
# - we garbage collect unused sections on linking

cflags = [
'-c', '-Os', '-ffunction-sections', '-mabi=ilp32', '-march=rv32imc'
'-c', '-Os', '-ffunction-sections', '-mabi=ilp32', '-march=rv32imc_zicsr'
]

ldflags = [
'-Wl,-gc-sections', '-Wl,-A,elf32lriscv', '-nostartfiles', '-nostdlib', '-mabi=ilp32', '-march=rv32imc'
'-Wl,-gc-sections', '-Wl,-A,elf32lriscv', '-nostartfiles', '-nostdlib', '-mabi=ilp32', '-march=rv32imc_zicsr'
]

dummy_libs = ['crt0', 'libm', 'libc', 'libgcc']
4 changes: 2 additions & 2 deletions cv32e40p/tests/embench/config/corev32/chips/speed/chip.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@
# - we garbage collect unused sections on linking

cflags = [
'-c', '-O2', '-ffunction-sections', '-mabi=ilp32', '-march=rv32im'
'-c', '-O2', '-ffunction-sections', '-mabi=ilp32', '-march=rv32im_zicsr'
]

ldflags = [
'-Wl,-gc-sections', '-Wl,-A,elf32lriscv', '-nostartfiles', '-mabi=ilp32', '-march=rv32im'
'-Wl,-gc-sections', '-Wl,-A,elf32lriscv', '-nostartfiles', '-mabi=ilp32', '-march=rv32im_zicsr'
]
user_libs = ['-lm']

Expand Down
67 changes: 67 additions & 0 deletions cv32e40p/tests/embench/config/corev32_pulp/arch.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
###############################################################################
#
# Copyright 2020 OpenHW Group
#
# Licensed under the Solderpad Hardware Licence, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://solderpad.org/licenses/
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.0
#
###############################################################################

# This is a python setting of parameters for the architecture. The following
# parameters may be set (other keys are silently ignored). Defaults are shown
# in brackets
# - cc ('cc')
# - ld (same value as for cc)
# - cflags ([])
# - ldflags ([])
# - cc_define_pattern ('-D{0}')
# - cc_incdir_pattern ('-I{0}')
# - cc_input_pattern ('{0}')
# - cc_output_pattern ('-o {0}')
# - ld_input_pattern ('{0}')
# - ld_output_pattern ('-o {0}')
# - user_libs ([])
# - dummy_libs ([])
# - cpu_mhz (1)
# - warmup_heat (1)

# The "flags" and "libs" parameters (cflags, ldflags, user_libs, dummy_libs)
# should be lists of arguments to be passed to the compile or link line as
# appropriate. Patterns are Python format patterns used to create arguments.
# Thus for GCC or Clang/LLVM defined constants can be passed using the prefix
# '-D', and the pattern '-D{0}' would be appropriate (which happens to be the
# default).

# "user_libs" may be absolute file names or arguments to the linker. In the
# latter case corresponding arguments in ldflags may be needed. For example
# with GCC or Clang/LLVM is "-l" flags are used in "user_libs", the "-L" flags
# may be needed in "ldflags".

# Dummy libs have their source in the "support" subdirectory. Thus if 'crt0'
# is specified, there should be a source file 'dummy-crt0.c' in the support
# directory.

# There is no need to set an unused parameter, and this file may be empty to
# set no flags.

# Parameter values which are duplicated in architecture, board, chip or
# command line are used in the following order of priority
# - default value
# - architecture specific value
# - chip specific value
# - board specific value
# - command line value

# For flags, this priority is applied to individual flags, not the complete
# list of flags.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
###############################################################################
#
# Copyright 2020 OpenHW Group
#
# Licensed under the Solderpad Hardware Licence, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://solderpad.org/licenses/
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.0
#
###############################################################################

# This is a python setting of parameters for the board. The following
# parameters may be set (other keys are silently ignored). Defaults are shown
# in brackets
# - cc ('cc')
# - ld (same value as for cc)
# - cflags ([])
# - ldflags ([])
# - cc_define_pattern ('-D{0}')
# - cc_incdir_pattern ('-I{0}')
# - cc_input_pattern ('{0}')
# - cc_output_pattern ('-o {0}')
# - ld_input_pattern ('{0}')
# - ld_output_pattern ('-o {0}')
# - user_libs ([])
# - dummy_libs ([])
# - cpu_mhz (1)
# - warmup_heat (1)

# The "flags" and "libs" parameters (cflags, ldflags, user_libs, dummy_libs)
# should be lists of arguments to be passed to the compile or link line as
# appropriate. Patterns are Python format patterns used to create arguments.
# Thus for GCC or Clang/LLVM defined constants can be passed using the prefix
# '-D', and the pattern '-D{0}' would be appropriate (which happens to be the
# default).

# "user_libs" may be absolute file names or arguments to the linker. In the
# latter case corresponding arguments in ldflags may be needed. For example
# with GCC or Clang/LLVM is "-l" flags are used in "user_libs", the "-L" flags
# may be needed in "ldflags".

# Dummy libs have their source in the "support" subdirectory. Thus if 'crt0'
# is specified, there should be a source file 'dummy-crt0.c' in the support
# directory.

# There is no need to set an unused parameter, and this file may be empty to
# set no flags.

# Parameter values which are duplicated in architecture, board, chip or
# command line are used in the following order of priority
# - default value
# - architecture specific value
# - chip specific value
# - board specific value
# - command line value

# For flags, this priority is applied to individual flags, not the complete
# list of flags.

cpu_mhz = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
**
** Copyright 2020 OpenHW Group
**
** Licensed under the Solderpad Hardware Licence, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** https://solderpad.org/licenses/
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
**
*******************************************************************************
*/

#include "boardsupport.h"

Loading

0 comments on commit 9ad9083

Please sign in to comment.