SLURM: Difference between revisions

From CSCWiki
Jump to navigation Jump to search
Content deleted Content added
No edit summary
S23adhik (talk | contribs)
No edit summary
 
Line 1: Line 1:
== Why ==
== Why ==
Slurm (Simple Linux Utility for Resource Management) is a job scheduler. Basically use this if too many people are trying to use a system at the same time and its crashing or you want to distribute resources more fairly.
Slurm (Simple Linux Utility for Resource Management) is a job scheduler. Use it when too many people are trying to use a machine at the same time and it keeps crashing, or when you want to share resources (especially GPUs) more fairly.


On '''tiramisu''' the two NVIDIA RTX PRO 6000 Blackwell GPUs can '''only''' be used through Slurm. Outside a job, <code>nvidia-smi</code> prints <code>Failed to initialize NVML: Insufficient Permissions</code>. That is expected: you get access to a GPU when your job starts, and lose it when the job ends.
== Job Config ==
Here are most of the configurable parameters (soon to include NVIDIA MPS)


== Rules on tiramisu ==
* <code>nodes</code> number of nodes (if you don't know, just use 1)
{| class="wikitable"
* <code>ntasks</code> the number of tasks
! What !! Limit
* <code>cpu-per-task</code> the number of CPU ''cores'' per tasks
|-
* <code>mem-per-cpu</code> the amount of ram per CPU core
| Running jobs per user || '''1''' (others wait in the queue, reason <code>QOSMaxJobsPerUserLimit</code>)
* <code>mem</code> the amount of ram (does NOT depend on CPU core count)
|-
Here is an example script<syntaxhighlight lang="bash" line="1" start="1">
| GPUs per job || '''1''' whole GPU (<code>--gres=gpu:1</code>), or a slice of one GPU with MPS (<code>--gres=mps:N</code>, N ≤ 100 = N% of one GPU)
|-
| Both GPUs || '''2''' GPUs (<code>--gres=gpu:2</code>) for at most '''1 hour'''
|-
| No GPU requested || You get <code>--gres=mps:25</code> (25% of one GPU) automatically
|-
| Time limit || Default '''4 hours''', maximum '''12 hours''' (2-GPU jobs: default and maximum 1 hour)
|-
| CPUs || 96 of the 128 CPUs are available to Slurm (the rest are kept for normal use of the machine). A whole-GPU job gets 16 CPUs by default
|-
| Memory || 2 GB per CPU by default (<code>--mem</code> / <code>--mem-per-cpu</code> to change)
|-
| Priority || Fair-share: the more GPU time you used recently, the lower your priority. A 2-GPU job counts double
|}
You can't combine <code>gpu</code> and <code>mps</code> in the same job. If a request breaks a rule, it is rejected at submit time with a message starting with <code>tiramisu:</code> that explains why.

Every current CSC member is registered automatically (synced from LDAP every hour). If you just renewed your membership and get <code>Invalid account</code>, wait up to an hour.

== Interactive sessions ==
Interactive jobs follow the same rules as batch jobs: they count as your one running job, and they end when the time limit is reached.

=== Shell on a GPU (recommended) ===
<syntaxhighlight lang="bash">
# one whole GPU for 2 hours
srun --gres=gpu:1 --time=2:00:00 --pty bash

# 25% of one GPU (the default if you leave out --gres), 1 hour
srun --gres=mps:25 --time=1:00:00 --pty bash

# both GPUs (the time is set to 1 hour automatically, which is also the maximum)
srun --gres=gpu:2 --pty bash

# more CPUs/RAM
srun --gres=gpu:1 --cpus-per-task=16 --mem=64G --time=3:00:00 --pty bash
</syntaxhighlight>
When the prompt comes back you are inside the job: <code>nvidia-smi</code> shows your GPU(s). Type <code>exit</code> to end the job and free the GPU.

'''Run it inside <code>tmux</code> or <code>screen</code>.''' If your SSH connection drops, <code>srun</code> and your job are killed. To keep it running:
<syntaxhighlight lang="bash">
tmux new -s gpu
srun --gres=gpu:1 --time=4:00:00 --pty bash
# detach: Ctrl-b d reattach later: tmux attach -t gpu
</syntaxhighlight>

=== salloc (allocate first, run steps later) ===
<syntaxhighlight lang="bash">
salloc --gres=gpu:1 --time=2:00:00
srun --pty bash # now you are in the job, on the GPU
# ... work, exit the inner shell, run more srun steps ...
exit # leave salloc: this ends the job and frees the GPU
</syntaxhighlight>
The shell <code>salloc</code> gives you is '''not''' inside the job (CUDA_VISIBLE_DEVICES is not set there). Always start work with <code>srun</code> inside it, or just use <code>srun --pty bash</code> directly as shown above.

=== Jupyter ===
On tiramisu (inside tmux), with a port number of your choice so you don't collide with others:
<syntaxhighlight lang="bash">
PORT=$((20000 + RANDOM % 10000)); echo $PORT
srun --gres=gpu:1 --time=3:00:00 --pty jupyter lab --no-browser --ip=127.0.0.1 --port=$PORT
</syntaxhighlight>
On your laptop:
<syntaxhighlight lang="bash">
ssh -N -L 8888:127.0.0.1:<PORT> <user>@tiramisu.csclub.uwaterloo.ca
</syntaxhighlight>
Then open the <code>http://127.0.0.1:8888/...?token=...</code> link Jupyter printed, replacing its port with 8888. Stop Jupyter (Ctrl-C twice) when you are done so the GPU is freed. Don't leave it idle until the time limit.

=== Getting a shell inside a job that is already running ===
Because you can only run one job at a time, a new <code>srun</code> waits while your batch job runs. To look at a running job (e.g. run <code>nvidia-smi</code> or <code>htop</code> on its GPU), attach to it instead:
<syntaxhighlight lang="bash">
srun --jobid=<JOBID> --overlap --pty bash
</syntaxhighlight>

== Batch jobs ==
=== Job config ===
* <code>--gres=gpu:1</code> one whole GPU; <code>--gres=gpu:2</code> both GPUs (max 1 hour); <code>--gres=mps:N</code> N% of one GPU
* <code>--time</code> time limit (e.g. <code>30:00</code>, <code>4:00:00</code>); ask for what you need, since shorter jobs start sooner
* <code>--ntasks</code> the number of tasks (usually 1)
* <code>--cpus-per-task</code> the number of CPUs per task
* <code>--mem-per-cpu</code> RAM per CPU, or <code>--mem</code> total RAM (does NOT depend on CPU count)
* <code>--job-name</code>, <code>--output</code> (default <code>slurm-<jobid>.out</code> in the directory you submitted from)

=== Example: one GPU ===
<syntaxhighlight lang="bash" line="1" start="1">
#!/bin/bash
#!/bin/bash
#SBATCH --job-name=my_test
#SBATCH --job-name=my_test
#SBATCH --nodes=1
#SBATCH --gres=gpu:1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=8
#SBATCH --mem=32G
#SBATCH --cpus-per-task=4 # Request 4 CPU cores
#SBATCH --time=4:00:00
#SBATCH --mem-per-cpu=2G # Request 2GB of RAM per core (total 8GB)
#SBATCH --output=%x-%j.out


nvidia-smi
# Your application command here
python train.py
./program
</syntaxhighlight>
</syntaxhighlight>
Submit with <code>sbatch job.sh</code>.

=== Example: both GPUs (max 1 hour) ===
<syntaxhighlight lang="bash" line="1" start="1">
#!/bin/bash
#SBATCH --job-name=two_gpu
#SBATCH --gres=gpu:2
#SBATCH --time=1:00:00 # more than 1:00:00 is rejected
#SBATCH --cpus-per-task=32

torchrun --nproc_per_node=2 train.py
</syntaxhighlight>
2-GPU jobs are put in the <code>gpu2</code> QOS automatically; you don't need <code>--qos</code>. They wait until both GPUs are free.

=== Example: a slice of a GPU (MPS) ===
<syntaxhighlight lang="bash" line="1" start="1">
#!/bin/bash
#SBATCH --gres=mps:50 # 50% of one GPU's compute
#SBATCH --time=2:00:00

python infer.py
</syntaxhighlight>
MPS limits the share of compute, '''not''' GPU memory, so be reasonable with memory, since others are sharing the card.

=== Email ===
You get an email at <code><user>@csclub.uwaterloo.ca</code> when a batch job ends. To turn this off, add <code>export SLURM_NO_MAIL=1</code> to your <code>~/.bashrc</code> (or run <code>SLURM_NO_MAIL=1 sbatch job.sh</code> for one job). <code>--mail-type=BEGIN,END,FAIL</code> / <code>--mail-user=</code> work as usual. Interactive (<code>srun</code>/<code>salloc</code>) jobs don't send email.

== Useful commands ==
<syntaxhighlight lang="bash">
sinfo # node/partition state
squeue # everyone's jobs (ST: R=running, PD=pending)
squeue --me # your jobs
squeue --me --start # estimated start time of pending jobs
scontrol show job <JOBID> # full details, incl. Reason= for pending jobs
scancel <JOBID> # cancel a job
sstat -j <JOBID>.batch # live CPU/memory use of a running batch job
sacct -j <JOBID> --format=JobID,Elapsed,State,ExitCode,MaxRSS
sshare -U # your fair-share standing
sprio -l # priority of pending jobs
</syntaxhighlight>

=== Why is my job pending? ===
{| class="wikitable"
! Reason !! Meaning
|-
| <code>QOSMaxJobsPerUserLimit</code> || You already have a running job. It starts when that one ends
|-
| <code>Resources</code> || Waiting for a GPU (or both GPUs) to be free
|-
| <code>Priority</code> || Someone with higher priority (less recent usage) is ahead of you
|-
| <code>QOSMaxWallDurationPerJobLimit</code> || The time limit is over what that QOS allows. Shouldn't happen, since such jobs are rejected at submit time
|}


== Installation/Config ==
== Installation/Config ==
This is the generic single-node setup. Tiramisu's actual config is described in the next section.
First you need to install the "slurm" packages and dependencies so run<syntaxhighlight lang="bash" start="1">

First install the Slurm packages and dependencies:<syntaxhighlight lang="bash" start="1">
sudo apt update
sudo apt update
sudo apt install slurm-wlm slurmd slurmctld munge -y
sudo apt install slurm-wlm slurmd slurmctld munge -y
</syntaxhighlight>Then you need to verify that there are MUNGE keys, which there should already be but run the following to check<syntaxhighlight lang="bash">
</syntaxhighlight>Then check that the MUNGE key exists (it should already):<syntaxhighlight lang="bash">
sudo test -f /etc/munge/munge.key && echo "Key exists" || echo "Key is missing"
sudo test -f /etc/munge/munge.key && echo "Key exists" || echo "Key is missing"
</syntaxhighlight>For this next part, you are going to need the systems hostname, CPU core count, and total RAM. Now create the file <code>/etc/slurm/slurm.conf</code> and write the following in it (replacing the temps with the mentioned data)<syntaxhighlight lang="ini" start="1" line="1">ClusterName=localcluster
</syntaxhighlight>For the next part you need the hostname, CPU count and total RAM. <code>slurmd -C</code> prints a ready-made <code>NodeName=</code> line. Create <code>/etc/slurm/slurm.conf</code> with the following, replacing the placeholders:<syntaxhighlight lang="ini" start="1" line="1">ClusterName=localcluster
SlurmctldHost=<your-hostname>
SlurmctldHost=<your-hostname>


Line 38: Line 175:
ProctrackType=proctrack/cgroup
ProctrackType=proctrack/cgroup
TaskPlugin=task/cgroup,task/affinity
TaskPlugin=task/cgroup,task/affinity
SelectType=select/cons_tres
SelectTypeParameters=CR_Core_Memory
SelectTypeParameters=CR_CPU_Memory


# Paths and logging
# Paths and logging
Line 50: Line 188:


# Node definition
# Node definition
NodeName=<your-hostname> CPUs=<CPU-cores> RealMemory=<Total-RAM> State=UNKNOWN
NodeName=<your-hostname> CPUs=<CPU-cores> RealMemory=<Total-RAM-MB> State=UNKNOWN


# Partition definition
# Partition definition
PartitionName=debug Nodes=<your-hostname> Default=YES MaxTime=INFINITE State=UP</syntaxhighlight>Also create the file <code>/etc/slurm/cgroup.conf</code> and write<syntaxhighlight lang="ini" line="1" start="1">
PartitionName=debug Nodes=<your-hostname> Default=YES MaxTime=INFINITE State=UP</syntaxhighlight>Also create <code>/etc/slurm/cgroup.conf</code> (<code>CgroupAutomount</code> is obsolete in current Slurm and is no longer needed):<syntaxhighlight lang="ini" line="1" start="1">
CgroupAutomount=yes
ConstrainCores=yes
ConstrainCores=yes
ConstrainRAMSpace=yes
ConstrainRAMSpace=yes
ConstrainDevices=yes
</syntaxhighlight>The last config step is to create the need directories for slurm's processes (state and spool) and transfer their ownership to slurm. To do that run the following<syntaxhighlight lang="bash">
</syntaxhighlight>Create the state and spool directories and make slurm their owner:<syntaxhighlight lang="bash">
sudo mkdir -p /var/lib/slurm/slurmd /var/lib/slurm/slurmctld
sudo mkdir -p /var/lib/slurm/slurmd /var/lib/slurm/slurmctld
sudo chown slurm:slurm /var/lib/slurm/slurmd /var/lib/slurm/slurmctld
sudo chown slurm:slurm /var/lib/slurm/slurmd /var/lib/slurm/slurmctld
</syntaxhighlight>Now enable the slurm controller/compute deamons <syntaxhighlight lang="bash">
</syntaxhighlight>Then enable and start the controller and compute daemons:<syntaxhighlight lang="bash">
sudo systemctl enable slurmctld slurmd
sudo systemctl enable --now slurmctld slurmd
sudo systemctl start slurmctld slurmd
</syntaxhighlight>
</syntaxhighlight>

== Tiramisu configuration (admins) ==
Slurm 24.11, one node (<code>tiramisu</code>), one partition <code>gpu</code> (DefaultTime 4h, MaxTime 12h). Files are in <code>/etc/slurm/</code>.

* '''Resources''': <code>select/cons_tres</code> with <code>CR_CPU_Memory</code>. <code>CoreSpecCount=32</code> and <code>MemSpecLimit=98304</code> keep 32 CPUs and 96 GB for normal use of the machine. <code>DefMemPerCPU=2048</code>, <code>DefCpuPerGPU=16</code>.
* '''GPUs''' (<code>gres.conf</code>): <code>gpu:nvidia_rtx_pro_6000_blackwell_server_edition:2</code> plus <code>mps:200</code> (100 per GPU). The MPS control daemon runs in multi-user mode (<code>nvidia-cuda-mps-control -d -M</code>).
* '''Accounting''': slurmdbd + MariaDB, <code>AccountingStorageEnforce=associations,limits,qos</code>, <code>AccountingStorageTRES=gres/gpu,gres/mps</code> (required or the GPU limits do nothing). Every user needs an association in account <code>gpu-users</code>. <code>/usr/local/sbin/slurm-sync-users</code> (hourly, <code>/etc/cron.d/slurm-sync-users</code>) adds current members from LDAP (<code>term</code>/<code>nonMemberTerm</code>) and removes lapsed ones. Extra always-allowed users go in <code>/etc/slurm/extra-users</code>.
* '''Priority''': <code>priority/multifactor</code>, <code>PriorityWeightFairShare=10000</code>, <code>PriorityWeightAge=1000</code>, <code>PriorityMaxAge=1-0</code>. Billing <code>CPU=0.01,GRES/gpu=1.0,GRES/mps=0.01</code>.
* '''QOS''':
{| class="wikitable"
! QOS !! Used by !! Limits
|-
| <code>gpu1</code> || Partition QOS (applies to every job) || <code>MaxJobsPerUser=1</code>, <code>MaxTRESPerJob=gres/gpu=1,gres/mps=100</code>, <code>Flags=DenyOnLimit</code>
|-
| <code>gpu2</code> || 2-GPU jobs (set by job_submit.lua) || <code>MaxTRESPerJob=gres/gpu=2,gres/mps=100</code>, <code>MaxWall=01:00:00</code>, <code>Flags=DenyOnLimit,OverPartQOS</code>. No <code>MaxJobsPerUser</code>, so <code>gpu1</code>'s one-job limit still applies
|}
: <code>gpu2</code> must be in the users' allowed QOS list: <code>sacctmgr modify account gpu-users set qos+=gpu2</code>.
* '''Submit filter''' (<code>job_submit.lua</code>): gives clear errors for >1 GPU, >mps:100, gpu+mps together, and per-socket requests. It defaults to <code>mps:25</code> when no GPU is requested, and turns on <code>--mail-type=END</code> for batch jobs (<code>SLURM_NO_MAIL=1</code> opts out). For 2-GPU jobs it sets <code>qos=gpu2</code> and <code>--time=60</code> if no time was given, rejects >60 min, and rejects <code>--qos=gpu2</code> on smaller jobs. The QOS limits are the real enforcement; the filter is for friendly messages.
* '''GPU ACLs''': <code>/dev/nvidia*</code> are <code>root:root 0660</code>. <code>prolog.sh</code> (<code>PrologFlags=Contain</code>, so it runs at allocation) adds <code>setfacl u:<uid>:rw</code> on <code>/dev/nvidiactl</code>, <code>/dev/nvidia-uvm*</code>, <code>/dev/nvidia-modeset</code> and the job's <code>/dev/nvidiaN</code>. It records each grant in <code>/run/gpu-acl/<ctl|gpuN>/<uid>.<jobid></code>. <code>epilog.sh</code> removes a user's ACL once they have no job left on that device. <code>ConstrainDevices=yes</code> also limits processes inside the job cgroup to the job's GPUs.
* '''Mail''': <code>MailDomain=csclub.uwaterloo.ca</code>. Exim relays via mail.csclub.uwaterloo.ca.

Setup scripts: <code>tiramisu-slurm-limits.sh</code> (base setup: dbd, QOS gpu1, filter, sync cron, mail) and <code>add-gpu2-qos.sh</code> (adds gpu2 and the 2-GPU filter; <code>--rollback</code> undoes it). Re-running <code>tiramisu-slurm-limits.sh apply</code> puts back the 1-GPU-only filter, so run <code>add-gpu2-qos.sh</code> again afterwards.


== Basic Testing ==
== Basic Testing ==
To check the install/to make sure it's running<syntaxhighlight lang="bash">
Check that the daemons are running:<syntaxhighlight lang="bash">
systemctl status slurmctld
systemctl status slurmctld slurmd slurmdbd
systemctl status slurmd
sinfo
sinfo
sacctmgr show qos format=name,flags%30,maxwall,maxtres%40,maxjobspu
</syntaxhighlight>If sinfo shows the node as down or drain, you can set it to idle by<syntaxhighlight lang="bash">sudo scontrol update nodename=localhost state=idle</syntaxhighlight>If sinfo fails to connect or the node is unresponsive, you can check the log by<syntaxhighlight lang="bash">
</syntaxhighlight>If sinfo shows the node as down or drain, set it back to idle:<syntaxhighlight lang="bash">sudo scontrol update nodename=tiramisu state=resume</syntaxhighlight>Quick GPU checks (as a normal user):<syntaxhighlight lang="bash">
sudo tail -f /var/log/slurmctld.log
srun --gres=gpu:1 nvidia-smi -L # 1 GPU
srun --gres=gpu:2 nvidia-smi -L # 2 GPUs, QOS gpu2, 1h limit
sbatch --gres=gpu:2 --time=2:00:00 --wrap=true # must be rejected
</syntaxhighlight>Check the ACLs while a job is running, and again after it ends (afterwards there should be no <code>user:</code> lines and <code>/run/gpu-acl</code> should be empty):<syntaxhighlight lang="bash">
getfacl -p /dev/nvidia0 /dev/nvidia1 /dev/nvidiactl | grep '^user:'
ls -R /run/gpu-acl
</syntaxhighlight>If sinfo fails to connect, the node is unresponsive, or jobs fail to start, check the logs:<syntaxhighlight lang="bash">
sudo tail -f /var/log/slurmctld.log /var/log/slurmd.log
journalctl -t slurm-gpu-acl -n 50 # prolog/epilog ACL messages
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 20:09, 19 November 2026

Why

Slurm (Simple Linux Utility for Resource Management) is a job scheduler. Use it when too many people are trying to use a machine at the same time and it keeps crashing, or when you want to share resources (especially GPUs) more fairly.

On tiramisu the two NVIDIA RTX PRO 6000 Blackwell GPUs can only be used through Slurm. Outside a job, nvidia-smi prints Failed to initialize NVML: Insufficient Permissions. That is expected: you get access to a GPU when your job starts, and lose it when the job ends.

Rules on tiramisu

What Limit
Running jobs per user 1 (others wait in the queue, reason QOSMaxJobsPerUserLimit)
GPUs per job 1 whole GPU (--gres=gpu:1), or a slice of one GPU with MPS (--gres=mps:N, N ≤ 100 = N% of one GPU)
Both GPUs 2 GPUs (--gres=gpu:2) for at most 1 hour
No GPU requested You get --gres=mps:25 (25% of one GPU) automatically
Time limit Default 4 hours, maximum 12 hours (2-GPU jobs: default and maximum 1 hour)
CPUs 96 of the 128 CPUs are available to Slurm (the rest are kept for normal use of the machine). A whole-GPU job gets 16 CPUs by default
Memory 2 GB per CPU by default (--mem / --mem-per-cpu to change)
Priority Fair-share: the more GPU time you used recently, the lower your priority. A 2-GPU job counts double

You can't combine gpu and mps in the same job. If a request breaks a rule, it is rejected at submit time with a message starting with tiramisu: that explains why.

Every current CSC member is registered automatically (synced from LDAP every hour). If you just renewed your membership and get Invalid account, wait up to an hour.

Interactive sessions

Interactive jobs follow the same rules as batch jobs: they count as your one running job, and they end when the time limit is reached.

Shell on a GPU (recommended)

# one whole GPU for 2 hours
srun --gres=gpu:1 --time=2:00:00 --pty bash

# 25% of one GPU (the default if you leave out --gres), 1 hour
srun --gres=mps:25 --time=1:00:00 --pty bash

# both GPUs (the time is set to 1 hour automatically, which is also the maximum)
srun --gres=gpu:2 --pty bash

# more CPUs/RAM
srun --gres=gpu:1 --cpus-per-task=16 --mem=64G --time=3:00:00 --pty bash

When the prompt comes back you are inside the job: nvidia-smi shows your GPU(s). Type exit to end the job and free the GPU.

Run it inside tmux or screen. If your SSH connection drops, srun and your job are killed. To keep it running:

tmux new -s gpu
srun --gres=gpu:1 --time=4:00:00 --pty bash
# detach: Ctrl-b d      reattach later: tmux attach -t gpu

salloc (allocate first, run steps later)

salloc --gres=gpu:1 --time=2:00:00
srun --pty bash          # now you are in the job, on the GPU
# ... work, exit the inner shell, run more srun steps ...
exit                     # leave salloc: this ends the job and frees the GPU

The shell salloc gives you is not inside the job (CUDA_VISIBLE_DEVICES is not set there). Always start work with srun inside it, or just use srun --pty bash directly as shown above.

Jupyter

On tiramisu (inside tmux), with a port number of your choice so you don't collide with others:

PORT=$((20000 + RANDOM % 10000)); echo $PORT
srun --gres=gpu:1 --time=3:00:00 --pty jupyter lab --no-browser --ip=127.0.0.1 --port=$PORT

On your laptop:

ssh -N -L 8888:127.0.0.1:<PORT> <user>@tiramisu.csclub.uwaterloo.ca

Then open the http://127.0.0.1:8888/...?token=... link Jupyter printed, replacing its port with 8888. Stop Jupyter (Ctrl-C twice) when you are done so the GPU is freed. Don't leave it idle until the time limit.

Getting a shell inside a job that is already running

Because you can only run one job at a time, a new srun waits while your batch job runs. To look at a running job (e.g. run nvidia-smi or htop on its GPU), attach to it instead:

srun --jobid=<JOBID> --overlap --pty bash

Batch jobs

Job config

  • --gres=gpu:1 one whole GPU; --gres=gpu:2 both GPUs (max 1 hour); --gres=mps:N N% of one GPU
  • --time time limit (e.g. 30:00, 4:00:00); ask for what you need, since shorter jobs start sooner
  • --ntasks the number of tasks (usually 1)
  • --cpus-per-task the number of CPUs per task
  • --mem-per-cpu RAM per CPU, or --mem total RAM (does NOT depend on CPU count)
  • --job-name, --output (default slurm-<jobid>.out in the directory you submitted from)

Example: one GPU

#!/bin/bash
#SBATCH --job-name=my_test
#SBATCH --gres=gpu:1
#SBATCH --cpus-per-task=8
#SBATCH --mem=32G
#SBATCH --time=4:00:00
#SBATCH --output=%x-%j.out

nvidia-smi
python train.py

Submit with sbatch job.sh.

Example: both GPUs (max 1 hour)

#!/bin/bash
#SBATCH --job-name=two_gpu
#SBATCH --gres=gpu:2
#SBATCH --time=1:00:00             # more than 1:00:00 is rejected
#SBATCH --cpus-per-task=32

torchrun --nproc_per_node=2 train.py

2-GPU jobs are put in the gpu2 QOS automatically; you don't need --qos. They wait until both GPUs are free.

Example: a slice of a GPU (MPS)

#!/bin/bash
#SBATCH --gres=mps:50              # 50% of one GPU's compute
#SBATCH --time=2:00:00

python infer.py

MPS limits the share of compute, not GPU memory, so be reasonable with memory, since others are sharing the card.

Email

You get an email at <user>@csclub.uwaterloo.ca when a batch job ends. To turn this off, add export SLURM_NO_MAIL=1 to your ~/.bashrc (or run SLURM_NO_MAIL=1 sbatch job.sh for one job). --mail-type=BEGIN,END,FAIL / --mail-user= work as usual. Interactive (srun/salloc) jobs don't send email.

Useful commands

sinfo                                  # node/partition state
squeue                                 # everyone's jobs (ST: R=running, PD=pending)
squeue --me                            # your jobs
squeue --me --start                    # estimated start time of pending jobs
scontrol show job <JOBID>              # full details, incl. Reason= for pending jobs
scancel <JOBID>                        # cancel a job
sstat -j <JOBID>.batch                 # live CPU/memory use of a running batch job
sacct -j <JOBID> --format=JobID,Elapsed,State,ExitCode,MaxRSS
sshare -U                              # your fair-share standing
sprio -l                               # priority of pending jobs

Why is my job pending?

Reason Meaning
QOSMaxJobsPerUserLimit You already have a running job. It starts when that one ends
Resources Waiting for a GPU (or both GPUs) to be free
Priority Someone with higher priority (less recent usage) is ahead of you
QOSMaxWallDurationPerJobLimit The time limit is over what that QOS allows. Shouldn't happen, since such jobs are rejected at submit time

Installation/Config

This is the generic single-node setup. Tiramisu's actual config is described in the next section.

First install the Slurm packages and dependencies:

sudo apt update
sudo apt install slurm-wlm slurmd slurmctld munge -y

Then check that the MUNGE key exists (it should already):

sudo test -f /etc/munge/munge.key && echo "Key exists" || echo "Key is missing"

For the next part you need the hostname, CPU count and total RAM. slurmd -C prints a ready-made NodeName= line. Create /etc/slurm/slurm.conf with the following, replacing the placeholders:

ClusterName=localcluster
SlurmctldHost=<your-hostname>

# Authentication
AuthType=auth/munge
CredType=cred/munge

# Process tracking and resource limits
ProctrackType=proctrack/cgroup
TaskPlugin=task/cgroup,task/affinity
SelectType=select/cons_tres
SelectTypeParameters=CR_CPU_Memory

# Paths and logging
SlurmUser=slurm
StateSaveLocation=/var/lib/slurm/slurmctld
SlurmdSpoolDir=/var/lib/slurm/slurmd
SlurmctldPidFile=/run/slurmctld.pid
SlurmdPidFile=/run/slurmd.pid
SlurmctldLogFile=/var/log/slurmctld.log
SlurmdLogFile=/var/log/slurmd.log

# Node definition
NodeName=<your-hostname> CPUs=<CPU-cores> RealMemory=<Total-RAM-MB> State=UNKNOWN

# Partition definition
PartitionName=debug Nodes=<your-hostname> Default=YES MaxTime=INFINITE State=UP

Also create /etc/slurm/cgroup.conf (CgroupAutomount is obsolete in current Slurm and is no longer needed):

ConstrainCores=yes
ConstrainRAMSpace=yes
ConstrainDevices=yes

Create the state and spool directories and make slurm their owner:

sudo mkdir -p /var/lib/slurm/slurmd /var/lib/slurm/slurmctld
sudo chown slurm:slurm /var/lib/slurm/slurmd /var/lib/slurm/slurmctld

Then enable and start the controller and compute daemons:

sudo systemctl enable --now slurmctld slurmd

Tiramisu configuration (admins)

Slurm 24.11, one node (tiramisu), one partition gpu (DefaultTime 4h, MaxTime 12h). Files are in /etc/slurm/.

  • Resources: select/cons_tres with CR_CPU_Memory. CoreSpecCount=32 and MemSpecLimit=98304 keep 32 CPUs and 96 GB for normal use of the machine. DefMemPerCPU=2048, DefCpuPerGPU=16.
  • GPUs (gres.conf): gpu:nvidia_rtx_pro_6000_blackwell_server_edition:2 plus mps:200 (100 per GPU). The MPS control daemon runs in multi-user mode (nvidia-cuda-mps-control -d -M).
  • Accounting: slurmdbd + MariaDB, AccountingStorageEnforce=associations,limits,qos, AccountingStorageTRES=gres/gpu,gres/mps (required or the GPU limits do nothing). Every user needs an association in account gpu-users. /usr/local/sbin/slurm-sync-users (hourly, /etc/cron.d/slurm-sync-users) adds current members from LDAP (term/nonMemberTerm) and removes lapsed ones. Extra always-allowed users go in /etc/slurm/extra-users.
  • Priority: priority/multifactor, PriorityWeightFairShare=10000, PriorityWeightAge=1000, PriorityMaxAge=1-0. Billing CPU=0.01,GRES/gpu=1.0,GRES/mps=0.01.
  • QOS:
QOS Used by Limits
gpu1 Partition QOS (applies to every job) MaxJobsPerUser=1, MaxTRESPerJob=gres/gpu=1,gres/mps=100, Flags=DenyOnLimit
gpu2 2-GPU jobs (set by job_submit.lua) MaxTRESPerJob=gres/gpu=2,gres/mps=100, MaxWall=01:00:00, Flags=DenyOnLimit,OverPartQOS. No MaxJobsPerUser, so gpu1's one-job limit still applies
gpu2 must be in the users' allowed QOS list: sacctmgr modify account gpu-users set qos+=gpu2.
  • Submit filter (job_submit.lua): gives clear errors for >1 GPU, >mps:100, gpu+mps together, and per-socket requests. It defaults to mps:25 when no GPU is requested, and turns on --mail-type=END for batch jobs (SLURM_NO_MAIL=1 opts out). For 2-GPU jobs it sets qos=gpu2 and --time=60 if no time was given, rejects >60 min, and rejects --qos=gpu2 on smaller jobs. The QOS limits are the real enforcement; the filter is for friendly messages.
  • GPU ACLs: /dev/nvidia* are root:root 0660. prolog.sh (PrologFlags=Contain, so it runs at allocation) adds setfacl u:<uid>:rw on /dev/nvidiactl, /dev/nvidia-uvm*, /dev/nvidia-modeset and the job's /dev/nvidiaN. It records each grant in /run/gpu-acl/<ctl|gpuN>/<uid>.<jobid>. epilog.sh removes a user's ACL once they have no job left on that device. ConstrainDevices=yes also limits processes inside the job cgroup to the job's GPUs.
  • Mail: MailDomain=csclub.uwaterloo.ca. Exim relays via mail.csclub.uwaterloo.ca.

Setup scripts: tiramisu-slurm-limits.sh (base setup: dbd, QOS gpu1, filter, sync cron, mail) and add-gpu2-qos.sh (adds gpu2 and the 2-GPU filter; --rollback undoes it). Re-running tiramisu-slurm-limits.sh apply puts back the 1-GPU-only filter, so run add-gpu2-qos.sh again afterwards.

Basic Testing

Check that the daemons are running:

systemctl status slurmctld slurmd slurmdbd
sinfo
sacctmgr show qos format=name,flags%30,maxwall,maxtres%40,maxjobspu

If sinfo shows the node as down or drain, set it back to idle:

sudo scontrol update nodename=tiramisu state=resume

Quick GPU checks (as a normal user):

srun --gres=gpu:1 nvidia-smi -L                     # 1 GPU
srun --gres=gpu:2 nvidia-smi -L                     # 2 GPUs, QOS gpu2, 1h limit
sbatch --gres=gpu:2 --time=2:00:00 --wrap=true      # must be rejected

Check the ACLs while a job is running, and again after it ends (afterwards there should be no user: lines and /run/gpu-acl should be empty):

getfacl -p /dev/nvidia0 /dev/nvidia1 /dev/nvidiactl | grep '^user:'
ls -R /run/gpu-acl

If sinfo fails to connect, the node is unresponsive, or jobs fail to start, check the logs:

sudo tail -f /var/log/slurmctld.log /var/log/slurmd.log
journalctl -t slurm-gpu-acl -n 50            # prolog/epilog ACL messages