Repository navigation
Add T-Head PPU monitoring through HGML - #546
Merged
Merged
Conversation
HGML defines hgmlDevice_t as a struct containing the opaque handle pointer, not as a pointer typedef. The old definition happened to work through the calling convention, but it did not match the ABI in hgml.h. Use the same wrapper struct as the SDK and update the test mock.
HGML uses a 28-byte busId and puts globalPpuId at offset 64, keeping the structure the same size as NVML's PCI info. The previous 32-byte busId shifted globalPpuId to offset 68 and made the structure four bytes too large. Assert the expected layout in the backend test.
The clock, temperature, and PCIe selectors are HGML enums, not plain unsigned values. Declare the corresponding types and use their named constants so the dynamically loaded prototypes match hgml.h exactly.
Mark processes without a fresh utilization sample as 0% when the HGML query succeeded or reported no samples, so idle processes do not show N/A. Leave the value unset when per-process utilization is unavailable or the query fails. Update the tests and documentation accordingly.
Use reallocarray and COMMON_PROCESS_LINEAR_REALLOC_INC so adding a process does not reallocate on every refresh. Check the addition for overflow and keep the existing graceful failure behavior.
Add add_sanitizers(ppuTests) and HAS_REALLOCARRAY like the NVIDIA test. Cover PCI normalization failures and fallback, static information, invalid dynamic values, and an empty process list.
Preserve dlerror() on load failures, use hgmlErrorString() for HGML return codes when available, and include strerror() for allocation failures. Reset the error state after a successful initialization.
Fall back to the unversioned hgmlDeviceGetPciInfo when the v3/v2 symbols are missing, and prefer hgmlDeviceGetMemoryInfo_v2 with a v1 fallback. Test both memory paths and the missing PCI symbol.
Merge the duplicate supported-vendor list, add the HGML build dependency, reflow the T-Head section, and clarify that process enumeration is compute-only.
hgmlDeviceGetTemperature is deprecated as of HGML API 13 in favor of hgmlDeviceGetTemperatureV, which takes an hgmlTemperature_t and reports the sensor type explicitly. Load the versioned symbol when present and fall back to the legacy query for older runtimes or when it fails. A negative temperature from the versioned query is HGML's "not available" sentinel, so leave the value unset instead of falling back to a possibly stale legacy reading.
A failed initialization left the dynamically loaded HGML function pointers dangling after dlclose, and calling get_device_handles twice would overwrite the previous device array and leak it. Clear the loaded symbols on shutdown and before a fresh load, make initialization idempotent, and refuse to enumerate the same devices twice. Add tests for the symbol cleanup and the double-enumeration guard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds monitoring for T-Head PPUs through the dynamically loaded HGML runtime. PPU devices now appear in NVTOP with utilization, memory, compute/memory clocks, temperature, power, PCIe telemetry, and compute process memory and utilization.
PPU_SUPPORTby default on Linux without requiring vendor development headers at build time.Validation:
PPU_SUPPORT=ON; CTest passed.