Coverage for cuda / core / system / _mig.pxi: 34.78%
23 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-29 01:27 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-29 01:27 +0000
1# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2#
3# SPDX-License-Identifier: Apache-2.0
6from typing import Iterable
9cdef class MigInfo:
10 cdef Device _device
12 def __init__(self, device: Device):
13 self._device = device 1ba
15 @property
16 def is_mig_device(self) -> bool:
17 """
18 Whether this device is a MIG (Multi-Instance GPU) device.
20 A MIG device handle is an NVML abstraction which maps to a MIG compute
21 instance. These overloaded references can be used (with some
22 restrictions) interchangeably with a GPU device handle to execute
23 queries at a per-compute instance granularity.
25 For Ampere™ or newer fully supported devices.
26 """
27 return bool(nvml.device_is_mig_device_handle(self._device._handle)) 1ba
29 @property
30 def mode(self) -> bool:
31 """
32 Get current MIG mode for the device.
34 For Ampere™ or newer fully supported devices.
36 Changing MIG modes may require device unbind or reset. The "pending" MIG
37 mode refers to the target mode following the next activation trigger.
39 Returns
40 -------
41 bool
42 `True` if current MIG mode is enabled.
43 """
44 current, _ = nvml.device_get_mig_mode(self._device._handle) 1a
45 return current == nvml.EnableState.FEATURE_ENABLED 1a
47 @mode.setter
48 def mode(self, mode: bool):
49 """
50 Set the MIG mode for the device.
52 For Ampere™ or newer fully supported devices.
54 Changing MIG modes may require device unbind or reset. The "pending" MIG
55 mode refers to the target mode following the next activation trigger.
57 Parameters
58 ----------
59 mode: bool
60 `True` to enable MIG mode, `False` to disable MIG mode.
61 """
62 nvml.device_set_mig_mode(
63 self._device._handle,
64 nvml.EnableState.FEATURE_ENABLED if mode else nvml.EnableState.FEATURE_DISABLED
65 )
67 @property
68 def pending_mode(self) -> bool:
69 """
70 Get pending MIG mode for the device.
72 For Ampere™ or newer fully supported devices.
74 Changing MIG modes may require device unbind or reset. The "pending" MIG
75 mode refers to the target mode following the next activation trigger.
77 If the device is not a MIG device, returns `False`.
79 Returns
80 -------
81 bool
82 `True` if pending MIG mode is enabled.
83 """
84 _, pending = nvml.device_get_mig_mode(self._device._handle) 1a
85 return pending == nvml.EnableState.FEATURE_ENABLED 1a
87 @property
88 def device_count(self) -> int:
89 """
90 Get the maximum number of MIG devices that can exist under this device.
92 Returns zero if MIG is not supported or enabled.
94 For Ampere™ or newer fully supported devices.
96 Returns
97 -------
98 int
99 The number of MIG devices (compute instances) on this GPU.
100 """
101 return nvml.device_get_max_mig_device_count(self._device._handle) 1a
103 @property
104 def parent(self) -> Device:
105 """
106 For MIG devices, get the parent GPU device.
108 For Ampere™ or newer fully supported devices.
110 Returns
111 -------
112 Device
113 The parent GPU device for this MIG device.
114 """
115 parent_handle = nvml.device_get_device_handle_from_mig_device_handle(self._device._handle)
116 parent_device = Device.__new__(Device)
117 parent_device._handle = parent_handle
118 return parent_device
120 def get_device_by_index(self, index: int) -> Device:
121 """
122 Get MIG device for the given index under its parent device.
124 If the compute instance is destroyed either explicitly or by destroying,
125 resetting or unbinding the parent GPU instance or the GPU device itself
126 the MIG device handle would remain invalid and must be requested again
127 using this API. Handles may be reused and their properties can change in
128 the process.
130 For Ampere™ or newer fully supported devices.
132 Parameters
133 ----------
134 index: int
135 The index of the MIG device (compute instance) to retrieve. Must be
136 between 0 and the value returned by `device_count - 1`.
138 Returns
139 -------
140 Device
141 The MIG device corresponding to the given index.
142 """
143 mig_device_handle = nvml.device_get_mig_device_handle_by_index(self._device._handle, index)
144 mig_device = Device.__new__(Device)
145 mig_device._handle = mig_device_handle
146 return mig_device
148 def get_all_devices(self) -> Iterable[Device]:
149 """
150 Get all MIG devices under its parent device.
152 If the compute instance is destroyed either explicitly or by destroying,
153 resetting or unbinding the parent GPU instance or the GPU device itself
154 the MIG device handle would remain invalid and must be requested again
155 using this API. Handles may be reused and their properties can change in
156 the process.
158 For Ampere™ or newer fully supported devices.
160 Returns
161 -------
162 list[Device]
163 A list of all MIG devices corresponding to this GPU.
164 """
165 for i in range(self.device_count): 1a
166 yield self.get_device_by_index(i)