This repository has been archived by the owner on Nov 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto.go
72 lines (59 loc) · 1.71 KB
/
auto.go
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
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"os"
"regexp"
"runtime"
nvml "github.com/mxpv/nvml-go"
"golang.org/x/sys/windows/registry"
)
// isWindows checks if the program is running on Windows and returns
func isWindows() bool {
return runtime.GOOS == "windows"
}
// Check whether Windows is 64bit or 32bit
func is64() bool {
// Works only with Windows
_, y := os.LookupEnv("ProgramFiles(x86)")
return y
}
// getWindowsVersion queries the Windows registry for the version number of Windows
func getWindowsVersion() int {
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
checkError(err)
defer k.Close()
_, _, err = k.GetIntegerValue("CurrentMajorVersionNumber")
if err == nil {
// Only Windows 10 has CurrentMajorVersionNumber
return 10
}
currentVersion, _, err := k.GetStringValue("CurrentVersion")
checkError(err)
switch currentVersion {
case "6.1":
return 7
case "6.2":
return 8
case "6.3":
return 8
default:
return 10
}
}
func parseGpuInfo(nvml nvml.API) (string, bool, bool) {
gpu, err := nvml.DeviceGetHandleByIndex(0)
checkError(err)
gpuName, err := nvml.DeviceGetName(gpu)
checkError(err)
// Check for M in the GPU name indicating a notebook model GPU
mobileGpuRegexp := regexp.MustCompile(`(GT|GTX)\s\d+M`)
isMobile := mobileGpuRegexp.MatchString(gpuName)
// Check if the gpu model is a Tesla (100) series GPU or newer
teslaRegexp := regexp.MustCompile(`(GTX|GT)\s\d+`)
isFermi := false
// Check if the gpu model is a Fermi (400) series GPU or newer
if teslaRegexp.MatchString(gpuName) {
fermiRegexp := regexp.MustCompile(`\s([456789]|1\d)\d+`)
isFermi = fermiRegexp.MatchString(gpuName)
}
return gpuName, isMobile, isFermi
}