From 52ae07279d9f06e0e5dc01b149d2ae23010e851b Mon Sep 17 00:00:00 2001 From: Mark Hillebrand Date: Tue, 14 Jun 2016 17:39:24 +0200 Subject: [PATCH] CNTK custom MKL support --- .gitignore | 4 + CNTK.Cpp.props | 40 +++++ .../README-for-redistributable.txt | 8 + Dependencies/CNTKCustomMKL/README.md | 24 +++ Dependencies/CNTKCustomMKL/build-linux.sh | 46 ++++++ Dependencies/CNTKCustomMKL/build-windows.cmd | 156 ++++++++++++++++++ Dependencies/CNTKCustomMKL/functions.txt | 17 ++ Dependencies/CNTKCustomMKL/headers.txt | 31 ++++ Dependencies/CNTKCustomMKL/version.txt | 1 + LICENSE.md | 18 +- Makefile | 18 +- Source/CNTK/prebuild.bat | 17 +- Source/Math/Math.vcxproj | 47 +++--- Source/Math/MathCUDA.vcxproj | 2 +- Tests/UnitTests/EvalTests/EvalTests.vcxproj | 4 +- .../MathTests/ConvolutionEngineTests.cpp | 2 +- Tests/UnitTests/MathTests/MathTests.vcxproj | 6 +- .../NetworkTests/NetworkTests.vcxproj | 4 +- .../UnitTests/ReaderTests/ReaderTests.vcxproj | 4 +- Tools/build-and-test | 38 ++++- Tools/generate_build_info | 49 +++--- configure | 37 +++-- 22 files changed, 491 insertions(+), 82 deletions(-) create mode 100644 Dependencies/CNTKCustomMKL/README-for-redistributable.txt create mode 100644 Dependencies/CNTKCustomMKL/README.md create mode 100755 Dependencies/CNTKCustomMKL/build-linux.sh create mode 100644 Dependencies/CNTKCustomMKL/build-windows.cmd create mode 100644 Dependencies/CNTKCustomMKL/functions.txt create mode 100644 Dependencies/CNTKCustomMKL/headers.txt create mode 100644 Dependencies/CNTKCustomMKL/version.txt diff --git a/.gitignore b/.gitignore index 8e76f9b3f..1eee77eab 100644 --- a/.gitignore +++ b/.gitignore @@ -190,3 +190,7 @@ Source/CNTK/buildinfo.h$$ # Unit test output Tests/UnitTests/ReaderTests/Control/**/*_Output.txt Tests/UnitTests/NetworkTests/Output/ + +Dependencies/CNTKCustomMKL/Publish +Dependencies/CNTKCustomMKL/CNTKCustomMKL-Linux-*.tgz +Dependencies/CNTKCustomMKL/CNTKCustomMKL-Windows-*.zip diff --git a/CNTK.Cpp.props b/CNTK.Cpp.props index 2f3e3bd54..7ced9f85a 100644 --- a/CNTK.Cpp.props +++ b/CNTK.Cpp.props @@ -29,6 +29,46 @@ + + + + ACML + $(ACML_PATH)\include + $(ACML_PATH)\lib + libacml_mp_dll.lib + libacml_mp_dll.dll + $(ACML_PATH)\lib\*.dll + $(OutDir)libacml_mp_dll.dll;$(OutDir)libifcoremd.dll;$(OutDir)libifportmd.dll;$(OutDir)libiomp*.dll;$(OutDir)libmmd.dll;$(OutDir)svml_dispmd.dll; + USE_ACML + + + + + + + 1 + $(CNTK_MKL_PATH)\$(CNTKCustomMKLVersion) + $(CNTKCustomMKLPath)\include + $(MathLibraryPath)\*.dll + USE_MKL + + + CNTK custom MKL Parallel (Version: $(CNTKCustomMKLVersion)) + $(CNTKCustomMKLPath)\x64\parallel + mkl_cntk_p.lib + mkl_cntk_p.dll + $(OutDir)mkl_cntk_p.dll;$(OutDir)libiomp5md.dll; + + + CNTK custom MKL Sequential (Version: $(CNTKCustomMKLVersion)) + $(CNTKCustomMKLPath)\x64\sequential + mkl_cntk_s.lib + mkl_cntk_s.dll + $(OutDir)mkl_cntk_s.dll; + + + + $(CUDA_PATH_V7_5) cudart64_75.dll diff --git a/Dependencies/CNTKCustomMKL/README-for-redistributable.txt b/Dependencies/CNTKCustomMKL/README-for-redistributable.txt new file mode 100644 index 000000000..790f5beb1 --- /dev/null +++ b/Dependencies/CNTKCustomMKL/README-for-redistributable.txt @@ -0,0 +1,8 @@ +This archive contains header files as well as redistributable components of +the Intel (r) Math Kernel Library (Intel (r) MKL). + +Included is also a custom library created out of Intel (r) Math Kernel Library +(Intel (r) MKL) required for building the Microsoft Computational Network +Toolkit (CNTK). More details on CNTK be found here: http://www.cntk.ai + +Please see LICENSE.md for full license information. diff --git a/Dependencies/CNTKCustomMKL/README.md b/Dependencies/CNTKCustomMKL/README.md new file mode 100644 index 000000000..f6e2ab1ca --- /dev/null +++ b/Dependencies/CNTKCustomMKL/README.md @@ -0,0 +1,24 @@ +# CNTK custom MKL + +This directory contains the necessary files to create a custom Intel® Math Kernel Library (MKL) +for usage by CNTK ("CNTK custom MKL" for short). + +By default, a CNTK binary with Intel® MKL support includes a prebuilt CNTK +custom MKL. +If you want to build CNTK with Intel® MKL support yourself, you can install a +prebuilt CNTK custom MKL, available for separate download from the CNTK +downloads page. +See [CNTK's setup instructions](https://github.com/Microsoft/CNTK/wiki/Setup-CNTK-on-your-machine) +for more details. + +If you want to add new Intel® MKL functions to be used by CNTK you will have to +build your own CNTK custom MKL. +This requires you to install the [Intel MKL SDK](https://software.intel.com/en-us/intel-mkl/) for your platform. +Then, in this directory, +* extend the file `headers.txt` to expose new headers, +* extend the file `functions.txt` to expose new functions, and +* use `build-linux.sh` or `build-windows.cmd` to build for your platform. + +For further documentation please see the Developer Guide for the Intel® MKL, in particular +[Building Custom Shared Objects (Linux)](https://software.intel.com/en-us/node/528533) and +[Building Custom Dynamic-link Libraries (Windows)](https://software.intel.com/en-us/node/528362). diff --git a/Dependencies/CNTKCustomMKL/build-linux.sh b/Dependencies/CNTKCustomMKL/build-linux.sh new file mode 100755 index 000000000..7361b3867 --- /dev/null +++ b/Dependencies/CNTKCustomMKL/build-linux.sh @@ -0,0 +1,46 @@ +#!/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. +# ============================================================================== +# + +# Stop on error, trace commands +set -e -x + +# Enter directory the script is located in +cd "$( dirname "${BASH_SOURCE[0]}" )" + +# TODO configurable +MKLROOT=/opt/intel/compilers_and_libraries_2016.2.181/linux/mkl +MKLBUILDERROOT=$MKLROOT/tools/builder +CNTKCUSTOMMKLVERSION=$(cat version.txt) + +rm -rf Publish + +mkdir Publish{,/$CNTKCUSTOMMKLVERSION{,/x64}} + +for THREADING in parallel sequential +do + LIBBASENAME=libmkl_cntk_$(echo $THREADING | cut -c 1) + make -f $MKLBUILDERROOT/makefile libintel64 \ + export=functions.txt \ + threading=$THREADING \ + name=$LIBBASENAME \ + MKLROOT=$MKLROOT + mkdir Publish/$CNTKCUSTOMMKLVERSION/x64/$THREADING + mv $LIBBASENAME.so Publish/$CNTKCUSTOMMKLVERSION/x64/$THREADING +done + +cp -p $MKLROOT/../compiler/lib/intel64_lin/libiomp5.so Publish/$CNTKCUSTOMMKLVERSION/x64/parallel + +rsync -av --files-from headers.txt $MKLROOT/include Publish/$CNTKCUSTOMMKLVERSION/include + +cp -p README-for-redistributable.txt Publish/$CNTKCUSTOMMKLVERSION/README.txt +cp -p ../../LICENSE.md Publish/$CNTKCUSTOMMKLVERSION + +cd Publish +tar -czf ../CNTKCustomMKL-Linux-$CNTKCUSTOMMKLVERSION.tgz $CNTKCUSTOMMKLVERSION +cd .. diff --git a/Dependencies/CNTKCustomMKL/build-windows.cmd b/Dependencies/CNTKCustomMKL/build-windows.cmd new file mode 100644 index 000000000..fdb36dd3b --- /dev/null +++ b/Dependencies/CNTKCustomMKL/build-windows.cmd @@ -0,0 +1,156 @@ +@echo off +REM +REM Copyright (c) Microsoft. All rights reserved. +REM +REM Licensed under the MIT license. See LICENSE.md file in the project root +REM for full license information. +REM ============================================================================== +REM +echo. +echo This batch file will build a custom MKL dynamic link library for usage by CNTK. +echo. +echo Requirements: +echo - Intel MKL SDK installed on the machine +echo - MKLROOT environment variable is set to the MKL directory inside the Intel MKL SDK +echo - Visual Studio 2013 installed and included in the path +echo. + +setlocal enableextensions enabledelayedexpansion + +pushd "%~dp0" +if errorlevel 1 ( + echo Could not change directory to script location. + exit /b 1 +) + +if not defined MKLROOT ( + echo Error: Environment variable MKLROOT is undefined. + exit /b 1 +) + +if not exist "%MKLROOT%" ( + echo Error: Directory doesn't exist: "%MKLROOT%". + exit /b 1 +) + +set MKLBUILDERROOT=%MKLROOT%\tools\builder + +if not exist "%MKLBUILDERROOT%" ( + echo Error: Directory doesn't exist: "%MKLBUILDERROOT%". + exit /b 1 +) + +where /q nmake.exe +if errorlevel 1 ( + echo Error: NMAKE.EXE not in path. + exit /b 1 +) + +where /q link.exe +if errorlevel 1 ( + echo Error: LINK.EXE not in path. + exit /b 1 +) + +set /p CNTKCUSTOMMKLVERSION=> buildinfo.h$$ +if "%CNTK_MKL%" == "1" ( + if "%CNTK_MKL_SEQUENTIAL%" == "1" ( + echo #define _MATHLIB_ "mkl-sequential">> buildinfo.h$$ + ) else ( + echo #define _MATHLIB_ "mkl">> buildinfo.h$$ + ) +) else ( + echo #define _MATHLIB_ "acml">> buildinfo.h$$ ) echo #define _BUILDER_ "%USERNAME%" >> buildinfo.h$$ diff --git a/Source/Math/Math.vcxproj b/Source/Math/Math.vcxproj index 25bc73266..97c471792 100644 --- a/Source/Math/Math.vcxproj +++ b/Source/Math/Math.vcxproj @@ -1,5 +1,5 @@ - - + + Debug @@ -31,7 +31,6 @@ true v120 Unicode - No DynamicLibrary @@ -39,8 +38,6 @@ v120 true Unicode - No - false @@ -55,17 +52,17 @@ - $(ACML_PATH)\include;$(SolutionDir)Source\Common\include;%(AdditionalIncludeDirectories) + $(MathIncludePath);$(SolutionDir)Source\Common\include;%(AdditionalIncludeDirectories) - $(ACML_PATH)\lib;$(OutDir) + $(MathLibraryPath);$(OutDir) NotUsing Level4 - USE_ACML; NO_SYNC; WIN32; _DEBUG; _WINDOWS; _USRDLL; MATH_EXPORTS; %(PreprocessorDefinitions) + $(MathDefine); NO_SYNC; WIN32; _DEBUG; _WINDOWS; _USRDLL; MATH_EXPORTS; %(PreprocessorDefinitions) true true Disabled @@ -77,13 +74,13 @@ Console true - libacml_mp_dll.lib;Common.lib;%(AdditionalDependencies) - libacml_mp_dll.dll; $(CudaDlls); %(DelayLoadDLLs) + $(MathLinkLibrary);Common.lib;%(AdditionalDependencies) + $(MathDelayLoad); $(CudaDlls); %(DelayLoadDLLs) true - xcopy /D /I /Y "$(ACML_PATH)\lib\*.dll" "$(OutputPath)" - Copying ACML DLLs + xcopy /D /I /Y "$(MathPostBuildCopyPattern)" "$(OutDir)" + Copying $(MathLibraryName) DLLs 64 @@ -103,7 +100,7 @@ MaxSpeed true true - USE_ACML; NO_SYNC; WIN32; NDEBUG; _WINDOWS; _USRDLL; MATH_EXPORTS; %(PreprocessorDefinitions) + $(MathDefine); NO_SYNC; WIN32; NDEBUG; _WINDOWS; _USRDLL; MATH_EXPORTS; %(PreprocessorDefinitions) true true Fast @@ -119,13 +116,13 @@ true true true - libacml_mp_dll.lib;Common.lib;%(AdditionalDependencies) + $(MathLinkLibrary);Common.lib;%(AdditionalDependencies) + $(MathDelayLoad); $(CudaDlls); %(DelayLoadDLLs) true - libacml_mp_dll.dll; $(CudaDlls); %(DelayLoadDLLs) - xcopy /D /I /Y "$(ACML_PATH)\lib\*.dll" "$(OutputPath)" - Copying ACML DLLs + xcopy /D /I /Y "$(MathPostBuildCopyPattern)" "$(OutDir)" + Copying $(MathLibraryName) DLLs true @@ -155,7 +152,7 @@ CPUONLY;%(PreprocessorDefinitions) - libacml_mp_dll.dll + $(MathDelayLoad) @@ -167,9 +164,9 @@ - + - + @@ -193,7 +190,7 @@ - + @@ -207,7 +204,7 @@ - + Create @@ -218,4 +215,8 @@ - \ No newline at end of file + + + + + diff --git a/Source/Math/MathCUDA.vcxproj b/Source/Math/MathCUDA.vcxproj index 9294eeabb..b8c8aa369 100644 --- a/Source/Math/MathCUDA.vcxproj +++ b/Source/Math/MathCUDA.vcxproj @@ -1,4 +1,4 @@ - + diff --git a/Tests/UnitTests/EvalTests/EvalTests.vcxproj b/Tests/UnitTests/EvalTests/EvalTests.vcxproj index bd1919a9f..ee7f68d42 100644 --- a/Tests/UnitTests/EvalTests/EvalTests.vcxproj +++ b/Tests/UnitTests/EvalTests/EvalTests.vcxproj @@ -158,10 +158,10 @@ $(OutDir)..\cudnn64_4.dll - + - + diff --git a/Tests/UnitTests/MathTests/ConvolutionEngineTests.cpp b/Tests/UnitTests/MathTests/ConvolutionEngineTests.cpp index 13591eaf8..07d568419 100644 --- a/Tests/UnitTests/MathTests/ConvolutionEngineTests.cpp +++ b/Tests/UnitTests/MathTests/ConvolutionEngineTests.cpp @@ -224,7 +224,7 @@ BOOST_AUTO_TEST_CASE(ConvolutionForward) std::string emsg; BOOST_REQUIRE_MESSAGE(!out.HasNan("out"), "out" << msgNan); - BOOST_REQUIRE_MESSAGE(CheckEqual(out, outB, emsg, relErr * 4, absErr * 8), "out" << msg << ". " << emsg); + BOOST_REQUIRE_MESSAGE(CheckEqual(out, outB, emsg, relErr * 4, absErr * 9), "out" << msg << ". " << emsg); BOOST_REQUIRE_MESSAGE(CountNans(outBuf) == crowOut * 2 * n, "out" << msgNotNan); } } diff --git a/Tests/UnitTests/MathTests/MathTests.vcxproj b/Tests/UnitTests/MathTests/MathTests.vcxproj index cea412b2d..ff7bde1e6 100644 --- a/Tests/UnitTests/MathTests/MathTests.vcxproj +++ b/Tests/UnitTests/MathTests/MathTests.vcxproj @@ -1,4 +1,4 @@ - + @@ -168,10 +168,10 @@ $(OutDir)..\cudnn64_4.dll - + - + diff --git a/Tests/UnitTests/NetworkTests/NetworkTests.vcxproj b/Tests/UnitTests/NetworkTests/NetworkTests.vcxproj index 93a3b0d5a..bcf2e255c 100644 --- a/Tests/UnitTests/NetworkTests/NetworkTests.vcxproj +++ b/Tests/UnitTests/NetworkTests/NetworkTests.vcxproj @@ -1,4 +1,4 @@ - + @@ -134,7 +134,7 @@ - + diff --git a/Tests/UnitTests/ReaderTests/ReaderTests.vcxproj b/Tests/UnitTests/ReaderTests/ReaderTests.vcxproj index b12bfad59..144e31e75 100644 --- a/Tests/UnitTests/ReaderTests/ReaderTests.vcxproj +++ b/Tests/UnitTests/ReaderTests/ReaderTests.vcxproj @@ -1,4 +1,4 @@ - + @@ -262,7 +262,7 @@ - + diff --git a/Tools/build-and-test b/Tools/build-and-test index 232d69d32..ad68a3410 100755 --- a/Tools/build-and-test +++ b/Tools/build-and-test @@ -1,4 +1,12 @@ #!/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. +# ============================================================================== +# +# TODO --math-library support on Windows # Setting some default values BUILD=1 @@ -9,6 +17,7 @@ RANDOM_OUTPUT=0 CODE_COVERAGE=no FLAVORS="debug:release" TARGETS="cpu:gpu" +MATH_LIBRARY="acml" TESTTARGETS="cpu:gpu" # parsing command line arguments: @@ -25,6 +34,7 @@ case $key in echo " -b|--build-only - just build, do not run" echo " -f|--flavors - which flavor to build (by default $FLAVORS)" echo " -t|--targets - which target to build (by default $TARGETS)" + echo " -m|--math-library - which math library to build with (by default $MATH_LIBRARY)" echo " -tt|--test-targets - which target to test (by default $TESTTARGETS)" echo " -cc|--code-coverage - build with support for code coverage (gcov)" echo " -cb|--clean-build - clean up the enlistment binaries before build" @@ -64,6 +74,24 @@ case $key in TARGETS="${2,,}" shift # past argument ;; + -m|--math-library) + case ${2,,} in + acml) + MATH_LIBRARY_OPTION="--with-acml=$ACML_PATH" + ;; + mkl) + MATH_LIBRARY_OPTION="--with-mkl=$MKL_PATH" + ;; + mkl-sequential) + MATH_LIBRARY_OPTION="--with-mkl-sequential=$MKL_PATH" + ;; + *) + echo Unknown math library $MATH_LIBRARY + exit 1 + ;; + esac + shift # past argument + ;; -tt|--test-targets) TESTTARGETS="${2,,}" shift # past argument @@ -76,7 +104,7 @@ case $key in shift # past argument ;; *) - echo Unkown option $key + echo Unknown option $key exit 1 ;; esac @@ -86,7 +114,7 @@ done # Step 0 -- Validate all necessary prerequisites and check for incompatible options # It is possible to use this script on Windows to build CNTK # from Cygwin window with Visual C++ environment loaded. -# In that case OS environment variable will be set and we +# In that case OS environment variable will be set and we # can use it to differentiate from Linux. if [[ $CLEAN_BEFORE == 1 && $RUN == 1 && $BUILD == 0 ]]; then echo "============ ERROR: Incompatible options RUN and CLEAN_BEFORE set without BUILD ============" @@ -99,7 +127,7 @@ if [[ $OS == "Windows_NT" && $OSTYPE == "cygwin" ]]; then PREFIX_DIR=x64 BIN_NAME=CNTK.exe BUILD_OS="windows" - + if [[ $VS120COMNTOOLS == "" ]]; then echo "============ Visual Studio 12.0 environment not properly setup or VS not installed ============" echo "============ Please find and run the appropriate vcvarsall.bat script ============" @@ -224,7 +252,7 @@ if [[ $BUILD == 1 ]]; then OneBitSGDOPT=yes fi fi - ./configure --with-build-top=$BUILD_DIR --with-acml=$ACML_PATH --with-buildtype=$FLAVOR --cuda=$CUDAOPT --with-code-coverage=$CODE_COVERAGE --1bitsgd=$OneBitSGDOPT + ./configure --with-build-top=$BUILD_DIR ${MATH_LIBRARY_OPTION} --with-buildtype=$FLAVOR --cuda=$CUDAOPT --with-code-coverage=$CODE_COVERAGE --1bitsgd=$OneBitSGDOPT if [[ $CLEAN_BEFORE == 1 ]]; then make -C $BUILD_DIR -f $MAKEFILE clean 1>&6 2>&7 || exit $? fi @@ -278,7 +306,7 @@ if [[ $RUN == 1 ]]; then fi OUT_FILE="$RUN_FILE.$FLAVOR.$TARGET.$TESTTARGET.out" - BIN_PATH=$CNTK_ROOT/$PREFIX_DIR/$FLAVOR_DIR/$BIN_NAME + BIN_PATH=$CNTK_ROOT/$PREFIX_DIR/$FLAVOR_DIR/$BIN_NAME if ! [[ -f $BIN_PATH ]]; then echo "============ ERROR: CNTK did not build properly for $TARGET/$FLAVOR ============" echo "Missing file: $BIN_PATH" diff --git a/Tools/generate_build_info b/Tools/generate_build_info index 580e878de..c569f4936 100755 --- a/Tools/generate_build_info +++ b/Tools/generate_build_info @@ -1,5 +1,11 @@ #!/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 infomation to be displayed at runtime: # BUILDTYPE (release/debug) @@ -24,7 +30,7 @@ usage () echo "This script assumes git can be used" echo "This script assumes Config.make has been made" echo "-------------------------------------------------------------------" - if [ ! -z "$1" ] ; then + if [ ! -z "$1" ] ; then echo "ERROR message: $1" fi exit 1 @@ -60,20 +66,20 @@ makebuildinfo() 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 + 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 + if [ ! -z "$CUB_PATH" ]; then printf "#define _CUB_PATH_ \"%s\"\n" "$CUB_PATH" fi - if [ ! -z "$CUDNN_PATH" ]; then + if [ ! -z "$CUDNN_PATH" ]; then printf "#define _CUDNN_PATH_ \"%s\"\n" $CUDNN_PATH fi printf "#define _BUILDTYPE_ \"%s\"\n" "$BUILDTYPE" - if [ ! -z "$WITH_1BITSGD" ]; then + if [ ! -z "$WITH_1BITSGD" ]; then printf "#define _WITH_1BITSGD_ \"yes\"\n" else printf "#define _WITH_1BITSGD_ \"no\"\n" @@ -87,48 +93,53 @@ makebuildinfo() #//////////////////////////////////////////////////////# # main function # -#//////////////////////////////////////////////////////# -if [ $# -ne 1 ]; then - usage +#//////////////////////////////////////////////////////# +if [ $# -ne 1 ]; then + usage fi config=$1 -# 1. check whether we have git and what is the sha-1 value +# 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` -# 2. looking into Config.make -if [ ! -e $config ] ; then +# Looking into Config.make +if [ ! -e $config ] ; then usage "Config.make not exists" fi source $config -# 3. whether we have CUDA_PATH -if [ -z "${CUDA_PATH+x}" ]; then +# Whether we have CUDA_PATH +if [ -z "${CUDA_PATH+x}" ]; then CUDAPATH="" else CUDAPATH=$CUDA_PATH fi -# 4. whether we have CUB_PATH -if [ -z "${CUB_PATH+x}" ]; then +# Whether we have CUB_PATH +if [ -z "${CUB_PATH+x}" ]; then CUBPATH="" else CUBPATH=$CUB_PATH fi -# 5. Build machine info +# Identify MKL variant being used +if [ "$MATHLIB" = "mkl" -a "$MKL_THREADING" = "sequential" ]; then + MATHLIB=mkl-sequential +fi + +# Build machine info BUILDER=$USER BUILDMACHINE=`hostname` BUILDPATH=`pwd` -# 6. make buildinfo.h (only update if changed) +# Make buildinfo.h (only update if changed) target=Source/CNTK/buildinfo.h -if [ ! -d Source ] ; then +if [ ! -d Source ] ; then usage fi diff --git a/configure b/configure index 362699eb9..f89613fc0 100755 --- a/configure +++ b/configure @@ -1,4 +1,11 @@ #!/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 @@ -12,9 +19,12 @@ have_acml=no acml_path= acml_check=include/acml.h +# CNTK Custom MKL Version +cntk_custom_mkl_version=1 + have_mkl=no mkl_path= -mkl_check=mkl/include/mkl.h +mkl_check=$cntk_custom_mkl_version/include/mkl.h # Experimental OpenBLAS support. have_openblas=no @@ -23,7 +33,7 @@ openblas_check=include/openblas_config.h have_kaldi=no kaldi_path= -kaldi_check=src/kaldi.mk +kaldi_check=src/kaldi.mk have_buildtype=no buildtype= @@ -58,11 +68,11 @@ default_use_code_coverage=no enable_code_coverage=$default_use_code_coverage # List from best to worst choice -default_path_list="/usr /usr/local /opt /opt/local /opt/intel" +default_path_list="/usr /usr/local /opt /opt/local" # List from best to worst choice default_acmls="acml5.3.1/ifort64_mp" -default_mkls="" +default_mkls="CNTKCustomMKL" default_openblas="" # NOTE: Will get compilation errors with cuda-6.0 @@ -171,7 +181,7 @@ function is_hardlinked () echo $r } -function default_use_cuda () +function default_use_cuda () { if test x$(find_cuda) = x || test x$(find_gdk) = x then @@ -182,7 +192,7 @@ function default_use_cuda () } enable_cuda=$(default_use_cuda) -function show_default () +function show_default () { if test x$1 = x then @@ -207,6 +217,7 @@ function show_help () echo " --with-cudnn[=directory] $(show_default $(find_cudnn))" echo " --with-acml[=directory] $(show_default $(find_acml))" 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))" @@ -392,12 +403,16 @@ do --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 mkl directory" + echo "Cannot find CNTK custom MKL directory" echo "Please specify a value for --with-mkl" exit 1 fi @@ -406,7 +421,7 @@ do then mkl_path=$optarg else - echo "Invalid mkl directory $optarg" + echo "Invalid CNTK custom MKL directory $optarg" exit 1 fi fi @@ -534,7 +549,7 @@ then if test x$mkl_path = x then echo "Cannot find a CPU math library." - echo "Please specify --with-acml, --with-mkl, --with-openblas with a path." + echo "Please specify --with-acml, --with-mkl, --with-mkl-sequential, --with-openblas with a path." exit 1 else mathlib=mkl @@ -637,6 +652,8 @@ 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 @@ -678,6 +695,6 @@ then echo all clean : >> $makefile printf '\t$(MAKE) -C $(dir) BUILD_TOP=$(BUILD_TOP) $@\n' >> $makefile fi -echo run +echo run echo '>make -j all' echo to build