-
Notifications
You must be signed in to change notification settings - Fork 9
/
ort.ps1
executable file
·250 lines (214 loc) · 10.6 KB
/
ort.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#Requires -RunAsAdministrator
Get-Content "$PSScriptRoot/utils/re-entry.ps1" -Raw | Invoke-Expression
$ErrorActionPreference="Stop"
. "$PSScriptRoot/env/mirror.ps1"
. "$PSScriptRoot/env/toolchain.ps1"
& "${Env:PYTHONHOME}/python.exe" -m pip install -U numpy | Out-Null
pushd ${Env:SCRATCH}
$repo="${Env:GIT_MIRROR}/microsoft/onnxruntime.git"
$proj="$($repo -replace '.*/','' -replace '.git$','')"
$root= Join-Path "${Env:SCRATCH}" "$proj"
cmd /c rmdir /S /Q "$root"
if (Test-Path "$root")
{
echo "Failed to remove `"$root`""
Exit 1
}
# Use latest release.
$latest_ver = 'v' + $($(git ls-remote --tags "$repo") -match '.*refs/tags/v[0-9\.]*$' -replace '.*refs/tags/v','' | sort {[Version]$_})[-1]
# Use latest release branch.
# $latest_ver = 'rel-' + $($(git ls-remote --heads "$repo") -match '.*refs/heads/rel-[0-9\.]*$' -replace '.*refs/heads/rel-','' | sort {[Version]$_})[-1]
# Use master.
# $latest_ver = 'master'
git clone --recursive -b "$latest_ver" -j100 "$repo"
pushd "$root"
# ================================================================================
# Build Options
# ================================================================================
$update_gtest = $true
$update_onnx = $false
$update_protobuf = $false
$use_bat = $false
# ================================================================================
# Experimental PR
# ================================================================================
# ================================================================================
# Patch
# ================================================================================
git remote add patch https://github.com/xkszltl/onnxruntime.git
git fetch patch
# ================================================================================
# Update GTest
# ================================================================================
if ($update_gtest)
{
pushd cmake/external/googletest
git fetch --tags
$gtest_latest_ver='release-' + $($(git tag) -match '^release-[0-9\.]*$' -replace '^release-','' | sort {[Version]$_})[-1]
git checkout "$gtest_latest_ver"
git submodule update --init
popd
}
# ================================================================================
# Update ONNX and its PyBind
#
# Warning:
# ONNX Breaking change on Mar 11, 2019 causes build error in Ort.
# https://github.com/onnx/onnx/pull/1834
# ================================================================================
if ($update_onnx)
{
pushd cmake/external/onnx
git pull origin master
git submodule update --init --recursive
pushd third_party/pybind11
git fetch --tags
$pybind_latest_ver='v' + $($(git tag) -match '^v[0-9\.]*$' -replace '^v','' | sort {[Version]$_})[-1]
git checkout "$pybind_latest_ver"
git submodule update --init --recursive
popd
git --no-pager diff
git commit -am "Automatic git submodule updates."
popd
}
# ================================================================================
# Update Protobuf
# ================================================================================
if ($update_protobuf)
{
pushd cmake/external/protobuf
git fetch --tags
$pb_latest_ver='v' + $($(git tag) -match '^v[0-9\.]*$' -replace '^v','' | sort {[Version]$_})[-1]
git checkout "$pb_latest_ver"
git remote add patch https://github.com/xkszltl/protobuf.git
git fetch patch
git submodule update --init
popd
}
# ================================================================================
# Commit
# ================================================================================
git --no-pager diff
git commit -am "Automatic git submodule updates."
# ================================================================================
# Build
# ================================================================================
if (-not $use_bat)
{
mkdir build
pushd build
}
if ($use_bat)
{
./build.bat `
--build_shared_lib `
--cmake_extra_defines `
BOOST_ROOT=`"${Env:ProgramFiles}/boost`" `
CMAKE_C_FLAGS=`"/w`" `
CMAKE_CXX_FLAGS=`"/w`" `
--config=Release `
--use_mklml
exit 1
}
else
{
# Turn off CUDA temporarily until Ort team switch back to static cudart.
# Turn off unit test due to missing protobuf 3.7 support.
#
# Ort team is removing prebuilt protobuf.
# -DONNX_CUSTOM_PROTOC_EXECUTABLE="${Env:ProgramFiles}/protobuf/bin/protoc.exe"
# -Donnxruntime_USE_PREBUILT_PB=ON
cmake `
-A x64 `
-DBOOST_ROOT="${Env:ProgramFiles}/boost" `
-DBUILD_SHARED_LIBS=OFF `
-DCMAKE_C_FLAGS="/GL /MP /Zi /arch:AVX2" `
-DCMAKE_CXX_FLAGS="/EHsc /GL /MP /Zi /arch:AVX2" `
-DCMAKE_EXE_LINKER_FLAGS="/DEBUG:FASTLINK /LTCG:incremental" `
-DCMAKE_INSTALL_PREFIX="${Env:ProgramFiles}/onnxruntime" `
-DCMAKE_PDB_OUTPUT_DIRECTORY="${PWD}/pdb" `
-DCMAKE_SHARED_LINKER_FLAGS="/DEBUG:FASTLINK /LTCG:incremental" `
-DCMAKE_STATIC_LINKER_FLAGS="/LTCG:incremental" `
-DCUDA_VERBOSE_BUILD=ON `
-Deigen_SOURCE_PATH="${Env:ProgramFiles}/Eigen3/include/eigen3" `
-Donnxruntime_BUILD_SHARED_LIB=ON `
-Donnxruntime_BUILD_UNIT_TESTS=ON `
-Donnxruntime_CUDNN_HOME="$(Split-Path (Get-Command nvcc).Source -Parent)/.." `
-Donnxruntime_ENABLE_MICROSOFT_INTERNAL=OFF `
-Donnxruntime_ENABLE_PYTHON=ON `
-Donnxruntime_RUN_ONNX_TESTS=ON `
-Donnxruntime_ENABLE_LANGUAGE_INTEROP_OPS=ON `
-Donnxruntime_ENABLE_LTO=OFF `
-Donnxruntime_PREFER_SYSTEM_LIB=OFF `
-Donnxruntime_USE_CUDA=ON `
-Donnxruntime_USE_DNNL=ON `
-Donnxruntime_USE_EIGEN_FOR_BLAS=ON `
-Donnxruntime_USE_FULL_PROTOBUF=ON `
-Donnxruntime_USE_JEMALLOC=OFF `
-Donnxruntime_USE_LLVM=OFF `
-Donnxruntime_USE_MKLML=OFF `
-Donnxruntime_USE_NGRAPH=OFF `
-Donnxruntime_USE_NUPHAR=OFF `
-Donnxruntime_USE_OPENBLAS=OFF `
-Donnxruntime_USE_OPENMP=OFF `
-Donnxruntime_USE_PREINSTALLED_EIGEN=OFF `
-Donnxruntime_USE_TENSORRT=OFF `
-Donnxruntime_USE_TVM=OFF `
-G"Visual Studio 16 2019" `
-T"host=x64" `
../cmake
cmake --build . --config Release -- -maxcpucount
if (-Not $?)
{
echo "Failed to build."
echo "Retry with single thread for logging."
echo "You may Ctrl-C this if you don't need the log file."
cmake --build . --config Release 2>&1 | tee ${Env:SCRATCH}/${proj}.log
exit 1
}
}
$model_path = "${Env:SCRATCH}/onnxruntime_models.zip"
rm -Force -Recurse -ErrorAction SilentlyContinue -WarningAction SilentlyContinue "${model_path}.downloading"
if (-not $(Test-Path $model_path))
{
& "${Env:ProgramFiles}/CURL/bin/curl.exe" -fkSL "https://onnxruntimetestdata.blob.core.windows.net/models/20190419.zip" -o "${model_path}.downloading"
mv -Force "${model_path}.downloading" "${model_path}"
}
if (Get-Command -Name unzip -ErrorAction SilentlyContinue)
{
unzip -ou "${model_path}" -d "${model_path}.d"
cmd /c mklink /D models "`"${model_path}.d`""
}
else
{
Expand-Archive "${model_path}" "models"
}
$ErrorActionPreference="SilentlyContinue"
cmake --build . --config Release --target run_tests -- -maxcpucount
if (-Not $?)
{
echo "Check failed but we temporarily bypass it. Trying to reproduce:"
pushd Release
./onnxruntime_test_all.exe
./onnxruntime_shared_lib_test.exe
popd
}
$ErrorActionPreference="Stop"
cmd /c rmdir /S /Q "${Env:ProgramFiles}/onnxruntime"
cmake --build . --config Release --target install -- -maxcpucount
cmd /c xcopy /i /f /y "pdb\Release\*.pdb" "${Env:ProgramFiles}\onnxruntime\bin"
# cmd /c xcopy /e /i /f /y "..\cmake\external\gsl\include" "${Env:ProgramFiles}\onnxruntime\include"
# cmd /c xcopy /e /i /f /y "..\cmake\external\onnx\onnx" "${Env:ProgramFiles}\onnxruntime\include\onnx"
# cmd /c xcopy /i /f /y "onnx\*.pb.h" "${Env:ProgramFiles}\onnxruntime\include\onnx"
# cmd /c xcopy /i /f /y "onnx\Release\*.lib" "${Env:ProgramFiles}\onnxruntime\lib"
# cmd /c xcopy /i /f /y "onnxruntime_config.h" "${Env:ProgramFiles}\onnxruntime\include\onnxruntime"
# cmd /c xcopy /e /i /f /y "..\onnxruntime\core" "${Env:ProgramFiles}\onnxruntime\include\onnxruntime\core"
Get-ChildItem "${Env:ProgramFiles}/onnxruntime" -Filter *.dll -Recurse | Foreach-Object { New-Item -Force -ItemType SymbolicLink -Path "${Env:SystemRoot}\System32\$_" -Value $_.FullName }
Get-ChildItem "${Env:ProgramFiles}/onnxruntime" -Filter *.exe -Recurse | Foreach-Object { New-Item -Force -ItemType SymbolicLink -Path "${Env:SystemRoot}\System32\$_" -Value $_.FullName }
onnx_test_runner -e cpu ./models
onnx_test_runner -e mkldnn ./models
onnx_test_runner -e cuda ./models
popd
popd
cmd /c rmdir /S /Q "$root"
popd