Пример #1
0
def run_raw(project, experiment, config, run_f, args, **kwargs):
    """
    Run the given binary wrapped with nothing.

    Args:
        project: The benchbuild.project.
        experiment: The benchbuild.experiment.
        config: The benchbuild.settings.config.
        run_f: The file we want to execute.
        args: List of arguments that should be passed to the wrapped binary.
        **kwargs: Dictionary with our keyword args. We support the following
            entries:

            project_name: The real name of our project. This might not
                be the same as the configured project name, if we got wrapped
                with ::benchbuild.project.wrap_dynamic
            has_stdin: Signals whether we should take care of stdin.
    """
    from benchbuild.utils.run import guarded_exec, handle_stdin
    from benchbuild.settings import CFG as c

    c.update(config)
    project.name = kwargs.get("project_name", project.name)

    run_cmd = local[run_f]
    run_cmd = r.handle_stdin(run_cmd[args], kwargs)
    with guarded_exec(run_cmd, project, experiment) as run:
        run()
Пример #2
0
def run_raw(project, experiment, config, run_f, args, **kwargs):
    """
    Run the given binary wrapped with nothing.

    Args:
        project: The benchbuild.project.
        experiment: The benchbuild.experiment.
        config: The benchbuild.settings.config.
        run_f: The file we want to execute.
        args: List of arguments that should be passed to the wrapped binary.
        **kwargs: Dictionary with our keyword args. We support the following
            entries:

            project_name: The real name of our project. This might not
                be the same as the configured project name, if we got wrapped
                with ::benchbuild.project.wrap_dynamic
            has_stdin: Signals whether we should take care of stdin.
    """
    from benchbuild.utils.run import track_execution
    from benchbuild.utils.run import handle_stdin
    from benchbuild.settings import CFG

    CFG.update(config)
    project.name = kwargs.get("project_name", project.name)

    run_cmd = local[run_f]
    run_cmd = handle_stdin(run_cmd[args], kwargs)
    with track_execution(run_cmd, project, experiment) as run:
        run()
Пример #3
0
    def main(self, *args):
        del args  # Unused

        print("Checking benchbuild binary dependencies...")
        provide_package("cmake")
        provide_package("fusermount")
        provide_package("unionfs")
        provide_package("postgres")

        has_uchroot = find_package("uchroot")
        if not has_uchroot:
            install_uchroot()
            has_uchroot = find_package("uchroot")
            if not has_uchroot:
                print("NOT INSTALLED")
        if has_uchroot:
            check_uchroot_config()

        provide_packages([
            "mkdir", "git", "tar", "mv", "rm", "bash", "rmdir", "time",
            "chmod", "cp", "ln", "make", "unzip", "cat", "patch", "find",
            "echo", "grep", "sed", "sh", "autoreconf", "ruby", "curl", "tail",
            "kill", "virtualenv", "timeout"
        ])

        if self.store_config:
            config_path = ".benchbuild.yml"
            CFG.store(config_path)
            print("Storing config in {0}".format(os.path.abspath(config_path)))
            exit(0)
Пример #4
0
def collect_compilestats(project, experiment, config, clang, **kwargs):
    """Collect compilestats."""
    from benchbuild.utils.run import guarded_exec, handle_stdin
    from benchbuild.settings import CFG as c
    from benchbuild.utils.db import persist_compilestats
    from benchbuild.utils.schema import CompileStat

    c.update(config)
    clang = handle_stdin(clang["-mllvm", "-stats"], kwargs)

    with local.env(BB_ENABLE=0):
        with guarded_exec(clang, project, experiment) as run:
            ri = run()


    if ri.retcode == 0:
        stats = []
        for stat in get_compilestats(ri.stderr):
            compile_s = CompileStat()
            compile_s.name = stat["desc"].rstrip()
            compile_s.component = stat["component"].rstrip()
            compile_s.value = stat["value"]
            stats.append(compile_s)

        components = c["cs"]["components"].value()
        if components is not None:
            stats = [s for s in stats if str(s.component) in components]
        names = c["cs"]["names"].value()
        if names is not None:
            stats = [s for s in stats if str(s.name) in names]

        persist_compilestats(ri.db_run, ri.session, stats)
