forked from microsoft/CNTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_build_info
executable file
·186 lines (169 loc) · 5.5 KB
/
generate_build_info
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
#!/bin/bash
#
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the MIT license. See LICENSE.md file in the project root
# for full license information.
# ==============================================================================
#
# Description: this script is used to generated buildinfo.h in Source/CNTK
# which will contain the following information to be displayed at runtime:
# BUILDTYPE (release/debug)
# BUILDTYPE (GPU/CPU-only)
# MATHLIB (MKL)
# CUDA_PATH (if exists, i.e., for GPU builds)
# CUB_PATH (if exists, i.e., for GPU builds)
# CUDNN_PATH (if exists, i.e., only for GPU builds)
# GIT_COMMIT (SHA1, and whether working directory is modified)
# GTT_BRANCH (the current branch)
# BUILDER (user under which the build was done)
# BUILDMACHINE (build machine)
# BUILDPATH (build path)
# MPI_NAME (mpi distribution)
# MPI_VERSION (mpi version)
usage ()
{
echo "usage: $0 <Config.make>"
echo "-------------------------------------------------------------------"
echo "This script is used to generate buildinfo.h in Source/CNTK/Generated/Linux"
echo "This script needs to be called from the top level directory of CNTK project"
echo "This script assumes git can be used"
echo "This script assumes Config.make has been made"
echo "-------------------------------------------------------------------"
if [ ! -z "$1" ] ; then
echo "ERROR message: $1"
fi
exit 1
}
Has_Git()
{
if hash git 2>/dev/null; then
return 0
else
return 1
fi
}
makebuildinfo()
{
local target=$1
local BUILDTYPE=$2
local MATHLIB=$3
local GIT_COMMIT=$4
local GIT_BRANCH=$5
local CUDA_PATH=$6
local CUB_PATH=$7
local WITH_ASGD=$8
local BUILDER=$9
local BUILDMACHINE=${10}
local BUILDPATH=${11}
local MPI_NAME=${12}
local MPI_VERSION=${13}
(
printf "#ifndef _BUILDINFO_H\n"
printf "#define _BUILDINFO_H\n"
printf "#define _GIT_EXIST\n"
printf "#define _MATHLIB_ \"%s\"\n" "$MATHLIB"
printf "#define _BUILDSHA1_ \"%s\"\n" "$GIT_COMMIT"
printf "#define _BUILDBRANCH_ \"%s\"\n" "$GIT_BRANCH"
if [ -z "$CUDA_PATH" ]; then
printf "#define _BUILDTARGET_ \"CPU-only\"\n"
else
printf "#define _BUILDTARGET_ \"GPU\"\n"
printf "#define _CUDA_PATH_ \"%s\"\n" "$CUDA_PATH"
fi
if [ ! -z "$CUB_PATH" ]; then
printf "#define _CUB_PATH_ \"%s\"\n" "$CUB_PATH"
fi
if [ ! -z "$CUDNN_PATH" ]; then
printf "#define _CUDNN_PATH_ \"%s\"\n" $CUDNN_PATH
fi
printf "#define _BUILDTYPE_ \"%s\"\n" "$BUILDTYPE"
if [ ! -z "$WITH_ASGD" ]; then
printf "#define _WITH_ASGD_ \"yes\"\n"
else
printf "#define _WITH_ASGD_ \"no\"\n"
fi
printf "#define _BUILDER_ \"%s\"\n" "$BUILDER"
printf "#define _BUILDMACHINE_ \"%s\"\n" "$BUILDMACHINE"
printf "#define _BUILDPATH_ \"%s\"\n" "$BUILDPATH"
printf "#define _MPI_NAME_ \"%s\"\n" "$MPI_NAME"
printf "#define _MPI_VERSION_ \"%s\"\n" "$MPI_VERSION"
printf "#endif\n"
) > "$target"
}
#//////////////////////////////////////////////////////#
# main function #
#//////////////////////////////////////////////////////#
if [ $# -ne 1 ]; then
usage
fi
config=$1
# Check whether we have git and what is the SHA-1 value
if Has_Git; then has_git=1; else has_git=0; usage "git does not exist"; fi
GIT_STATUS=' (modified)'
git diff --quiet && git diff --cached --quiet && GIT_STATUS=''
GIT_COMMIT=`git rev-parse HEAD`$GIT_STATUS
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`
# Looking into Config.make
if [ ! -e $config ] ; then
usage "Config.make not exists"
fi
source $config
# Whether we have CUDA_PATH
if [ -z "${CUDA_PATH+x}" ]; then
CUDAPATH=""
else
CUDAPATH=$CUDA_PATH
fi
# Whether we have CUB_PATH
if [ -z "${CUB_PATH+x}" ]; then
CUBPATH=""
else
CUBPATH=$CUB_PATH
fi
# Identify MKL variant being used
if [ "$MATHLIB" = "mkl" -a "$MKL_THREADING" = "sequential" ]; then
MATHLIB=mkl-sequential
fi
# MPI info
MPI_NAME=Unknown
MPI_VERSION=Unknown
if hash ${MPI_PATH}/bin/mpirun 2>/dev/null; then
if [ -e ${MPI_PATH}/bin/ompi_info ]; then
MPI_NAME="Open MPI"
MPI_VERSION=`${MPI_PATH}/bin/ompi_info --parsable | grep ident | cut -f 2 -d ":"`
elif [ -e ${MPI_PATH}/bin/mpirun_rsh ]; then
MPI_NAME=`${MPI_PATH}/bin/mpiname`
MPI_VERSION=`${MPI_PATH}/bin/mpiname -v`
fi
fi
# Build machine info
BUILDER=$USER
BUILDMACHINE=`hostname`
BUILDPATH=`pwd`
# Delete the old versions of the buildinfo file, as they can break the build in some scenarios if left hanging around
[ ! -e Source/CNTK/buildinfo.h ] || rm Source/CNTK/buildinfo.h
[ ! -e Source/CNTKv2LibraryDll/buildinfo.h ] || rm Source/CNTKv2LibraryDll/buildinfo.h
target=Source/CNTKv2LibraryDll/Generated/Linux/buildinfo.h
if [ ! -d Source ] ; then
usage
fi
# Make buildinfo.h (only update if changed)
if [ ! -d Source/CNTKv2LibraryDll/Generated/Linux ]; then
mkdir -p Source/CNTKv2LibraryDll/Generated/Linux
fi
makebuildinfo \
"$target\$\$" \
"$BUILDTYPE" \
"$MATHLIB" \
"$GIT_COMMIT" \
"$GIT_BRANCH" \
"$CUDAPATH" \
"$CUBPATH" \
"$CNTK_ENABLE_ASGD" \
"$BUILDER" \
"$BUILDMACHINE" \
"$BUILDPATH" \
"$MPI_NAME" \
"$MPI_VERSION"
cmp -s "$target\$\$" "$target" || mv "$target\$\$" "$target"