forked from microsoft/CNTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprebuild.bat
123 lines (107 loc) · 4.42 KB
/
prebuild.bat
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
@echo off
setlocal enableDelayedexpansion
::: Copyright (c) Microsoft. All rights reserved.
:::
::: Licensed under the MIT license. See LICENSE.md file in the project root
::: for full license information.
::: ==============================================================================
:::
::: This is called as a pre-build step for the CNTK executable, taking parameters below.
::: It creates buildinfo.h, which makes version information available to the executable itself.
:: Grab the parameters
::
:: Note: don't rely on environment variables, since properties may have been
:: overridden at msbuild invocation. By convention, we let parameters start with p_, locals with l_.
:: A Vim search for [%!]\([lp]_\)\@!\w\+[%!:] should only match
:: well-known (non-CNTK-specific) environment variables.
set p_Configuration=%~1
set p_CNTK_MKL_SEQUENTIAL=%~2
set p_CNTK_ENABLE_1BitSGD=%~3
set p_CudaPath=%~4
set p_CUDNN_PATH=%~5
set p_CUB_PATH=%~6
set p_CNTK_ENABLE_ASGD=%~7
echo #ifndef _BUILDINFO_H > buildinfo.h$$
echo #define _BUILDINFO_H >> buildinfo.h$$
FOR /F %%i IN ('hostname') DO SET HOST=%%i
:: assuming hostname always exists
:: note: we'll only use git which is in path
where -q git
if not errorlevel 1 (
call git --version > NUL 2>&1
if not errorlevel 1 (
echo #define _GIT_EXIST >> buildinfo.h$$
FOR /F %%i IN ('call git rev-parse --abbrev-ref HEAD') DO SET l_BRANCH=%%i
FOR /F %%i IN ('call git rev-parse HEAD') DO SET l_COMMIT=%%i
set l_STATUS=
call git diff --quiet --cached
if not errorlevel 1 call git diff --quiet
if errorlevel 1 set l_STATUS= ^(modified^)
echo #define _BUILDBRANCH_ "!l_BRANCH!" >> buildinfo.h$$
echo #define _BUILDSHA1_ "!l_COMMIT!!l_STATUS!">> buildinfo.h$$
)
)
if "%p_CNTK_MKL_SEQUENTIAL%" == "1" (
echo #define _MATHLIB_ "mkl-sequential">> buildinfo.h$$
) else (
echo #define _MATHLIB_ "mkl">> buildinfo.h$$
)
echo #define _BUILDER_ "%USERNAME%" >> buildinfo.h$$
echo #define _BUILDMACHINE_ "%HOST%" >> buildinfo.h$$
set l_scriptpath=%~dp0
set l_buildpath="%l_scriptpath:\=\\%"
echo #define _BUILDPATH_ %l_buildpath% >> buildinfo.h$$
set l_build_type=Unknown
set l_build_target=Unknown
:: Configuration property provided by CNTK.vcxproj
if /i "%p_Configuration%" == "Debug" set l_build_type=Debug&set l_build_target=GPU
if /i "%p_Configuration%" == "Debug_CpuOnly" set l_build_type=Debug&set l_build_target=CPU-only
if /i "%p_Configuration%" == "Release" set l_build_type=Release&set l_build_target=GPU
if /i "%p_Configuration%" == "Release_CpuOnly" set l_build_type=Release&set l_build_target=CPU-only
echo #define _BUILDTYPE_ "%l_build_type%">> buildinfo.h$$
echo #define _BUILDTARGET_ "%l_build_target%">> buildinfo.h$$
if "%p_CNTK_ENABLE_1BitSGD%" == "true" (
echo #define _WITH_1BITSGD_ "yes">>buildinfo.h$$
) else (
echo #define _WITH_1BITSGD_ "no">>buildinfo.h$$
)
:: assuming CNTK_ENABLE_ASGD was true as default value
if "%p_CNTK_ENABLE_ASGD%" == "false" (
echo #define _WITH_ASGD_ "no">>buildinfo.h$$
) else (
echo #define _WITH_ASGD_ "yes">>buildinfo.h$$
)
if not %l_build_target% == CPU-only (
if "%p_CudaPath%" == "" (
echo #define _CUDA_PATH_ "NOT_DEFINED" >> buildinfo.h$$
) else (
echo #define _CUDA_PATH_ "!p_CudaPath:\=\\!" >> buildinfo.h$$
)
if not "%p_CUDNN_PATH%" == "" (
echo #define _CUDNN_PATH_ "%p_CUDNN_PATH:\=\\%" >> buildinfo.h$$
)
if not "%p_CUB_PATH%" == "" (
echo #define _CUB_PATH_ "%p_CUB_PATH:\=\\%" >> buildinfo.h$$
)
)
:: MPI info
set MPI_NAME="Unknown"
set MPI_VERSION="Unknown"
where -q mpiexec && mpiexec.exe -help > NUL 2>&1
if not errorlevel 1 (
for /f "tokens=1 delims= " %%i in ('mpiexec -help ^| findstr Version') do (
if "%%i" == "Microsoft" (
set MPI_NAME="Microsoft MPI"
for /f "tokens=6 delims=] " %%i in ('mpiexec -help ^| findstr Version') do set MPI_VERSION="%%i"
) else if "%%i" == "Intel" (
set MPI_NAME="Intel MPI"
for /f "tokens=8 delims= " %%i in ('mpiexec -help ^| findstr Version') do set MPI_VERSION="%%i"
)
)
)
echo #define _MPI_NAME_ %MPI_NAME% >> buildinfo.h$$
echo #define _MPI_VERSION_ %MPI_VERSION% >> buildinfo.h$$
echo #endif >> buildinfo.h$$
::: update file only if it changed (otherwise CNTK.cpp will get rebuilt each time)
fc buildinfo.h$$ buildinfo.h > NUL 2>&1
if errorlevel 1 move /Y buildinfo.h$$ buildinfo.h