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

feat!: improved GPU job support #173

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
3 changes: 2 additions & 1 deletion docs/further.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ You can use the following specifications:
| `--cpus-per-task` | `cpus_per_task` | number of cpus per task (in case of SMP, rather use `threads`) |
| `--nodes` | `nodes` | number of nodes |
| `--clusters` | `clusters` | comma separated string of clusters |
| `--gres` | `gres` | generic resource specification, e.g. `gres=gpu:1`, allows for arbitray strings after the `=` |

Each of these can be part of a rule, e.g.:
Each of these can be part of a rule, e.g.:

``` python
rule:
Expand Down
42 changes: 42 additions & 0 deletions snakemake_executor_plugin_slurm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class ExecutorSettings(ExecutorSettingsBase):
# Required:
# Implementation of your executor
class Executor(RemoteExecutor):
gres_re = re.compile(r"^[a-zA-Z0-9_]+:([a-zA-Z0-9_]+:)?\d+$")
gpu_model_re = re.compile(r"^[a-zA-Z0-9_]+$")

def __post_init__(self):
# run check whether we are running in a SLURM job context
self.warn_on_jobcontext()
Expand Down Expand Up @@ -158,6 +161,45 @@ def run_job(self, job: JobExecutorInterface):
if self.workflow.executor_settings.requeue:
call += " --requeue"

if job.resources.get("gres"):
# Validate GRES format (e.g., "gpu:1", "gpu:tesla:2")
gres = job.resources.gres
if not Executor.gres_re.match(gres):
raise WorkflowError(
f"Invalid GRES format: {gres}. Expected format: "
"'<name>:<number>' or '<name>:<type>:<number>'"
)
gres_string = f" --gres={job.resources.gres}"
if job.resources.get("gpu"):
# ensure that gres is not set, if gpu and gpu_model are set
if job.resources.get("gres"):
raise WorkflowError(
"GRES and GPU are set. Please only set one of them."
)
# ensure that 'gpu' is an integer
if not isinstance(job.resources.gpu, int):
raise WorkflowError(
"The 'gpu' resource must be an integer. "
f"Got: {job.resources.gpu} ({type(job.resources.gpu)})."
)
gres_string = f" --gres=gpu:{job.resources.gpu}"
if job.resources.get("gpu_model") and job.resources.get("gpu"):
# validate GPU model format
if not Executor.gpu_model_re.match(job.resources.gpu_model):
raise WorkflowError(
f"Invalid GPU model format: {job.resources.gpu_model}. "
"Expected format: '<name>'"
)
gres_string = f" --gres=gpu:{job.resources.gpu_model}:{job.resources.gpu}"
elif job.resources.get("gpu_model") and not job.resources.get("gpu"):
raise WorkflowError(
"GPU model is set, but no GPU number is given. "
"Please set 'gpu' as well."
)
call += (
gres_string if job.resources.get("gres") or job.resources.get("gpu") else ""
)

if job.resources.get("clusters"):
call += f" --clusters {job.resources.clusters}"

Expand Down
Loading