Skip to content

Instantly share code, notes, and snippets.

@coderhh
Last active October 1, 2020 03:48
Show Gist options
  • Save coderhh/c2d4bb0812d5a6804c589b19c31a6975 to your computer and use it in GitHub Desktop.
Save coderhh/c2d4bb0812d5a6804c589b19c31a6975 to your computer and use it in GitHub Desktop.
PowerShell Script to setup tensorflow gpu on Windows 10
<#
Script to setup gpu support for tensorflow on Windows 10
Author: Yehang Han
#>
Clear-Host
# 1. Install Microsoft Visual C++ Compiler
Write-Host "Installing Microsoft Visual C++ Compiler" -ForegroundColor Green
if (Get-Module -ListAvailable -Name VSSetup) {
#Write-Host "Module VSSetup exists"
}
else {
#Write-Host "Module VSSetup does not exist"
Install-Module -Name VSSetup
}
if (Get-VSSetupInstance -All | Select-VSSetupInstance -Require 'Microsoft.VisualStudio.Workload.NativeDesktop' -Latest) {
Write-Host "Microsoft Visual C++ Compiler exists, skipping..." -ForegroundColor Green
}
else {
Write-Host "Microsoft Visual C++ Compiler not exist" -ForegroundColor Green -BackgroundColor White
Invoke-Webrequest -uri "https://download.visualstudio.microsoft.com/download/pr/9fcc1f0c-c63f-4424-bc46-7351a59fba06/1ed7863dc633c57c42a88c5cef907048/vs_community.exe" -OutFile vs_community.exe
Start-Process -NoNewWindow -FilePath "vs_community.exe" -ArgumentList "--layout c:\vslayout","--add Microsoft.VisualStudio.Workload.NativeDesktop","--includeRecommended", "--lang en-US"
Start-Process -NoNewWindow -FilePath "c:\vslayout\vs_community.exe" -ArgumentList "--noweb", "--add Microsoft.VisualStudio.Workload.NativeDesktop","--includeOptional"
}
# 2. Install CUDA Toolkit
Write-Host "Installing CUDA Toolkit" -ForegroundColor Green
if(!(Test-Path "cuda.exe")){
Invoke-Webrequest -uri "http://developer.download.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda_10.1.243_426.00_win10.exe" -OutFile cuda.exe
}else{
Start-Process -NoNewWindow -FilePath "cuda.exe" -ArgumentList "-s" -ErrorAction Stop
}
# 3. Install cuDNN
Write-Host "Installing cuDNN" -ForegroundColor Green
if(!(Test-Path "cudnn.zip")){
Invoke-Webrequest -uri "http://download1491.mediafire.com/8glofqtxelzg/47vmj62ysaytdps/cudnn-10.1-windows10-x64-v7.6.5.32.zip -OutFile cudnn.zip
}else{
If (Test-Path "cudnn")
{
Remove-Item "cudnn" -Recurse
}
Expand-Archive -Path cudnn.Zip -DestinationPath cudnn -ErrorAction Stop
# Back up cudnn folders
Compress-Archive -Path "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin\*" bin_bak.zip
Compress-Archive -Path "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include\*" include_bak.zip
Compress-Archive -Path "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64\*" lib_x64_bak.zip
Copy-Item .\cudnn\cuda\bin\*.dll "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin"
Copy-Item .\cudnn\cuda\include\*.h "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include"
Copy-Item .\cudnn\cuda\lib\x64\*.lib "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64"
}
# 4. Install TensorFlow·
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment