MCPcopy
hub / github.com/google/gvisor / getCurrentDriver

Function getCurrentDriver

tools/gpu/drivers/install_driver.go:192–226  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

190}
191
192func getCurrentDriver() (nvconf.DriverVersion, error) {
193 _, err := os.Stat(nvidiaSMIPath)
194 // If the nvidia-smi executable does not exist, then we don't have a driver installed.
195 if os.IsNotExist(err) {
196 return nvconf.DriverVersion{}, fmt.Errorf("nvidia-smi does not exist at path: %q", nvidiaSMIPath)
197 }
198 if err != nil {
199 return nvconf.DriverVersion{}, fmt.Errorf("failed to stat nvidia-smi: %w", err)
200 }
201 out, err := exec.Command(nvidiaSMIPath, []string{"--query-gpu", "driver_version", "--format=csv,noheader"}...).CombinedOutput()
202 if err != nil {
203 log.Warningf("failed to run nvidia-smi: %v", err)
204 return nvconf.DriverVersion{}, fmt.Errorf("failed to run nvidia-smi: %w", err)
205 }
206 // If there are multiple GPUs, there will be one version per line.
207 // Make sure they are all the same version.
208 sameVersion := ""
209 for _, line := range strings.Split(string(out), "\n") {
210 line = strings.TrimSpace(line)
211 if line == "" {
212 continue
213 }
214 if sameVersion == "" {
215 sameVersion = line
216 continue
217 }
218 if line != sameVersion {
219 return nvconf.DriverVersion{}, fmt.Errorf("multiple driver versions found: %q and %q", sameVersion, line)
220 }
221 }
222 if sameVersion == "" {
223 return nvconf.DriverVersion{}, fmt.Errorf("no driver version found")
224 }
225 return nvconf.DriverVersionFrom(sameVersion)
226}
227
228// ListSupportedDrivers prints the driver to stderr in a format that can be
229// consumed by the Makefile to iterate tests across drivers.

Callers

nothing calls this directly

Calls 7

WarningfFunction · 0.92
DriverVersionFromFunction · 0.92
StatMethod · 0.65
ErrorfMethod · 0.65
SplitMethod · 0.65
CombinedOutputMethod · 0.45
CommandMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…