-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0. | ||
*/ | ||
|
||
package nvidia_smi | ||
|
||
import ( | ||
"encoding/xml" | ||
"github.com/traas-stack/holoinsight-agent/pkg/appconfig" | ||
"github.com/traas-stack/holoinsight-agent/pkg/core" | ||
"os/exec" | ||
"sync" | ||
) | ||
|
||
type ( | ||
NvidiaSmiLog struct { | ||
GPU []NvidiaSmiLog_Gpu `xml:"gpu"` | ||
} | ||
NvidiaSmiLog_Gpu struct { | ||
ProductName string `xml:"product_name"` | ||
Uuid string `xml:"uuid"` | ||
MinorNumber string `xml:"minor_number"` | ||
} | ||
) | ||
|
||
var ( | ||
nvidiaSmiLog = &NvidiaSmiLog{} | ||
initNvidiaSmiLogOnce = sync.Once{} | ||
) | ||
|
||
func GetNvidiaSmiLog() *NvidiaSmiLog { | ||
initNvidiaSmiLogOnce.Do(initNvidiaSmiLog) | ||
return nvidiaSmiLog | ||
} | ||
|
||
func initNvidiaSmiLog() { | ||
if !IsNvidiaEnabled() { | ||
return | ||
} | ||
var cmd *exec.Cmd | ||
switch appconfig.StdAgentConfig.Mode { | ||
case core.AgentModeDaemonset: | ||
cmd = exec.Command("chroot", core.GetHostfs(), "nvidia-smi", "-q", "-x") | ||
case core.AgentModeSidecar: | ||
cmd = exec.Command("nvidia-smi", "-q", "-x") | ||
default: | ||
return | ||
} | ||
|
||
b, err := cmd.CombinedOutput() | ||
if err != nil { | ||
// return err | ||
return | ||
} | ||
err = xml.Unmarshal(b, nvidiaSmiLog) | ||
if err != nil { | ||
return | ||
} | ||
} |