Skip to content

Commit

Permalink
Fixing per review comments -
Browse files Browse the repository at this point in the history
Added separate install_packages_from_url()
Moved wget class under base_tools/
Some cleanups and fixes.
  • Loading branch information
sharsonia committed May 24, 2021
1 parent b79e573 commit 5df21cd
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 231 deletions.
21 changes: 18 additions & 3 deletions lisa/base_tools/wget.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ class Wget(Tool):
r"([\w\W]*?)(-|File) (‘|')(?P<path>.+?)(’|') (saved|already there)"
)

# regex to validate url
# source -
# https://github.com/django/django/blob/stable/1.3.x/django/core/validators.py#L45
__url_pattern = re.compile(
r"^(?:http|ftp)s?://" # http:// or https://
r"(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)"
r"+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|" # ...domain
r"localhost|" # localhost...
r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})" # ...or ip
r"(?::\d+)?" # optional port
r"(?:/?|[/?]\S+)$",
re.IGNORECASE,
)

@property
def command(self) -> str:
return "wget"
Expand All @@ -23,9 +37,8 @@ def can_install(self) -> bool:
return True

def install(self) -> bool:
if not self._check_exists():
posix_os: Posix = self.node.os # type: ignore
posix_os.install_packages([self])
posix_os: Posix = self.node.os # type: ignore
posix_os.install_packages([self])
return self._check_exists()

