Enable resource binding
To enable resource binding, modify theTaskPlugin variable in the Slurm configuration section of the SUNK Helm chart.
In the slurmConfig section of the Slurm values.yaml file, set the TaskPlugin variable to task/affinity,task/cgroup:
task/affinity and task/cgroup plugins, which work together to optimize resource allocations in the SUNK cluster. The task/affinity plugin controls how processes bind to CPU resources on a Compute node. The task/cgroup plugin uses the cgroup filesystem and its controllers to enforce the resource limits and binding policies specified by Slurm.
Configure the task cgroup plugin
With resource binding enabled, the next step is to configure how Slurm enforces those bindings. SUNK supports Linux cgroups through thecgroup.conf value, slurmConfig.cgroupConfig, which uses kernel cgroups to enforce CPU, GPU, and memory constraints on each task.
To use Linux cgroups in SUNK, do the following:
- Add the
task/cgroupvalue to theTaskPluginvariable, as shown in the Enable resource binding section. - In the
slurmConfigsection of the Slurmvalues.yaml, set theprocTrackTypevariable toproctrack/cgroup. If you don’t set this parameter correctly, Slurm doesn’t apply your Linux cgroups settings.
Constrain settings enforce binding and limits for different resources, as follows:
ConstrainCores=yesenforces CPU binding.ConstrainDevices=yesenforces limits on GPU devices.ConstrainRAMSpace=yesenforces 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.
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.