@@ -472,43 +472,13 @@ func runDockerCVM(ctx context.Context, log slog.Logger, client dockerutil.Docker
472
472
if flags .hostUsrLibDir == "" {
473
473
return xerrors .Errorf ("when using GPUs, %q must be specified" , EnvUsrLibDir )
474
474
}
475
+
475
476
// Unmount GPU drivers in /proc as it causes issues when creating any
476
477
// container in some cases (even the image metadata container).
477
478
_ , err = xunix .TryUnmountProcGPUDrivers (ctx , log )
478
479
if err != nil {
479
480
return xerrors .Errorf ("unmount /proc GPU drivers: %w" , err )
480
481
}
481
-
482
- devs , binds , err := xunix .GPUs (ctx , log , flags .hostUsrLibDir )
483
- if err != nil {
484
- return xerrors .Errorf ("find gpus: %w" , err )
485
- }
486
-
487
- for _ , dev := range devs {
488
- devices = append (devices , container.DeviceMapping {
489
- PathOnHost : dev .Path ,
490
- PathInContainer : dev .Path ,
491
- CgroupPermissions : "rwm" ,
492
- })
493
- }
494
-
495
- for _ , bind := range binds {
496
- // If the bind has a path that points to the host-mounted /usr/lib
497
- // directory we need to remap it to /usr/lib inside the container.
498
- mountpoint := bind .Path
499
- if strings .HasPrefix (mountpoint , flags .hostUsrLibDir ) {
500
- mountpoint = filepath .Join (
501
- "/usr/lib" ,
502
- strings .TrimPrefix (mountpoint , strings .TrimSuffix (flags .hostUsrLibDir , "/" )),
503
- )
504
- }
505
- mounts = append (mounts , xunix.Mount {
506
- Source : bind .Path ,
507
- Mountpoint : mountpoint ,
508
- ReadOnly : slices .Contains (bind .Opts , "ro" ),
509
- })
510
- }
511
- envs = append (envs , xunix .GPUEnvs (ctx )... )
512
482
}
513
483
514
484
log .Debug (ctx , "fetching image metadata" ,
@@ -598,6 +568,39 @@ func runDockerCVM(ctx context.Context, log slog.Logger, client dockerutil.Docker
598
568
}
599
569
}
600
570
571
+ if flags .addGPU {
572
+ devs , binds , err := xunix .GPUs (ctx , log , flags .hostUsrLibDir )
573
+ if err != nil {
574
+ return xerrors .Errorf ("find gpus: %w" , err )
575
+ }
576
+
577
+ for _ , dev := range devs {
578
+ devices = append (devices , container.DeviceMapping {
579
+ PathOnHost : dev .Path ,
580
+ PathInContainer : dev .Path ,
581
+ CgroupPermissions : "rwm" ,
582
+ })
583
+ }
584
+
585
+ for _ , bind := range binds {
586
+ // If the bind has a path that points to the host-mounted /usr/lib
587
+ // directory we need to remap it to /usr/lib inside the container.
588
+ mountpoint := bind .Path
589
+ if strings .HasPrefix (mountpoint , flags .hostUsrLibDir ) {
590
+ mountpoint = filepath .Join (
591
+ "/usr/lib" ,
592
+ strings .TrimPrefix (mountpoint , strings .TrimSuffix (flags .hostUsrLibDir , "/" )),
593
+ )
594
+ }
595
+ mounts = append (mounts , xunix.Mount {
596
+ Source : bind .Path ,
597
+ Mountpoint : mountpoint ,
598
+ ReadOnly : slices .Contains (bind .Opts , "ro" ),
599
+ })
600
+ }
601
+ envs = append (envs , xunix .GPUEnvs (ctx )... )
602
+ }
603
+
601
604
blog .Info ("Creating workspace..." )
602
605
603
606
// Create the inner container.
0 commit comments