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/info"
|
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
|
|
|
|
|
|
|
// 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) {
|
2024-03-26 10:37:09 +00:00
|
|
|
return resolveMode(logger, mode, image, nil)
|
2023-06-05 13:47:38 +00:00
|
|
|
}
|
|
|
|
|
2024-03-26 10:37:09 +00:00
|
|
|
func resolveMode(logger logger.Interface, mode string, image image.CUDA, propertyExtractor info.PropertyExtractor) (rmode string) {
|
2022-05-09 14:05:21 +00:00
|
|
|
if mode != "auto" {
|
2024-03-26 10:37:09 +00:00
|
|
|
logger.Infof("Using requested mode '%s'", mode)
|
2022-05-09 14:05:21 +00:00
|
|
|
return mode
|
|
|
|
}
|
|
|
|
defer func() {
|
2024-03-26 10:37:09 +00:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2024-03-26 10:37:09 +00:00
|
|
|
nvinfo := info.New(
|
|
|
|
info.WithLogger(logger),
|
|
|
|
info.WithPropertyExtractor(propertyExtractor),
|
|
|
|
)
|
2023-08-25 07:58:06 +00:00
|
|
|
|
2024-03-26 10:37:09 +00:00
|
|
|
switch nvinfo.ResolvePlatform() {
|
|
|
|
case info.PlatformNVML, info.PlatformWSL:
|
|
|
|
return "legacy"
|
|
|
|
case info.PlatformTegra:
|
2022-05-09 14:05:21 +00:00
|
|
|
return "csv"
|
|
|
|
}
|
|
|
|
return "legacy"
|
|
|
|
}
|