-
Notifications
You must be signed in to change notification settings - Fork 296
Expand file tree
/
Copy pathcontainer_virtual_device_test.go
More file actions
697 lines (573 loc) · 23.1 KB
/
Copy pathcontainer_virtual_device_test.go
File metadata and controls
697 lines (573 loc) · 23.1 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
// +build functional
package cri_containerd
import (
"context"
"fmt"
"os/exec"
"strings"
"testing"
"time"
"github.com/Microsoft/hcsshim/osversion"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
)
const containerDeviceUtilPath = "C:\\device-util.exe"
const gpuWin32InstanceIDPrefix = "PCI#VEN_10DE"
// makeGPUExecCommand constructs the container command to check for the
// existence of a nvidia GPU device and returns the command in an
// ExecSyncRequest
func makeGPUExecCommand(os string, containerID string) *runtime.ExecSyncRequest {
cmd := []string{"ls", "/dev/nvidia0"}
if os == "windows" {
cmd = []string{containerDeviceUtilPath, "obj-dir"}
}
return &runtime.ExecSyncRequest{
ContainerId: containerID,
Cmd: cmd,
Timeout: 20,
}
}
// verifyGPUIsPresent is a helper function that runs a command in the container
// to verify the existence of a GPU and fails the running test is none are found
func verifyGPUIsPresentLCOW(t *testing.T, client runtime.RuntimeServiceClient, ctx context.Context, containerID string) {
execReq := makeGPUExecCommand("linux", containerID)
response := execSync(t, client, ctx, execReq)
if len(response.Stderr) != 0 {
t.Fatalf("expected to see no error, instead saw %s", string(response.Stderr))
}
if len(response.Stdout) == 0 {
t.Fatal("expected to see GPU device on container, not present")
}
}
func isGPUPresentWCOW(t *testing.T, client runtime.RuntimeServiceClient, ctx context.Context, containerID string) bool {
execReq := makeGPUExecCommand("windows", containerID)
response := execSync(t, client, ctx, execReq)
if len(response.Stderr) != 0 {
t.Fatalf("expected to see no error, instead saw %s", string(response.Stderr))
}
out := string(response.Stdout)
devices := strings.Split(out, ",")
if len(devices) == 0 {
t.Fatal("expected to see devices on container, none found")
}
for _, d := range devices {
if strings.HasPrefix(d, gpuWin32InstanceIDPrefix) {
return true
}
}
return false
}
// verifyGPUIsNotPresent is a helper function that runs a command in the container
// to verify that there are no GPUs present in the container and fails the running test
// if any are found
func verifyGPUIsNotPresentLCOW(t *testing.T, client runtime.RuntimeServiceClient, ctx context.Context, containerID string) {
execReq := makeGPUExecCommand("linux", containerID)
response := execSync(t, client, ctx, execReq)
if len(response.Stderr) == 0 {
t.Fatal("expected to see an error as file /dev/nvidia0 should not exist, instead saw none")
} else if len(response.Stdout) != 0 {
t.Fatal("expected to not see GPU device on container, but some are present")
}
}
// findTestNvidiaGPUDevice returns the first nvidia pcip device on the host
func findTestNvidiaGPUDevice() (string, error) {
out, err := exec.Command(
"powershell",
`(Get-PnpDevice -presentOnly | where-object {$_.InstanceID -Match 'PCIP\\VEN_10DE.*'})[0].InstanceId`,
).Output()
if err != nil {
return "", err
}
return strings.TrimSpace(string(out)), nil
}
// findTestNvidiaGPULocationPath returns the location path of the first pci nvidia device on the host
func findTestNvidiaGPULocationPath() (string, error) {
out, err := exec.Command(
"powershell",
`((Get-PnpDevice -presentOnly | where-object {$_.InstanceID -Match 'PCI\\VEN_10DE.*'})[0] | Get-PnpDeviceProperty DEVPKEY_Device_LocationPaths).Data[0]`,
).Output()
if err != nil {
return "", nil
}
return strings.TrimSpace(string(out)), nil
}
// findTestVirtualDeviceID returns the instance ID of the first generic pcip device on the host
func findTestVirtualDeviceID() (string, error) {
out, err := exec.Command(
"powershell",
`(Get-PnpDevice -presentOnly | where-object {$_.InstanceID -Match 'PCIP.*'})[0].InstanceId`,
).Output()
if err != nil {
return "", nil
}
return strings.TrimSpace(string(out)), nil
}
func getGPUPodRequestLCOW(t *testing.T) *runtime.RunPodSandboxRequest {
return &runtime.RunPodSandboxRequest{
Config: &runtime.PodSandboxConfig{
Metadata: &runtime.PodSandboxMetadata{
Name: t.Name(),
Namespace: testNamespace,
},
Annotations: map[string]string{
"io.microsoft.virtualmachine.lcow.kerneldirectboot": "false",
"io.microsoft.virtualmachine.computetopology.memory.allowovercommit": "false",
"io.microsoft.virtualmachine.lcow.preferredrootfstype": "initrd",
"io.microsoft.virtualmachine.devices.virtualpmem.maximumcount": "0",
"io.microsoft.virtualmachine.lcow.vpcienabled": "true",
// we believe this is a sufficiently large high MMIO space amount for this test.
// if a given gpu device needs more, this test will fail to create the container
// and may hang.
"io.microsoft.virtualmachine.computetopology.memory.highmmiogapinmb": "64000",
"io.microsoft.virtualmachine.lcow.bootfilesrootpath": testGPUBootFiles,
},
},
RuntimeHandler: lcowRuntimeHandler,
}
}
func getGPUContainerRequestLCOW(t *testing.T, podID string, podConfig *runtime.PodSandboxConfig, device *runtime.Device) *runtime.CreateContainerRequest {
return &runtime.CreateContainerRequest{
Config: &runtime.ContainerConfig{
Metadata: &runtime.ContainerMetadata{
Name: t.Name() + "-Container",
},
Image: &runtime.ImageSpec{
Image: imageLcowAlpine,
},
Command: []string{
"top",
},
Devices: []*runtime.Device{
device,
},
Linux: &runtime.LinuxContainerConfig{},
Annotations: map[string]string{
"io.microsoft.container.gpu.capabilities": "utility",
},
},
PodSandboxId: podID,
SandboxConfig: podConfig,
}
}
func getGPUContainerRequestWCOW(t *testing.T, podID string, podConfig *runtime.PodSandboxConfig, device *runtime.Device) *runtime.CreateContainerRequest {
return &runtime.CreateContainerRequest{
Config: &runtime.ContainerConfig{
Metadata: &runtime.ContainerMetadata{
Name: t.Name() + "-Container",
},
Image: &runtime.ImageSpec{
Image: imageWindowsNanoserver,
},
Command: []string{
"cmd",
"/c",
"ping",
"-t",
"127.0.0.1",
},
Devices: []*runtime.Device{
device,
},
Mounts: []*runtime.Mount{
{
HostPath: testDeviceUtilFilePath,
ContainerPath: containerDeviceUtilPath,
},
},
Annotations: map[string]string{
"io.microsoft.assigneddevice.kerneldrivers": testDriversPath,
},
},
PodSandboxId: podID,
SandboxConfig: podConfig,
}
}
func Test_RunContainer_VirtualDevice_GPU_LCOW(t *testing.T) {
requireFeatures(t, featureLCOW, featureGPU)
if osversion.Build() < osversion.V20H1 {
t.Skip("Requires build +20H1")
}
testDeviceInstanceID, err := findTestNvidiaGPUDevice()
if err != nil {
t.Fatalf("skipping test, failed to find assignable nvidia gpu on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Fatal("skipping test, host has no assignable nvidia gpu devices")
}
pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
client := newTestRuntimeClient(t)
podctx := context.Background()
sandboxRequest := getGPUPodRequestLCOW(t)
podID := runPodSandbox(t, client, podctx, sandboxRequest)
defer removePodSandbox(t, client, podctx, podID)
defer stopPodSandbox(t, client, podctx, podID)
device := &runtime.Device{
HostPath: "gpu://" + testDeviceInstanceID,
}
containerRequest := getGPUContainerRequestLCOW(t, podID, sandboxRequest.Config, device)
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
containerID := createContainer(t, client, ctx, containerRequest)
defer removeContainer(t, client, ctx, containerID)
startContainer(t, client, ctx, containerID)
defer stopContainer(t, client, ctx, containerID)
verifyGPUIsPresentLCOW(t, client, ctx, containerID)
}
func Test_RunContainer_VirtualDevice_GPU_Multiple_LCOW(t *testing.T) {
requireFeatures(t, featureLCOW, featureGPU)
if osversion.Build() < osversion.V20H1 {
t.Skip("Requires build +20H1")
}
numContainers := 2
testDeviceInstanceID, err := findTestNvidiaGPUDevice()
if err != nil {
t.Fatalf("skipping test, failed to find assignable nvidia gpu on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Fatal("skipping test, host has no assignable nvidia gpu devices")
}
pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
client := newTestRuntimeClient(t)
podctx := context.Background()
sandboxRequest := getGPUPodRequestLCOW(t)
podID := runPodSandbox(t, client, podctx, sandboxRequest)
defer removePodSandbox(t, client, podctx, podID)
defer stopPodSandbox(t, client, podctx, podID)
device := &runtime.Device{
HostPath: "gpu://" + testDeviceInstanceID,
}
containerRequest := getGPUContainerRequestLCOW(t, podID, sandboxRequest.Config, device)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
for i := 0; i < numContainers; i++ {
name := t.Name() + "-Container-" + fmt.Sprintf("%d", i)
containerRequest.Config.Metadata.Name = name
containerID := createContainer(t, client, ctx, containerRequest)
defer removeContainer(t, client, ctx, containerID)
startContainer(t, client, ctx, containerID)
defer stopContainer(t, client, ctx, containerID)
verifyGPUIsPresentLCOW(t, client, ctx, containerID)
}
}
func Test_RunContainer_VirtualDevice_GPU_and_NoGPU_LCOW(t *testing.T) {
requireFeatures(t, featureLCOW, featureGPU)
if osversion.Build() < osversion.V20H1 {
t.Skip("Requires build +20H1")
}
testDeviceInstanceID, err := findTestNvidiaGPUDevice()
if err != nil {
t.Fatalf("skipping test, failed to find assignable nvidia gpu on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Fatal("skipping test, host has no assignable nvidia gpu devices")
}
pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
client := newTestRuntimeClient(t)
podctx := context.Background()
sandboxRequest := getGPUPodRequestLCOW(t)
podID := runPodSandbox(t, client, podctx, sandboxRequest)
defer removePodSandbox(t, client, podctx, podID)
defer stopPodSandbox(t, client, podctx, podID)
device := &runtime.Device{
HostPath: "gpu://" + testDeviceInstanceID,
}
containerGPURequest := getGPUContainerRequestLCOW(t, podID, sandboxRequest.Config, device)
containerNoGPURequest := &runtime.CreateContainerRequest{
Config: &runtime.ContainerConfig{
Metadata: &runtime.ContainerMetadata{
Name: "No-GPU-Container",
},
Image: &runtime.ImageSpec{
Image: imageLcowAlpine,
},
Command: []string{
"top",
},
Linux: &runtime.LinuxContainerConfig{},
},
PodSandboxId: podID,
SandboxConfig: sandboxRequest.Config,
}
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
// create container with a GPU present
gpuContainerID := createContainer(t, client, ctx, containerGPURequest)
defer removeContainer(t, client, ctx, gpuContainerID)
startContainer(t, client, ctx, gpuContainerID)
defer stopContainer(t, client, ctx, gpuContainerID)
// verify that we can access the GPU in the GPU-Container
verifyGPUIsPresentLCOW(t, client, ctx, gpuContainerID)
// create container without a GPU
noGPUContainerID := createContainer(t, client, ctx, containerNoGPURequest)
defer removeContainer(t, client, ctx, noGPUContainerID)
startContainer(t, client, ctx, noGPUContainerID)
defer stopContainer(t, client, ctx, noGPUContainerID)
// verify that we can't access the GPU in the No-GPU-Container
verifyGPUIsNotPresentLCOW(t, client, ctx, noGPUContainerID)
}
func Test_RunContainer_VirtualDevice_GPU_Multiple_Removal_LCOW(t *testing.T) {
requireFeatures(t, featureLCOW, featureGPU)
if osversion.Build() < osversion.V20H1 {
t.Skip("Requires build +20H1")
}
testDeviceInstanceID, err := findTestNvidiaGPUDevice()
if err != nil {
t.Fatalf("skipping test, failed to find assignable nvidia gpu on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Fatal("skipping test, host has no assignable nvidia gpu devices")
}
pullRequiredLcowImages(t, []string{imageLcowK8sPause, imageLcowAlpine})
client := newTestRuntimeClient(t)
podctx := context.Background()
sandboxRequest := getGPUPodRequestLCOW(t)
podID := runPodSandbox(t, client, podctx, sandboxRequest)
defer removePodSandbox(t, client, podctx, podID)
defer stopPodSandbox(t, client, podctx, podID)
device := &runtime.Device{
HostPath: "gpu://" + testDeviceInstanceID,
}
containerRequest := getGPUContainerRequestLCOW(t, podID, sandboxRequest.Config, device)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// create and start up first container with GPU
containerRequest.Config.Metadata.Name = t.Name() + "-Container-1"
containerOneID := createContainer(t, client, ctx, containerRequest)
defer removeContainer(t, client, ctx, containerOneID)
startContainer(t, client, ctx, containerOneID)
defer stopContainer(t, client, ctx, containerOneID)
// run full lifetime of second container with GPU
containerRequest.Config.Metadata.Name = t.Name() + "-Container-2"
containerTwoID := createContainer(t, client, ctx, containerRequest)
runContainerLifetime(t, client, ctx, containerTwoID)
// verify after removing second container that we can still see
// the GPU on the first container
verifyGPUIsPresentLCOW(t, client, ctx, containerOneID)
}
func Test_RunContainer_VirtualDevice_LocationPath_WCOW_Process(t *testing.T) {
requireFeatures(t, featureWCOWProcess, featureGPU)
testDeviceLocationPath, err := findTestNvidiaGPULocationPath()
if err != nil {
t.Fatalf("skipping test, failed to retrieve assignable device on host with: %v", err)
}
if testDeviceLocationPath == "" {
t.Fatal("skipping test, host has no assignable devices")
}
pullRequiredImages(t, []string{imageWindowsNanoserver})
client := newTestRuntimeClient(t)
podctx := context.Background()
sandboxRequest := getRunPodSandboxRequest(t, wcowProcessRuntimeHandler)
podID := runPodSandbox(t, client, podctx, sandboxRequest)
defer removePodSandbox(t, client, podctx, podID)
defer stopPodSandbox(t, client, podctx, podID)
device := &runtime.Device{
HostPath: "vpci-location-path://" + testDeviceLocationPath,
}
containerRequest := getGPUContainerRequestWCOW(t, podID, sandboxRequest.Config, device)
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
containerID := createContainer(t, client, ctx, containerRequest)
runContainerLifetime(t, client, ctx, containerID)
if !isGPUPresentWCOW(t, client, ctx, containerID) {
t.Fatalf("expected to see a GPU device on container %s, none present", containerID)
}
}
func Test_RunContainer_VirtualDevice_ClassGUID_WCOW_Process(t *testing.T) {
requireFeatures(t, featureWCOWProcess, featureGPU)
// instance ID is only used here to ensure there are devices present on the host
instanceID, err := findTestNvidiaGPUDevice()
if err != nil {
t.Fatalf("skipping test, failed to retrieve assignable device on host with: %v", err)
}
if instanceID == "" {
t.Fatal("skipping test, host has no assignable devices")
}
// use fixed GPU class guid
testDeviceClassGUID := "5B45201D-F2F2-4F3B-85BB-30FF1F953599"
pullRequiredImages(t, []string{imageWindowsNanoserver})
client := newTestRuntimeClient(t)
podctx := context.Background()
sandboxRequest := getRunPodSandboxRequest(t, wcowProcessRuntimeHandler)
podID := runPodSandbox(t, client, podctx, sandboxRequest)
defer removePodSandbox(t, client, podctx, podID)
defer stopPodSandbox(t, client, podctx, podID)
device := &runtime.Device{
HostPath: "class://" + testDeviceClassGUID,
}
containerRequest := getGPUContainerRequestWCOW(t, podID, sandboxRequest.Config, device)
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
containerID := createContainer(t, client, ctx, containerRequest)
runContainerLifetime(t, client, ctx, containerID)
if !isGPUPresentWCOW(t, client, ctx, containerID) {
t.Fatalf("expected to see a GPU device on container %s, none present", containerID)
}
}
func Test_RunContainer_VirtualDevice_GPU_WCOW_Hypervisor(t *testing.T) {
requireFeatures(t, featureWCOWHypervisor, featureGPU)
if osversion.Build() < osversion.V20H1 {
t.Skip("Requires build +20H1")
}
testDeviceInstanceID, err := findTestNvidiaGPUDevice()
if err != nil {
t.Fatalf("skipping test, failed to retrieve assignable device on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Fatal("skipping test, host has no assignable devices")
}
pullRequiredImages(t, []string{imageWindowsNanoserver})
client := newTestRuntimeClient(t)
podctx := context.Background()
sandboxRequest := getRunPodSandboxRequest(t, wcowHypervisorRuntimeHandler)
sandboxRequest.Config.Annotations = map[string]string{
"io.microsoft.virtualmachine.fullyphysicallybacked": "true",
}
podID := runPodSandbox(t, client, podctx, sandboxRequest)
defer removePodSandbox(t, client, podctx, podID)
defer stopPodSandbox(t, client, podctx, podID)
device := &runtime.Device{
HostPath: "vpci://" + testDeviceInstanceID,
}
containerRequest := getGPUContainerRequestWCOW(t, podID, sandboxRequest.Config, device)
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
containerID := createContainer(t, client, ctx, containerRequest)
defer removeContainer(t, client, ctx, containerID)
startContainer(t, client, ctx, containerID)
defer stopContainer(t, client, ctx, containerID)
if !isGPUPresentWCOW(t, client, ctx, containerID) {
t.Fatalf("expected to see a GPU device on container %s, none present", containerID)
}
}
func Test_RunContainer_VirtualDevice_GPU_and_NoGPU_WCOW_Hypervisor(t *testing.T) {
requireFeatures(t, featureWCOWHypervisor, featureGPU)
if osversion.Build() < osversion.V20H1 {
t.Skip("Requires build +20H1")
}
testDeviceInstanceID, err := findTestNvidiaGPUDevice()
if err != nil {
t.Fatalf("skipping test, failed to retrieve assignable device on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Fatal("skipping test, host has no assignable devices")
}
pullRequiredImages(t, []string{imageWindowsNanoserver})
client := newTestRuntimeClient(t)
podctx := context.Background()
sandboxRequest := getRunPodSandboxRequest(t, wcowHypervisorRuntimeHandler)
sandboxRequest.Config.Annotations = map[string]string{
"io.microsoft.virtualmachine.fullyphysicallybacked": "true",
}
podID := runPodSandbox(t, client, podctx, sandboxRequest)
defer removePodSandbox(t, client, podctx, podID)
defer stopPodSandbox(t, client, podctx, podID)
device := &runtime.Device{
HostPath: "vpci://" + testDeviceInstanceID,
}
containerRequest := getGPUContainerRequestWCOW(t, podID, sandboxRequest.Config, device)
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
// create container with a GPU present
gpuContainerID := createContainer(t, client, ctx, containerRequest)
defer removeContainer(t, client, ctx, gpuContainerID)
startContainer(t, client, ctx, gpuContainerID)
defer stopContainer(t, client, ctx, gpuContainerID)
if !isGPUPresentWCOW(t, client, ctx, gpuContainerID) {
t.Fatalf("expected to see a GPU device on container %s, none present", gpuContainerID)
}
// create container without a GPU
noGPUName := t.Name() + "-No-GPU-Container"
containerRequest.Config.Metadata.Name = noGPUName
containerRequest.Config.Devices = []*runtime.Device{}
noGPUContainerID := createContainer(t, client, ctx, containerRequest)
defer removeContainer(t, client, ctx, noGPUContainerID)
startContainer(t, client, ctx, noGPUContainerID)
defer stopContainer(t, client, ctx, noGPUContainerID)
// verify that we can't access the GPU in the No-GPU-Container
if isGPUPresentWCOW(t, client, ctx, noGPUContainerID) {
t.Fatalf("expected to see NO GPU device in container %s", noGPUContainerID)
}
}
func Test_RunContainer_VirtualDevice_GPU_Multiple_WCOW_Hypervisor(t *testing.T) {
requireFeatures(t, featureWCOWHypervisor, featureGPU)
if osversion.Build() < osversion.V20H1 {
t.Skip("Requires build +20H1")
}
numContainers := 2
testDeviceInstanceID, err := findTestNvidiaGPUDevice()
if err != nil {
t.Fatalf("skipping test, failed to retrieve assignable device on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Fatal("skipping test, host has no assignable devices")
}
pullRequiredImages(t, []string{imageWindowsNanoserver})
client := newTestRuntimeClient(t)
podctx := context.Background()
sandboxRequest := getRunPodSandboxRequest(t, wcowHypervisorRuntimeHandler)
sandboxRequest.Config.Annotations = map[string]string{
"io.microsoft.virtualmachine.fullyphysicallybacked": "true",
}
podID := runPodSandbox(t, client, podctx, sandboxRequest)
defer removePodSandbox(t, client, podctx, podID)
defer stopPodSandbox(t, client, podctx, podID)
device := &runtime.Device{
HostPath: "vpci://" + testDeviceInstanceID,
}
containerRequest := getGPUContainerRequestWCOW(t, podID, sandboxRequest.Config, device)
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
for i := 0; i < numContainers; i++ {
name := t.Name() + "-GPU-Container" + fmt.Sprintf("%d", i)
containerRequest.Config.Metadata.Name = name
containerID := createContainer(t, client, ctx, containerRequest)
defer removeContainer(t, client, ctx, containerID)
startContainer(t, client, ctx, containerID)
defer stopContainer(t, client, ctx, containerID)
if !isGPUPresentWCOW(t, client, ctx, containerID) {
t.Fatalf("expected to see a GPU device on container %s, none present", containerID)
}
}
}
func Test_RunContainer_VirtualDevice_GPU_Multiple_Removal_WCOW_Hypervisor(t *testing.T) {
requireFeatures(t, featureWCOWHypervisor, featureGPU)
if osversion.Build() < osversion.V20H1 {
t.Skip("Requires build +20H1")
}
testDeviceInstanceID, err := findTestNvidiaGPUDevice()
if err != nil {
t.Fatalf("skipping test, failed to retrieve assignable device on host with: %v", err)
}
if testDeviceInstanceID == "" {
t.Fatal("skipping test, host has no assignable devices")
}
pullRequiredImages(t, []string{imageWindowsNanoserver})
client := newTestRuntimeClient(t)
podctx := context.Background()
sandboxRequest := getRunPodSandboxRequest(t, wcowHypervisorRuntimeHandler)
sandboxRequest.Config.Annotations = map[string]string{
"io.microsoft.virtualmachine.fullyphysicallybacked": "true",
}
podID := runPodSandbox(t, client, podctx, sandboxRequest)
defer removePodSandbox(t, client, podctx, podID)
defer stopPodSandbox(t, client, podctx, podID)
device := &runtime.Device{
HostPath: "vpci://" + testDeviceInstanceID,
}
containerRequest := getGPUContainerRequestWCOW(t, podID, sandboxRequest.Config, device)
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
// create container with a GPU present
gpuContainerIDOne := createContainer(t, client, ctx, containerRequest)
defer removeContainer(t, client, ctx, gpuContainerIDOne)
startContainer(t, client, ctx, gpuContainerIDOne)
defer stopContainer(t, client, ctx, gpuContainerIDOne)
// run full lifetime of second container with GPU
containerRequest.Config.Metadata.Name = t.Name() + "-GPU-Container-2"
gpuContainerIDTwo := createContainer(t, client, ctx, containerRequest)
runContainerLifetime(t, client, ctx, gpuContainerIDTwo)
// verify after removing second container that we can still see
// the GPU on the first container
if !isGPUPresentWCOW(t, client, ctx, gpuContainerIDOne) {
t.Fatalf("expected to see a GPU device on container %s, none present", gpuContainerIDOne)
}
}