File: nvidia_legacy.go

package info (click to toggle)
singularity-container 4.0.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 21,672 kB
  • sloc: asm: 3,857; sh: 2,125; ansic: 1,677; awk: 414; makefile: 110; python: 99
file content (59 lines) | stat: -rw-r--r-- 1,916 bytes parent folder | download | duplicates (2)
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
// Copyright (c) 2018-2020, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.

package gpu

import (
	"fmt"
	"os"
	"path/filepath"

	"github.com/sylabs/singularity/v4/pkg/sylog"
)

// NvidiaPaths returns a list of Nvidia libraries/binaries that should be
// mounted into the container in order to use Nvidia GPUs
func NvidiaPaths(configFilePath string) ([]string, []string, error) {
	nvidiaFiles, err := gpuliblist(configFilePath)
	if err != nil {
		return nil, nil, fmt.Errorf("could not read %s: %v", filepath.Base(configFilePath), err)
	}

	return paths(nvidiaFiles)
}

// NvidiaIpcsPath returns a list of nvidia driver ipcs.
// Currently this is only the persistenced socket (if found).
func NvidiaIpcsPath() ([]string, error) {
	const persistencedSocket = "/var/run/nvidia-persistenced/socket"
	var nvidiaFiles []string
	_, err := os.Stat(persistencedSocket)
	// If it doesn't exist that's okay - probably persistenced isn't running.
	if os.IsNotExist(err) {
		sylog.Verbosef("persistenced socket %s not found", persistencedSocket)
		return nil, nil
	}
	// If we can't stat it, we probably can't bind mount it.
	if err != nil {
		return nil, fmt.Errorf("could not stat %s: %v", persistencedSocket, err)
	}

	nvidiaFiles = append(nvidiaFiles, persistencedSocket)
	return nvidiaFiles, nil
}

// NvidiaDevices return list of all non-GPU nvidia devices present on host. If withGPU
// is true all GPUs are included in the resulting list as well.
func NvidiaDevices(withGPU bool) ([]string, error) {
	nvidiaGlob := "/dev/nvidia*"
	if !withGPU {
		nvidiaGlob = "/dev/nvidia[^0-9]*"
	}
	devs, err := filepath.Glob(nvidiaGlob)
	if err != nil {
		return nil, fmt.Errorf("could not list nvidia devices: %v", err)
	}
	return devs, nil
}