Browse Source

Update nvidia_smi to specify GPU ID

master
squeaky otter 5 years ago
parent
commit
071e959871
Signed by: dashie GPG Key ID: C2D57B325840B755
  1. 12
      nvidia_smi/nvidia_smi.go

12
nvidia_smi/nvidia_smi.go

@ -8,9 +8,10 @@ import (
"strings"
)
func getResult(bin string, metric string, verbose bool) string {
func getResult(bin string, metric string, verbose bool, gpuId int) string {
query := fmt.Sprintf("--query-gpu=%s", metric)
opts := []string{"--format=noheader,nounits,csv", query}
gpu := fmt.Sprintf("--id=%d", gpuId)
opts := []string{"--format=noheader,nounits,csv", query, gpu}
if verbose {
fmt.Print("Going to run ")
@ -29,6 +30,7 @@ func getResult(bin string, metric string, verbose bool) string {
func main() {
binPath := flag.String("bin", "C:\\Program Files\\NVIDIA Corporation\\NVSMI\\nvidia-smi.exe", "nvidia-smi full path")
verbose := flag.Bool("verbose", false, "display some things")
gpuId := flag.Int("gpu", 0, "select GPU to query")
flag.Parse()
@ -38,7 +40,7 @@ func main() {
}
metrics := "fan.speed,memory.total,memory.used,memory.free,pstate,temperature.gpu,name,uuid,compute_mode"
results := getResult(*binPath, metrics, *verbose)
results := getResult(*binPath, metrics, *verbose, *gpuId)
if results == "" {
return // exit
@ -46,10 +48,8 @@ func main() {
splitResults := strings.Split(results, ",")
// tags
fmt.Printf("nvidiasmi,uuid=%s ", strings.TrimSpace(splitResults[7])) // it should be available ... if no, you have some problems
// values
fmt.Printf("gpu_name=\"%s\",", strings.TrimSpace(splitResults[6]))
fmt.Printf("gpu_compute_mode=\"%s\",", strings.TrimSpace(splitResults[8]))
@ -62,4 +62,4 @@ func main() {
fmt.Printf("pstate=%s,", strings.TrimSpace(strings.Replace(splitResults[4], "P", "", -1))) // strip the P
fmt.Printf("temperature=%s\n", strings.TrimSpace(splitResults[5])) // in degrees Celcius
}
}

Loading…
Cancel
Save