Skip to content

Commit 12fa592

Browse files
committed
Updated cuDNN install script for Windows
1 parent 59559b1 commit 12fa592

File tree

1 file changed

+148
-89
lines changed

1 file changed

+148
-89
lines changed

devops/install/install_CUDnn.bat

Lines changed: 148 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@ REM Settings
3939

4040
set dryRun=false
4141

42+
:: The location of large packages that need to be downloaded (eg an AWS S3 bucket
43+
:: name). This will be overwritten using the value from appsettings.json
44+
REM set assetStorageUrl=https://codeproject-ai.s3.ca-central-1.amazonaws.com/server/assets/
45+
set assetStorageUrl=https://codeproject-ai-bunny.b-cdn.net/server/assets/
46+
REM set assetStorageUrl=https://www.codeproject.com/ai/download/server/assets/
47+
4248
set cuDNNLocation=https://developer.nvidia.com/rdp/cudnn-download
43-
set cuDNNArchiveDownloadUrl=https://codeproject-ai.s3.ca-central-1.amazonaws.com/server/assets/libraries/
49+
set cuDNNArchiveDownloadUrl=!assetStorageUrl!libraries/
4450

45-
set CUDA10_cuDNN_version=8.4.1.50
46-
set CUDA11_cuDNN_version=8.9.4.25
47-
set CUDA12_cuDNN_version=8.9.7.29
51+
set CUDA10_cuDNN_version=8.7.0.84
52+
set CUDA11_cuDNN_version=8.9.7.29
53+
set CUDA12_cuDNN_version=9.5.1
4854

4955
set zLibLocation=http://www.winimage.com/zLibDll/
5056
set zLibArchiveName=zlib123dllx64
@@ -84,9 +90,23 @@ if "!cuda_major_version!" == "10" (
8490
set cuda_version=12
8591
set cuDNN_version=!CUDA12_cuDNN_version!
8692
)
87-
set cuDNNArchiveFilename=cudnn-windows-x86_64-!cuDNN_version!_cuda!cuda_version!-archive.zip
88-
set cuDNNPattern=cudnn-windows-x86_64-*_cuda!cuda_version!-archive.zip
89-
set "cuDNNRegex=cudnn-windows-x86_64-([0-9]*).([0-9]*).([0-9]*).([0-9]*)_cuda!cuda_version!-archive.zip"
93+
94+
if "!cuda_major_version!" == "12" (
95+
set cuDNNInstallerFilename=cudnn_!cuDNN_version!_windows.exe
96+
set cuDNNPattern=cudnn_*_windows.exe
97+
set "cuDNNRegex=cudnn-([0-9]*).([0-9]*).([0-9]*)_windows.exe"
98+
) else (
99+
set cuDNNArchiveFilename=cudnn-windows-x86_64-!cuDNN_version!_cuda!cuda_version!-archive.zip
100+
set cuDNNPattern=cudnn-windows-x86_64-*_cuda!cuda_version!-archive.zip
101+
set "cuDNNRegex=cudnn-windows-x86_64-([0-9]*).([0-9]*).([0-9]*).([0-9]*)_cuda!cuda_version!-archive.zip"
102+
)
103+
104+
REM Check
105+
106+
if exist "C:\Program Files\NVIDIA\CUDNN\v*.*" (
107+
echo cuDNN is installed.
108+
goto:eof
109+
)
90110

91111

92112
REM Install
@@ -105,125 +125,164 @@ set zLibInstalled=false
105125
:: but before we start lets ensure we attempt to have at least one version present.
106126

