Best Python code snippet using lisa_python
features.py
Source:features.py  
...462        super()._initialize(*args, **kwargs)463        self._initialize_information(self._node)464        self._is_nvidia = True465    @classmethod466    def _install_by_platform(cls, *args: Any, **kwargs: Any) -> None:467        template: Any = kwargs.get("template")468        environment = cast(Environment, kwargs.get("environment"))469        log = cast(Logger, kwargs.get("log"))470        log.debug("updating arm template to support GPU extension.")471        resources = template["resources"]472        # load a copy to avoid side effect.473        gpu_template = json.loads(cls._gpu_extension_template)474        node: Node = environment.nodes[0]475        runbook = node.capability.get_extended_runbook(AzureNodeSchema)476        if re.match(cls._amd_supported_skus, runbook.vm_size):477            # skip AMD, because no AMD GPU Linux extension.478            ...479        else:480            gpu_template["properties"] = cls._gpu_extension_nvidia_properties...gpu.py
Source:gpu.py  
...72        """73        settings = cast(GpuSettings, kwargs.get("settings"))74        # default to install by platform, unless it's specified to skip.75        if (settings.is_enabled) and settings.install_by_platform:76            cls._install_by_platform(*args, **kwargs)77    @classmethod78    def remove_virtual_gpus(cls, devices: List[PciDevice]) -> List[PciDevice]:79        return [x for x in devices if x.vendor != "Microsoft Corporation"]80    def enabled(self) -> bool:81        return True82    def is_supported(self) -> bool:83        raise NotImplementedError84    def is_module_loaded(self) -> bool:85        lsmod_tool = self._node.tools[Lsmod]86        if (len(self.gpu_vendor) > 0) and all(87            lsmod_tool.module_exists(vendor) for vendor in self.gpu_vendor88        ):89            return True90        return False91    def install_compute_sdk(self, version: str = "") -> None:92        # install GPU dependencies before installing driver93        self._install_gpu_dep()94        try:95            # install LIS driver if required and not already installed.96            self._node.tools[LisDriver]97        except Exception as identifier:98            self._log.debug(99                f"LisDriver is not installed. It might not be required. {identifier}"100            )101        # install the driver102        supported_driver = self.get_supported_driver()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"...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!!
