|
| 1 | +################################################################################ |
| 2 | +# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +################################################################################ |
| 17 | + |
| 18 | +import sys |
| 19 | +import platform |
| 20 | +from threading import Lock |
| 21 | +from cuda import cudart |
| 22 | +from cuda import cuda |
| 23 | + |
| 24 | +guard_platform_info = Lock() |
| 25 | + |
| 26 | +class PlatformInfo: |
| 27 | + def __init__(self): |
| 28 | + self.is_wsl_system = False |
| 29 | + self.wsl_verified = False |
| 30 | + self.is_integrated_gpu_system = False |
| 31 | + self.is_integrated_gpu_verified = False |
| 32 | + self.is_aarch64_platform = False |
| 33 | + self.is_aarch64_verified = False |
| 34 | + |
| 35 | + def is_wsl(self): |
| 36 | + with guard_platform_info: |
| 37 | + # Check if its already verified as WSL system or not. |
| 38 | + if not self.wsl_verified: |
| 39 | + try: |
| 40 | + # Open /proc/version file |
| 41 | + with open("/proc/version", "r") as version_file: |
| 42 | + # Read the content |
| 43 | + version_info = version_file.readline() |
| 44 | + version_info = version_info.lower() |
| 45 | + self.wsl_verified = True |
| 46 | + |
| 47 | + # Check if "microsoft" is present in the version information |
| 48 | + if "microsoft" in version_info: |
| 49 | + self.is_wsl_system = True |
| 50 | + except Exception as e: |
| 51 | + print(f"ERROR: Opening /proc/version failed: {e}") |
| 52 | + |
| 53 | + return self.is_wsl_system |
| 54 | + |
| 55 | + def is_integrated_gpu(self): |
| 56 | + #Using cuda apis to identify whether integrated/discreet |
| 57 | + #This is required to distinguish Tegra and ARM_SBSA devices |
| 58 | + with guard_platform_info: |
| 59 | + #Cuda initialize |
| 60 | + if not self.is_integrated_gpu_verified: |
| 61 | + cuda_init_result, = cuda.cuInit(0) |
| 62 | + if cuda_init_result == cuda.CUresult.CUDA_SUCCESS: |
| 63 | + #Get cuda devices count |
| 64 | + device_count_result, num_devices = cuda.cuDeviceGetCount() |
| 65 | + if device_count_result == cuda.CUresult.CUDA_SUCCESS: |
| 66 | + #If atleast one device is found, we can use the property from |
| 67 | + #the first device |
| 68 | + if num_devices >= 1: |
| 69 | + #Get properties from first device |
| 70 | + property_result, properties = cudart.cudaGetDeviceProperties(0) |
| 71 | + if property_result == cuda.CUresult.CUDA_SUCCESS: |
| 72 | + print("Is it Integrated GPU? :", properties.integrated) |
| 73 | + self.is_integrated_gpu_system = properties.integrated |
| 74 | + self.is_integrated_gpu_verified = True |
| 75 | + else: |
| 76 | + print("ERROR: Getting cuda device property failed: {}".format(property_result)) |
| 77 | + else: |
| 78 | + print("ERROR: No cuda devices found to check whether iGPU/dGPU") |
| 79 | + else: |
| 80 | + print("ERROR: Getting cuda device count failed: {}".format(device_count_result)) |
| 81 | + else: |
| 82 | + print("ERROR: Cuda init failed: {}".format(cuda_init_result)) |
| 83 | + |
| 84 | + return self.is_integrated_gpu_system |
| 85 | + |
| 86 | + def is_platform_aarch64(self): |
| 87 | + #Check if platform is aarch64 using uname |
| 88 | + if not self.is_aarch64_verified: |
| 89 | + if platform.uname()[4] == 'aarch64': |
| 90 | + self.is_aarch64_platform = True |
| 91 | + self.is_aarch64_verified = True |
| 92 | + return self.is_aarch64_platform |
| 93 | + |
| 94 | +sys.path.append('/opt/nvidia/deepstream/deepstream/lib') |
0 commit comments