107127
echo Searching for existing cuDNN installers !cuDNNPattern!
108-
IF not exist "!cuDNNPattern!" (
128+
If not exist "!cuDNNPattern!" (
109129
echo No cuDNN archive found. Downloading !cuDNNArchiveFilename!...
110-
powershell -command "Start-BitsTransfer -Source '!cuDNNArchiveDownloadUrl!!cuDNNArchiveFilename!' -Destination '!cuDNNArchiveFilename!'"
130+
if "!cuda_major_version!" == "12" (
131+
powershell -command "Start-BitsTransfer -Source '!cuDNNArchiveDownloadUrl!!cuDNNInstallerFilename!' -Destination '!cuDNNInstallerFilename!'"
132+
) else (
133+
powershell -command "Start-BitsTransfer -Source '!cuDNNArchiveDownloadUrl!!cuDNNArchiveFilename!' -Destination '!cuDNNArchiveFilename!'"
134+
)
111135
)
112136

113-
IF exist "!cuDNNPattern!" (
114-
for /F "usebackq delims=" %%f in (`dir /B /A-D /O-N !cuDNNPattern!`) do (
137+
if "!cuda_major_version!" == "12" (
138+
If exist "!cuDNNPattern!" (
139+
for /F "usebackq delims=" %%f in (`dir /B /A-D /O-N !cuDNNPattern!`) do (
115140

116-
REM We have a cuDNN archive. Get the archive name with and without extension
117-
set cuDNNInstallerFilename=%%~nxf
118-
set cuDNNInstallerNameNoExt=%%~nf
141+
REM We have a cuDNN archive. Get the archive name with and without extension
142+
set cuDNNInstallerFilename=%%~nxf
143+
echo Found !cuDNNInstallerFilename!
119144

120-
echo Found !cuDNNInstallerFilename!
145+
REM Get the version. Filename is similar to cudnn-9.5.1_windows.exe
146+
REM where the version here is 9.5.1. We only need major/minor.
121147

122-
REM Get the version. Filename is similar to cudnn-windows-x86_64-8.5.0.96_cuda11-archive.zip,
123-
REM where the version here is 8.5.0.96. We only need major/minor.
148+
for /f "delims=" %%i in ('
149+
powershell -c "'!cuDNNInstallerFilename!' -replace '!cuDNNRegex!','$1.$2'"
150+
') do set version=%%i
124151

125-
for /f "delims=" %%i in ('
126-
powershell -c "'!cuDNNInstallerFilename!' -replace '!cuDNNRegex!','$1.$2'"
127-
') do set version=%%i
152+
if "!version!" == "" (
153+
echo No installer available.
154+
goto:eof
155+
)
156+
echo Found cuDNN installer for version !version!. Installing...
157+
158+
!cuDNNInstallerFilename!
159+
160+
del !cuDNNInstallerFilename!
161+
162+
set cuDNNInstalled=true
128163

129-
if "!version!" == "" (
130-
echo No installer available.
131-
goto:eof
164+
echo done.
165+
166+
REM Only process the first archive we find
167+
call :InstallChecks
132168
)
133-
echo Found cuDNN installer for version !version!. Expanding...
169+
)
134170

135-
REM Expand the archive
171+
) else (
172+
IF exist "!cuDNNPattern!" (
173+
for /F "usebackq delims=" %%f in (`dir /B /A-D /O-N !cuDNNPattern!`) do (
136174

137-
rem echo Expanding...
138-
139-
set tarExists=true
140-
tar -xf "!cuDNNInstallerFilename!" > nul 2>nul
141-
if "%errorlevel%" == "9009" set tarExists=false
175+
REM We have a cuDNN archive. Get the archive name with and without extension
176+
set cuDNNInstallerFilename=%%~nxf
177+
set cuDNNInstallerNameNoExt=%%~nf
142178

143-
if "!tarExists!" == "false" (
144-
powershell -command "Expand-Archive -Path '!cuDNNInstallerFilename!' -DestinationPath '!cuDNNInstallerNameNoExt!' -Force"
145-
)
179+
echo Found !cuDNNInstallerFilename!
146180

147-
REM Move the directories into C:\Program Files\NVIDIA\CUDNN\v<version>
181+
REM Get the version. Filename is similar to cudnn-windows-x86_64-8.5.0.96_cuda11-archive.zip,
182+
REM where the version here is 8.5.0.96. We only need major/minor.
148183

149-
echo Installing cuDNN files...
184+
for /f "delims=" %%i in ('
185+
powershell -c "'!cuDNNInstallerFilename!' -replace '!cuDNNRegex!','$1.$2'"
186+
') do set version=%%i
150187

151-
if not exist "C:\Program Files\NVIDIA" mkdir "C:\Program Files\NVIDIA" > NUL
152-
if not exist "C:\Program Files\NVIDIA\CUDNN" mkdir "C:\Program Files\NVIDIA\CUDNN" > NUL
153-
if not exist "C:\Program Files\NVIDIA\CUDNN\v!version!\" mkdir "C:\Program Files\NVIDIA\CUDNN\v!version!\" > NUL
188+
if "!version!" == "" (
189+
echo No installer available.
190+
goto:eof
191+
)
192+
echo Found cuDNN installer for version !version!. Expanding...
154193

155-
robocopy /e "!cuDNNInstallerNameNoExt! " "C:\Program Files\NVIDIA\CUDNN\v!version! " /MOVE /NC /NS /NJS /NJH > NUL
194+
REM Expand the archive
156195

157-
set cuDNNInstalled=true
196+
rem echo Expanding...
197+
198+
set tarExists=true
199+
tar -xf "!cuDNNInstallerFilename!" > nul 2>nul
200+
if "%errorlevel%" == "9009" set tarExists=false
158201

202+
if "!tarExists!" == "false" (
203+
powershell -command "Expand-Archive -Path '!cuDNNInstallerFilename!' -DestinationPath '!cuDNNInstallerNameNoExt!' -Force"
204+
)
159205

160-
echo Installing ZLib
206+
REM Move the directories into C:\Program Files\NVIDIA\CUDNN\v<version>
161207

162-
REM Next step is to grab ZLib and intall that. We'll place it next to the cuDNN files in
163-
REM C:\Program Files\NVIDIA\CUDNN\v<version>\zLib
208+
echo Installing cuDNN files...
164209

165-
if not exist "!zLibArchiveName!.zip" (
166-
powershell -command "Start-BitsTransfer -Source '!zLibLocation!!zLibArchiveName!.zip' -Destination '!zLibArchiveName!.zip'"
167-
)
210+
if not exist "C:\Program Files\NVIDIA" mkdir "C:\Program Files\NVIDIA" > NUL
211+
if not exist "C:\Program Files\NVIDIA\CUDNN" mkdir "C:\Program Files\NVIDIA\CUDNN" > NUL
212+
if not exist "C:\Program Files\NVIDIA\CUDNN\v!version!\" mkdir "C:\Program Files\NVIDIA\CUDNN\v!version!\" > NUL
168213

169-
if exist "!zLibArchiveName!.zip" (
170-
echo Expanding ZLib...
171-
if "!tarExists!" == "true" (
172-
if not exist "!zLibArchiveName!" mkdir "!zLibArchiveName!" > NUL
173-
copy !zLibArchiveName!.zip !zLibArchiveName!\ > NUL
174-
pushd !zLibArchiveName! > NUL
175-
tar -xf "!zLibArchiveName!.zip" > nul 2>nul
176-
del !zLibArchiveName!.zip > NUL
177-
popd > NUL
178-
) else (
179-
powershell -command "Expand-Archive -Path '!zLibArchiveName!.zip' -DestinationPath '!zLibArchiveName!' -Force"
180-
)
214+
robocopy /e "!cuDNNInstallerNameNoExt! " "C:\Program Files\NVIDIA\CUDNN\v!version! " /MOVE /NC /NS /NJS /NJH > NUL
181215

182-
echo Installing ZLib...
183-
if not exist "C:\Program Files\NVIDIA\CUDNN\v!version!\zlib" mkdir "C:\Program Files\NVIDIA\CUDNN\v!version!\zlib"
184-
robocopy /e "!zLibArchiveName! " "C:\Program Files\NVIDIA\CUDNN\v!version!\zlib\ " /MOVE /NC /NS /NJS /NJH > NUL
216+
set cuDNNInstalled=true
185217

186-
set zLibInstalled=true
187-
)
188218

189-
if /i "!dryRun!" == "false" (
190-
REM We need to set the PATH variable. Some caveats:
191-
REM 1. When you set the PATH variable, %PATH% will not reflect the update you just made, so
192-
REM doing "PATH = PATH + change1" followed by "PATH = PATH + change2" results in just Change2
193-
REM being added. So: do all the changes in one fell swoop.
194-
REM 2. We can't use setx /M PATH "%PATH%;C:\Program Files\NVIDIA\CUDNN\v!version!\zlib\dll_x64"
195-
REM because setx truncates the path to 1024 characters. In 2022. Insanity.
196-
REM 3. Only update the path if we need to. Check for existance before modifying!
219+
echo Installing ZLib
197220

198-
echo Updating PATH environment variable...
221+
REM Next step is to grab ZLib and install that. We'll place it next to the cuDNN files in
222+
REM C:\Program Files\NVIDIA\CUDNN\v<version>\zLib
199223

200-
set newPath=!PATH!
224+
if not exist "!zLibArchiveName!.zip" (
225+
powershell -command "Start-BitsTransfer -Source '!zLibLocation!!zLibArchiveName!.zip' -Destination '!zLibArchiveName!.zip'"
226+
)
201227

202-
REM Add ZLib path if it hasn't already been added
203-
if "!zLibInstalled!" == "true" (
204-
if /i "!PATH:C:\Program Files\NVIDIA\CUDNN\v!version!\zlib=!" == "!PATH!" (
205-
set newPath=!newPath!;C:\Program Files\NVIDIA\CUDNN\v!version!\zlib\dll_x64
228+
if exist "!zLibArchiveName!.zip" (
229+
echo Expanding ZLib...
230+
if "!tarExists!" == "true" (
231+
if not exist "!zLibArchiveName!" mkdir "!zLibArchiveName!" > NUL
232+
copy !zLibArchiveName!.zip !zLibArchiveName!\ > NUL
233+
pushd !zLibArchiveName! > NUL
234+
tar -xf "!zLibArchiveName!.zip" > nul 2>nul
235+
del !zLibArchiveName!.zip > NUL
236+
popd > NUL
237+
) else (
238+
powershell -command "Expand-Archive -Path '!zLibArchiveName!.zip' -DestinationPath '!zLibArchiveName!' -Force"
206239
)
240+
241+
echo Installing ZLib...
242+
if not exist "C:\Program Files\NVIDIA\CUDNN\v!version!\zlib" mkdir "C:\Program Files\NVIDIA\CUDNN\v!version!\zlib"
243+
robocopy /e "!zLibArchiveName! " "C:\Program Files\NVIDIA\CUDNN\v!version!\zlib\ " /MOVE /NC /NS /NJS /NJH > NUL
244+
245+
set zLibInstalled=true
207246
)
208-
REM Add cuDNN path if it hasn't already been added
209-
if /i "!PATH:C:\Program Files\NVIDIA\CUDNN\v!version!\bin=!" == "!PATH!" (
210-
set newPath=!newPath!;C:\Program Files\NVIDIA\CUDNN\v!version!\bin
211-
)
212247

213-
if /i "!newPath" NEQ "!PATH!" (
214-
rem echo New Path is !newPath!
215-
powershell -command "[Environment]::SetEnvironmentVariable('PATH', '!newPath!','Machine');
248+
if /i "!dryRun!" == "false" (
249+
REM We need to set the PATH variable. Some caveats:
250+
REM 1. When you set the PATH variable, %PATH% will not reflect the update you just made, so
251+
REM doing "PATH = PATH + change1" followed by "PATH = PATH + change2" results in just Change2
252+
REM being added. So: do all the changes in one fell swoop.
253+
REM 2. We can't use setx /M PATH "%PATH%;C:\Program Files\NVIDIA\CUDNN\v!version!\zlib\dll_x64"
254+
REM because setx truncates the path to 1024 characters. In 2022. Insanity.
255+
REM 3. Only update the path if we need to. Check for existance before modifying!
256+
257+
echo Updating PATH environment variable...
258+
259+
set newPath=!PATH!
260+
261+
REM Add ZLib path if it hasn't already been added
262+
if "!zLibInstalled!" == "true" (
263+
if /i "!PATH:C:\Program Files\NVIDIA\CUDNN\v!version!\zlib=!" == "!PATH!" (
264+
set newPath=!newPath!;C:\Program Files\NVIDIA\CUDNN\v!version!\zlib\dll_x64
265+
)
266+
)
267+
REM Add cuDNN path if it hasn't already been added
268+
if /i "!PATH:C:\Program Files\NVIDIA\CUDNN\v!version!\bin=!" == "!PATH!" (
269+
set newPath=!newPath!;C:\Program Files\NVIDIA\CUDNN\v!version!\bin
270+
)
271+
272+
if /i "!newPath" NEQ "!PATH!" (
273+
rem echo New Path is !newPath!
274+
powershell -command "[Environment]::SetEnvironmentVariable('PATH', '!newPath!','Machine');
275+
)
216276
)
217-
)
218277

219-
echo done.
278+
echo done.
220279

221-
REM Only process the first archive we find
222-
call :InstallChecks
280+
REM Only process the first archive we find
281+
call :InstallChecks
282+
)
223283
)
224284
)
225285

226-
227286
goto:eof
228287

229288
:InstallChecks

0 commit comments

Comments
 (0)