-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathdeviceinfo.go
More file actions
275 lines (239 loc) · 7.78 KB
/
Copy pathdeviceinfo.go
File metadata and controls
275 lines (239 loc) · 7.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"fmt"
"github.com/Masterminds/semver/v3"
"github.com/NVIDIA/go-nvml/pkg/nvml"
resourceapi "k8s.io/api/resource/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/dynamic-resource-allocation/deviceattribute"
"k8s.io/utils/ptr"
)
// Represents a specific, full, physical GPU device.
type GpuInfo struct {
UUID string `json:"uuid"`
minor int
migCapable bool
migEnabled bool
vfioEnabled bool
memoryBytes uint64
productName string
brand string
architecture string
cudaComputeCapability string
driverVersion string
cudaDriverVersion string
pciBusID string
pciBusIDAttr *deviceattribute.DeviceAttribute
pcieRootAttr *deviceattribute.DeviceAttribute
migProfiles []*MigProfileInfo
addressingMode *string
// The following properties that can only be known after inspecting MIG
// profiles.
maxCapacities PartCapacityMap
memSliceCount int
}
// Represents a specific (concrete, incarnated, created) MIG device. Annotated
// properties are stored in the checkpoint JSON upon prepare.
type MigDeviceInfo struct {
// Selectively serialize some properties to the checkpoint JSON file (needed
// mainly for controlled deletion in the unprepare flow).
UUID string `json:"uuid"`
Profile string `json:"profile"`
ParentUUID string `json:"parentUUID"`
GiProfileID int `json:"profileId"`
// TODO: maybe embed MigLiveTuple.
ParentMinor int `json:"parentMinor"`
CIID int `json:"ciId"`
GIID int `json:"giId"`
// Store PlacementStart in the JSON checkpoint because in CanonicalName() we
// rely on this -- and this must work after JSON deserialization.
PlacementStart int `json:"placementStart"`
PlacementSize int `json:"placementSize"`
gIInfo *nvml.GpuInstanceInfo
cIInfo *nvml.ComputeInstanceInfo
parent *GpuInfo
giProfileInfo *nvml.GpuInstanceProfileInfo
ciProfileInfo *nvml.ComputeInstanceProfileInfo
}
type VfioDeviceInfo struct {
UUID string `json:"uuid"`
deviceID string
vendorID string
index int
parent *GpuInfo
productName string
PciBusID string `json:"pciBusID"`
pciBusIDAttr *deviceattribute.DeviceAttribute
pcieRootAttr *deviceattribute.DeviceAttribute
numaNode int
iommuGroup int
iommuFDEnabled bool
addressableMemoryBytes uint64
preConfigureDriver string
}
// CanonicalName returns the nameused for device announcement (in ResourceSlice
// objects). There is quite a bit of history to using the minor number for
// device announcement. Some context can be found at
// https://sigs.k8s.io/dra-driver-nvidia-gpu/issues/563#issuecomment-3345631087.
func (d *GpuInfo) CanonicalName() DeviceName {
return fmt.Sprintf("gpu-%d", d.minor)
}
// String returns both the GPU minor for easy recognizability, but also the
// UUID for precision. It is intended for usage in log messages.
func (d *GpuInfo) String() string {
return fmt.Sprintf("%s-%s", d.CanonicalName(), d.UUID)
}
func (m *MigDeviceInfo) SpecTuple() *MigSpecTuple {
return &MigSpecTuple{
ParentMinor: m.ParentMinor,
ProfileID: m.GiProfileID,
PlacementStart: m.PlacementStart,
}
}
func (m *MigDeviceInfo) LiveTuple() *MigLiveTuple {
return &MigLiveTuple{
ParentMinor: m.ParentMinor,
ParentUUID: m.ParentUUID,
GIID: m.GIID,
CIID: m.CIID,
MigUUID: m.UUID,
}
}
// Return the canonical MIG device name. The name unambiguously defines the
// physical configuration, but doesn't reflect the fact that this represents a
// curently-live MIG device.
func (d *MigDeviceInfo) CanonicalName() string {
return d.SpecTuple().ToCanonicalName(d.Profile)
}
func (d *VfioDeviceInfo) CanonicalName() string {
return fmt.Sprintf("gpu-vfio-%d", d.index)
}
// Populate internal data structures -- detail that is only known after
// inspecting all individual MIG profiles associated with this physical GPU.
func (d *GpuInfo) AddDetailAfterWalkingMigProfiles(maxcap PartCapacityMap, memSliceCount int) {
d.maxCapacities = maxcap
d.memSliceCount = memSliceCount
}
func (d *GpuInfo) Attributes() map[resourceapi.QualifiedName]resourceapi.DeviceAttribute {
attrs := map[resourceapi.QualifiedName]resourceapi.DeviceAttribute{
"type": {
StringValue: ptr.To(GpuDeviceType),
},
"uuid": {
StringValue: &d.UUID,
},
"productName": {
StringValue: &d.productName,
},
"brand": {
StringValue: &d.brand,
},
"architecture": {
StringValue: &d.architecture,
},
"cudaComputeCapability": {
VersionValue: ptr.To(semver.MustParse(d.cudaComputeCapability).String()),
},
"driverVersion": {
VersionValue: ptr.To(semver.MustParse(d.driverVersion).String()),
},
"cudaDriverVersion": {
VersionValue: ptr.To(semver.MustParse(d.cudaDriverVersion).String()),
},
}
if d.pciBusIDAttr != nil {
attrs[d.pciBusIDAttr.Name] = d.pciBusIDAttr.Value
}
if d.pcieRootAttr != nil {
attrs[d.pcieRootAttr.Name] = d.pcieRootAttr.Value
}
if d.pciBusIDAttr != nil {
attrs[d.pciBusIDAttr.Name] = d.pciBusIDAttr.Value
}
if d.addressingMode != nil {
attrs["addressingMode"] = resourceapi.DeviceAttribute{
StringValue: d.addressingMode,
}
}
return attrs
}
func (d *GpuInfo) GetDevice() resourceapi.Device {
device := resourceapi.Device{
Name: d.CanonicalName(),
Attributes: d.Attributes(),
Capacity: d.fullGpuCapacity(),
}
return device
}
func (d *MigDeviceInfo) GetDevice() resourceapi.Device {
attrs := CommonAttributesMig(d.parent, d.Profile)
attrs["uuid"] = resourceapi.DeviceAttribute{
StringValue: &d.UUID,
}
device := resourceapi.Device{
Name: d.CanonicalName(),
Attributes: attrs,
Capacity: CommonCapacitiesMig(d.giProfileInfo),
}
// Note(JP): noted elsewhere; what's the purpose of announcing memory slices
// as capacity? Do we want to allow users to request specific placement?
for i := d.PlacementStart; i < d.PlacementStart+d.PlacementSize; i++ {
capacity := resourceapi.QualifiedName(fmt.Sprintf("memorySlice%d", i))
device.Capacity[capacity] = resourceapi.DeviceCapacity{
Value: *resource.NewQuantity(1, resource.BinarySI),
}
}
return device
}
func (d *VfioDeviceInfo) GetDevice() resourceapi.Device {
device := resourceapi.Device{
Name: d.CanonicalName(),
Attributes: map[resourceapi.QualifiedName]resourceapi.DeviceAttribute{
"type": {
StringValue: ptr.To(VfioDeviceType),
},
"uuid": {
StringValue: &d.UUID,
},
"deviceID": {
StringValue: &d.deviceID,
},
"vendorID": {
StringValue: &d.vendorID,
},
"numa": {
IntValue: ptr.To(int64(d.numaNode)),
},
"productName": {
StringValue: &d.productName,
},
"iommuFDEnabled": {
BoolValue: ptr.To(d.iommuFDEnabled),
},
},
Capacity: map[resourceapi.QualifiedName]resourceapi.DeviceCapacity{
"addressableMemory": {
Value: *resource.NewQuantity(int64(d.addressableMemoryBytes), resource.BinarySI),
},
},
}
if d.pciBusIDAttr != nil {
device.Attributes[d.pciBusIDAttr.Name] = d.pciBusIDAttr.Value
}
if d.pcieRootAttr != nil {
device.Attributes[d.pcieRootAttr.Name] = d.pcieRootAttr.Value
}
return device
}