Пример #5
0
        def _track_compilestats(project, experiment, config, clang, **kwargs):
            """Compile the project and track the compilestats."""
            from benchbuild.settings import CFG
            from benchbuild.utils.run import handle_stdin

            CFG.update(config)
            clang = handle_stdin(clang["-mllvm", "-polli-collect-modules"],
                                 kwargs)
            with track_execution(clang, project, experiment) as run:
                run()
Пример #6
0
        def _track_compilestats(project, experiment, config, clang,
                                **kwargs):
            """ Compile the project and track the compilestats. """
            from benchbuild.settings import CFG as c
            from benchbuild.utils.run import handle_stdin

            c.update(config)
            clang = handle_stdin(clang["-mllvm", "-polli-collect-modules"],
                                 kwargs)
            with guarded_exec(clang, project, experiment) as run:
                run()
Пример #7
0
def run_without_recompile(project, experiment, config, jobs, run_f, args,
                          **kwargs):
    """
    Run the given binary wrapped with time.

    Args:
        project: The benchbuild.project.
        experiment: The benchbuild.experiment.
        config: The benchbuild.settings.config.
        jobs: Number of cores we should use for this exection.
        run_f: The file we want to execute.
        args: List of arguments that should be passed to the wrapped binary.
        **kwargs: Dictionary with our keyword args. We support the following
            entries:

            project_name: The real name of our project. This might not
                be the same as the configured project name, if we got wrapped
                with ::benchbuild.project.wrap_dynamic
            has_stdin: Signals whether we should take care of stdin.
    """
    from benchbuild.utils.run import track_execution, fetch_time_output
    from benchbuild.settings import CFG
    from benchbuild.utils.db import persist_time, persist_config

    CFG.update(config)
    project.name = kwargs.get("project_name", project.name)
    timing_tag = "BB-JIT: "

    may_wrap = kwargs.get("may_wrap", True)

    run_cmd = local[run_f]
    run_cmd = run_cmd[args]
    if may_wrap:
        run_cmd = time["-f", timing_tag + "%U-%S-%e", run_cmd]

    with local.env(OMP_NUM_THREADS=str(jobs),
                   POLLI_LOG_FILE=CFG["slurm"]["extra_log"].value()):
        with track_execution(run_cmd, project, experiment) as run:
            ri = run()

        if may_wrap:
            timings = fetch_time_output(timing_tag,
                                        timing_tag + "{:g}-{:g}-{:g}",
                                        ri.stderr.split("\n"))
            if timings:
                persist_time(ri.db_run, ri.session, timings)
    persist_config(
        ri.db_run, ri.session, {
            "cores": str(jobs - 1),
            "cores-config": str(jobs),
            "recompilation": "disabled"
        })
    return ri
Пример #8
0
def run_with_time(project, experiment, config, jobs, run_f, args, **kwargs):
    """
    Run the given binary wrapped with time.

    Args:
        project: The benchbuild project that has called us.
        experiment: The benchbuild experiment which we operate under.
        config: The benchbuild configuration we are running with.
        jobs: The number of cores we are allowed to use. This may differ
            from the actual amount of available cores, obey it.
            We should enforce this from the outside. However, at the moment we
            do not do this.
        run_f: The file we want to execute.
        args: List of arguments that should be passed to the wrapped binary.
        **kwargs: Dictionary with our keyword args. We support the following
            entries:

            project_name: The real name of our project. This might not
                be the same as the configured project name, if we got wrapped
                with ::benchbuild.project.wrap_dynamic
            has_stdin: Signals whether we should take care of stdin.
            may_wrap:
                Project may signal that it they are not suitable for
                wrapping. Usually because they scan/parse the output, which
                may interfere with the output of the wrapper binary.
    """
    CFG.update(config)
    project.name = kwargs.get("project_name", project.name)
    timing_tag = "BB-TIME: "

    may_wrap = kwargs.get("may_wrap", True)

    run_cmd = local[run_f]
    run_cmd = run_cmd[args]
    if may_wrap:
        run_cmd = time["-f", timing_tag + "%U-%S-%e", run_cmd]

    def handle_timing_info(ri):
        if may_wrap:
            timings = fetch_time_output(timing_tag,
                                        timing_tag + "{:g}-{:g}-{:g}",
                                        ri.stderr.split("\n"))
            if timings:
                persist_time(ri.db_run, ri.session, timings)
            else:
                logging.warn("No timing information found.")
        return ri

    with track_execution(run_cmd, project, experiment, **kwargs) as run:
        ri = handle_timing_info(run())
    persist_config(ri.db_run, ri.session, {"cores": str(jobs)})
    return ri
