Skip to content

Commit

Permalink
adding-wget-steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Abhishek committed Apr 24, 2023
1 parent 65e2747 commit 9c0a714
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .pipelines/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pool:
vmImage: windows-latest

variables:
VcVersion : 0.11.18
VcVersion : 0.11.19
ROOT: $(Build.SourcesDirectory)
CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
ENABLE_PRS_DELAYSIGN: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ public async Task CUDAAndNvidiaGPUDriverInstallationDependencyExecutesCorrectIns
this.fixture.FileSystem.Setup(fe => fe.FileStream.Create(It.IsAny<string>(), FileMode.Create, FileAccess.Write, FileShare.None))
.Returns(Stream.Null);

this.fixture.FileSystem.Setup(fe => fe.Directory.GetFiles(It.IsAny<string>()))
.Returns(new string[] { this.fixture.Combine(this.mockPackage.Path, "NvidiaDrivers", "nvidiaDriversInstaller.exe") });

this.fixture.FileSystem.Setup(fe => fe.Directory.GetCurrentDirectory())
.Returns(this.mockPackage.Path);

Expand All @@ -151,7 +154,7 @@ public async Task CUDAAndNvidiaGPUDriverInstallationDependencyExecutesCorrectIns
}
else
{
this.SetupProcessManager(this.fixture.Combine(this.mockPackage.Path, "NvidiaDriversForWindows", "nvidiaDriversInstaller.exe"), "-y -s", Environment.CurrentDirectory);
this.SetupProcessManager(this.fixture.Combine(this.mockPackage.Path, "NvidiaDrivers", "nvidiaDriversInstaller.exe"), "-y -s", Environment.CurrentDirectory);
}

this.component = new TestComponent(this.fixture.Dependencies, this.fixture.Parameters);
Expand All @@ -175,7 +178,6 @@ private void SetupDefaultMockBehavior(PlatformID platformID)
{ "LinuxLocalRunFile", "https://developer.download.nvidia.com/compute/cuda/11.6.0/local_installers/cuda_11.6.0_510.39.01_linux.run" },
{ "WinCommandLineArgs", "-y -s" },
{ "WinCudaDriversPackageDownloadedFromBlob", false },
{ "WinCudaToolkitExeLink", "https://in.download.nvidia.com/tesla/527.41/527.41-data-center-tesla-desktop-win10-win11-64bit-dch-international.exe" },
{ "RebootRequired", false }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,6 @@ public bool WinCudaDriversPackageDownloadedFromBlob
}
}

/// <summary>
/// The Cuda Toolkit executable downloaded from web to install Cuda and Nvidia GPU driver.
/// Alternatively, the package can also be downloaded from Blob storage using DependencyPackageInstallation.
/// </summary>
public string WinCudaToolkitExeLink
{
get
{
return this.Parameters.GetValue<string>(nameof(CudaAndNvidiaGPUDriverInstallation.WinCudaToolkitExeLink), string.Empty);
}
}

/// <summary>
/// A policy that defines how the component will retry when
/// it experiences transient issues.
Expand Down Expand Up @@ -218,15 +206,6 @@ await this.CudaAndNvidiaGPUDriverInstallationOnWindowsAsync(telemetryContext, ca

SystemManagement.IsRebootRequested = this.RebootRequired;
}
else
{
// CUDA and Nvidia driver installation for other platforms to be added.
throw new WorkloadException(
$"CUDA and Nvidia GPU Driver Installtion is not supported on VirtualClient on the current platform {this.Platform}" +
$"Supported Platforms include:" +
$" Unix, Windows ",
ErrorReason.PlatformNotSupported);
}
}

this.Logger.LogTraceMessage($"{this.TypeName}.ExecutionCompleted", telemetryContext);
Expand Down Expand Up @@ -402,36 +381,6 @@ private List<string> PostInstallationCommands()
};
}

