2024-03-26 10:37:09 +00:00
|
|
|
/**
|
|
|
|
# Copyright 2024 NVIDIA CORPORATION
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
**/
|
|
|
|
|
|
|
|
package info
|
|
|
|
|
|
|
|
import (
|
2024-05-21 09:47:14 +00:00
|
|
|
"github.com/NVIDIA/go-nvml/pkg/nvml"
|
|
|
|
|
2024-03-26 10:37:09 +00:00
|
|
|
"github.com/NVIDIA/go-nvlib/pkg/nvlib/device"
|
|
|
|
)
|
|
|
|
|
2024-05-21 09:47:14 +00:00
|
|
|
type infolib struct {
|
|
|
|
PropertyExtractor
|
|
|
|
PlatformResolver
|
|
|
|
}
|
|
|
|
|
|
|
|
type options struct {
|
2024-03-26 10:37:09 +00:00
|
|
|
logger basicLogger
|
2024-05-21 09:47:14 +00:00
|
|
|
root root
|
2024-03-26 10:37:09 +00:00
|
|
|
nvmllib nvml.Interface
|
|
|
|
devicelib device.Interface
|
|
|
|
|
2024-05-21 09:47:14 +00:00
|
|
|
platform Platform
|
|
|
|
propertyExtractor PropertyExtractor
|
2024-03-26 10:37:09 +00:00
|
|
|
}
|
|
|
|
|
2024-05-21 09:47:14 +00:00
|
|
|
// New creates a new instance of the 'info' interface.
|
2024-03-26 10:37:09 +00:00
|
|
|
func New(opts ...Option) Interface {
|
2024-05-21 09:47:14 +00:00
|
|
|
o := &options{}
|
2024-03-26 10:37:09 +00:00
|
|
|
for _, opt := range opts {
|
2024-05-21 09:47:14 +00:00
|
|
|
opt(o)
|
2024-03-26 10:37:09 +00:00
|
|
|
}
|
2024-05-21 09:47:14 +00:00
|
|
|
if o.logger == nil {
|
|
|
|
o.logger = &nullLogger{}
|
2024-03-26 10:37:09 +00:00
|
|
|
}
|
2024-05-21 09:47:14 +00:00
|
|
|
if o.root == "" {
|
|
|
|
o.root = "/"
|
2024-03-26 10:37:09 +00:00
|
|
|
}
|
2024-05-21 09:47:14 +00:00
|
|
|
if o.nvmllib == nil {
|
|
|
|
o.nvmllib = nvml.New(
|
|
|
|
nvml.WithLibraryPath(o.root.tryResolveLibrary("libnvidia-ml.so.1")),
|
|
|
|
)
|
2024-03-26 10:37:09 +00:00
|
|
|
}
|
2024-05-21 09:47:14 +00:00
|
|
|
if o.devicelib == nil {
|
2024-05-28 11:28:28 +00:00
|
|
|
o.devicelib = device.New(o.nvmllib)
|
2024-03-26 10:37:09 +00:00
|
|
|
}
|
2024-05-21 09:47:14 +00:00
|
|
|
if o.platform == "" {
|
|
|
|
o.platform = PlatformAuto
|
2024-03-26 10:37:09 +00:00
|
|
|
}
|
2024-05-21 09:47:14 +00:00
|
|
|
if o.propertyExtractor == nil {
|
|
|
|
o.propertyExtractor = &propertyExtractor{
|
|
|
|
root: o.root,
|
|
|
|
nvmllib: o.nvmllib,
|
|
|
|
devicelib: o.devicelib,
|
2024-03-26 10:37:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return &infolib{
|
2024-05-21 09:47:14 +00:00
|
|
|
PlatformResolver: &platformResolver{
|
|
|
|
logger: o.logger,
|
|
|
|
platform: o.platform,
|
|
|
|
propertyExtractor: o.propertyExtractor,
|
|
|
|
},
|
|
|
|
PropertyExtractor: o.propertyExtractor,
|
2024-03-26 10:37:09 +00:00
|
|
|
}
|
|
|
|
}
|