Пример #9
0
def bb_cfg() -> s.Configuration:
    """Get the current benchbuild config."""
    global _BB_CFG  # pylint: disable=global-statement
    if not _BB_CFG:
        from benchbuild.settings import CFG as BB_CFG  # pylint: disable=C0415
        add_vara_experiment_options(BB_CFG, vara_cfg())
        bb_root = str(vara_cfg()["benchbuild_root"])
        if bb_root:
            bb_cfg_path = Path(bb_root) / ".benchbuild.yml"
            if bb_cfg_path.exists():
                BB_CFG.load(local.path(bb_cfg_path))
        _BB_CFG = BB_CFG
    return _BB_CFG
Пример #10
0
 def main(self, *args):
     print("Checking container binary dependencies...")
     if not bootstrap.find_package("uchroot"):
         if not bootstrap.find_package("cmake"):
             self.install_cmake_and_exit()
         bootstrap.install_uchroot()
     print("...OK")
     config_file = str(CFG["config_file"])
     if not (config_file and os.path.exists(config_file)):
         config_file = ".benchbuild.json"
     CFG.store(config_file)
     print("Storing config in {0}".format(os.path.abspath(config_file)))
     print(
         "Future container commands from this directory will automatically"
         " source the config file.")
Пример #11
0
 def main(self, *args):
     print("Checking container binary dependencies...")
     if not find_package("uchroot"):
         if not find_package("cmake"):
             self.install_cmake_and_exit()
         install_uchroot()
     print("...OK")
     config_file = CFG["config_file"].value()
     if not (config_file and os.path.exists(config_file)):
         config_file = ".benchbuild.json"
     CFG.store(config_file)
     print("Storing config in {0}".format(os.path.abspath(config_file)))
     print(
         "Future container commands from this directory will automatically"
         " source the config file.")
Пример #12
0
def run_with_likwid(project, experiment, config, jobs, run_f, args, **kwargs):
    """
    Run the given file wrapped by likwid.

    Args:
        project: The benchbuild.project.
        experiment: The benchbuild.experiment.
        config: The benchbuild.settings.config.
        jobs: Number of cores we should use for this exection.
        run_f: The file we want to execute.
        args: List of arguments that should be passed to the wrapped binary.
        **kwargs: Dictionary with our keyword args. We support the following
            entries:

            project_name: The real name of our project. This might not
                be the same as the configured project name, if we got wrapped
                with ::benchbuild.project.wrap_dynamic
            has_stdin: Signals whether we should take care of stdin.
    """
    from benchbuild.settings import CFG
    from benchbuild.utils.run import track_execution, handle_stdin
    from benchbuild.utils.db import persist_likwid, persist_config
    from benchbuild.likwid import get_likwid_perfctr

    CFG.update(config)
    project.name = kwargs.get("project_name", project.name)
    likwid_f = project.name + ".txt"

    for group in ["CLOCK"]:
        likwid_path = path.join(CFG["likwiddir"], "bin")
        likwid_perfctr = local[path.join(likwid_path, "likwid-perfctr")]
        run_cmd = \
            likwid_perfctr["-O", "-o", likwid_f, "-m",
                           "-C", "0-{0:d}".format(jobs),
                           "-g", group, run_f]
        run_cmd = handle_stdin(run_cmd[args], kwargs)

        with local.env(POLLI_ENABLE_LIKWID=1):
            with track_execution(run_cmd, project, experiment) as run:
                ri = run()

        likwid_measurement = get_likwid_perfctr(likwid_f)
        persist_likwid(run, ri.session, likwid_measurement)
        persist_config(run, ri.session, {
            "cores": str(jobs),
            "likwid.group": group
        })
        rm("-f", likwid_f)
