|
| 1 | +/** |
| 2 | +# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +**/ |
| 16 | + |
| 17 | +package modifier |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + |
| 22 | + "github.com/NVIDIA/nvidia-container-toolkit/internal/config/image" |
| 23 | + "github.com/NVIDIA/nvidia-container-toolkit/internal/cuda" |
| 24 | + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" |
| 25 | + "github.com/NVIDIA/nvidia-container-toolkit/internal/requirements" |
| 26 | +) |
| 27 | + |
| 28 | +// checkRequirements evaluates NVIDIA_REQUIRE_* constraints using the host |
| 29 | +// CUDA driver version and the compute capability of CUDA device 0. This |
| 30 | +// matches the subset enforced in CSV mode and is shared with CDI / JIT-CDI |
| 31 | +// modes (driver and brand constraints are not populated here). |
| 32 | +func checkRequirements(logger logger.Interface, image *image.CUDA) error { |
| 33 | + if image == nil || image.HasDisableRequire() { |
| 34 | + logger.Debugf("NVIDIA_DISABLE_REQUIRE=%v; skipping requirement checks", true) |
| 35 | + return nil |
| 36 | + } |
| 37 | + |
| 38 | + imageRequirements, err := image.GetRequirements() |
| 39 | + if err != nil { |
| 40 | + return fmt.Errorf("failed to get image requirements: %v", err) |
| 41 | + } |
| 42 | + |
| 43 | + r := requirements.New(logger, imageRequirements) |
| 44 | + |
| 45 | + cudaVersion, err := cuda.Version() |
| 46 | + if err != nil { |
| 47 | + logger.Warningf("Failed to get CUDA version: %v", err) |
| 48 | + } else { |
| 49 | + r.AddVersionProperty(requirements.CUDA, cudaVersion) |
| 50 | + } |
| 51 | + |
| 52 | + compteCapability, err := cuda.ComputeCapability(0) |
| 53 | + if err != nil { |
| 54 | + logger.Warningf("Failed to get CUDA Compute Capability: %v", err) |
| 55 | + } else { |
| 56 | + r.AddVersionProperty(requirements.ARCH, compteCapability) |
| 57 | + } |
| 58 | + |
| 59 | + return r.Assert() |
| 60 | +} |
0 commit comments