From 8bd8d1f53abaacbe055b11f5af04071309a0ca02 Mon Sep 17 00:00:00 2001 From: Marcel Koch <marcel.koch@uni-muenster.de> Date: Mon, 18 Feb 2019 14:55:28 +0100 Subject: [PATCH] add instrumentation level 4 --- .../loopy/transformations/instrumentation.py | 38 ++++++++++--------- python/dune/codegen/pdelab/driver/timings.py | 18 +++++++++ 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/python/dune/codegen/loopy/transformations/instrumentation.py b/python/dune/codegen/loopy/transformations/instrumentation.py index 7b13a09e..2fab53a6 100644 --- a/python/dune/codegen/loopy/transformations/instrumentation.py +++ b/python/dune/codegen/loopy/transformations/instrumentation.py @@ -1,9 +1,11 @@ """ Add instrumentation instructions to a kernel """ from dune.codegen.generation import (dump_accumulate_timer, + register_liwkid_timer, post_include, ) from dune.codegen.options import get_option +from dune.codegen.pdelab.driver.timings import start_region_timer_instruction, stop_region_timer_instruction import loopy as lp @@ -67,28 +69,25 @@ def add_instrumentation(knl, match, identifier, level, filetag='operatorfile', o # Define the start instruction and correct dependencies for it start_id = "{}_start".format(ident) start_depends = _union(tuple(i.depends_on for i in insns)).difference(frozenset(i.id for i in insns)) - start_insn = lp.CInstruction([], - "HP_TIMER_START({});".format(identifier), - id=start_id, - within_inames=within, - depends_on=depends_on.union(start_depends), - boostable_into=frozenset(), - tags=uniontags, - ) + start_insn = start_region_timer_instruction(identifier, + id=start_id, + within_inames=within, + depends_on=depends_on.union(start_depends), + boostable_into=frozenset(), + tags=uniontags,) # Add dependencies on the timing instructions rewritten_insns.extend([i.copy(depends_on=i.depends_on.union(frozenset({start_id}))) for i in insns]) # Define the stop instruction and correct dependencies for it stop_id = "{}_stop".format(ident) - stop_insn = lp.CInstruction([], - "HP_TIMER_STOP({});".format(identifier), - id=stop_id, - within_inames=within, - depends_on=frozenset(i.id for i in insns), - boostable_into=frozenset(), - tags=uniontags, - ) + stop_insn = stop_region_timer_instruction(identifier, + id=stop_id, + within_inames=within, + depends_on=frozenset(i.id for i in insns), + boostable_into=frozenset(), + tags=uniontags, + ) # Find all the instructions that should depend on stop dep_insns = filter(lambda i: _intersect((i.depends_on, frozenset(i.id for i in insns))), @@ -97,8 +96,11 @@ def add_instrumentation(knl, match, identifier, level, filetag='operatorfile', o rewritten_insns.extend([i.copy(depends_on=i.depends_on.union(frozenset({stop_id}))) for i in dep_insns]) # Trigger code generation on the file/operator level - post_include('HP_DECLARE_TIMER({});'.format(identifier), filetag=filetag) - dump_accumulate_timer(identifier) + if get_option("use_likwid"): + register_liwkid_timer(identifier) + else: + post_include('HP_DECLARE_TIMER({});'.format(identifier), filetag=filetag) + dump_accumulate_timer(identifier) # Filter all the instructions which were untouched other_insns = list(filter(lambda i: i.id not in [j.id for j in rewritten_insns], knl.instructions)) diff --git a/python/dune/codegen/pdelab/driver/timings.py b/python/dune/codegen/pdelab/driver/timings.py index 4dbc29b3..c4c7bd3f 100644 --- a/python/dune/codegen/pdelab/driver/timings.py +++ b/python/dune/codegen/pdelab/driver/timings.py @@ -190,6 +190,24 @@ def stop_region_timer(region): "DUMP_TIMER({}, {}, {}, true);".format(get_option("instrumentation_level"), region, timestream)] +def start_region_timer_instruction(region, **kwargs): + if get_option("use_likwid"): + code = "LIKWID_MARKER_START(\"{}\");".format(region) + else: + code = "HP_TIMER_START({});".format(region) + from loopy import CInstruction + return CInstruction([], code, **kwargs) + + +def stop_region_timer_instruction(region, **kwargs): + if get_option("use_likwid"): + code = "LIKWID_MARKER_STOP(\"{}\");".format(region) + else: + code = "HP_TIMER_STOP({});".format(region) + from loopy import CInstruction + return CInstruction([], code, **kwargs) + + def timed_region(region, actions): if isinstance(actions, str): actions = [actions] -- GitLab