Пример #13
0
def run_with_likwid(project, experiment, config, jobs, run_f, args, **kwargs):
    """
    Run the given file wrapped by likwid.

    Args:
        project: The benchbuild.project.
        experiment: The benchbuild.experiment.
        config: The benchbuild.settings.config.
        jobs: Number of cores we should use for this exection.
        run_f: The file we want to execute.
        args: List of arguments that should be passed to the wrapped binary.
        **kwargs: Dictionary with our keyword args. We support the following
            entries:

            project_name: The real name of our project. This might not
                be the same as the configured project name, if we got wrapped
                with ::benchbuild.project.wrap_dynamic
            has_stdin: Signals whether we should take care of stdin.
    """
    from benchbuild.settings import CFG as c
    from benchbuild.utils.run import guarded_exec, handle_stdin
    from benchbuild.utils.db import persist_likwid, persist_config
    from benchbuild.likwid import get_likwid_perfctr

    c.update(config)
    project.name = kwargs.get("project_name", project.name)
    likwid_f = project_name + ".txt"

    for group in ["CLOCK"]:
        likwid_path = path.join(c["likwiddir"], "bin")
        likwid_perfctr = local[path.join(likwid_path, "likwid-perfctr")]
        run_cmd = \
            likwid_perfctr["-O", "-o", likwid_f, "-m",
                           "-C", "0-{0:d}".format(jobs),
                           "-g", group, run_f]
        run_cmd = handle_stdin(run_cmd[args], kwargs)

        with local.env(POLLI_ENABLE_LIKWID=1):
            with guarded_exec(run_cmd, project, experiment) as run:
                ri = run()

        likwid_measurement = get_likwid_perfctr(likwid_f)
        persist_likwid(run, ri.session, likwid_measurement)
        persist_config(run, ri.session, {
            "cores": str(jobs),
            "likwid.group": group
        })
        rm("-f", likwid_f)
Пример #14
0
def run_with_perf(project, experiment, config, jobs, run_f, args, **kwargs):
    """
    Run the given binary wrapped with time.

    Args:
        project: The benchbuild.project.
        experiment: The benchbuild.experiment.
        config: The benchbuild.settings.config.
        jobs: Number of cores we should use for this exection.
        run_f: The file we want to execute.
        args: List of arguments that should be passed to the wrapped binary.
        **kwargs: Dictionary with our keyword args. We support the following
            entries:

            project_name: The real name of our project. This might not
                be the same as the configured project name, if we got wrapped
                with ::benchbuild.project.wrap_dynamic
            has_stdin: Signals whether we should take care of stdin.
    """
    from benchbuild.settings import CFG as c
    from benchbuild.utils.run import guarded_exec, handle_stdin
    from benchbuild.utils.db import persist_perf, persist_config
    from plumbum.cmd import perf

    c.update(config)
    project.name = kwargs.get("project_name", project.name)
    run_cmd = local[run_f]
    run_cmd = handle_stdin(run_cmd[args], kwargs)
    run_cmd = perf["record", "-q", "-F", 6249, "-g", run_cmd]

    with local.env(OMP_NUM_THREADS=str(jobs)):
        with guarded_exec(run_cmd, project, experiment) as run:
            ri = run(retcode=None)

        fg_path = path.join(c["src_dir"], "extern/FlameGraph")
        if path.exists(fg_path):
            sc_perf = local[path.join(fg_path, "stackcollapse-perf.pl")]
            flamegraph = local[path.join(fg_path, "flamegraph.pl")]

            fold_cmd = ((perf["script"] | sc_perf) > run_f + ".folded")
            graph_cmd = (flamegraph[run_f + ".folded"] > run_f + ".svg")

            fold_cmd()
            graph_cmd()
            persist_perf(ri.db_run, ri.session, run_f + ".svg")
            persist_config(ri.db_run, ri.session, {"cores": str(jobs)})
