CNTK/Tools/generate_build_info

183 строки
5.1 KiB
Plaintext
Исходник Обычный вид История

#!/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.
# ==============================================================================
#
# Description: this script is used to generated buildinfo.h in Source/CNTK
# which will contain the following infomation to be displayed at runtime:
# BUILDTYPE (release/debug)
# BUILDTYPE (GPU/CPU-only)
# WITH_1BITSGD (whether 1bit-SGD support was enabled)
2016-08-16 16:08:08 +03:00
# 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)
usage ()
{
echo "usage: $0 <Config.make>"
echo "-------------------------------------------------------------------"
echo "This script is used to generate buildinfo.h in Source/CNTK"
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
echo "ERROR message: $1"
fi
exit 1
}
Has_Git()
{
if hash git 2>/dev/null; then
return 0
else
return 1
fi
}
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
local WITH_1BITSGD=$8
local WITH_ASGD=$9
local BUILDER=$10
local BUILDMACHINE=${11}
local BUILDPATH=${12}
local MPI_NAME=${13}
local MPI_VERSION=${14}
(
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
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
printf "#define _CUB_PATH_ \"%s\"\n" "$CUB_PATH"
fi
2016-06-14 18:39:24 +03:00
if [ ! -z "$CUDNN_PATH" ]; then
printf "#define _CUDNN_PATH_ \"%s\"\n" $CUDNN_PATH
fi
printf "#define _BUILDTYPE_ \"%s\"\n" "$BUILDTYPE"
2016-06-14 18:39:24 +03:00
if [ ! -z "$WITH_1BITSGD" ]; then
printf "#define _WITH_1BITSGD_ \"yes\"\n"
else
printf "#define _WITH_1BITSGD_ \"no\"\n"
fi
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 #
2016-06-14 18:39:24 +03:00
#//////////////////////////////////////////////////////#
if [ $# -ne 1 ]; then
usage
fi
config=$1
2016-06-14 18:39:24 +03:00
# 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`
2016-06-14 18:39:24 +03:00
# Looking into Config.make
if [ ! -e $config ] ; then
usage "Config.make not exists"
fi
source $config
2016-06-14 18:39:24 +03:00
# Whether we have CUDA_PATH
if [ -z "${CUDA_PATH+x}" ]; then
CUDAPATH=""
else
CUDAPATH=$CUDA_PATH
fi
2016-06-14 18:39:24 +03:00
# Whether we have CUB_PATH
if [ -z "${CUB_PATH+x}" ]; then
CUBPATH=""
else
CUBPATH=$CUB_PATH
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
# MPI info
which ompi_info > /dev/null &&
{
MPI_NAME=openmpi
MPI_VERSION=`ompi_info --parsable | grep ident | cut -f 2 -d ":"`
} ||
{
MPI_NAME=mvapich2
MPI_VERSION=`mpiname -v`
}
2016-06-14 18:39:24 +03:00
# Build machine info
BUILDER=$USER
BUILDMACHINE=`hostname`
BUILDPATH=`pwd`
2016-06-14 18:39:24 +03:00
# Make buildinfo.h (only update if changed)
target=Source/CNTK/buildinfo.h
2016-06-14 18:39:24 +03:00
if [ ! -d Source ] ; then
usage
fi
makebuildinfo \
"$target\$\$" \
"$BUILDTYPE" \
"$MATHLIB" \
"$GIT_COMMIT" \
"$GIT_BRANCH" \
"$CUDAPATH" \
"$CUBPATH" \
"$CNTK_ENABLE_1BitSGD" \
"$CNTK_ENABLE_ASGD" \
"$BUILDER" \
"$BUILDMACHINE" \
"$BUILDPATH" \
"$MPI_NAME" \
"$MPI_VERSION"
cmp -s "$target\$\$" "$target" || mv "$target\$\$" "$target"