2015-11-25 03:38:37 +03:00
|
|
|
#!/bin/bash
|
2016-06-14 18:39:24 +03:00
|
|
|
#
|
|
|
|
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the MIT license. See LICENSE.md file in the project root
|
|
|
|
# for full license information.
|
|
|
|
# ==============================================================================
|
|
|
|
#
|
2016-02-02 10:31:52 +03:00
|
|
|
# Description: this script is used to generated buildinfo.h in Source/CNTK
|
2017-06-23 10:44:56 +03:00
|
|
|
# which will contain the following information to be displayed at runtime:
|
2016-02-02 10:31:52 +03:00
|
|
|
# BUILDTYPE (release/debug)
|
|
|
|
# BUILDTYPE (GPU/CPU-only)
|
2016-08-16 16:08:08 +03:00
|
|
|
# MATHLIB (MKL)
|
2016-02-02 10:31:52 +03:00
|
|
|
# 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)
|
2017-01-03 23:29:58 +03:00
|
|
|
# MPI_NAME (mpi distribution)
|
|
|
|
# MPI_VERSION (mpi version)
|
2015-11-25 03:38:37 +03:00
|
|
|
|
|
|
|
usage ()
|
|
|
|
{
|
2016-02-02 10:31:52 +03:00
|
|
|
echo "usage: $0 <Config.make>"
|
|
|
|
echo "-------------------------------------------------------------------"
|
2018-06-06 21:49:57 +03:00
|
|
|
echo "This script is used to generate buildinfo.h in Source/CNTK/Generated/Linux"
|
2016-02-02 10:31:52 +03:00
|
|
|
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 "-------------------------------------------------------------------"
|
2016-06-14 18:39:24 +03:00
|
|
|
if [ ! -z "$1" ] ; then
|
2016-02-02 10:31:52 +03:00
|
|
|
echo "ERROR message: $1"
|
|
|
|
fi
|
|
|
|
exit 1
|
2015-11-25 03:38:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Has_Git()
|
|
|
|
{
|
2016-02-02 10:31:52 +03:00
|
|
|
if hash git 2>/dev/null; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
2015-11-25 03:38:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
makebuildinfo()
|
|
|
|
{
|
2016-04-17 12:28:13 +03:00
|
|
|
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
|
2018-03-07 00:17:20 +03:00
|
|
|
local WITH_ASGD=$8
|
|
|
|
local BUILDER=$9
|
|
|
|
local BUILDMACHINE=${10}
|
|
|
|
local BUILDPATH=${11}
|
|
|
|
local MPI_NAME=${12}
|
|
|
|
local MPI_VERSION=${13}
|
2016-02-02 10:31:52 +03:00
|
|
|
(
|
|
|
|
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"
|
2016-06-14 18:39:24 +03:00
|
|
|
if [ -z "$CUDA_PATH" ]; then
|
2016-02-02 10:31:52 +03:00
|
|
|
printf "#define _BUILDTARGET_ \"CPU-only\"\n"
|
|
|
|
else
|
|
|
|
printf "#define _BUILDTARGET_ \"GPU\"\n"
|
|
|
|
printf "#define _CUDA_PATH_ \"%s\"\n" "$CUDA_PATH"
|
|
|
|
fi
|
2016-06-14 18:39:24 +03:00
|
|
|
if [ ! -z "$CUB_PATH" ]; then
|
2016-02-02 10:31:52 +03:00
|
|
|
printf "#define _CUB_PATH_ \"%s\"\n" "$CUB_PATH"
|
|
|
|
fi
|
2016-06-14 18:39:24 +03:00
|
|
|
if [ ! -z "$CUDNN_PATH" ]; then
|
2016-02-02 10:31:52 +03:00
|
|
|
printf "#define _CUDNN_PATH_ \"%s\"\n" $CUDNN_PATH
|
|
|
|
fi
|
|
|
|
printf "#define _BUILDTYPE_ \"%s\"\n" "$BUILDTYPE"
|
2016-10-25 06:50:58 +03:00
|
|
|
if [ ! -z "$WITH_ASGD" ]; then
|
2016-02-16 10:46:04 +03:00
|
|
|
printf "#define _WITH_ASGD_ \"yes\"\n"
|
|
|
|
else
|
|
|
|
printf "#define _WITH_ASGD_ \"no\"\n"
|
2016-02-02 10:31:52 +03:00
|
|
|
fi
|
|
|
|
printf "#define _BUILDER_ \"%s\"\n" "$BUILDER"
|
|
|
|
printf "#define _BUILDMACHINE_ \"%s\"\n" "$BUILDMACHINE"
|
|
|
|
printf "#define _BUILDPATH_ \"%s\"\n" "$BUILDPATH"
|
2016-09-28 02:29:50 +03:00
|
|
|
printf "#define _MPI_NAME_ \"%s\"\n" "$MPI_NAME"
|
|
|
|
printf "#define _MPI_VERSION_ \"%s\"\n" "$MPI_VERSION"
|
2016-02-02 10:31:52 +03:00
|
|
|
printf "#endif\n"
|
|
|
|
) > "$target"
|
2015-11-25 03:38:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#//////////////////////////////////////////////////////#
|
2016-02-02 10:31:52 +03:00
|
|
|
# main function #
|
2016-06-14 18:39:24 +03:00
|
|
|
#//////////////////////////////////////////////////////#
|
|
|
|
if [ $# -ne 1 ]; then
|
|
|
|
usage
|
2015-11-25 03:38:37 +03:00
|
|
|
fi
|
|
|
|
|
2015-11-25 08:34:30 +03:00
|
|
|
config=$1
|
2015-11-25 03:38:37 +03:00
|
|
|
|
2016-06-14 18:39:24 +03:00
|
|
|
# Check whether we have git and what is the SHA-1 value
|
2016-02-02 10:31:52 +03:00
|
|
|
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
|
2015-11-25 03:38:37 +03:00
|
|
|
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`
|
|
|
|
|
2016-06-14 18:39:24 +03:00
|
|
|
# Looking into Config.make
|
|
|
|
if [ ! -e $config ] ; then
|
2016-02-02 10:31:52 +03:00
|
|
|
usage "Config.make not exists"
|
2015-11-25 03:38:37 +03:00
|
|
|
fi
|
2015-11-25 08:34:30 +03:00
|
|
|
source $config
|
2015-11-25 03:38:37 +03:00
|
|
|
|
2016-06-14 18:39:24 +03:00
|
|
|
# Whether we have CUDA_PATH
|
|
|
|
if [ -z "${CUDA_PATH+x}" ]; then
|
2016-02-02 10:31:52 +03:00
|
|
|
CUDAPATH=""
|
2015-11-25 03:38:37 +03:00
|
|
|
else
|
2016-02-02 10:31:52 +03:00
|
|
|
CUDAPATH=$CUDA_PATH
|
2015-11-25 03:38:37 +03:00
|
|
|
fi
|
|
|
|
|
2016-06-14 18:39:24 +03:00
|
|
|
# Whether we have CUB_PATH
|
|
|
|
if [ -z "${CUB_PATH+x}" ]; then
|
2016-02-02 10:31:52 +03:00
|
|
|
CUBPATH=""
|
2015-11-25 03:38:37 +03:00
|
|
|
else
|
2016-02-02 10:31:52 +03:00
|
|
|
CUBPATH=$CUB_PATH
|
2015-11-25 03:38:37 +03:00
|
|
|
fi
|
|
|
|
|
2016-06-14 18:39:24 +03:00
|
|
|
# Identify MKL variant being used
|
|
|
|
if [ "$MATHLIB" = "mkl" -a "$MKL_THREADING" = "sequential" ]; then
|
|
|
|
MATHLIB=mkl-sequential
|
|
|
|
fi
|
|
|
|
|
2016-09-28 02:29:50 +03:00
|
|
|
# MPI info
|
2017-01-03 23:29:58 +03:00
|
|
|
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
|
2016-09-28 02:29:50 +03:00
|
|
|
|
2016-06-14 18:39:24 +03:00
|
|
|
# Build machine info
|
2016-02-02 10:31:52 +03:00
|
|
|
BUILDER=$USER
|
|
|
|
BUILDMACHINE=`hostname`
|
|
|
|
BUILDPATH=`pwd`
|
|
|
|
|
2018-06-07 02:36:23 +03:00
|
|
|
# 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
|
|
|
|
|
2018-06-06 21:49:57 +03:00
|
|
|
target=Source/CNTKv2LibraryDll/Generated/Linux/buildinfo.h
|
2016-06-14 18:39:24 +03:00
|
|
|
if [ ! -d Source ] ; then
|
2016-02-02 10:31:52 +03:00
|
|
|
usage
|
2015-11-25 03:38:37 +03:00
|
|
|
fi
|
2016-02-02 10:31:52 +03:00
|
|
|
|
2018-06-06 21:49:57 +03:00
|
|
|
# Make buildinfo.h (only update if changed)
|
|
|
|
if [ ! -d Source/CNTKv2LibraryDll/Generated/Linux ]; then
|
|
|
|
mkdir -p Source/CNTKv2LibraryDll/Generated/Linux
|
|
|
|
fi
|
|
|
|
|
2016-02-02 10:31:52 +03:00
|
|
|
makebuildinfo \
|
2016-03-11 21:22:21 +03:00
|
|
|
"$target\$\$" \
|
2016-02-02 10:31:52 +03:00
|
|
|
"$BUILDTYPE" \
|
|
|
|
"$MATHLIB" \
|
|
|
|
"$GIT_COMMIT" \
|
|
|
|
"$GIT_BRANCH" \
|
|
|
|
"$CUDAPATH" \
|
|
|
|
"$CUBPATH" \
|
2016-02-25 15:54:35 +03:00
|
|
|
"$CNTK_ENABLE_ASGD" \
|
2016-02-02 10:31:52 +03:00
|
|
|
"$BUILDER" \
|
|
|
|
"$BUILDMACHINE" \
|
2016-09-28 02:29:50 +03:00
|
|
|
"$BUILDPATH" \
|
|
|
|
"$MPI_NAME" \
|
|
|
|
"$MPI_VERSION"
|
2016-03-11 21:22:21 +03:00
|
|
|
|
|
|
|
cmp -s "$target\$\$" "$target" || mv "$target\$\$" "$target"
|