2022-05-09 14:05:21 +00:00
|
|
|
/**
|
|
|
|
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
2023-06-06 19:42:56 +00:00
|
|
|
import (
|
2023-11-15 20:36:23 +00:00
|
|
|
"github.com/NVIDIA/go-nvlib/pkg/nvlib/device"
|
|
|
|
"github.com/NVIDIA/go-nvlib/pkg/nvlib/info"
|
2024-04-18 13:01:20 +00:00
|
|
|
"github.com/NVIDIA/go-nvml/pkg/nvml"
|
2023-12-01 01:10:10 +00:00
|
|
|
|
2023-06-05 14:03:03 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image"
|
2023-06-06 19:42:56 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
|
|
|
)
|
2022-05-09 14:05:21 +00:00
|
|
|
|
2023-06-05 13:47:38 +00:00
|
|
|
// infoInterface provides an alias for mocking.
|
|
|
|
//
|
|
|
|
//go:generate moq -stub -out info-interface_mock.go . infoInterface
|
2023-08-25 07:58:06 +00:00
|
|
|
type infoInterface interface {
|
|
|
|
info.Interface
|
|
|
|
// UsesNVGPUModule indicates whether the system is using the nvgpu kernel module
|
|
|
|
UsesNVGPUModule() (bool, string)
|
|
|
|
}
|
2023-06-05 13:47:38 +00:00
|
|
|
|
|
|
|
type resolver struct {
|
|
|
|
logger logger.Interface
|
2023-08-25 07:58:06 +00:00
|
|
|
info infoInterface
|
2023-06-05 13:47:38 +00:00
|
|
|
}
|
|
|
|
|
2022-05-09 14:05:21 +00:00
|
|
|
// ResolveAutoMode determines the correct mode for the platform if set to "auto"
|
2023-06-05 14:03:03 +00:00
|
|
|
func ResolveAutoMode(logger logger.Interface, mode string, image image.CUDA) (rmode string) {
|
2023-06-05 13:47:38 +00:00
|
|
|
nvinfo := info.New()
|
2023-08-25 07:58:06 +00:00
|
|
|
nvmllib := nvml.New()
|
|
|
|
devicelib := device.New(
|
|
|
|
device.WithNvml(nvmllib),
|
|
|
|
)
|
|
|
|
|
|
|
|
info := additionalInfo{
|
|
|
|
Interface: nvinfo,
|
|
|
|
nvmllib: nvmllib,
|
|
|
|
devicelib: devicelib,
|
|
|
|
}
|
|
|
|
|
2023-06-05 13:47:38 +00:00
|
|
|
r := resolver{
|
|
|
|
logger: logger,
|
2023-08-25 07:58:06 +00:00
|
|
|
info: info,
|
2023-06-05 13:47:38 +00:00
|
|
|
}
|
2023-06-05 14:03:03 +00:00
|
|
|
return r.resolveMode(mode, image)
|
2023-06-05 13:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// resolveMode determines the correct mode for the platform if set to "auto"
|
2023-06-05 14:03:03 +00:00
|
|
|
func (r resolver) resolveMode(mode string, image image.CUDA) (rmode string) {
|
2022-05-09 14:05:21 +00:00
|
|
|
if mode != "auto" {
|
2023-12-15 14:30:03 +00:00
|
|
|
r.logger.Infof("Using requested mode '%s'", mode)
|
2022-05-09 14:05:21 +00:00
|
|
|
return mode
|
|
|
|
}
|
|
|
|
defer func() {
|
2023-06-05 13:47:38 +00:00
|
|
|
r.logger.Infof("Auto-detected mode as '%v'", rmode)
|
2022-05-09 14:05:21 +00:00
|
|
|
}()
|
|
|
|
|
2023-10-10 11:48:38 +00:00
|
|
|
if image.OnlyFullyQualifiedCDIDevices() {
|
2023-06-05 14:03:03 +00:00
|
|
|
return "cdi"
|
|
|
|
}
|
|
|
|
|
2023-06-05 13:47:38 +00:00
|
|
|
isTegra, reason := r.info.IsTegraSystem()
|
|
|
|
r.logger.Debugf("Is Tegra-based system? %v: %v", isTegra, reason)
|
2022-05-09 14:05:21 +00:00
|
|
|
|
2023-06-05 13:47:38 +00:00
|
|
|
hasNVML, reason := r.info.HasNvml()
|
|
|
|
r.logger.Debugf("Has NVML? %v: %v", hasNVML, reason)
|
2022-05-11 12:52:59 +00:00
|
|
|
|
2023-08-25 07:58:06 +00:00
|
|
|
usesNVGPUModule, reason := r.info.UsesNVGPUModule()
|
|
|
|
r.logger.Debugf("Uses nvgpu kernel module? %v: %v", usesNVGPUModule, reason)
|
|
|
|
|
|
|
|
if (isTegra && !hasNVML) || usesNVGPUModule {
|
2022-05-09 14:05:21 +00:00
|
|
|
return "csv"
|
|
|
|
}
|
|
|
|
|
|
|
|
return "legacy"
|
|
|
|
}
|