def get(
Expand All @@ -36,6 +49,8 @@ def get(
overwrite: bool = True,
executable: bool = False,
) -> str:
if re.match(self.__url_pattern, url) is None:
raise LisaException(f"Invalid URL '{url}'")
# create folder when it doesn't exist
self.node.execute(f"mkdir -p {file_path}", shell=True)
# combine download file path
Expand Down
95 changes: 59 additions & 36 deletions lisa/features/gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

import re
from enum import Enum
from typing import Any, cast
from typing import Any

from lisa.base_tools.wget import Wget
from lisa.feature import Feature
from lisa.operating_system import Linux, Redhat, Ubuntu
from lisa.operating_system import Redhat, Ubuntu
from lisa.tools import Uname
from lisa.util import LisaException
from lisa.util import LisaException, SkippedException
from lisa.util.logger import get_logger

FEATURE_NAME_GPU = "Gpu"

Expand All @@ -31,91 +33,112 @@
class Gpu(Feature):
def __init__(self, node: Any, platform: Any) -> None:
super().__init__(node, platform)
self._log = self._node.log
self._log = get_logger("gpu", self.name(), self._node.log)

@classmethod
def name(cls) -> str:
return FEATURE_NAME_GPU

# download and install NVIDIA grid driver
def _install_grid_driver(self, version: str) -> None:
self._log.info("Starting GRID driver installation")
if not version.strip():
version = GRID_DRIVER

# grid_filename = "NVIDIA-Linux-x86_64-grid.run"
def _is_supported(self) -> bool:
raise NotImplementedError()

# download and install NVIDIA grid driver
def _install_grid_driver(self, driver_url: str = GRID_DRIVER) -> None:
self._log.debug("Starting GRID driver installation")
# download and install the NVIDIA GRID driver
wget_tool = self._node.tools[Wget]
grid_file_path = wget_tool.get(
driver_url,
str(self._node.working_path),
"NVIDIA-Linux-x86_64-grid.run",
executable=True,
)
result = self._node.execute(
f"{grid_file_path} --no-nouveau-check --silent --no-cc-version-check"
)
if result.exit_code != 0:
raise LisaException(
"Failed to install the GRID driver! "
f"exit-code: {result.exit_code} stderr: {result.stderr}"
)

self._log.debug("Successfully installed the GRID driver")

# download and install CUDA Driver
def _install_cuda_driver(self, version: str) -> None:
self._log.info("Starting CUDA driver installation")
def _install_cuda_driver(self, version: str = "10.1.105-1") -> None:
self._log.debug("Starting CUDA driver installation")
cuda_repo = ""
linux_os: Linux = cast(Linux, self._node.os)

if not version.strip():
version = "10.1.105-1"
os_version = self._node.os.os_version

# CUDA driver installation for redhat distros
if isinstance(self._node.os, Redhat):
cuda_repo_pkg = f"cuda-repo-rhel7-{version}.x86_64.rpm"
release = os_version.release.split(".")[0]
cuda_repo_pkg = f"cuda-repo-rhel{release}-{version}.x86_64.rpm"
cuda_repo = (
"http://developer.download.nvidia.com/"
f"compute/cuda/repos/rhel7/x86_64/{cuda_repo_pkg}"
f"compute/cuda/repos/rhel{release}/x86_64/{cuda_repo_pkg}"
)
linux_os = Redhat(self._node)

# CUDA driver installation for Ubuntu distros
elif isinstance(self._node.os, Ubuntu):
release_version = self._node.os._os_version.release
release = re.sub("[^0-9]+", "", release_version)
release = re.sub("[^0-9]+", "", os_version.release)
cuda_repo_pkg = f"cuda-repo-ubuntu{release}_{version}_amd64.deb"
cuda_repo = (
"http://developer.download.nvidia.com/compute/"
f"cuda/repos/ubuntu{release}/x86_64/{cuda_repo_pkg}"
)
linux_os = Ubuntu(self._node)

else:
raise LisaException(
f"Distro {self._node.os.__class__.__name__}"
"not supported to install CUDA driver."
)

# download and install the cuda driver package from the repo
linux_os.install_packages(f"{cuda_repo}", signed=False)
self._node.os._install_package_from_url(f"{cuda_repo}", signed=False)

def install_gpu_dep(self) -> None:
def _install_gpu_dep(self) -> None:
uname_tool = self._node.tools[Uname]
uname_ver = uname_tool.get_linux_information().uname_version

# install dependency libraries for redhat and CentOS
# install dependency libraries for distros
if isinstance(self._node.os, Redhat):
# install the kernel-devel and kernel-header packages
package_name = f"kernel-devel-{uname_ver} kernel-headers-{uname_ver}"
self._node.os.install_packages(package_name)

# mesa-libEGL install/update is require to avoid a conflict between
# libraries - bugzilla.redhat 1584740
package_name = "mesa-libGL mesa-libEGL libglvnd-devel"
self._node.os.install_packages(package_name)

# install dkms
package_name = "dkms"
self._node.os.install_packages(package_name, signed=False)

# install dependency libraraies for Ubuntu
elif isinstance(self._node.os, Ubuntu):
package_name = (
f"build-essential libelf-dev linux-tools-{uname_ver}"
f" linux-cloud-tools-{uname_ver} python libglvnd-dev ubuntu-desktop"
)
self._node.os.install_packages(package_name)
else:
raise LisaException(
f"Distro {self._node.os.__class__.__name__}"
" is not supported for GPU."
)

def check_support(self) -> None:
# TODO: more supportability can be defined here
if not self._is_supported():
raise SkippedException(f"GPU is not supported with distro {self._node.os}")

def install_compute_sdk(
self, driver: ComputeSDK = ComputeSDK.CUDA, version: str = ""
) -> None:
# install GPU dependencies before installing driver
self._install_gpu_dep()

def install_compute_sdk(self, driver: ComputeSDK, version: str = "") -> None:
# install the driver
if driver == ComputeSDK.GRID:
self._install_grid_driver(version)
elif driver == ComputeSDK.CUDA:
self._install_cuda_driver(version)
else:
raise LisaException("No valid driver SDK name provided to install.")
raise LisaException(
f"{ComputeSDK} is invalid."
"No valid driver SDK name provided to install."
)
Loading

0 comments on commit 5df21cd

Please sign in to comment.