Skip to content

Commit e4d3dbb

Browse files
committed
feat: cpu-function altered to support cpus-per-gpu, too
1 parent 13b72f5 commit e4d3dbb

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

snakemake_executor_plugin_slurm_jobstep/__init__.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,26 @@ def get_exec_mode(self) -> ExecMode:
155155
return ExecMode.REMOTE
156156

157157

158-
def get_cpus_per_task(job: JobExecutorInterface):
159-
cpus_per_task = job.threads
158+
def get_cpus_per_task(job: JobExecutorInterface, gpu: bool) -> str:
159+
cpus_per_task = cpus_per_gpu = job.threads
160160
if job.resources.get("cpus_per_task"):
161+
cpus_per_task = job.resources.cpus_per_task
161162
if not isinstance(cpus_per_task, int):
162163
raise WorkflowError(
163164
f"cpus_per_task must be an integer, but is {cpus_per_task}"
164165
)
165-
cpus_per_task = job.resources.cpus_per_task
166-
# ensure that at least 1 cpu is requested
167-
# because 0 is not allowed by slurm
168-
return max(1, cpus_per_task)
166+
# ensure that at least 1 cpu is requested
167+
# because 0 is not allowed by slurm
168+
cpus_per_task = max(1, job.resources.cpus_per_task)
169+
cpu_string = f"--cpus-per-task={cpus_per_task}"
170+
elif gpu and job.resources.get("cpus_per_gpu"):
171+
cpus_per_gpu = job.resources.cpus_per_gpu
172+
if not isinstance(cpus_per_gpu, int):
173+
raise WorkflowError(
174+
f"cpus_per_gpu must be an integer, but is {cpus_per_gpu}"
175+
)
176+
# ensure that at least 1 cpu is requested
177+
# because 0 is not allowed by slurm
178+
cpus_per_gpu = max(1, job.resources.cpus_per_gpu)
179+
cpu_string = f"--cpus-per-gpu={cpus_per_gpu}"
180+
return cpu_string

0 commit comments

Comments
 (0)