CNTK/Tools/make_binary_drop_linux

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

#!/bin/bash
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#
# WARNING. This will run in Microsoft Internal Environment ONLY, to generate CNTK binary drops.
scriptName="$(basename "${BASH_SOURCE[0]}")"
scriptDir="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")"
parsedArgs=$(getopt -o '' --long target-configuration:,verbose,release-tag:,commit: -n "$scriptName" -- "$@")
[ $? != 0 ] && {
echo Terminating...
exit 1
}
eval set -- "$parsedArgs"
targetConfiguration=
verbose= # TODO
releaseTag=unknown
while true; do
case "$1" in
--target-configuration)
targetConfiguration="${2,,}"
shift 2
;;
--commit)
commit="${2,,}"
shift 2
;;
--release-tag)
releaseTag="${2,,}"
shift 2
;;
--verbose)
verbose=1
shift
;;
--)
shift
break
;;
esac
done
[ $# = 0 ] || {
echo Extra parameters detected: $*
exit 1
}
[[ -n $commit ]] || {
echo Must specify --commit option.
exit 1
}
case $targetConfiguration in
cpu)
publicTargetConfiguration=CPU-Only
;;
gpu)
publicTargetConfiguration=GPU
;;
'')
echo Must specify --target-configuration option.
exit 1
;;
*)
echo Unknown target configuration $targetConfiguration.
exit 1
;;
esac
[[ $releaseTag = unknown ]] || [[ $releaseTag =~ ^[1-9][0-9a-z-]*$ ]] || {
echo \'--release-tag $releaseTag\' option does not match expected format.
exit 1
}
outputFile=CNTK-$releaseTag-Linux-64bit-$publicTargetConfiguration.tar.gz
# Stop on Error
set -e -o pipefail
# Enable verbose mode if needed
# stderr is NOT changed
if [[ -n $verbose ]]; then
exec 3>&1
else
exec 3>/dev/null
fi
# Define helper function
# File List Copy function
# usage: CopyFilesFromList source_path file_name_array destination_path
function CopyFilesFromList ()
{
declare -a fileNames=(${!2})
2017-02-10 12:35:55 +03:00
for fileName in "${fileNames[@]}"
do
2017-02-10 12:35:55 +03:00
cp -p "$1/$fileName" "$3"
done
}
# Main script
echo "Making binary drops..." >&3
cd "$scriptDir/.."
# Dependency files
# MKL
Merge release/2.4 Squashed commit of the following: commit 82e025bbe319008c535741a9fc78367032cc3be0 Merge: 0702c09c3 ed5451c83 Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 21:23:23 2018 -0800 Merge branch 'release/2.4' into manikj/merge-release-2.4 commit 0702c09c3c3cc1ae1e4cba28df3ce64f091a8c3e Merge: 32f6844ca 1afe40461 Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 21:23:11 2018 -0800 Merge branch 'release/2.4' (early part) into manikj/merge-release-2.4 commit 32f6844ca84797db2dac8959eeb72576692986d0 Merge: 42a47a326 1f15d4649 Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 21:21:55 2018 -0800 Merge branch 'release/2.4' (early part) into manikj/merge-release-2.4 commit ed5451c83416c5084dedf1a684f03653fe5863ee Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 19:32:04 2018 -0800 MakeBinaryDrop: Fix lib names commit c528a56d4a1fa12f967e4bbab022a0d06b5704ea Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 12:35:40 2018 -0800 Update README.md commit 490a58e4a9cf01d9114373b9444f0fbaf055581b Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 12:08:57 2018 -0800 Add Halide to Release notes commit 2196299a71325b0959dc626ce548035db0634e58 Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 11:48:45 2018 -0800 MakeBinaryDrop: Change Cuda libs to 9.0 commit 3df48ddd3ac38c24c5aa25bdb9b77d98116a3d8d Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 06:06:29 2018 -0800 Add release notes commit 1afe404611f1f9a7cde0f43923382101cf15b823 Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 06:05:05 2018 -0800 Replace 2.4+ with 2.4 commit 1f15d464960956a8192f137ebedf2753a36d83cc Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 06:04:24 2018 -0800 Bump version to 2.4
2018-02-01 08:35:22 +03:00
declare -a mklFiles=("libmklml_intel.so" "libiomp5.so" "libmkldnn.so.0")
# Open CV
declare -a opencvFiles=("libopencv_core.so.3.1" "libopencv_imgproc.so.3.1" "libopencv_imgproc.so.3.1" "libopencv_imgcodecs.so.3.1")
# libzip
2016-10-12 17:28:20 +03:00
declare -a libzipFiles=("libzip.so.4")
# CUDA
declare -a cudaFiles=("libcudart.so.9.0" "libcublas.so.9.0" "libcurand.so.9.0" "libcusparse.so.9.0")
# cuDNN
# Note: can be only a single file currently, see copy below.
declare -a cudnnFiles=("libcudnn.so")
2018-01-24 09:18:32 +03:00
# NCCL
declare -a ncclFiles=("libnccl.so.2.1.2")
2016-10-13 17:53:55 +03:00
# OpenBLAS (Needed by Kaldi)
declare -a openblasFiles=("libopenblas.so.0")
# Kaldi
declare -a kaldiFiles=("libkaldi-util.so" "libkaldi-matrix.so" "libkaldi-base.so" "libkaldi-hmm.so" "libkaldi-cudamatrix.so" "libkaldi-nnet.so" "libkaldi-lat.so" "libkaldi-tree.so")
# OpenFst (from Kaldi)
declare -a openfstFiles=("libfst.so.3")
2016-07-12 12:11:45 +03:00
# Include files
declare -a includeFiles=("Eval.h")
# Include files 2.0
declare -a includeFiles20=("CNTKLibrary.h" "CNTKLibraryInternals.h" "CNTKLibraryC.h" "HalfConverter.hpp")
declare -a includeInternalFiles20=("ComputationGraphAlgorithms.h" "EvaluatorWrapper.h" "PrimitiveFunctionAttribute.h" "PrimitiveFunction.h" "PrimitiveOpType.h")
# Set dependency sources paths
CNTK support for CUDA 9 CNTK now supports CUDA 9/cuDNN 7. This requires an update to build environment to Ubuntu 16/GCC 5 for Linux, and Visual Studio 2017/VCTools 14.11 for Windows. With CUDA 9, CNTK also added a preview for 16-bit floating point (a.k.a FP16) computation. Please check out the example of FP16 in ResNet50 at /Examples/Image/Classification/ResNet/Python/TrainResNet_ImageNet_Distributed.py Notes on FP16 preview: * FP16 implementation on CPU is not optimized, and it's not supposed to be used in CPU inference directly. User needs to convert the model to 32-bit floating point before running on CPU. * Loss/Criterion for FP16 training needs to be 32bit for accumulation without overflow, using cast function. Please check the example above. * Readers do not have FP16 output unless using numpy to feed data, cast from FP32 to FP16 is needed. Please check the example above. * FP16 gradient aggregation is currently only implemented on GPU using NCCL2. Distributed training with FP16 with MPI is not supported. * FP16 math is a subset of current FP32 implementation. Some model may get Feature Not Implemented exception using FP16. * FP16 is currently not supported in BrainScript. Please use Python for FP16. To setup build and runtime environment on Windows: * Install [Visual Studio 2017](https://www.visualstudio.com/downloads/) with following workloads and components. From command line (use Community version installer as example): vs_community.exe --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.Universal --add Microsoft.Component.PythonTools --add Microsoft.VisualStudio.Component.VC.Tools.14.11 * Install [NVidia CUDA 9](https://developer.nvidia.com/cuda-90-download-archive?target_os=Windows&target_arch=x86_64) * From PowerShell, run: /Tools/devInstall/Windows/DevInstall.ps1 * Start VCTools 14.11 command line, run: cmd /k "%VS2017INSTALLDIR%\VC\Auxiliary\Build\vcvarsall.bat" x64 --vcvars_ver=14.11 * Open /CNTK.sln from the VCTools 14.11 command line. Note that starting CNTK.sln other than VCTools 14.11 command line, would causes CUDA 9 [build error](https://developercommunity.visualstudio.com/content/problem/163758/vs-2017-155-doesnt-support-cuda-9.html). To setup build and runtime environment on Linux using docker, please build Unbuntu 16.04 docker image using Dockerfiles /Tools/docker. For other Linux systems, please refer to the Dockerfiles to setup dependent libraries for CNTK.
2018-01-23 03:58:56 +03:00
mklPath="/usr/local/lib"
2016-10-13 17:53:55 +03:00
opencvVersion="3.1.0"
opencvPath="/usr/local/opencv-$opencvVersion/lib"
libzipPath="/usr/local/lib"
cudaPath="/usr/local/cuda/lib64"
cudnnPath="/usr/local/cudnn-7.0/cuda/lib64"
2018-01-24 09:18:32 +03:00
ncclPath="/usr/lib/x86_64-linux-gnu"
2016-10-13 17:53:55 +03:00
openblasPath="/usr/local/openblas/lib"
kaldiVersion="c024e8aa"
kaldiPath="/usr/local/kaldi-$kaldiVersion/src/lib"
openfstPath="/usr/local/kaldi-$kaldiVersion/tools/openfst/lib"
# Set build paths
buildPath="build/$targetConfiguration/release"
basePath="BinaryDrops"
baseDropPath="$basePath/cntk"
baseBinariesPath="$baseDropPath/cntk"
baseDependenciesPath="$baseBinariesPath/dependencies/lib"
baseIncludePath="$baseDropPath/Include"
baseIncludeInternalPath="$baseIncludePath/Internals"
2016-07-12 12:11:45 +03:00
includePath="Source/Common/Include"
includePath20="Source/CNTKv2LibraryDll/API"
includeInternalPath20="$includePath20/Internals"
extrasPath="Tools/cntk-binary-drop/linux/$targetConfiguration"
# Make BinaryDrops directory
mkdir -p $baseBinariesPath
echo "Copying Python wheels..." >&3
mkdir $basePath/$publicTargetConfiguration
cp -p $buildPath/python/*.whl $basePath/$publicTargetConfiguration
echo "Copying build binaries..." >&3
2017-02-10 12:35:55 +03:00
cp -pr $buildPath/* $baseBinariesPath
# Remove unnecessary file(s) if exist(s)
#
# General TODO: Implement White List of Binary Drop contents.
# For the time being "cherry pick" removal of unneeded files
#
rm -f $baseBinariesPath/bin/brainscripttests
2016-07-07 12:06:38 +03:00
rm -f $baseBinariesPath/bin/cppevalclient
rm -f $baseBinariesPath/bin/cppevalextendedclient
rm -f $baseBinariesPath/bin/cppevalv2client
rm -f $baseBinariesPath/bin/evaltests
rm -f $baseBinariesPath/bin/mathtests
rm -f $baseBinariesPath/bin/multiversotests
rm -f $baseBinariesPath/bin/networktests
rm -f $baseBinariesPath/bin/readertests
2017-02-10 12:35:55 +03:00
rm -f $baseBinariesPath/bin/V2LibraryEndToEndTests
rm -f $baseBinariesPath/bin/v2librarytests
rm -rf $baseBinariesPath/python
rm -f $baseBinariesPath/lib/java/Main.class
2016-07-12 12:11:45 +03:00
# Make Include directory
mkdir -p $baseIncludePath
mkdir -p $baseIncludeInternalPath
2016-07-12 12:11:45 +03:00
# Copy Include
echo "Copying Include files..." >&3
2017-02-10 12:35:55 +03:00
CopyFilesFromList $includePath includeFiles[@] $baseIncludePath
echo "Copying Include files for Version 2..." >&3
2017-02-10 12:35:55 +03:00
CopyFilesFromList $includePath20 includeFiles20[@] $baseIncludePath
echo "Copying Include internal files for Version 2..." >&3
CopyFilesFromList $includeInternalPath20 includeInternalFiles20[@] $baseIncludeInternalPath
2016-07-12 12:11:45 +03:00
# Copy Examples
echo "Copying Examples..." >&3
2017-02-10 12:35:55 +03:00
cp -pr Examples $baseDropPath
2016-07-06 16:57:25 +03:00
# Copy Tutorials
echo "Copying Tutorials..." >&3
2017-02-10 12:35:55 +03:00
cp -pr Tutorials $baseDropPath
# Copy PretrainedModels
echo "Copying PretrainedModels..." >&3
cp -pr PretrainedModels $baseDropPath
# Copy Manual
echo "Copying Manual..." >&3
cp -pr Manual $baseDropPath
2016-07-06 16:57:25 +03:00
# Copy Scripts (Scripts folder from the root of the Repo)
echo "Copying Scripts..." >&3
2017-02-10 12:35:55 +03:00
cp -pr Scripts $baseDropPath
# Remove some unneeded files
2016-07-07 10:17:08 +03:00
rm -f $baseDropPath/Scripts/pytest.ini
2017-02-10 12:35:55 +03:00
rm -rf $baseDropPath/Scripts/install/windows
2016-07-07 10:17:08 +03:00
# Copy Extras
echo "Copying Extras..." >&3
2017-02-10 12:35:55 +03:00
cp -pr $extrasPath/* $baseDropPath
# Copy Dependencies
echo "Copying Dependencies..." >&3
# Make dependencies directory
mkdir -p $baseDependenciesPath
# Copy MKL
echo "Copying MKL" >&3
CopyFilesFromList $mklPath mklFiles[@] $baseDependenciesPath
# Copy Open CV
echo "Copying Open CV..." >&3
CopyFilesFromList $opencvPath opencvFiles[@] $baseDependenciesPath
# Copy libzip
echo "Copying libzip..." >&3
CopyFilesFromList $libzipPath libzipFiles[@] $baseDependenciesPath
2016-10-13 17:53:55 +03:00
# Copy OpenBLAS (for Kaldi)
echo "Copying OpenBLAS (for Kaldi)..." >&3
CopyFilesFromList $openblasPath openblasFiles[@] $baseDependenciesPath
# Copy Kaldi
echo "Copying Kaldi..." >&3
CopyFilesFromList $kaldiPath kaldiFiles[@] $baseDependenciesPath
# Copy OpenFst (from Kaldi)
echo "Copying OpenFst (Kaldi)..." >&3
CopyFilesFromList $openfstPath openfstFiles[@] $baseDependenciesPath
# GPU Drops only
if [[ $targetConfiguration != "cpu" ]]; then
# Copy CUDA
echo "Copying CUDA..." >&3
CopyFilesFromList $cudaPath cudaFiles[@] $baseDependenciesPath
# Copy cuDNN
echo "Copying cuDNN..." >&3
Merge release/2.4 Squashed commit of the following: commit 82e025bbe319008c535741a9fc78367032cc3be0 Merge: 0702c09c3 ed5451c83 Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 21:23:23 2018 -0800 Merge branch 'release/2.4' into manikj/merge-release-2.4 commit 0702c09c3c3cc1ae1e4cba28df3ce64f091a8c3e Merge: 32f6844ca 1afe40461 Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 21:23:11 2018 -0800 Merge branch 'release/2.4' (early part) into manikj/merge-release-2.4 commit 32f6844ca84797db2dac8959eeb72576692986d0 Merge: 42a47a326 1f15d4649 Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 21:21:55 2018 -0800 Merge branch 'release/2.4' (early part) into manikj/merge-release-2.4 commit ed5451c83416c5084dedf1a684f03653fe5863ee Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 19:32:04 2018 -0800 MakeBinaryDrop: Fix lib names commit c528a56d4a1fa12f967e4bbab022a0d06b5704ea Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 12:35:40 2018 -0800 Update README.md commit 490a58e4a9cf01d9114373b9444f0fbaf055581b Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 12:08:57 2018 -0800 Add Halide to Release notes commit 2196299a71325b0959dc626ce548035db0634e58 Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 11:48:45 2018 -0800 MakeBinaryDrop: Change Cuda libs to 9.0 commit 3df48ddd3ac38c24c5aa25bdb9b77d98116a3d8d Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 06:06:29 2018 -0800 Add release notes commit 1afe404611f1f9a7cde0f43923382101cf15b823 Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 06:05:05 2018 -0800 Replace 2.4+ with 2.4 commit 1f15d464960956a8192f137ebedf2753a36d83cc Author: Manik Jindal <manikj@microsoft.com> Date: Wed Jan 31 06:04:24 2018 -0800 Bump version to 2.4
2018-02-01 08:35:22 +03:00
CopyFilesFromList $cudnnPath cudnnFiles[@] $baseDependenciesPath/libcudnn.so.7
2018-01-24 09:18:32 +03:00
# Copy NCCL
echo "Copying NCCL..." >&3
CopyFilesFromList $ncclPath ncclFiles[@] $baseDependenciesPath/libnccl.so.2
fi
echo "Creating version.txt file" >&3
printf 'CNTK-%s\nRelease\n%s\n%s\n' \
"$releaseTag" "$publicTargetConfiguration" "$commit" \
> $baseDropPath/version.txt
echo "Making Archive and cleaning up..." >&3
# Make GZipped TAR
cd $basePath
tar --owner=root ${verbose:+-v} -czf "$outputFile" cntk
# Log some file hashes
sha256sum "$outputFile" $publicTargetConfiguration/*.whl
2017-02-10 12:35:55 +03:00
# Remove TAR sources
rm -r cntk