|
| 1 | +/** |
| 2 | +# Copyright 2024 NVIDIA CORPORATION |
| 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 info |
| 18 | + |
| 19 | +// Platform represents a supported plaform. |
| 20 | +type Platform string |
| 21 | + |
| 22 | +const ( |
| 23 | + PlatformAuto = Platform("auto") |
| 24 | + PlatformNVML = Platform("nvml") |
| 25 | + PlatformTegra = Platform("tegra") |
| 26 | + PlatformWSL = Platform("wsl") |
| 27 | + PlatformUnknown = Platform("unknown") |
| 28 | +) |
| 29 | + |
| 30 | +type platformResolver struct { |
| 31 | + logger basicLogger |
| 32 | + platform Platform |
| 33 | + propertyExtractor PropertyExtractor |
| 34 | +} |
| 35 | + |
| 36 | +func (p platformResolver) ResolvePlatform() Platform { |
| 37 | + if p.platform != PlatformAuto { |
| 38 | + p.logger.Infof("Using requested platform '%s'", p.platform) |
| 39 | + return p.platform |
| 40 | + } |
| 41 | + |
| 42 | + hasDXCore, reason := p.propertyExtractor.HasDXCore() |
| 43 | + p.logger.Debugf("Is WSL-based system? %v: %v", hasDXCore, reason) |
| 44 | + |
| 45 | + hasTegraFiles, reason := p.propertyExtractor.HasTegraFiles() |
| 46 | + p.logger.Debugf("Is Tegra-based system? %v: %v", hasTegraFiles, reason) |
| 47 | + |
| 48 | + hasNVML, reason := p.propertyExtractor.HasNvml() |
| 49 | + p.logger.Debugf("Is NVML-based system? %v: %v", hasNVML, reason) |
| 50 | + |
| 51 | + usesOnlyNVGPUModule, reason := p.propertyExtractor.UsesOnlyNVGPUModule() |
| 52 | + p.logger.Debugf("Uses nvgpu kernel module? %v: %v", usesOnlyNVGPUModule, reason) |
| 53 | + |
| 54 | + switch { |
| 55 | + case hasDXCore: |
| 56 | + return PlatformWSL |
| 57 | + case (hasTegraFiles && !hasNVML), usesOnlyNVGPUModule: |
| 58 | + return PlatformTegra |
| 59 | + case hasNVML: |
| 60 | + return PlatformNVML |
| 61 | + default: |
| 62 | + return PlatformUnknown |
| 63 | + } |
| 64 | +} |
0 commit comments