Skip to content

Commit

Permalink
Automatically run a profiler with the executable
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed Nov 1, 2024
1 parent 939514f commit 61dc564
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions benchmarks/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class SpackTest(rfm.RegressionTest):
build_system = 'Spack'
spack_spec = variable(str, value='', loggable=True)
spack_spec_dict = variable(str, value='', loggable=True)
profiler = variable(str, value='', loggable=True)

@run_before('compile')
def setup_spack_environment(self):
Expand Down Expand Up @@ -274,7 +275,7 @@ def setup_spack_environment(self):
result_dict = {spec.name: {"compiler": {"name": spec.compiler.name, "version": str(spec.compiler.versions).lstrip("=")}, "variants": {key: str(spec.variants.dict[key].value) if isinstance(spec.variants.dict[key].value, bool) else "" if spec.variants.dict[key].value is None else list(spec.variants.dict[key].value) if isinstance(spec.variants.dict[key].value, tuple) else spec.variants.dict[key].value for key in key_list_for_each[i]},"mpi":str(spec["mpi"]) if "mpi" in spec else "" } for i, spec in enumerate(spec_list)};\
print(result_dict)'
self.postrun_cmds.append(f'echo "spack_spec_dict: $(spack -e {self.build_system.environment} python -c \'{cmd_spack_spec_dict}\')"')

# Keep the `spack.lock` file in the output directory so that the Spack
# environment can be faithfully reproduced later.
self.keep_files.append(os.path.realpath(os.path.join(self.build_system.environment, 'spack.lock')))
Expand All @@ -287,13 +288,38 @@ def get_full_variants(self):
# convert all single quotes to double quotes since JSON does not recognise it
self.spack_spec_dict = self.spack_spec_dict.replace("'", "\"")


@run_before('compile')
def setup_build_system(self):
# The `self.spack_spec` attribute is the user-facing and loggable
# variable we use for setting the Spack spec, but then we need to
# forward its value to `self.build_system.specs`, which is the way to
# inform ReFrame which Spack specs to use.
self.build_system.specs = [self.spack_spec]
self.build_system.specs.append(self.spack_spec)


@run_before('compile')
def add_profiler(self):
if self.profiler:
if self.profiler == 'vtune':
# Spack package providing the profiler
self.build_system.specs.append('intel-oneapi-vtune')
# Name of output directort
vtune_out_dir = 'vtune-profiling'
# Prepend VTune call to the executable
self.executable = f'vtune -collect hotspots -r {vtune_out_dir} -- ' + self.executable
# Save the output directory
self.keep_files.append(vtune_out_dir)
elif self.profiler == 'nsight':
# Spack package providing the profiler
self.build_system.specs.append('nvidia-nsight-systems')
# Name of output file
nsys_out_file = 'nsys-trace'
# Prepend nsys call to the executable
self.executable = f'nsys profile --trace=cuda,mpi,nvtx,openmp,osrt,opengl,syscall --output {nsys_out_file} ' + self.executable
# Save the output file
self.keep_files.append(f'{nsys_out_file}.nsys-rep')


@run_before('compile')
def set_sge_num_slots(self):
Expand Down

0 comments on commit 61dc564

Please # to comment.