Ejemplo n.º 1
0
func writeGPUInfoJSON(wr io.Writer) {
	var err error

	r := struct {
		Version struct{ Driver, CUDA string }
		Devices []nvidia.Device
	}{
		Devices: Devices,
	}
	r.Version.Driver, err = nvidia.GetDriverVersion()
	assert(err)
	r.Version.CUDA, err = nvidia.GetCUDAVersion()
	assert(err)

	assert(json.NewEncoder(wr).Encode(r))
}
Ejemplo n.º 2
0
func dockerCLIVolumes(names []string) ([]string, error) {
	vols := make([]string, 0, len(Volumes))

	drv, err := nvidia.GetDriverVersion()
	if err != nil {
		return nil, err
	}
	if len(names) == 1 && (names[0] == "*" || names[0] == "") {
		for _, v := range Volumes {
			vols = append(vols, fmt.Sprintf("%s_%s:%s:%s", v.Name, drv, v.Mountpoint, v.MountOptions))
		}
	} else {
		for _, n := range names {
			v, ok := Volumes[n]
			if !ok {
				return nil, fmt.Errorf("invalid volume: %s", n)
			}
			vols = append(vols, fmt.Sprintf("%s_%s:%s:%s", v.Name, drv, v.Mountpoint, v.MountOptions))
		}
	}
	return vols, nil
}
Ejemplo n.º 3
0
func volumesArgs(vols []string) ([]string, error) {
	args := make([]string, 0, len(vols))

	drv, err := nvidia.GetDriverVersion()
	if err != nil {
		return nil, err
	}
	for _, vol := range nvidia.Volumes {
		for _, v := range vols {
			if v == vol.Name {
				// Check if the volume exists locally otherwise fallback to using the plugin
				n := fmt.Sprintf("%s_%s", vol.Name, drv)
				if _, err := docker.VolumeInspect(n); err == nil {
					args = append(args, fmt.Sprintf("--volume=%s:%s:%s", n, vol.Mountpoint, vol.MountOptions))
				} else {
					args = append(args, fmt.Sprintf("--volume-driver=%s", nvidia.DockerPlugin))
					args = append(args, fmt.Sprintf("--volume=%s:%s:%s", n, vol.Mountpoint, vol.MountOptions))
				}
				break
			}
		}
	}
	return args, nil
}