Enable resource binding
SUNK enables resource binding by default. The operator setsTaskPlugin to task/cgroup,task/affinity, so you don’t need to turn it on. Confirm the value on your cluster with the following command:
TaskPlugin as a top-level key under slurmConfig. On SUNK Standard, set it in the Slurm chart’s values. On SUNK Self-Service, set it under spec.slurmConfig on the SunkCluster resource:
slurmConfig in the Slurm parameter reference.
The task/affinity and task/cgroup plugins work together to optimize resource allocations in the SUNK cluster.
- The
task/affinityplugin controls how processes bind to CPU resources on a Compute node. - The
task/cgroupplugin uses the cgroup filesystem and its controllers to enforce the resource limits and binding policies specified by Slurm.
Configure the task cgroup plugin
Slurm enforces those bindings through Linux cgroups, which constrain the CPU, GPU, and memory available to each task. SUNK exposes thecgroup.conf settings through slurmConfig.cgroupConfig.
SUNK configures cgroups by default. Confirm that both of the following are in place on your cluster:
TaskPluginincludestask/cgroup, as shown in the Enable resource binding section.ProctrackTypeis set toproctrack/cgroupas a top-level key underslurmConfig. If this parameter isn’t set correctly, Slurm doesn’t apply your Linux cgroups settings.
cgroupConfig key:
Constrain settings enforce binding and limits for different resources, as follows:
ConstrainCoresenforces CPU binding.ConstrainDevicesenforces limits on GPU devices.ConstrainRAMSpaceenforces memory limits.
Bind tasks to GPUs
Once the task plugins and cgroup configuration are in place, you can control how Slurm assigns individual jobs to GPUs. Use the--gpu-bind parameter in your job script’s #SBATCH directives to manage how Slurm assigns tasks to GPUs:
verbose option to your other binding options, separated by a comma. This can be helpful when debugging or checking your binding strategy.
The --gpu-bind parameter supports multiple options, including:
For a complete list of available
--gpu-bind options, see SchedMD’s Slurm documentation.
Run two jobs on one GPU node
Slurm can run multiple jobs on the same node when each job requests only the resources it needs. This example submits two jobs to one node with at least two available GPUs. Each job requests one GPU, one CPU, and 1 GB of memory. The node’s remaining resources stay available to other jobs. To submit the jobs, complete these steps:-
Create a job script named
gpu-share.sh: -
Submit the script twice to the same node. Replace
[NODE-NAME]with the name of a node that has at least two available GPUs:
squeue shows that both jobs run on the same node. Slurm’s gres/gpu allocation sets SLURM_JOB_GPUS in each job’s environment to the physical GPU it holds. The job output files, gpu-share-${job_one}.out and gpu-share-${job_two}.out, show a different SLURM_JOB_GPUS value for each job, confirming that Slurm assigned them separate GPUs.
CUDA_VISIBLE_DEVICES isn’t a reliable way to tell the jobs apart. With ConstrainDevices=yes, Linux cgroups restrict each job to only its allocated GPU device file, and Slurm remaps CUDA_VISIBLE_DEVICES to a job-local index that starts at 0. Because each job in this example holds a single GPU, both output files show CUDA_VISIBLE_DEVICES=0, even though the jobs run on different physical GPUs. Without ConstrainDevices=yes, a job can access every GPU on the node instead of only the one it was assigned, so CUDA_VISIBLE_DEVICES reports the real GPU index but doesn’t restrict access to it. Either way, use SLURM_JOB_GPUS or scontrol show job -d [JOB-ID] to find a job’s actual physical GPU.
Replace [JOB-ID] with either job ID captured in job_one or job_two by the submission commands.
Bind tasks to CPU cores
In addition to GPU binding, you can pin tasks to specific CPU cores to improve cache locality and reduce contention. Use the--cpu-bind parameter in your job script’s #SBATCH directives to control which CPU cores your tasks bind to. For example:
verbose option to your other binding options, separated by a comma. This can be helpful when debugging or checking your binding strategy.
The --cpu-bind parameter supports multiple options, including:
For a full list of available
--cpu-bind options, see SchedMD’s Slurm documentation.