Пример #15
0
def run_with_perf(project, experiment, config, jobs, run_f, args, **kwargs):
    """
    Run the given binary wrapped with time.

    Args:
        project: The benchbuild.project.
        experiment: The benchbuild.experiment.
        config: The benchbuild.settings.config.
        jobs: Number of cores we should use for this exection.
        run_f: The file we want to execute.
        args: List of arguments that should be passed to the wrapped binary.
        **kwargs: Dictionary with our keyword args. We support the following
            entries:

            project_name: The real name of our project. This might not
                be the same as the configured project name, if we got wrapped
                with ::benchbuild.project.wrap_dynamic
            has_stdin: Signals whether we should take care of stdin.
    """
    from benchbuild.settings import CFG
    from benchbuild.utils.run import track_execution, handle_stdin
    from benchbuild.utils.db import persist_perf, persist_config
    from benchbuild.utils.cmd import perf

    CFG.update(config)
    project.name = kwargs.get("project_name", project.name)
    run_cmd = local[run_f]
    run_cmd = handle_stdin(run_cmd[args], kwargs)
    run_cmd = perf["record", "-q", "-F", 6249, "-g", run_cmd]

    with local.env(OMP_NUM_THREADS=str(jobs)):
        with track_execution(run_cmd, project, experiment) as run:
            ri = run(retcode=None)

        fg_path = path.join(CFG["src_dir"], "extern/FlameGraph")
        if path.exists(fg_path):
            sc_perf = local[path.join(fg_path, "stackcollapse-perf.pl")]
            flamegraph = local[path.join(fg_path, "flamegraph.pl")]

            fold_cmd = ((perf["script"] | sc_perf) > run_f + ".folded")
            graph_cmd = (flamegraph[run_f + ".folded"] > run_f + ".svg")

            fold_cmd()
            graph_cmd()
            persist_perf(ri.db_run, ri.session, run_f + ".svg")
            persist_config(ri.db_run, ri.session, {"cores": str(jobs)})
Пример #16
0
def run_with_time(project, experiment, config, jobs, run_f, args, **kwargs):
    """
    Run the given binary wrapped with time.

    Args:
        project: The benchbuild.project.
        experiment: The benchbuild.experiment.
        config: The benchbuild.settings.config.
        jobs: Number of cores we should use for this exection.
        run_f: The file we want to execute.
        args: List of arguments that should be passed to the wrapped binary.
        **kwargs: Dictionary with our keyword args. We support the following
            entries:

            project_name: The real name of our project. This might not
                be the same as the configured project name, if we got wrapped
                with ::benchbuild.project.wrap_dynamic
            has_stdin: Signals whether we should take care of stdin.
    """
    from benchbuild.utils.run import guarded_exec, handle_stdin, fetch_time_output
    from benchbuild.settings import CFG as c
    from benchbuild.utils.db import persist_time, persist_config

    c.update(config)
    project.name = kwargs.get("project_name", project.name)
    timing_tag = "BB-JIT: "

    run_cmd = time["-f", timing_tag + "%U-%S-%e", run_f]
    run_cmd = handle_stdin(run_cmd[args], kwargs)

    with local.env(OMP_NUM_THREADS=str(jobs)):
        with guarded_exec(run_cmd, project, experiment) as run:
            ri = run()
        timings = fetch_time_output(
            timing_tag, timing_tag + "{:g}-{:g}-{:g}", ri.stderr.split("\n"))
        if not timings:
            return

    persist_time(ri.db_run, ri.session, timings)
    persist_config(ri.db_run, ri.session, {"cores": str(jobs)})
Пример #17
0
def collect_compilestats(project, experiment, config, clang, **kwargs):
    """Collect compilestats."""
    from benchbuild.utils.run import track_execution, handle_stdin
    from benchbuild.settings import CFG as c
    from benchbuild.utils.db import persist_compilestats
    from benchbuild.utils.schema import CompileStat

    c.update(config)
    clang = handle_stdin(clang["-mllvm", "-stats"], kwargs)

    with local.env(BB_ENABLE=0):
        with track_execution(clang, project, experiment) as run:
            ri = run()

    if ri.retcode == 0:
        stats = []
        for stat in get_compilestats(ri.stderr):
            compile_s = CompileStat()
            compile_s.name = stat["desc"].rstrip()
            compile_s.component = stat["component"].rstrip()
            compile_s.value = stat["value"]
            stats.append(compile_s)

        components = c["cs"]["components"].value()
        if components is not None:
            stats = [s for s in stats if str(s.component) in components]
        names = c["cs"]["names"].value()
        if names is not None:
            stats = [s for s in stats if str(s.name) in names]

        log = logging.getLogger()
        log.info("\n=========================================================")
        log.info("{:s} results for project {:s}:".format(
            experiment.NAME, project.NAME))
        log.info("=========================================================\n")
        for s in stats:
            log.info("{:s} - {:s}".format(str(s.name), str(s.value)))
        log.info("=========================================================\n")
        persist_compilestats(ri.db_run, ri.session, stats)
