Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding SLURM-compatibility to Benchexec #995

Merged
merged 62 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
49f52ed
Added slurm executor
leventeBajczi Feb 17, 2024
687cdb4
Fixed memory calculation
leventeBajczi Feb 17, 2024
a53f6d6
Fixed memory calculation #2
leventeBajczi Feb 17, 2024
7b11e4b
Implemented slurm executor
leventeBajczi Feb 17, 2024
9577b1c
Fixed timelimit
leventeBajczi Feb 17, 2024
2496c19
Fixed subprocess
leventeBajczi Feb 17, 2024
be275ea
Fixed stdout
leventeBajczi Feb 17, 2024
3f72aa8
Fixed stdout
leventeBajczi Feb 17, 2024
f2f385b
Added logging
leventeBajczi Feb 17, 2024
754ab98
Fixed memory limit
leventeBajczi Feb 17, 2024
4f0f006
Adding 6 lines of metadata to beginning of file
leventeBajczi Feb 17, 2024
ea9b778
Reformatted file
leventeBajczi Feb 17, 2024
4d5af97
Cleared up commands
leventeBajczi Feb 18, 2024
e7cdee6
Formatted file
leventeBajczi Feb 18, 2024
6a7dbfb
Moved --slurm out of main benchexec code
leventeBajczi Feb 18, 2024
00ed378
Fixed path
leventeBajczi Feb 18, 2024
4e837d3
Fixed formatting command
leventeBajczi Feb 18, 2024
f78ff8f
Using --no-home instead of specifying -B
leventeBajczi Feb 18, 2024
a0c662d
Added --contain
leventeBajczi Feb 18, 2024
394a7c4
Added -B $PWD:$HOME
leventeBajczi Feb 18, 2024
2ea64b9
Added log
leventeBajczi Feb 18, 2024
82d960a
ntasks=1
leventeBajczi Feb 18, 2024
26d4472
removed unused import
leventeBajczi Feb 18, 2024
18ffb45
Added fusemount options
leventeBajczi Feb 18, 2024
c88e5dc
Added temp files
leventeBajczi Feb 18, 2024
1fbd3e4
Reformatted
leventeBajczi Feb 18, 2024
0d7246b
Updated copyright, added readme
leventeBajczi Feb 19, 2024
9f62e8e
Updated copyright
leventeBajczi Feb 19, 2024
26d1933
Added myself to the list of contributors
leventeBajczi Feb 19, 2024
501e43b
Added contact info to top of README
leventeBajczi Feb 19, 2024
9b2f445
Updated README regarding contact
leventeBajczi Feb 20, 2024
493ce92
Update README with better description on the workflow.
leventeBajczi Feb 20, 2024
6a5d5e6
Moved contributor entry to correct place in alphabetical order
leventeBajczi Feb 20, 2024
a9f1c7b
Added links in preliminaries
leventeBajczi Feb 20, 2024
67dcd61
Updated requirement description
leventeBajczi Feb 20, 2024
3f28a45
Moved disclaimer to limitations instead
leventeBajczi Feb 20, 2024
17f02ef
REmoved confusing documentation comment
leventeBajczi Feb 20, 2024
6b6cd65
Modified help text
leventeBajczi Feb 20, 2024
2a2ffe0
Reworked param passing
leventeBajczi Feb 20, 2024
6425071
Removed starttime
leventeBajczi Feb 20, 2024
a7501c2
Moved to factory method for ProcessExitCode
leventeBajczi Feb 20, 2024
61f7fe7
Replaced bash pipes with python code, moved regexes
leventeBajczi Feb 20, 2024
de4e23c
Removed unused import
leventeBajczi Feb 20, 2024
7307acc
Fixed missing str()
leventeBajczi Feb 20, 2024
8ef0505
Added extra logging
leventeBajczi Feb 20, 2024
28da4ac
Fixed bug in exit code parsing
leventeBajczi Feb 20, 2024
86574f2
Fixed quoting issue
leventeBajczi Feb 20, 2024
46247d7
Minor fixes: typo, logging
leventeBajczi Feb 20, 2024
e6b108e
Formatting fix
leventeBajczi Feb 20, 2024
f110bcc
Updated README and requering --no-hyperthreading
leventeBajczi Feb 20, 2024
2e6e2d9
Added exception to when exit code is not parsed
leventeBajczi Feb 20, 2024
bb9f5bf
Added new line to limitations
leventeBajczi Feb 20, 2024
9b86b5f
Formatting fix
leventeBajczi Feb 20, 2024
d742e30
Minor fixes from feedback
leventeBajczi Feb 20, 2024
ae7ebcc
Formatted file
leventeBajczi Feb 20, 2024
255eb6d
Not using shell anymore
leventeBajczi Feb 20, 2024
4368b34
str() wrap around ints
leventeBajczi Feb 20, 2024
e07ce23
Added comma
leventeBajczi Feb 20, 2024
24dd37e
str() wrap around ints
leventeBajczi Feb 20, 2024
1563694
Implemented some fixes
leventeBajczi Feb 20, 2024
d9fba5d
Formatted file
leventeBajczi Feb 20, 2024
e6e9b92
better handling of bad scratchdir
leventeBajczi Feb 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Contributors:
- [Thomas Stieglmaier](https://stieglmaier.me/)
- [Martin Yankov](https://github.com/marto97)
- [Ilja Zakharov](https://github.com/IljaZakharov)
- [Levente Bajczi](https://github.com/leventeBajczi)
leventeBajczi marked this conversation as resolved.
Show resolved Hide resolved
- and [lots of more people who integrated tools into BenchExec](https://github.com/sosy-lab/benchexec/graphs/contributors)

### Users of BenchExec
Expand Down
1 change: 1 addition & 0 deletions contrib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Content:
- `create_yaml_files.py`: Script for creating task-definition files from old input files that have expected verdicts encoded in the file name
- [`p4-benchmark.py`](p4): BenchExec extension for [P4](https://p4.org/) programs for programmable switches
- [`plots`](plots): Scripts and examples for generating plots from BenchExec results using Gnuplot or PGFPlots for LaTeX
- [`slurm-benchmark.py`](slurm): BenchExec extension for execution benchmark runs via [SLURM](https://slurm.schedmd.com/documentation.html)
- `serveFileFromZIP.php`: Script for letting a web server serve files from a ZIP archive as if the archive would have been expanded. This is useful for hosting HTML tables with results and links to log files in ZIP archives.
- `vcloud-benchmark.py`: BenchExec extension for executing benchmark runs on the VerifierCloud service

Expand Down
75 changes: 75 additions & 0 deletions contrib/slurm-benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env python3

# This file is part of BenchExec, a framework for reliable benchmarking:
# https://github.com/sosy-lab/benchexec
#
# SPDX-FileCopyrightText: 2007-2020 Dirk Beyer <https://www.sosy-lab.org>
# SPDX-FileCopyrightText: 2024 Levente Bajczi
# SPDX-FileCopyrightText: Critical Systems Research Group
# SPDX-FileCopyrightText: Budapest University of Technology and Economics <https://www.ftsrg.mit.bme.hu>
#
# SPDX-License-Identifier: Apache-2.0

import logging
import os
import sys

import benchexec.benchexec
import benchexec.tools
import benchexec.util

sys.dont_write_bytecode = True # prevent creation of .pyc files

# Add ./benchmark/tools to __path__ of benchexec.tools package
# such that additional tool-wrapper modules can be placed in this directory.
benchexec.tools.__path__ = [
os.path.join(os.path.dirname(__file__), "benchmark", "tools")
] + benchexec.tools.__path__


class Benchmark(benchexec.benchexec.BenchExec):
"""
An extension of BenchExec for use with CPAchecker
leventeBajczi marked this conversation as resolved.
Show resolved Hide resolved
to execute benchmarks using SLURM, optionally via Singularity.
"""

def create_argument_parser(self):
parser = super(Benchmark, self).create_argument_parser()

slurm_args = parser.add_argument_group("Options for using SLURM")
slurm_args.add_argument(
"--slurm",
dest="slurm",
action="store_true",
help="Use SLURM to execute benchmarks.",
)
slurm_args.add_argument(
"--singularity",
dest="singularity",
type=str,
help="The path to the singularity .sif file to use. Will bind $PWD to $HOME when run.",
)
slurm_args.add_argument(
"--scratchdir",
dest="scratchdir",
type=str,
default="./",
help="The path to the singularity .sif file to use. Will bind $PWD to $HOME when run.",
leventeBajczi marked this conversation as resolved.
Show resolved Hide resolved
)

return parser

def load_executor(self):
if self.config.slurm:
from slurm import slurmexecutor as executor
else:
logging.warning(
"SLURM flag was not specified. Benchexec will be executed only on the local machine."
)
executor = super(Benchmark, self).load_executor()

return executor


if __name__ == "__main__":
benchexec.benchexec.main(Benchmark())
86 changes: 86 additions & 0 deletions contrib/slurm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!--
This file is part of BenchExec, a framework for reliable benchmarking:
https://github.com/sosy-lab/benchexec

SPDX-FileCopyrightText: 2021 Dirk Beyer <https://www.sosy-lab.org>
SPDX-FileCopyrightText: 2024 Levente Bajczi
SPDX-FileCopyrightText: Critical Systems Research Group
SPDX-FileCopyrightText: Budapest University of Technology and Economics <https://www.ftsrg.mit.bme.hu>

SPDX-License-Identifier: Apache-2.0
-->
# BenchExec Extension for Benchmarking via SLURM

This Python script extends BenchExec, a benchmarking framework, to facilitate benchmarking via SLURM, optionally using a Singularity container.

In case of problems, contact / tag in an issue: [Levente Bajczi](https://github.com/leventeBajczi)
leventeBajczi marked this conversation as resolved.
Show resolved Hide resolved

## Preliminaries

* *SLURM* is an open-source job scheduling and workload management system used primarily in high-performance computing (HPC) environments.
* *Singularity* is a containerization platform designed for scientific and high-performance computing (HPC) workloads, providing users with a reproducible and portable environment for running applications and workflows.
leventeBajczi marked this conversation as resolved.
Show resolved Hide resolved

## Requirements

* Singularity (optional), tested with `singularity-ce version 4.0.1`
* SLURM, tested with `slurm 22.05.7` on `Red Hat Enterprise Linux 8.6 (Ootpa)`, kernel version `4.18.0-372.9.1.el8.x86_64`
leventeBajczi marked this conversation as resolved.
Show resolved Hide resolved

## Usage
1. Run the script with Python 3:
```
python3 $BENCHEXEC_FOLDER/contrib/slurm-benchmark.py [options]
```
Options:
- `--slurm`: Use SLURM to execute benchmarks. Will revert to regular (local) benchexec if not given.
- `--singularity <path_to_sif>`: Specify the path to the Singularity .sif file to use. See usage later.
- `--scratchdir <path>`: Specify the directory for temporary files. The script will use this parameter to create temporary directories for file storage per-run, which get discarded later. By default, this is the CWD, which might result in temporary files being generated by the thousands in the working directory. On some systems, this must be on the same mount, or even under the same hierarchy as the current directory. Must exist, be writable, and be a directory.
- `-N <N>`: Specify the factor of parallelism, i.e., how many instances to start at a time. Tested with up to `1000`, probably works with much higher values as well.

## Overview of the Workflow

The workflow is based on `localexecution.py`, and uses the same general layout. However, instead of delegating to `runexec`, it delegates to `srun`.
leventeBajczi marked this conversation as resolved.
Show resolved Hide resolved

1. If the `--singularity` option is given, the script wraps the command to run in a container. This is useful for dependency management (in most HPC environments, arbitrary package installations are frowned upon). For a simple container, use the following:

```singularity
BootStrap: docker
From: ubuntu:22.04

%post
apt -y update
apt -y install openjdk-17-jre-headless libgomp1 libmpfr-dev fuse-overlayfs
```

Use `singularity build [--remote / --fakeroot] --fix-perms <name>.sif <name>.def` to build the container.

Notice the `fuse-overlayfs` package. That is mandatory for the overlay filesystem to work properly.

The script parameterizes `singularity exec` with the following params:
* `-B $PWD:/lower`: Bind the working directory to `/lower` (could be read-only)
* `--no-home`: Do not bind the home directory
* `-B {tempdir}:/overlay`: Bind the temporary directory to `/overlay` (must be writeable)
* `--fusemount "container:fuse-overlayfs -o lowerdir=/lower -o upperdir=/overlay/upper -o workdir=/overlay/work $HOME"`: mount an overlay filesystem at $HOME, where modifications go in the temp dir but files can be read from the current dir

Modifications to the script are necessary if the user on the host and the container differ (due to using $HOME). Also, files not under the current directory will not be visible.
leventeBajczi marked this conversation as resolved.
Show resolved Hide resolved

2. Currently, the following parameters are passed to `srun` (calculated from the benchmark's parameters):
* `-t <hh:mm:ss>` CPU timelimit (generally, SLURM will round up to nearest minute)
* `-c <cpus>` number of cpus
* `--threads-per-core=1` only use one thread per core
leventeBajczi marked this conversation as resolved.
Show resolved Hide resolved
* `--mem-per-cpu <mem/cpus>` memory allocaiton in MBs per cpu
* `--ntasks=1` number of tasks per node

3. The script parses the resulting job ID, and after the job finishes, runs `seff` to gather resource usage data:
* Exit code
* CPU time [s]
* Wall time [s]
* Memory [MB]

## Limitations

Currently, there are the following limitations compared to local benchexec:

1. No advanced resource constraining / monitoring: only CPU time, CPU core and memory limits are handled, and only CPU time, wall time, and memory usage are monitored.
2. No exotic paths in the command are handled: only the current working directory and its children are visible in the container
3. Without singularity, no constraint is placed on the resulting files of the runs: this will populate the current directory with all the output files of all the runs.
4. For timed-out runs, where SLURM terminated the run, no CPU time values are available.
9 changes: 9 additions & 0 deletions contrib/slurm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file is part of BenchExec, a framework for reliable benchmarking:
# https://github.com/sosy-lab/benchexec
#
# SPDX-FileCopyrightText: 2007-2020 Dirk Beyer <https://www.sosy-lab.org>
# SPDX-FileCopyrightText: 2024 Levente Bajczi
# SPDX-FileCopyrightText: Critical Systems Research Group
# SPDX-FileCopyrightText: Budapest University of Technology and Economics <https://www.ftsrg.mit.bme.hu>
#
# SPDX-License-Identifier: Apache-2.0
Loading
Loading