Skip to content

[GPU Reset 2/3] Add per-GPU MIG partitioning and device/metrics lifecycle helpers - #643

Open
ankitjoju-google wants to merge 4 commits into
GoogleCloudPlatform:masterfrom
ankitjoju-google:gpu-reset-2-prep
Open

ankitjoju-google wants to merge 4 commits into
GoogleCloudPlatform:masterfrom
ankitjoju-google:gpu-reset-2-prep

Conversation

@ankitjoju-google

Copy link
Copy Markdown
Collaborator

GPU Reset, PR 2/3. Depends on PR 1/3 (#642); only the last commit is new here.

Why

A GPU reset must touch only the target GPUs and then put them back the way they were. Today MIG partitioning works on all GPUs at once, the manager has no way to mark individual GPUs unhealthy and restore them, and the metrics server holds NVML handles with no way to release them.

What

  • pkg/gpu/nvidia/mig: per-GPU (by PCI bus ID) helpers to check, destroy, and re-create MIG partitions; partition_gpu uses them with no behaviour change.
  • manager.go: PhysicalGPUIDs, DeviceHealth, UpdateGPUHealth (notifies ListAndWatch), MIGDeviceManager, exported IsMPSHealthy.
  • Health checker: RefreshDevices() so re-created MIG instances are tracked.
  • Metrics: Stop() / Start() that release NVML while keeping /metrics up, Registerer(), and ListPodGPUDevices (kubelet PodResources to namespace/pod).

No user-visible behaviour change on its own.

Testing

  • go vet ./..., go test -race ./pkg/gpu/nvidia/... ./cmd/... ./partition_gpu/...
  • Exercised as part of the GPU reset hardware runs on A4 (B200, including MIG 1g.23gb rebuild) and A4X Max (GB300).

Replaced the deprecated gpu-monitoring-tools library with the official go-nvml library.
Updated method signatures to use raw types for easier testability and mocking, avoiding issues with non-mockable nvml.Device struct.
Updated test cases to match new signatures and smaller mock instance IDs.
- Make Stop() idempotent, synchronize Start()/Stop() with a mutex, and
  wait for background goroutines (listenToEvents, setXIDheartbeat,
  resetXIDConditionWithBackoff) via sync.WaitGroup before freeing the
  NVML event set.
- Keep a single long-lived EventBroadcaster across Stop()/Start() cycles
  instead of attempting an invalid interface assertion in Stop() or
  leaking broadcasters on restart.
- Spawn background goroutines only after NVML device registration
  succeeds, and clean up the allocated eventSet on early Start() failure.
- Restore upstream/master MIG behavior: treat nvml.ERROR_NOT_SUPPORTED
  from GetMigMode() as MIG disabled, verify currentMode == pendingMode,
  and resolve MIG parent UUID and GI/CI IDs via go-nvml handles for
  modern R470+ MIG-<uuid> format with fallback to legacy regex parsing.
- Add unit tests covering idempotent Stop(), Stop()/Start() restart
  without broadcaster leaks, Start() error cleanup, and modern/legacy
  MIG UUID handling.
…el and optimize MIG

- Select on hc.stop when sending to hc.health in catchError so Stop()
  cannot deadlock if the health channel is full or unconsumed during
  teardown.
- Deduplicate physDevice.RegisterEvents calls per physical GPU UUID when
  multiple MIG instances share a parent GPU.
- Skip MIG NVML handle lookups in resolveMigDeviceInfo and
  GPUDevice.parseMigDeviceUUID when the device UUID does not start with
  "MIG-".
- Add TestStopUnderHealthChannelBackpressure and verify single
  RegisterEvents per physical GPU in TestMIGSupportModernAndLegacyUUIDs.
- Extract shared per-GPU MIG partitioning helpers (BuildPartitionStr,
  IsGPUPartitioned, DestroyPartitions, CreatePartitions, DiscoverGPU,
  PartitionIDs) into pkg/gpu/nvidia/mig and update partition_gpu.
- Add PhysicalGPUIDs, MIGDeviceManager, DeviceHealth, UpdateGPUHealth,
  and exported IsMPSHealthy helpers on nvidiaGPUManager.
- Add RefreshDevices on GPUHealthChecker to re-discover MIG instances
  across resets.
- Add Stop/Start/Registerer lifecycle methods on MetricServer and
  ListPodGPUDevices for kubelet PodResources attribution.

BUG=581484470
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