Пример #18
0
def run_with_time(project, experiment, config, jobs, run_f, args, **kwargs):
    """
    Run the given binary wrapped with time.

    Args:
        project: The benchbuild project that has called us.
        experiment: The benchbuild experiment which we operate under.
        config: The benchbuild configuration we are running with.
        jobs: The number of cores we are allowed to use. This may differ
            from the actual amount of available cores, obey it.
            We should enforce this from the outside. However, at the moment we
            do not do this.
        run_f: The file we want to execute.
        args: List of arguments that should be passed to the wrapped binary.
        **kwargs: Dictionary with our keyword args. We support the following
            entries:

            project_name: The real name of our project. This might not
                be the same as the configured project name, if we got wrapped
                with ::benchbuild.project.wrap_dynamic
            has_stdin: Signals whether we should take care of stdin.
    """
    CFG.update(config)
    project.name = kwargs.get("project_name", project.name)
    timing_tag = "BB-TIME: "

    run_cmd = time["-f", timing_tag + "%U-%S-%e", run_f]
    run_cmd = handle_stdin(run_cmd[args], kwargs)

    with local.env(OMP_NUM_THREADS=str(jobs)):
        with guarded_exec(run_cmd, project, experiment) as run:
            ri = run()
        timings = fetch_time_output(
            timing_tag, timing_tag + "{:g}-{:g}-{:g}", ri.stderr.split("\n"))
        if not timings:
            return

    persist_time(ri.db_run, ri.session, timings)
    persist_config(ri.db_run, ri.session, {"cores": str(jobs)})
Пример #19
0
def run_with_papi(project, experiment, config, jobs, run_f, args, **kwargs):
    """
    Run the given file with PAPI support.

    This just runs the project as PAPI support should be compiled in
    already. If not, this won't do a lot.

    Args:
        project: The benchbuild.project.
        experiment: The benchbuild.experiment.
        config: The benchbuild.settings.config.
        jobs: Number of cores we should use for this exection.
        run_f: The file we want to execute.
        args: List of arguments that should be passed to the wrapped binary.
        **kwargs: Dictionary with our keyword args. We support the following
            entries:

            project_name: The real name of our project. This might not
                be the same as the configured project name, if we got wrapped
                with ::benchbuild.project.wrap_dynamic
            has_stdin: Signals whether we should take care of stdin.
    """
    from benchbuild.settings import CFG as c
    from benchbuild.utils.run import guarded_exec, handle_stdin
    from benchbuild.utils.db import persist_config

    c.update(config)
    project.name = kwargs.get("project_name", project.name)
    run_cmd = local[run_f]
    run_cmd = handle_stdin(run_cmd[args], kwargs)

    with local.env(POLLI_ENABLE_PAPI=1, OMP_NUM_THREADS=jobs):
        with guarded_exec(run_cmd, project, experiment) as run:
            ri = run()

    persist_config(ri.db_run, ri.session,
                   {"cores": str(jobs)})
Пример #20
0
def setup_bash_in_container(builddir, container, outfile, mounts, shell):
    """
    Setup a bash environment inside a container.

    Creates a new chroot, which the user can use as a bash to run the wanted
    projects inside the mounted container, that also gets returned afterwards.
    """
    with local.cwd(builddir):
        # Switch to bash inside uchroot
        print("Entering bash inside User-Chroot. Prepare your image and "
              "type 'exit' when you are done. If bash exits with a non-zero"
              "exit code, no new container will be stored.")
        store_new_container = True
        try:
            run_in_container(shell, container, mounts)
        except ProcessExecutionError:
            store_new_container = False

        if store_new_container:  # pylint: disable=W0104
            print("Packing new container image.")
            pack_container(container, outfile)
            config_path = CFG["config_file"].value()
            CFG.store(config_path)
            print("Storing config in {0}".format(os.path.abspath(config_path)))
