Skip to content

amdgpu: include KFD compute occupancy in per-process usage - #555

Merged
Syllo merged 1 commit into
masterfrom
amdgpu-kfd-cu-occupancy
Nov 14, 2026
Merged

Syllo merged 1 commit into
masterfrom
amdgpu-kfd-cu-occupancy

Conversation

@Syllo

@Syllo Syllo commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Summary

ROCm/HIP submit work through KFD compute queues, which are not tracked by the
amdgpu DRM context manager. Their work therefore does not appear in the
drm-engine-* fdinfo counters, so an AMD GPU process that only uses KFD could
be listed without any gpu_usage.

This reads the per-process KFD compute-unit occupancy from
/sys/class/kfd/kfd/proc/<pid>/stats_<gpu_id>/cu_occupancy and adds it to the
process GPU utilization. OpenGL, Vulkan and OpenCL DRM contexts remain covered
by fdinfo; the two sources are disjoint.

Changes

  • Resolve the KFD gpu_id and active CU count from the topology node matching
    the DRM render minor.
  • Convert the CU count to a percentage of the node's active CUs, rounding to
    nearest.
  • Mark processes known to KFD as compute, instead of letting the generic fdinfo
    sweep default them to graphical.
  • Skip silently when the kernel or ASIC does not expose cu_occupancy.

Kernel support is documented in the README: CDNA since 5.11/6.2/6.6, RDNA 3/4
since 7.3, RDNA 1/2 since 7.4.

Testing

  • cmake --build build
  • ctest — 28/28 pass
  • Verified with a HIP workload on Linux 7.4.0-rc1: cu_occupancy reports the
    process's occupied CUs while its fdinfo has no engine counters.

KFD/HSA compute queues are not tracked by the amdgpu context manager, so
their work never appears in the DRM fdinfo engine counters. ROCm/HIP
processes can therefore be listed without a gpu_usage value even while they
are actively using the GPU. DRM contexts used by OpenGL, Vulkan and OpenCL
remain covered by fdinfo.

Read the per-process KFD compute unit occupancy from
/sys/class/kfd/kfd/proc/<pid>/stats_<gpu_id>/cu_occupancy, convert it to a
percentage of the node's active compute units, and add it to the process
gpu_usage. The KFD gpu_id is read from the matching topology node because
the stats directory is keyed by it rather than by the node directory index.

KFD-aware processes that the generic fdinfo sweep defaulted to graphical are
marked as compute. The sysfs file is optional: kernels and ASICs without
cu_occupancy support are skipped.

Tested on gfx1030 (Radeon RX 6800 XT) with Linux 7.4.0-rc1: an active HIP
process reports 64 of 72 CUs while its fdinfo contains no engine counters.
@Syllo
Syllo merged commit 6494389 into master Nov 14, 2026
8 checks passed
@Syllo
Syllo deleted the amdgpu-kfd-cu-occupancy branch November 14, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant