mirror of
https://github.com/clearml/go-nvlib
synced 2025-05-04 12:11:03 +00:00
Add HasDXCore to info package
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
6fe07bb333
commit
bcbaf5a0de
@ -27,6 +27,7 @@ import (
|
|||||||
|
|
||||||
// Interface provides the API to the info package
|
// Interface provides the API to the info package
|
||||||
type Interface interface {
|
type Interface interface {
|
||||||
|
HasDXCore() (bool, string)
|
||||||
HasNvml() (bool, string)
|
HasNvml() (bool, string)
|
||||||
IsTegraSystem() (bool, string)
|
IsTegraSystem() (bool, string)
|
||||||
}
|
}
|
||||||
@ -37,17 +38,26 @@ type infolib struct {
|
|||||||
|
|
||||||
var _ Interface = &infolib{}
|
var _ Interface = &infolib{}
|
||||||
|
|
||||||
|
// HasDXCore returns true if DXCore is detected on the system.
|
||||||
|
func (i *infolib) HasDXCore() (bool, string) {
|
||||||
|
const (
|
||||||
|
libraryName = "libdxcore.so"
|
||||||
|
)
|
||||||
|
if err := assertHasLibrary(libraryName); err != nil {
|
||||||
|
return false, fmt.Sprintf("could not load DXCore library: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, "found DXCore library"
|
||||||
|
}
|
||||||
|
|
||||||
// HasNvml returns true if NVML is detected on the system
|
// HasNvml returns true if NVML is detected on the system
|
||||||
func (i *infolib) HasNvml() (bool, string) {
|
func (i *infolib) HasNvml() (bool, string) {
|
||||||
const (
|
const (
|
||||||
nvmlLibraryName = "libnvidia-ml.so.1"
|
libraryName = "libnvidia-ml.so.1"
|
||||||
nvmlLibraryLoadFlags = dl.RTLD_LAZY
|
|
||||||
)
|
)
|
||||||
lib := dl.New(nvmlLibraryName, nvmlLibraryLoadFlags)
|
if err := assertHasLibrary(libraryName); err != nil {
|
||||||
if err := lib.Open(); err != nil {
|
return false, fmt.Sprintf("could not load NVML library: %v", err)
|
||||||
return false, fmt.Sprintf("could not load NVML: %v", err)
|
|
||||||
}
|
}
|
||||||
defer lib.Close()
|
|
||||||
|
|
||||||
return true, "found NVML library"
|
return true, "found NVML library"
|
||||||
}
|
}
|
||||||
@ -76,3 +86,17 @@ func (i *infolib) IsTegraSystem() (bool, string) {
|
|||||||
|
|
||||||
return false, fmt.Sprintf("%v has no 'tegra' prefix", tegraFamilyFile)
|
return false, fmt.Sprintf("%v has no 'tegra' prefix", tegraFamilyFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// assertHasLibrary returns an error if the specified library cannot be loaded
|
||||||
|
func assertHasLibrary(libraryName string) error {
|
||||||
|
const (
|
||||||
|
libraryLoadFlags = dl.RTLD_LAZY
|
||||||
|
)
|
||||||
|
lib := dl.New(libraryName, libraryLoadFlags)
|
||||||
|
if err := lib.Open(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer lib.Close()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user