Skip to content

feat(detector): support Hygon MIG detection - #22

Merged
thxCode merged 4 commits into
gpustack:mainfrom
thxCode:spec/hygon-mig-detection
Aug 31, 2026
Merged

feat(detector): support Hygon MIG detection#22
thxCode merged 4 commits into
gpustack:mainfrom
thxCode:spec/hygon-mig-detection

Conversation

@thxCode

@thxCode thxCode commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

What

Align the Hygon detector with the operator's Hygon MIG support (gpustack-operator v0.8.6), the same way NVIDIA and T-Head MIG are already handled:

  • gpustack_runtime/detector/pydmi/ — a vendored ctypes binding for the vendor's libhydmi_mig.so (DMI MIG library). The vendor exports this API under NVML's symbol names while implementing something else, so every wrapper is dmi-prefixed and the library is loaded RTLD_LOCAL to avoid colliding with libnvidia-ml.so in a process that has both. Struct layouts follow the vendor's dmi_mig.h (v1.3.1), not pynvml. The vendor API has no init/shutdown calls, so dmiInit only loads and resolves the library.
  • detect_info — when the node-wide MIG mode is on, each reachable card is marked mig: True and its live instances are enumerated into appendix["mig_devices"] with the same inventory detail a plain device carries: conf-registry UUID (MIG-<uuid>, synthetic MIG-<bdf>-gi<G>-ci<C> fallback), profile-derived name/memory/cores, GI/CI ids, and placement. Numbering rides the shared index_mig_devices per-card blocks. With MIG enabled HSA exposes only a partition's view of the card, so the physical core count is derived from the GPU-instance profiles. A missing library, an unreadable mode, or a DMI-unreachable card degrades to exactly today's physical-only behavior; one unreadable instance is suppressed individually and never aborts the sweep.
  • detect_usage — each live instance's memory total/used and cores utilization are read through its own MIG device handle and merged by UUID via merge_devices_usage.

The detector stays strictly read-only: no create/destroy/set-mode symbols are bound, hy-smi is never invoked, and no new dependencies are added.

Test plan

  • make lint clean; uv run pytest tests/ — 605 passed, 20 skipped (new: test_pydmi.py binding/layout/error-path tests, Hygon MIG inventory/usage/degradation tests, CLI mig_devices JSON serialization case).
  • End-to-end on root@10.211.10.37 (8x Hygon C-3000, DTK 25.04.4): with MIG off, output is identical to before (8 physical cards, no MIG keys); with MIG on and 4 instances across 2 cards (4g.31gb + 2g.15gb mixes), the detector output matches hy-smi mig -lgi/-lci and /etc/dmi_mig_config/ci/*.conf one-to-one on UUID, memory, GI/CI ids, and placement. The machine was restored afterwards (instances destroyed, MIG mode disabled).

Notes

Known fail-safe gaps on non-standard configurations (heterogeneous MIG capacities, sub-GI compute profiles) and standalone docker/podman deployment of Hygon MIG partitions are deliberately out of scope here and tracked as follow-ups.

- ctypes binding over libhydmi_mig.so, loaded RTLD_LOCAL (the vendor
  exports NVML symbol names; global linkage would collide with
  libnvidia-ml.so), searched on the default linker path plus
  /opt/hyhal/lib and /opt/dtk/lib
- struct layouts follow the vendor's dmi_mig.h v1.3.1, not pynvml
- DMI-prefixed wrappers raise the package's own DMIError subclasses on
  any non-success return, never a bare OSError
- array queries re-wrap handles at full pointer width; the vendor API
  has no init/shutdown entry point, so dmiInit only loads the library
- smoke-validated on root@10.211.10.37 against libhydmi_mig.so.1.3:
  load, node-wide MIG mode, handle-by-BDF, memory reads on all 8 DCUs

Task 1 of hygon-mig-detection.

Signed-off-by: thxCode <thxcode0824@gmail.com>
- read the node-wide MIG mode via pydmi; when enabled, every card
  reachable through libhydmi_mig.so is marked mig: true and carries its
  live instances in appendix.mig_devices
- enumerate instances by sweeping the node-global MIG index space,
  attributing each handle by its GI info's parent device, never by
  index ranges; per-instance failures are suppressed individually
- instance identity comes from the vendor registry
  /etc/dmi_mig_config/ci/dev<N>gi<G>ci<C>.conf (reported as MIG-<uuid>),
  falling back to a synthetic MIG-<bdf>-gi<G>-ci<C> when unreadable
- name/memory/cores come from the GI profile sweep; indexes are
  assigned by index_mig_devices; a missing library or an unreadable
  mode degrades to physical-only detection

Task 2 of hygon-mig-detection.

Signed-off-by: thxCode <thxcode0824@gmail.com>
- read each instance's memory and compute utilization through its own
  MIG device handle and merge by UUID via merge_devices_usage
- a single unreadable instance is suppressed individually, never
  aborting the sweep; instances carry the card's temperature and power
- the usage query re-reads the node-wide MIG mode and stays
  physical-only when the mode is off or the library is missing

Task 3 of hygon-mig-detection.

Signed-off-by: thxCode <thxcode0824@gmail.com>
- keep a MIG device's per-card discovery ordinal when an earlier
  instance's read fails, instead of renumbering the survivors
- derive the physical core count from GPU-instance profiles while MIG
  is enabled, where HSA exposes only a partition's view
- carry the card's memory-health verdict into its MIG entries
- tolerate non-UTF-8 vendor strings in profile names and the conf
  registry instead of aborting the whole detection

Signed-off-by: thxCode <thxcode0824@gmail.com>
Copilot AI lite review requested due to automatic review settings August 31, 2026 07:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces Python bindings for the Hygon DMI Multi-Instance library (pydmi) and implements Multi-Instance GPU (MIG) detection and usage tracking for Hygon GPUs. It also adds comprehensive unit tests for both the pydmi bindings and the updated Hygon detector.

Feedback on the changes suggests refactoring duplicated code in hygon.py into helper functions, specifically for checking if MIG is enabled and for retrieving the DMI device handle and index. Additionally, it is recommended to use the with statement for managing threading.Lock in pydmi/__init__.py to ensure idiomatic and safe lock handling.

Comment thread gpustack_runtime/detector/hygon.py
Comment thread gpustack_runtime/detector/hygon.py
Comment thread gpustack_runtime/detector/hygon.py
Comment thread gpustack_runtime/detector/hygon.py
Comment thread gpustack_runtime/detector/pydmi/__init__.py
Comment thread gpustack_runtime/detector/pydmi/__init__.py
@thxCode
thxCode merged commit 5918765 into gpustack:main Aug 31, 2026
7 checks passed
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.

2 participants