Best Python code snippet using lisa_python
gpu.py
Source:gpu.py  
...103        for driver in supported_driver:104            if driver == ComputeSDK.GRID:105                if not version:106                    version = DEFAULT_GRID_DRIVER_URL107                    self._install_grid_driver(version)108                    self.gpu_vendor.add("nvidia")109            elif driver == ComputeSDK.CUDA:110                if not version:111                    version = DEFAULT_CUDA_DRIVER_VERSION112                    self._install_cuda_driver(version)113                    self.gpu_vendor.add("nvidia")114            else:115                raise LisaException(f"{driver} is not a valid value of ComputeSDK")116        if not self.gpu_vendor:117            raise LisaException("No supported gpu driver/vendor found for this node.")118    def get_gpu_count_with_lsvmbus(self) -> int:119        lsvmbus_device_count = 0120        bridge_device_count = 0121        lsvmbus_tool = self._node.tools[Lsvmbus]122        device_list = lsvmbus_tool.get_device_channels()123        for device in device_list:124            for name, id, bridge_count in NvidiaSmi.gpu_devices:125                if id in device.device_id:126                    lsvmbus_device_count += 1127                    bridge_device_count = bridge_count128                    self._log.debug(f"GPU device {name} found!")129                    break130        return lsvmbus_device_count - bridge_device_count131    def get_gpu_count_with_lspci(self) -> int:132        lspci_tool = self._node.tools[Lspci]133        device_list = lspci_tool.get_devices_by_type(134            constants.DEVICE_TYPE_GPU, force_run=True135        )136        # Remove Microsoft Virtual one. It presents with GRID driver.137        device_list = self.remove_virtual_gpus(device_list)138        return len(device_list)139    def get_gpu_count_with_vendor_cmd(self) -> int:140        nvidiasmi = self._node.tools[NvidiaSmi]141        return nvidiasmi.get_gpu_count()142    def get_supported_driver(self) -> List[ComputeSDK]:143        raise NotImplementedError()144    def _initialize(self, *args: Any, **kwargs: Any) -> None:145        self.gpu_vendor: Set[str] = set()146    @classmethod147    def _install_by_platform(cls, *args: Any, **kwargs: Any) -> None:148        raise NotImplementedError()149    # download and install NVIDIA grid driver150    def _install_grid_driver(self, driver_url: str) -> None:151        self._log.debug("Starting GRID driver installation")152        # download and install the NVIDIA GRID driver153        wget_tool = self._node.tools[Wget]154        grid_file_path = wget_tool.get(155            driver_url,156            str(self._node.working_path),157            "NVIDIA-Linux-x86_64-grid.run",158            executable=True,159        )160        result = self._node.execute(161            f"{grid_file_path} --no-nouveau-check --silent --no-cc-version-check"162        )163        result.assert_exit_code(164            0,...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
