CNTK/configure

770 строки
21 KiB
Bash
Executable File

#!/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.
# ==============================================================================
#
configure=$0
build_top=$PWD
have_cuda=no
cuda_path=
cuda_check=include/cuda.h
enable_cuda=
# CNTK Custom MKL Version
cntk_custom_mkl_version=2
have_mkl=no
mkl_path=
mkl_check=$cntk_custom_mkl_version/include/mkl.h
# Experimental OpenBLAS support.
have_openblas=no
openblas_path=
openblas_check=include/openblas_config.h
# Boost library
boost_path=
boost_check=include/boost/test/unit_test.hpp
have_kaldi=no
kaldi_path=
kaldi_check=src/kaldi.mk
have_buildtype=no
buildtype=
default_buildtype=release
have_gdk_include=no
gdk_include_path=
gdk_include_check=nvml.h
have_gdk_nvml_lib=no
gdk_nvml_lib_path=
gdk_nvml_lib_check=libnvidia-ml.so
have_cub=no
cub_path=
cub_check=cub/cub.cuh
have_cudnn=no
cudnn_path=
cudnn_check=cuda/include/cudnn.h
have_opencv=no
opencv_path=
opencv_check=include/opencv2/opencv.hpp
have_libzip=no
libzip_path=
libzip_check=include/zip.h
mathlib=
default_use_1bitsgd=no
enable_1bitsgd=$default_use_1bitsgd
default_use_code_coverage=no
enable_code_coverage=$default_use_code_coverage
default_use_asgd=yes
enable_asgd=$default_use_asgd
# List from best to worst choice
default_path_list="/usr /usr/local /opt /opt/local"
# List from best to worst choice
default_mkls="CNTKCustomMKL"
default_openblas=""
default_boost="boost-1.60.0"
# NOTE: Will get compilation errors with cuda-6.0
default_cudas="cuda-7.5 cuda-7.0 cuda-6.5"
default_kaldis="kaldi-trunk kaldi-c024e8aa"
default_gdk_includes="include/nvidia/gdk"
default_gdk_nvml_libs="src/gdk/nvml/lib"
default_cubs="cub-1.4.1"
default_cudnns="cudnn-5.1 cudnn-5.0"
default_opencvs="opencv-3.1.0 opencv-3.0.0"
default_libzips="libzip-1.1.2"
function default_paths ()
{
echo $build_top $HOME $default_path_list
}
# $1 is directory
# $2 is file that must be present
function check_dir ()
{
if test -e $1/$2
then
echo yes
else
echo no
fi
}
# $1 is the list of tails to search, ordered by preference
# $2 is some file that must exist in $1
function find_dir ()
{
# Loop over list of tails to search, including empty (just default_path + search file)
for tail in $1 ''
do
for head in $(default_paths)
do
[ -n "$tail" ] && search_path="$head/$tail" || search_path=$head
if test x$(check_dir "$search_path" $2) = xyes
then
echo $search_path
return 0
fi
done
done
}
function find_mkl ()
{
find_dir "$default_mkls" "$mkl_check"
}
function find_openblas ()
{
find_dir "$default_openblas" "$openblas_check"
}
function find_boost ()
{
find_dir "$default_boost" "$boost_check"
}
function find_cuda ()
{
find_dir "$default_cudas" "$cuda_check"
}
function find_kaldi ()
{
find_dir "$default_kaldis" "$kaldi_check"
}
function find_gdk_include ()
{
find_dir "$default_gdk_includes" "$gdk_include_check"
}
function find_gdk_nvml_lib ()
{
find_dir "$default_gdk_nvml_libs" "$gdk_nvml_lib_check"
}
function find_cub ()
{
find_dir "$default_cubs" "$cub_check"
}
function find_cudnn ()
{
find_dir "$default_cudnns" "$cudnn_check"
}
function find_opencv ()
{
find_dir "$default_opencvs" "$opencv_check"
}
function find_libzip ()
{
find_dir "$default_libzips" "$libzip_check"
}
function is_hardlinked ()
{
r=no
if test -e $1 && test -e $2
then
r=yes
[ "`stat -c '%i' $1`" != "`stat -c '%i' $2`" ] && r=no
fi
echo $r
}
function default_use_cuda ()
{
if test x$(find_cuda) = x || test x$(find_gdk_include) = x || test x$(find_gdk_nvml_lib) = x || test x$(find_cudnn) = x || test x$(find_cub) = x
then
echo no
else
echo yes
fi
}
enable_cuda=$(default_use_cuda)
function show_default ()
{
if test x$1 = x
then
echo "(no default)"
else
echo "(default $1)"
fi
}
function show_help ()
{
echo "Usage: configure [options]"
echo "Options:"
echo " -h|--help this help"
echo " --with-build-top=directory build directory $(show_default $build_top)"
echo " --add directory add directory to library search path"
echo " --1bitsgd[=(yes|no)] use 1Bit SGD $(show_default $(default_use_1bitsgd))"
echo " --asgd[=(yes|no)] use asgd powered by Multiverso $(show_default $(default_use_asgd))"
echo " --cuda[=(yes|no)] use cuda GPU $(show_default $(default_use_cuda))"
echo " --with-cuda[=directory] $(show_default $(find_cuda))"
echo " --with-cub[=directory] $(show_default $(find_cub))"
echo " --with-gdk-include[=directory] $(show_default $(find_gdk_include))"
echo " --with-gdk-nvml-lib[=directory] $(show_default $(find_gdk_nvml_lib))"
echo " --with-cudnn[=directory] $(show_default $(find_cudnn))"
echo " --with-mkl[=directory] $(show_default $(find_mkl))"
echo " --with-mkl-sequential[=directory] $(show_default $(find_mkl))"
echo " --with-openblas[=directory] (experimental) $(show_default $(find_openblas))"
echo " --with-buildtype=(debug|release) $(show_default $default_buildtype)"
echo " --with-kaldi[=directory] $(show_default $(find_kaldi))"
echo " --with-opencv[=directory] $(show_default $(find_opencv))"
echo " --with-libzip[=directory] $(show_default $(find_libzip))"
echo " --with-code-coverage[=(yes|no)] $(show_default ${default_use_code_coverage})"
echo " --with-boost[=directory] $(show_default $(find_boost))"
echo "Libraries search path:"
for head in $(default_paths)
do
echo " $head"
done
}
while [[ $# > 0 ]]
do
key="$1"
case $key in
*=?*) optarg=`expr "X$key" : '[^=]*=\(.*\)'` ;;
*=) optarg= ;;
*) optarg= ;;
esac
case $key in
-h|--help)
show_help
exit 1
;;
--with-build-top*)
if test x$optarg != x
then
build_top=$optarg
mkdir -p $build_top
fi
;;
--add*)
if test x$optarg = x
then
shift ; optarg=$1
fi
default_path_list="$optarg $default_path_list"
;;
--1bitsgd*)
if test x$optarg = xyes || test x$optarg = xno
then
enable_1bitsgd=$optarg
else
echo "Invalid value for --1bitsgd $optarg"
show_help
exit
fi
;;
--with-code-coverage*)
if test x$optarg = xyes || test x$optarg = xno
then
enable_code_coverage=$optarg
else
echo "Invalid value for --with-code-coverage $optarg"
show_help
exit
fi
;;
--asgd*)
if test x$optarg = xyes || test x$optarg = xno
then
enable_asgd=$optarg
else
echo "Invalid value for --asgd $optarg"
show_help
exit
fi
;;
--cuda*)
if test x$optarg = xyes || test x$optarg = xno
then
enable_cuda=$optarg
else
echo "Invalid value for --cuda $optarg"
show_help
exit
fi
;;
--with-cuda*)
have_cuda=yes
enable_cuda=yes
if test x$optarg = x
then
cuda_path=$(find_cuda)
if test x$cuda_path = x
then
echo "Cannot find cuda directory."
echo "Please specify a value for --with-cuda"
exit 1
fi
else
if test $(check_dir $optarg $cuda_check) = yes
then
cuda_path=$optarg
else
echo "Invalid cuda directory $optarg"
exit 1
fi
fi
;;
--with-cub*)
have_cub=yes
if test x$optarg = x
then
cub_path=$(find_cub)
if test x$cub_path = x
then
echo "Cannot find NVIDIA CUB directory."
echo "Please specify a value for --with-cub"
echo "NVIDIA CUB can be downloaded from https://github.com/NVlabs/cub/archive/1.4.1.zip, extract the archive to /usr/local"
exit 1
fi
else
if test $(check_dir $optarg $cub_check) = yes
then
cub_path=$optarg
else
echo "Invalid CUB directory $optarg"
exit 1
fi
fi
;;
--with-gdk-include*)
have_gdk_include=yes
if test x$optarg = x
then
gdk_include_path=$(find_gdk_include)
if test x$gdk_include_path = x
then
echo "Cannot find GDK include directory."
echo "Please specify a value for --with-gdk-include"
exit 1
fi
else
if test $(check_dir $optarg $gdk_include_check) = yes
then
gdk_include_path=$optarg
else
echo "Invalid GDK include directory $optarg"
exit 1
fi
fi
;;
--with-gdk-nvml-lib*)
have_gdk_nvml_lib=yes
if test x$optarg = x
then
gdk_nvml_lib_path=$(find_gdk_nvml_lib)
if test x$gdk_nvml_lib_path = x
then
echo "Cannot find GDK NVML library directory."
echo "Please specify a value for --with-gdk-nvml-lib"
exit 1
fi
else
if test $(check_dir $optarg $gdk_nvml_lib_check) = yes
then
gdk_nvml_lib_path=$optarg
else
echo "Invalid GDK NVML library directory $optarg"
exit 1
fi
fi
;;
--with-cudnn*)
have_cudnn=yes
if test x$optarg = x
then
cudnn_path=$(find_cudnn)
if test x$cudnn_path = x
then
echo "Cannot find NVIDIA cuDNN directory."
echo "Please specify a value for --with-cudnn"
exit 1
fi
else
if test $(check_dir $optarg $cudnn_check) = yes
then
cudnn_path=$optarg
else
echo "Invalid cuDNN directory $optarg"
exit 1
fi
fi
;;
--with-mkl*)
have_mkl=yes
mathlib=mkl
mkl_threading=parallel
case $key in
--with-mkl-sequential*) mkl_threading=sequential ;;
esac
if test x$optarg = x
then
mkl_path=$(find_mkl)
if test x$mkl_path = x
then
echo "Cannot find CNTK custom MKL directory (version $cntk_custom_mkl_version)"
echo "Please specify a value for --with-mkl"
exit 1
fi
else
if test $(check_dir $optarg $mkl_check) = yes
then
mkl_path=$optarg
else
echo "Invalid CNTK custom MKL directory $optarg"
exit 1
fi
fi
;;
--with-openblas*)
have_openblas=yes
mathlib=openblas
if test x$optarg = x
then
openblas_path=$(find_openblas)
if test x$openblas_path = x
then
echo "Cannot find openblas directory"
echo "Please specify a value for --with-openblas"
exit 1
fi
else
if test $(check_dir $optarg $openblas_check) = yes
then
openblas_path=$optarg
else
echo "Invalid openblas directory $optarg"
exit 1
fi
fi
;;
--with-boost*)
if test x$optarg = x
then
boost_path=$(find_boost)
if test x$boost_path = x
then
echo "Cannot find Boost directory"
echo "Please specify a value for --with-boost"
exit 1
fi
else
if test $(check_dir $optarg $boost_check) = yes
then
boost_path=$optarg
else
echo "Invalid Boost directory $optarg"
exit 1
fi
fi
;;
--with-buildtype*)
have_buildtype=yes
case $optarg in
debug|release)
buildtype=$optarg
;;
*)
echo Invalid buildtype $optarg
echo Must be debug or release
exit 1
esac
;;
--with-kaldi*)
have_kaldi=yes
if test x$optarg = x
then
kaldi_path=$(find_kaldi)
if test x$kaldi_path = x
then
echo "Cannot find kaldi directory"
echo "Please specify a value for --with-kaldi"
exit 1
fi
else
if test $(check_dir $optarg $kaldi_check)
then
kaldi_path=$optarg
else
echo "Invalid kaldi directory $optarg"
exit 1
fi
fi
;;
--with-opencv*)
have_opencv=yes
if test x$optarg = x
then
opencv_path=$(find_opencv)
if test x$opencv_path = x
then
echo "Cannot find OpenCV directory."
echo "Please specify a value for --with-opencv"
echo "OpenCV can be downloaded from http://opencv.org/downloads.html, install instructions http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation"
exit 1
fi
else
if test $(check_dir $optarg $opencv_check) = yes
then
opencv_path=$optarg
else
echo "Invalid OpenCV directory $optarg"
exit 1
fi
fi
;;
--with-libzip*)
have_libzip=yes
if test x$optarg = x
then
libzip_path=$(find_libzip)
if test x$libzip_path = x
then
echo "Cannot find libzip directory."
echo "Please specify a value for --with-libzip"
echo "libzip (v.1.1.2 or higher) can be downloaded from http://www.nih.at/libzip/"
exit 1
fi
else
if test $(check_dir $optarg $libzip_check) = yes
then
libzip_path=$optarg
else
echo "Invalid libzip directory $optarg"
exit 1
fi
fi
;;
*)
echo Invalid option $key
show_help
exit 1
esac
shift
done
if test x$buildtype = x
then
buildtype=$default_buildtype
echo Defaulting to --with-buildtype=release
fi
# If no math library was specified, search for mkl
if test x$have_mkl = xno && test x$have_openblas = xno
then
mkl_path=$(find_mkl)
if test x$mkl_path = x
then
echo "Cannot find a CPU math library."
echo "Please specify --with-mkl, --with-mkl-sequential, --with-openblas with a path."
exit 1
else
mathlib=mkl
fi
fi
# If no cuda library specified, search for one
if test x$enable_cuda = xyes && test x$cuda_path = x
then
cuda_path=$(find_cuda)
if test x$cuda_path = x ; then
echo Cannot locate a cuda directory
echo GPU will be disabled
enable_cuda=no
else
echo Found cuda at $cuda_path
fi
fi
if test $enable_cuda = yes && test x$gdk_include_path = x
then
gdk_include_path=$(find_gdk_include)
if test x$gdk_include_path = x ; then
echo Cannot locate a GDK include directory
echo GPU will be disabled
enable_cuda=no
else
echo Found GDK include at $gdk_include_path
fi
fi
if test $enable_cuda = yes && test x$gdk_nvml_lib_path = x
then
gdk_nvml_lib_path=$(find_gdk_nvml_lib)
if test x$gdk_nvml_lib_path = x ; then
echo Cannot locate a GDK NVML library directory
echo GPU will be disabled
enable_cuda=no
else
echo Found GDK NVML library at $gdk_nvml_lib_path
fi
fi
if test $enable_cuda = yes && test x$cub_path = x
then
cub_path=$(find_cub)
if test x$cub_path = x ; then
echo Cannot locate NVIDIA CUB directory
echo GPU will be disabled
echo NVIDIA CUB can be downloaded from https://github.com/NVlabs/cub/archive/1.4.1.zip, extract the archive to /usr/local
enable_cuda=no
else
echo Found CUB at $cub_path
fi
fi
if test $enable_cuda = yes && test x$cudnn_path = x
then
cudnn_path=$(find_cudnn)
if test x$cudnn_path = x ; then
echo Cannot locate NVIDIA cuDNN directory
echo CNTK will use default convolution engine.
else
echo Found cuDNN at $cudnn_path
fi
fi
if test x$opencv_path = x
then
opencv_path=$(find_opencv)
if test x$opencv_path = x ; then
echo Cannot locate OpenCV 3.0.0 directory
echo ImageReader will NOT be built.
else
echo Found OpenCV at $opencv_path
fi
fi
if test x$libzip_path = x
then
libzip_path=$(find_libzip)
if test x$libzip_path = x ; then
echo Cannot locate libzip files
echo ImageReader will be built without zip container support.
else
echo Found libzip at $libzip_path
fi
fi
if test x$kaldi_path = x
then
kaldi_path=$(find_kaldi)
if test x$kaldi_path = x ; then
echo Cannot locate Kaldi files
echo Kaldi2Reader will NOT be built.
else
echo Found Kaldi at $kaldi_path
fi
fi
if test x$boost_path = x
then
boost_path=$(find_boost)
if test x$boost_path = x
then
echo Cannot locate Boost libraries
echo ImageReader and Unit tests will NOT be built.
else
echo Found Boost at $boost_path
fi
fi
config=$build_top/Config.make
echo Generating $config
echo "#Configuration file for cntk" > $config
echo BUILDTYPE=$buildtype >> $config
echo MATHLIB=$mathlib >> $config
case $mathlib in
mkl)
echo MKL_PATH=$mkl_path >> $config
echo MKL_THREADING=$mkl_threading >> $config
echo CNTK_CUSTOM_MKL_VERSION=$cntk_custom_mkl_version >> $config
;;
openblas)
echo OPENBLAS_PATH=$openblas_path >> $config
;;
esac
if test $enable_cuda = yes ; then
echo CUDA_PATH=$cuda_path >> $config
echo GDK_INCLUDE_PATH=$gdk_include_path >> $config
echo GDK_NVML_LIB_PATH=$gdk_nvml_lib_path >> $config
echo CUB_PATH=$cub_path >> $config
echo CUDNN_PATH=$cudnn_path >> $config
fi
if test x$kaldi_path != x ; then
echo KALDI_PATH=$kaldi_path >> $config
fi
if test x$opencv_path != x ; then
echo OPENCV_PATH=$opencv_path >> $config
fi
if test x$libzip_path != x ; then
echo LIBZIP_PATH=$libzip_path >> $config
fi
if test $enable_1bitsgd = yes ; then
echo CNTK_ENABLE_1BitSGD=true >> $config
fi
if test $enable_code_coverage = yes ; then
echo CNTK_CODE_COVERAGE=true >> $config
fi
if test x$boost_path != x; then
echo BOOST_PATH=$boost_path >> $config
fi
if test $enable_asgd = yes ; then
echo CNTK_ENABLE_ASGD=true >> $config
fi
# If we are not in the configure directory, generate a trampoline Makefile
makefile=$build_top/Makefile
if test $(is_hardlinked "$configure" "$build_top/configure") = no
then
echo Generating $makefile
realconf=`readlink -f $configure`
dir=`dirname $realconf`
echo "#Generate Makefile" > $makefile
echo dir=$dir >> $makefile
echo BUILD_TOP=$build_top >> $makefile
echo >> $makefile
echo all clean : >> $makefile
printf '\t$(MAKE) -C $(dir) BUILD_TOP=$(BUILD_TOP) $@\n' >> $makefile
fi
echo run
echo '>make -j all'
echo to build