Пример #21
0
def run_with_papi(project, experiment, config, jobs, run_f, args, **kwargs):
    """
    Run the given file with PAPI support.

    This just runs the project as PAPI support should be compiled in
    already. If not, this won't do a lot.

    Args:
        project: The benchbuild.project.
        experiment: The benchbuild.experiment.
        config: The benchbuild.settings.config.
        jobs: Number of cores we should use for this exection.
        run_f: The file we want to execute.
        args: List of arguments that should be passed to the wrapped binary.
        **kwargs: Dictionary with our keyword args. We support the following
            entries:

            project_name: The real name of our project. This might not
                be the same as the configured project name, if we got wrapped
                with ::benchbuild.project.wrap_dynamic
            has_stdin: Signals whether we should take care of stdin.
    """
    from benchbuild.settings import CFG
    from benchbuild.utils.run import track_execution, handle_stdin
    from benchbuild.utils.db import persist_config

    CFG.update(config)
    project.name = kwargs.get("project_name", project.name)
    run_cmd = local[run_f]
    run_cmd = handle_stdin(run_cmd[args], kwargs)

    with local.env(POLLI_ENABLE_PAPI=1, OMP_NUM_THREADS=jobs):
        with track_execution(run_cmd, project, experiment) as run:
            run_info = run()

    persist_config(run_info.db_run, run_info.session, {"cores": str(jobs)})
Пример #22
0
def setup_bash_in_container(builddir, _container, outfile, shell):
    """
    Setup a bash environment inside a container.

    Creates a new chroot, which the user can use as a bash to run the wanted
    projects inside the mounted container, that also gets returned afterwards.
    """
    with local.cwd(builddir):
        # Switch to bash inside uchroot
        print("Entering bash inside User-Chroot. Prepare your image and "
              "type 'exit' when you are done. If bash exits with a non-zero"
              "exit code, no new container will be stored.")
        store_new_container = True
        try:
            run_in_container(shell, _container)
        except ProcessExecutionError:
            store_new_container = False

        if store_new_container:
            print("Packing new container image.")
            pack_container(_container, outfile)
            config_path = str(CFG["config_file"])
            CFG.store(config_path)
            print("Storing config in {0}".format(os.path.abspath(config_path)))
Пример #23
0
    def main(self):
        """Main entry point of benchbuild run."""
        project_names = self._project_names
        group_name = self._group_name

        experiments.discover()

        registry = experiment.ExperimentRegistry
        exps = registry.experiments

        if self._list_experiments:
            for exp_name in registry.experiments:
                exp_cls = exps[exp_name]
                print(exp_cls.NAME)
                docstring = exp_cls.__doc__ or "-- no docstring --"
                print(("    " + docstring))
            exit(0)

        if self._list:
            for exp_name in self._experiment_names:
                exp_cls = exps[exp_name]
                exp = exp_cls(self._project_names, self._group_name)
                print_projects(exp)
            exit(0)

        if self.show_config:
            print(repr(CFG))
            exit(0)

        if self.store_config:
            config_path = ".benchbuild.json"
            CFG.store(config_path)
            print("Storing config in {0}".format(os.path.abspath(config_path)))
            exit(0)

        if self._project_names:
            builddir = os.path.abspath(str(CFG["build_dir"]))
            if not os.path.exists(builddir):
                response = True
                if sys.stdin.isatty():
                    response = ui.query_yes_no(
                        "The build directory {dirname} does not exist yet."
                        "Should I create it?".format(dirname=builddir), "no")

                if response:
                    mkdir("-p", builddir)
                    print("Created directory {0}.".format(builddir))

        actns = []
        for exp_name in self._experiment_names:
            if exp_name in exps:
                exp_cls = exps[exp_name]
                exp = exp_cls(project_names, group_name)
                eactn = Experiment(exp, exp.actions())
                actns.append(eactn)
            else:
                from logging import error
                error("Could not find {} in the experiment registry.",
                      exp_name)

        num_actions = sum([len(x) for x in actns])
        print("Number of actions to execute: {}".format(num_actions))
        for a in actns:
            print(a)
        print()

        if not self.pretend:
            for a in actns:
                a()