/// <summary>
/// Downloads the CUDA and Nvidia GPU driver installer from web
/// </summary>
/// <returns></returns>
private async Task DownloadCudaAndNvidiaGPUDriverForWindowsFromWeb(string installerPath, CancellationToken cancellationToken)
{
using var restClient = new RestClientBuilder().Build();

try
{
HttpResponseMessage httpResponse = await restClient.GetAsync(new Uri(this.WinCudaToolkitExeLink), cancellationToken, HttpCompletionOption.ResponseHeadersRead);

if (httpResponse.IsSuccessStatusCode)
{
using Stream fileStream = this.systemManager.FileSystem.FileStream.Create(installerPath, FileMode.Create, FileAccess.Write, FileShare.None);
await httpResponse.Content.CopyToAsync(fileStream);
}
else
{
throw new DependencyException(
$"Failed to download NVIDIA drivers from given link {this.WinCudaToolkitExeLink}.", ErrorReason.DependencyInstallationFailed);
}
}
catch (Exception e)
{
throw new DependencyException(
$"Failed to download NVIDIA drivers from given link {this.WinCudaToolkitExeLink}.", e, ErrorReason.DependencyInstallationFailed);
}
}

private async Task CudaAndNvidiaGPUDriverInstallationOnWindowsAsync(EventContext telemetryContext, CancellationToken cancellationToken)
{
string installerPath = string.Empty;
Expand All @@ -446,13 +395,16 @@ private async Task CudaAndNvidiaGPUDriverInstallationOnWindowsAsync(EventContext
}
else
{
this.systemManager.FileSystem.Directory.CreateDirectory("NvidiaDriversForWindows");
installerPath = this.PlatformSpecifics.Combine(
this.systemManager.FileSystem.Directory.GetCurrentDirectory(),
"NvidiaDriversForWindows",
"nvidiaDriversInstaller.exe");
DependencyPath nvidiaDriverInstallerPackage = await this.packageManager.GetPackageAsync(
this.PackageName, cancellationToken)
.ConfigureAwait(false);

if (this.systemManager.FileSystem.Directory.GetFiles(nvidiaDriverInstallerPackage.Path).Length == 0)
{
throw new DependencyException($"The installer file was not found in the directory {nvidiaDriverInstallerPackage.Path}", ErrorReason.DependencyNotFound);
}

await this.DownloadCudaAndNvidiaGPUDriverForWindowsFromWeb(installerPath, cancellationToken);
installerPath = this.fileSystem.Directory.GetFiles(nvidiaDriverInstallerPackage.Path)[0];
}

await this.ExecuteCommandAsync(installerPath, this.WinCommandLineArgs, Environment.CurrentDirectory, telemetryContext, cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ protected override async Task ExecuteAsync(EventContext telemetryContext, Cancel

await this.packageManager.ExtractPackageAsync(downloadedPackagePath, installationPath, cancellationToken, archiveType);
}
else
{
// This section is for the standalone files which are not zipped. The file will be copied to a location in installationPath and then
// file at original download path is deleted as in above case for zip file.
string installationFilePath = this.GetPackagePath(this.PackageName, Path.GetFileName(this.PackageUri.ToString()));
installationPath = this.GetPackagePath(this.PackageName);
this.fileSystem.Directory.CreateDirectory(installationPath);
this.fileSystem.File.Copy(downloadedPackagePath, installationFilePath);
}

// Note that installation path is the final path even though we are using the packages path above
// as the destination.
Expand Down
111 changes: 111 additions & 0 deletions website/docs/dependencies/0031-install-cuda-and-nvidia-drivers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Install CUDA and NVIDIA GPU Drivers
Virtual Client has a dependency component that can be added to a workload or monitor profile to install CUDA and NVIDIA drivers in Linux and Windows systems. The following section illustrates the
details for integrating this into the profile.

- [NVIDIA Official Drivers Page](https://www.nvidia.com/Download/index.aspx)
- [CUDA Toolkit Downloads](https://developer.nvidia.com/cuda-downloads)

## Supported Platform/Architectures
* linux-x64 (Ubuntu, Debian, CentOS7, RHEL7, RHEL8, SUSE)
* win-x64

## Profile Component Parameters for Windows
This dependency component can be used to download the drivers on Windows either from Web using Wget, or from a blob storage using the DependencyPackageInstallation.
The following section describes the parameters used by the individual component in the profile in Windows:

| **Parameter** | **Required** | **Description** | **Default** |
|---------------|--------------|----------------------------|-------------------------------------------------|
| PackageName | Yes | The logical name of the package that will be registered with the Virtual Client runtime. This name can be used by other profile components to reference the installation parent directory location for Drivers. | |
| Scenario | No | A name/identifier for the specific component in the profile. This is used for telemetry purposes only with components in dependency sections of the profile (i.e. cannot be used with --scenarios option on the command line). | |
| WinCommandLineArgs | No | The command line arguments that will be used with the Windows exe installer. | -y -s |
| WinCudaDriversPackageDownloadedFromBlob | No | A 'true' value would mean that drivers package is downloaded from Blob and DependencyPackageInstallation is present in dependencies. A 'false' value would imply that WgetPackageInstallation is present in dependencies to download the NVIDIA drivers installer from Web | false |
| RebootRequired | No | Whether or not reboot is required after installing the drivers. | false |

## Profile Component Parameters for Linux
The following section describes the parameters used by the individual component in the profile in Windows:

| **Parameter** | **Required** | **Description** | **Default** |
|---------------|--------------|----------------------------|-------------------------------------------------|
| PackageName | Yes | The logical name of the package that will be registered with the Virtual Client runtime. This name can be used by other profile components to reference the installation parent directory location for Drivers. | |
| Scenario | No | A name/identifier for the specific component in the profile. This is used for telemetry purposes only with components in dependency sections of the profile (i.e. cannot be used with --scenarios option on the command line). | |
| LinuxCudaVersion | Yes | The version of CUDA to be installed in Linux Systems | |
| LinuxDriverVersion | Yes | The version of Nvidia GPU driver to be installed in Linux Systems | |
| LinuxLocalRunFile | Yes | The link to local runfile to install Cuda and Nvidia GPU driver in Linux Systems | |
| Username | No | The user who has the ssh identity registered for. | <Current UserName> |

## Example
The following sections provides examples for how to integrate the component into a profile.

### Windows example for downloading drivers from Web
A sample URL for NVIDIA Drivers for Windows 10/11 is mentioned in example. The exact URL for the specific OS and Driver Version can be taken from NVIDIA Drivers website, given above.
<div class="code-section">

```json
{
"Type": "WgetPackageInstallation",
"Parameters": {
"Scenario": "DownloadCudaAndNvidiaDriverUsingWget",
"PackageUri": "https://us.download.nvidia.com/tesla/528.33/528.33-data-center-tesla-desktop-win10-win11-64bit-dch-international.exe",
"PackageName": "nvidiaDrivers",
"Extract": true
}
},
{
"Type": "CudaAndNvidiaGPUDriverInstallation",
"Parameters": {
"Scenario": "InstallCudaAndNvidiaGPUDriverForWindows",
"WinCudaDriversPackageDownloadedFromBlob": false,
"RebootRequired": false,
"WinCommandLineArgs": "-y -s",
"PackageName": "nvidiaDrivers"
}
}
```
</div>

### Windows example for downloading drivers from Web

<div class="code-section">

```json
{
"Type": "DependencyPackageInstallation",
"Parameters": {
"Scenario": "DownloadCudaAndNvidiaDriverFromBlob",
"BlobContainer": "packages",
"BlobName": "<package-name-in-blob>",
"PackageName": "nvidiaDrivers",
"Extract": true
}
},
{
"Type": "CudaAndNvidiaGPUDriverInstallation",
"Parameters": {
"Scenario": "InstallCudaAndNvidiaGPUDriverForWindows",
"WinCudaDriversPackageDownloadedFromBlob": true,
"RebootRequired": false,
"WinCommandLineArgs": "-y -s",
"PackageName": "nvidiaDrivers"
}
}
```
</div>


### Linux example for downloading drivers
A sample URL for NVIDIA Drivers RunFile for Linux Ubuntu is mentioned in example. The exact URL for the specific OS and Driver Version can be taken from CUDA Toolkit website, given above.
<div class="code-section">

```json
{
"Type": "NvidiaCudaInstallation",
"Parameters": {
"Scenario": "InstallNvidiaCuda",
"CudaVersion": "12.0",
"DriverVersion": "525",
"Username": "",
"LocalRunFile": "https://developer.download.nvidia.com/compute/cuda/12.0.0/local_installers/cuda_12.0.0_525.60.13_linux.run"
}
},
```
</div>

0 comments on commit 9c0a714

Please sign in to comment.