Skip to content

Commit 27d8e2d

Browse files
authored
fix: avoid remounting GPU drivers (#67)
1 parent 4ffaa0e commit 27d8e2d

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

cli/docker.go

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -472,43 +472,13 @@ func runDockerCVM(ctx context.Context, log slog.Logger, client dockerutil.Docker
472472
if flags.hostUsrLibDir == "" {
473473
return xerrors.Errorf("when using GPUs, %q must be specified", EnvUsrLibDir)
474474
}
475+
475476
// Unmount GPU drivers in /proc as it causes issues when creating any
476477
// container in some cases (even the image metadata container).
477478
_, err = xunix.TryUnmountProcGPUDrivers(ctx, log)
478479
if err != nil {
479480
return xerrors.Errorf("unmount /proc GPU drivers: %w", err)
480481
}
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)...)
512482
}
513483

514484
log.Debug(ctx, "fetching image metadata",
@@ -598,6 +568,39 @@ func runDockerCVM(ctx context.Context, log slog.Logger, client dockerutil.Docker
598568
}
599569
}
600570

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+
601604
blog.Info("Creating workspace...")
602605

603606
// Create the inner container.

0 commit comments

Comments
 (0)