Пример #24
0
def time_polyjit_and_polly(project: Project, experiment: Experiment,
                           config: Configuration, jobs: int, run_f: str,
                           args: Iterable[str], **kwargs):
    """
    Run the given binary wrapped with time.

    Args:
        project: The benchbuild.project.
        experiment: The benchbuild.experiment.
        config: The benchbuild.settings.config.
        jobs: Number of cores we should use for this execution.
        run_f: The file we want to execute.
        args: List of arguments that should be passed to the wrapped binary.
        **kwargs: Dictionary with our keyword args. We support the following
            entries:

            project_name: The real name of our project. This might not
                be the same as the configured project name, if we got wrapped
                with ::benchbuild.project.wrap_dynamic
            has_stdin: Signals whether we should take care of stdin.
    """
    from benchbuild.utils.run import track_execution, fetch_time_output
    from benchbuild.settings import CFG
    from benchbuild.utils.db import persist_time, persist_config

    CFG.update(config)
    project.name = kwargs.get("project_name", project.name)
    timing_tag = "BB-JIT: "

    may_wrap = kwargs.get("may_wrap", True)

    run_cmd = local[run_f]
    run_cmd = run_cmd[args]
    if may_wrap:
        run_cmd = time["-f", timing_tag + "%U-%S-%e", run_cmd]

    def handle_timing_info(run_info):
        if may_wrap:
            timings = fetch_time_output(timing_tag,
                                        timing_tag + "{:g}-{:g}-{:g}",
                                        run_info.stderr.split("\n"))
            if timings:
                persist_time(run_info.db_run, run_info.session, timings)
            else:
                logging.warning("No timing information found.")
        return run_info

    ri_1 = RunInfo()
    ri_2 = RunInfo()
    with track_execution(run_cmd, project, experiment) as run:
        with local.env(OMP_NUM_THREADS=str(jobs),
                       POLLI_LOG_FILE=CFG["slurm"]["extra_log"].value()):
            ri_1 = handle_timing_info(run())
            persist_config(
                ri_1.db_run, ri_1.session, {
                    "cores": str(jobs - 1),
                    "cores-config": str(jobs),
                    "recompilation": "enabled",
                    "specialization": "enabled"
                })

    with track_execution(run_cmd, project, experiment) as run:
        with local.env(OMP_NUM_THREADS=str(jobs),
                       POLLI_DISABLE_SPECIALIZATION=1,
                       POLLI_LOG_FILE=CFG["slurm"]["extra_log"].value()):
            ri_2 = handle_timing_info(run())
            persist_config(
                ri_2.db_run, ri_2.session, {
                    "cores": str(jobs - 1),
                    "cores-config": str(jobs),
                    "recompilation": "enabled",
                    "specialization": "disabled"
                })

    return ri_1 + ri_2
Пример #25
0
    def main(self):
        """Main entry point of benchbuild run."""
        from benchbuild.utils.cmd import mkdir  # pylint: disable=E0401

        project_names = self._project_names
        group_name = self._group_name

        experiments.discover()

        registry = experiment.ExperimentRegistry
        exps = registry.experiments

        if self._list_experiments:
            for exp_name in registry.experiments:
                exp_cls = exps[exp_name]
                print(exp_cls.NAME)
                docstring = exp_cls.__doc__ or "-- no docstring --"
                print(("    " + docstring))
            exit(0)

        if self._list:
            for exp_name in self._experiment_names:
                exp_cls = exps[exp_name]
                exp = exp_cls(self._project_names, self._group_name)
                print_projects(exp)
            exit(0)

        if self.show_config:
            print(repr(CFG))
            exit(0)

        if self.store_config:
            config_path = ".benchbuild.json"
            CFG.store(config_path)
            print("Storing config in {0}".format(os.path.abspath(config_path)))
            exit(0)

        if self._project_names:
            builddir = os.path.abspath(str(CFG["build_dir"]))
            if not os.path.exists(builddir):
                response = True
                if sys.stdin.isatty():
                    response = ui.query_yes_no(
                        "The build directory {dirname} does not exist yet."
                        "Should I create it?".format(dirname=builddir), "no")

                if response:
                    mkdir("-p", builddir)
                    print("Created directory {0}.".format(builddir))

        actns = []
        for exp_name in self._experiment_names:
            if exp_name in exps:
                exp_cls = exps[exp_name]
                exp = exp_cls(project_names, group_name)
                eactn = Experiment(exp, exp.actions())
                actns.append(eactn)
            else:
                from logging import error
                error("Could not find {} in the experiment registry.",
                      exp_name)

        num_actions = sum([len(x) for x in actns])
        print("Number of actions to execute: {}".format(num_actions))
        for a in actns:
            print(a)
        print()

        if not self.pretend:
            for a in actns:
                a()
Пример #26
0
 def wrap_store_config(self, *args, **kwargs):
     """Wrapper that contains the actual storage call for the config."""
     p = os.path.abspath(os.path.join(self.builddir))
     CFG.store(os.path.join(p, ".benchbuild.json"))
     return func(self, *args, **kwargs)