Beispiel #1
0
func CreateLocalVolumes() error {
	drv, err := nvidia.GetDriverVersion()
	if err != nil {
		return err
	}
	vols, err := nvidia.LookupVolumes("")
	if err != nil {
		return err
	}

	for _, v := range vols {
		n := fmt.Sprintf("%s_%s", v.Name, drv)
		if _, err := docker.InspectVolume(n); err == nil {
			if err = docker.RemoveVolume(n); err != nil {
				return fmt.Errorf("cannot remove %s: volume is in use", n)
			}
		}

		if err := docker.CreateVolume(n); err != nil {
			return err
		}
		path, err := docker.InspectVolume(n)
		if err != nil {
			docker.RemoveVolume(n)
			return err
		}
		if err := v.CreateAt(path); err != nil {
			docker.RemoveVolume(n)
			return err
		}
		fmt.Println(n)
	}
	return nil
}
Beispiel #2
0
func CreateLocalVolumes() error {
	drv, err := nvidia.GetDriverVersion()
	if err != nil {
		return err
	}
	vols, err := nvidia.LookupVolumes("")
	if err != nil {
		return err
	}

	for _, v := range vols {
		n := fmt.Sprintf("%s_%s", v.Name, drv)
		if err := docker.CreateVolume(n); err != nil {
			return err
		}
		path, err := docker.InspectVolume(n)
		if err != nil {
			return err
		}
		if err := volumeEmpty(n, path); err != nil {
			return err
		}
		if err := v.CreateAt(path); err != nil {
			return err
		}
		fmt.Println(n)
	}
	return nil
}
Beispiel #3
0
func main() {
	var err error

	flag.Parse()
	defer exit()

	log.Println("Loading NVIDIA management library")
	assert(nvidia.Init())
	defer func() { assert(nvidia.Shutdown()) }()

	log.Println("Loading NVIDIA unified memory")
	assert(nvidia.LoadUVM())

	log.Println("Discovering GPU devices")
	Devices, err = nvidia.LookupDevices()
	assert(err)

	log.Println("Provisioning volumes at", VolumesPath)
	Volumes, err = nvidia.LookupVolumes(VolumesPath)
	assert(err)

	plugin := NewPluginAPI(SocketPath)
	remote := NewRemoteAPI(ListenAddr)

	log.Println("Serving plugin API at", SocketPath)
	log.Println("Serving remote API at", ListenAddr)
	p := plugin.Serve()
	r := remote.Serve()

	join, joined := make(chan int, 2), 0
L:
	for {
		select {
		case <-p:
			remote.Stop()
			p = nil
			join <- 1
		case <-r:
			plugin.Stop()
			r = nil
			join <- 1
		case j := <-join:
			if joined += j; joined == cap(join) {
				break L
			}
		}
	}
	assert(plugin.Error())
	assert(remote.Error())
	log.Println("Successfully terminated")
}