Optimizing Slurm GPU Jobs with Zymtrace
Run Zymtrace, the AI Infrastructure Optimization Platform, on Slurm and trace GPU bottlenecks back to the PyTorch code, CUDA kernels or threads behind them, with no code changes.
Garry Richardson
This blog post provides a hands-on guide to optimizing Slurm jobs with Zymtrace. If you’re already familiar with Slurm and the Zymtrace installation, feel free to skip straight to Now let’s optimize a Slurm GPU job with Zymtrace.
Slurm (Simple Linux Utility for Resource Management) is still how most research labs, HPC (high-performance computing) centers and AI teams share GPU clusters. Its main purpose is to decide who gets a GPU and when. But it cannot tell you what happened once the job started: whether the GPU was doing useful work, or sitting idle waiting on data, memory or the CPU.
The limited visibility matters. A job can occupy dozens of GPUs for twelve hours and finish with a clean “completed”, and still have spent most of that time stalled. On a shared production cluster, those hidden stalls compound into longer queues, unhappy users or customers, and capacity that’s allocated but not productive.
In this guide, we’ll close that gap. We’ll deploy Zymtrace, the AI Infrastructure Optimization Platform, on a single all-in-one node, with the Slurm controller and GPU compute on the same machine. Every Slurm job is then automatically analyzed for wasted GPU time, with actionable fixes to get more throughput from the same hardware and no changes to your application code.
Environment Prerequisites
- Slurm already installed with cgroup v2. In this blog we tested with Slurm 23.11.4
- NVIDIA GPU with CUDA 12.x or later
- Docker Compose already installed
- A Linux node to run the Zymtrace backend components (in this guide, the same all-in-one node)
Validate the Slurm configuration
cgroup v2 check
Zymtrace relies on cgroup v2 to identify which Slurm job each GPU sample belongs to. Most modern Linux distributions use cgroup v2 by default, and Slurm uses it to isolate each job.
Check that cgroup v2 is enabled. The command should return cgroup2fs.
stat -fc %T /sys/fs/cgroup
The Zymtrace profiler already reads the cgroup of every process it samples, so it picks up the Slurm job context straight from the kernel. There’s no sidecar, no instrumentation and no change to your job scripts. The job_<jobid> part of the cgroup path gives slurm.job.id, and Zymtrace looks up the job’s name and user from the metadata Slurm records for that cgroup.
Because the tag comes from the cgroup, it sits alongside every other dimension Zymtrace collects. A GPU job shows up with its slurm.job.* attributes plus its gpu.name, host.name, container.name and, on NVIDIA, its MIG instance. That means you can go from “which of Joe’s jobs is hottest on the GPU?” straight to the exact CUDA or HIP kernel responsible.
Slurm attribution applies everywhere in Zymtrace:
- GPU flamegraphs: CUDA and HIP kernels, memory operations and synchronization, linked to the CPU stacks that launched them
- GPU and host metrics: utilization, memory, power and other NVIDIA and AMD device metrics
- CPU profiles: native code, Python, Go, Java, Node, Ruby and more
slurm.conf validation
Most production Slurm clusters already use cgroup plugins: proctrack/cgroup and task/cgroup. If yours does and runs on cgroup v2, Zymtrace can attribute profiles to jobs with no Slurm configuration changes.
Check that slurm.conf sets the required plugins.
# slurm.conf
# Required for Zymtrace job attribution
ProctrackType=proctrack/cgroup
TaskPlugin=task/cgroup,task/affinity
# Recommended for per-job accounting; not needed for attribution
JobAcctGatherType=jobacct_gather/cgroup
cgroup.conf validation
Zymtrace only needs CgroupPlugin=cgroup/v2 in cgroup.conf. The Constrain* options are Slurm’s standard resource-isolation controls. We recommend them, but job attribution works without them.
# cgroup.conf
CgroupPlugin=cgroup/v2
ConstrainCores=yes
ConstrainRAMSpace=yes
ConstrainSwapSpace=no
ConstrainDevices=yes
If you’re running Slurm 26.05 or later, cgroup v2 job directories are named by SLUID by default rather than by job ID. To keep job IDs in the path, add CgroupJobIdPaths=yes to cgroup.conf.
Restart the controller and compute daemons to apply the changes. If you also changed ProctrackType in the previous step, check that no jobs are running before you restart (squeue should be empty).
sudo systemctl restart slurmctld
sudo systemctl restart slurmd
Verify Slurm and cgroup v2 before installing Zymtrace
Before installing Zymtrace, check each job runs in its own cgroup.
If jobs do not get their own cgroup, Zymtrace cannot tag profiles with Slurm job details.
To confirm that each job runs in its own cgroup, replace labuser with your username and run:
sudo -iu labuser srun --gres=gpu:1 cat /proc/self/cgroup
/proc/self/cgroup shows the cgroup that the current process (here, cat running inside the job) belongs to. You should see something like:
0::/system.slice/slurmstepd.scope/job_3/step_0/user/task_0
job_3: the Slurm job ID. This part has to be there before installing Zymtrace.
Install Zymtrace Backend (Docker Compose)
The Zymtrace backend stores, processes and analyzes the profiler data collected. All the core backend services are written in Rust, and the front end is a combination of ReactJS and WASM. See the architecture for details.
Data flows: the profiler pushes stack traces, metrics and metadata to the Zymtrace gateway service, which routes them to the appropriate backend services for analysis.
Download the latest Docker Compose file for the Zymtrace backend onto a Linux node that the GPU nodes can reach over the network. In this guide, that’s our all-in-one node.
mkdir ~/zymtrace && cd ~/zymtrace
curl -LO https://dl.zystem.io/zymtrace/latest/noarch/docker-compose.yml
Start the backend in the background and check every service came up:
sudo docker compose up -d --remove-orphans
The first run can take a few minutes while the images download.
Check the status of each container:
sudo docker compose ps
Every service should show running, healthy, or Up in the STATUS column.
Then confirm the UI is responding through the gateway:
curl -sI http://localhost:8080 | head -1
You should see HTTP/1.1 200 OK. If you see Connection refused, the gateway isn’t up yet: wait a moment and try again, or check docker compose ps.
Open the UI. Browse to http://localhost:8080.
Once the UI loads, the backend is ready. Next, we’ll install the profiler so it starts sending data.
Install Zymtrace Profiler (binary + systemd)
The profiler runs directly on the host as root, outside Slurm. That way it sees every process on the node, including every Slurm job, without needing to be inside one. On our all-in-one node, it sends its data to the backend running on the same machine.
The profiler needs root to load its eBPF programs into the kernel. That’s how we see every CPU and GPU process on the node. For GPU profiling, add one environment variable to your sbatch script, but there are no changes to your application code.
Download and extract the profiler
curl -LO https://dl.zystem.io/zymtrace/latest/amd64/zymtrace-profiler.tar.gz
sudo tar -xzvf zymtrace-profiler.tar.gz -C / --no-same-owner
amd64: the build for x86-64 nodes. Use thearm64build on Arm systems.-C /: extracts to the root filesystem, because the tarball already contains its full install path. Everything lands in/opt/zymtrace/profiler/.--no-same-owner: makes the extracted files owned by root rather than the user ID they had when the tarball was built.
Check the files are in place:
ls /opt/zymtrace/profiler/
You should see:
zymtrace-profiler: the profiler itself, which runs on the host and sends data to the backend.libzymtracecudaprofiler.so: the CUDA profiling library.
Test the profiler in the foreground
We recommend running the profiler as a service, but first let’s run it once in the foreground. This confirms it can start, load its eBPF programs and reach the backend, and any errors print straight to your terminal.
sudo /opt/zymtrace/profiler/zymtrace-profiler \
--collection-agent localhost:8080 \
--disable-tls \
--nvml-auto-scan
--collection-agent localhost:8080: where to send profiling data.--disable-tls: connects without TLS. That’s fine for a lab, but enabling TLS is recommended and supported in production environments.--nvml-auto-scan: finds the node’s NVIDIA GPUs automatically through NVML (NVIDIA’s management library), so GPU metrics are collected without listing devices by hand.
Run the profiler as a systemd service
Running the profiler in the foreground is fine for a quick test, but it stops as soon as you close the terminal or the node reboots. For continuous profiling, we run it as a systemd service instead. systemd then starts it automatically on boot, restarts it if it stops, and collects its logs so you can check on it with journalctl.
This is our recommended way to run the profiler on any node you want to profile long term.
Create the service file at /etc/systemd/system/zymtrace.service:
Here, we are using a single all-in-one node. Replace localhost:8080 with the IP or host name of the backend node.
sudo tee /etc/systemd/system/zymtrace.service > /dev/null <<'EOF'
[Unit]
Description=zymtrace profiler service
After=network-online.target docker.service
Wants=network-online.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/zymtrace/profiler
ExecStart=/opt/zymtrace/profiler/zymtrace-profiler --collection-agent localhost:8080 --disable-tls --nvml-auto-scan
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
Then load, enable and start it:
sudo systemctl daemon-reload
sudo systemctl enable --now zymtrace
Check it’s running and connected:
sudo systemctl status zymtrace
The output should show active (running), as follows. The logs should show the same connection message you saw in the smoke test.
Injecting the profiler into your workload
CPU profiling already works for every job, because the profiler is watching the whole node. To see what happens on the GPU, which CUDA kernels run, how long they take and why they stall, each job needs one environment variable.
When a program starts using CUDA, the CUDA driver checks CUDA_INJECTION64_PATH. If it points to a library, CUDA loads that library into the process automatically. NVIDIA’s own tools, such as Nsight, use the same mechanism.
Pointing it at the Zymtrace CUDA library lets Zymtrace capture GPU activity and link it back to the CPU code that launched it. You add one environment variable to the job, but your application code, and the way you run it, stay exactly the same.
Per sbatch job method
Add this line to any sbatch script, before starting the sbatch workload:
export CUDA_INJECTION64_PATH=/opt/zymtrace/profiler/libzymtracecudaprofiler.so
This is the easiest way to start: you choose which jobs get GPU profiling, and other jobs are unaffected. Because Slurm passes your environment to the job, you can also set the variable in your shell before srun or sbatch, but putting it in the script makes it explicit and repeatable.
Now let’s optimize a Slurm GPU job with Zymtrace
To test the setup, we run a synthetic GPU workload modeled on a thermal simulation. Each step launches over 100 small GPU kernels across a 512 MB grid, then forces the CPU to wait for the result before starting the next one. It’s a pattern you see a lot in real research code, and it’s exactly the kind of waste Zymtrace is built to surface.
To investigate our workload we will analyze two Slurm jobs, job ID 5 and job ID 8, both run as user joe. Let’s look into the following areas in the Zymtrace UI:
Efficiency IQ > Top 5 Functions investigation
First, we selected Slurm job 5 and looked at the Top 5 Functions:
void at::native::vectorized_elementwise_kernel<4, at::native::BinaryFunctor<float, float, float, at::native::binary_internal::MulFunctor<float> >, std::array<char*, (unsigned long)3>, false>(int, at::native::BinaryFunctor<float, float, float, at::native::binary_internal::MulFunctor<float> >, std::array<char*, (unsigned long)3>)
This is one of the many single-operation kernels launched every step. Each one makes a full round trip through GPU memory to do a tiny amount of math, which is an inefficient way to use a GPU.
Each cooling_step in our code multiplies two tensors three times, once inside each thermal_response call, and once more for conduction. Over 8 iterations, that’s about 24 separate kernel launches per simulation step, just for multiplication.
Analyzing the CUDA flamegraph
The flamegraph also clearly surfaces the inefficiencies in our workload. The same pattern repeats for division, subtraction and addition, with each one launching its own kernel cudaLaunchKernel and making its own trip through High Bandwidth Memory.
What do the recommendations tell us?
Looking at the suggested recommendations, Zymtrace is surfacing Unfused elementwise GELU saturates HBM bandwidth, and additional details in the event Wrap cooling_step/simulate_thermal_diffusion in torch.compile (Inductor) so the whole step becomes one or two fused elementwise kernels.
We wrapped the step in torch.compile and re-ran it as job 8
With the change applied, let’s analyze it again.
Repeating the same process as before, we can see in the Top 5 Functions the following:
triton_poi_fused_add_div_erf_mul_sub_0
After applying torch.compile, 99.8% of GPU time sits in a single CUDA kernel: triton_poi_fused_add_div_erf_mul_sub_0. The 100 separate multiply, divide, erf, add and subtract kernels from the v1 workload (job ID 5) have been fused into one, and the name lists the operations it merged. Everything else, including the memory copy and the max reduction, accounts for less than 0.2%.
The Diff Function Details view below shows the cudaLaunchKernel time before and after for job ID 5 vs job ID 8.
The GPU is now spending its time on real math rather than launching hundreds of single-operation kernels. Each element is read once, put through 8 iterations of calculations, and written back once, so the work has shifted from memory-bound towards compute-bound.
The GPU memory metrics also show another win. GPU memory use dropped from about 4.2 GiB in job ID 5 to 1.66 GiB in job ID 8, because the fused kernel no longer stores a temporary copy of the data after every operation.
Summary
Slurm decides who gets a GPU, but not what happens once a job starts. In this guide, we closed that gap by deploying Zymtrace on a Slurm node. Every job is now profiled automatically, with no changes to application code and just one environment variable for GPU profiling.
Using a synthetic thermal simulation, Zymtrace showed the problem straight away: dozens of single-operation kernels per step, each making its own trip through GPU memory. Adding torch.compile fused them into a single kernel, reducing time spent in cudaLaunchKernel from about 44 minutes to under half a second, and cutting GPU memory use from about 4.2 GiB to 1.66 GiB, on the same hardware.
That’s the value of seeing inside every Slurm job: finding wasted GPU time and turning it into more throughput from the GPUs you already have.
Get started
Get started with Zymtrace at no cost.
Deploy Zymtrace, install the profiler, and give your coding agent the runtime context it needs to find bottlenecks, prepare fixes, and verify the result.