[windows 10编译CNTK]

CNTK Production Build and Test configuration

CNTK may be successfully run in many Windows configurations, but in case you want to avoid possible compatibility issues you may get yourself familiar with the CNTK Production Build and Test configuration where we list all dependency components and component versions that we use.

Known limitations

IMPORTANT! There are some limitations in the CNTK build machine configuration. We are working on fixing this, but for the time being please ensure the following:

  • System locale on Build Machine is set to English (known bug)
  • Do not use very long paths to CNTK code and build directories. Build procedure using XCOPY that usually has issues with the paths over 259 characters
  • We found that if you have Visual Studio 2013 and Visual Studio 2012 or Visual Studio 2010 installed simultaneously it may cause build failures. Therefore we recommend to have a "clean" installation of Visual Studio 2013.

And now let's proceed to the setup.

64-bit OS

You need a 64-bit Windows installation to use CNTK.

OPTIONAL. Setting all required environment variables in batch mode

Almost all installation procedures described below involve some manual environment variables setting. In case you accept the default/suggested paths for the required prerequisite components, you may set all required environment variables by creating a batch file with the code below and running it (you need to run this procedure as Administrator). The set of the variables imply that you install all mandatory and optional components for GPU enabled configuration using ACML as Math library. The commands below also create some basic root directories used as example paths at this page. If you do not need it at this stage, omit all mkdir commands.

mkdir c:\src
mkdir c:\local
mkdir c:\AMD
mkdir c:\NVIDIA\cudnn-4.0
mkdir c:\zip
setx           CUDA_PATH "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5"
setx      CUDA_PATH_V7_5 "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5"
setx            CUB_PATH c:\src\cub-1.4.1\
setx          CUDNN_PATH C:\NVIDIA\cudnn-4.0\cuda
setx  BOOST_INCLUDE_PATH c:\local\boost_1_59_0
setx      BOOST_LIB_PATH c:\local\boost_1_59_0\lib64-msvc-12.0
setx           ACML_PATH C:\AMD\acml5.3.1\ifort64_mp
setx         OPENCV_PATH C:\src\opencv\build
setx           ZLIB_PATH C:\zip

Depending on your configuration, you may also need these:

setx ACML_FMA 0
setx CNTK_ENABLE_1BitSGD true

You may verify that the required PATH environment variables were set by running the following set of commands:

dir "%CUDA_PATH%"
dir "%CUDA_PATH_V7_5%"
dir %CUB_PATH%
dir %CUDNN_PATH%
dir %BOOST_INCLUDE_PATH%
dir %BOOST_LIB_PATH%
dir %ACML_PATH%
dir %OPENCV_PATH%
dir %ZLIB_PATH%

You may also run the commands above at the end of the component installation to ensure all paths contain the required files.

Visual Studio 2013

Install Microsoft Visual Studio 2013. You may use any edition.

After installation install the latest update available. At the time of this guide writing this is Update 5. You may install it using any of the following methods:

  • Start Visual Studio and go the following Menu: Tools -> Extensions and Updates -> Updates -> Product Updates -> Visual Studio 2013 Update 5
  • Download the Update 5 for your edition of Visual Studio using this link and install it

IMPORTANT Today CNTK is designed to be compiled with Visual Studio 2013. Though it is possible to compile with other Visual Studio versions, it may require extra debugging and configuration work. Also in case of GPU configurations be aware, that NVIDIA CUDA 7.5 does NOT support Visual Studio versions higher, than 2013.

Git

You need to have Git installed to work with the CNTK code base. You may use the following methods:

You may also consider the following Git packages:

ACML

Install the AMD Core Math Library (ACML):

setx ACML_PATH C:\AMD\acml5.3.1\ifort64_mp
  • If you are using an Intel processor with FMA3 support, it may be required to add the following environment variable to work around a known bug in this version of the ACML library:
setx ACML_FMA 0

OPTIONAL. MKL

An alternative to the ACML library is the Intel Math Kernel Library (Intel MKL). CNTK supports using the Intel MKL via a custom library version ("CNTK custom MKL").

IMPORTANT You can NOT directly build CNTK using a regular installed Intel MKL SDK, the build is configured to work with a custom generated CNTK custom MKL library (This way you don't need to go through the process of installing the complete Intel MKL SDK). You can obtain the CNTK custom MKL library if you follow the steps below. If you need to build your own custom version, you can find the needed information here.

Installing the CNTK custom MKL library:

  • Set the environment variable CNTK_MKL to 1 and clear the ACML_PATH variable, if you have previously configured it:
setx CNTK_MKL 1
setx ACML_PATH ""
  • Create a directory on your machine to hold CNTK custom MKL versions, e.g.:
mkdir c:\local\CNTKCustomMKL
  • Set the environment variable CNTK_MKL_PATH to point to this directory:
setx CNTK_MKL_PATH c:\local\CNTKCustomMKL
  • Download the required CNTK custom MKL from the CNTK web site. Unzip it into your CNTK MKL path, creating a numbered sub directory within. For example, if you are on latest master, download CNTKCustomMKL-Windows-1.zip and extract its contents toc:\local\CNTKCustomMKL\1.

    Note: if you want to build other CNTK source versions, you may need to install alternate CNTK custom MKL versions. Check the tag <CNTKCustomMKLVersion> in the CNTK build properties file CNTK.Cpp.props to determine which.

MS-MPI

Install the latest version of Microsoft MPI (MS-MPI), a Microsoft implementation of the Message Passing Interface standard. CNTK requires at least Version 7.

IMPORTANT! You need to download and install both Run-time and SDK (files msmpisdk.msi andMSMpiSetup.exe`).

Boost Library

We are using the Boost Library for unit tests. We are probably going to incorporate the Boost library into CNTK code in the future. But today you are required to install it manually:

  • Download and install Boost version 1.59 (you need msvc-12.0 binaries) from Sourceforge.
  • Set the environment variable BOOST_INCLUDE PATH to your Boost installation, e.g.:
setx BOOST_INCLUDE_PATH c:\local\boost_1_59_0
  • Set the environment variable BOOST_LIB_PATH to the Boost libraries, e.g.:
setx BOOST_LIB_PATH c:\local\boost_1_59_0\lib64-msvc-12.0
  • To integrate Boost into the Visual Studio Test Framework you can install a runner for Boost tests in Visual Studio from the Visual Studio Gallery.

GPU Specific Packages

This section outlines the packages you need to setup in order for CNTK to leverage GPUs.

If you do NOT intend to use any GPUs with CNTK and will rely on the CPU only, you may skip directly to the next general section. Otherwise proceed further.

Checking your GPU compatibility

You need a CUDA-compatible graphic card available to use CNTK GPU capabilities. You can check whether your card is CUDA-compatible here and here (for older cards).

IMPORTANT. CNTK uses cuDNN library for GPU acceleration. Because of this your GPU cardCompute Capability (CC) should be 3.0 or more. Using cards with lesser CC revision will very likely result in the incorrect processing results (like described in this issue - see Question 3 in the initial post). You may check the CC revision of your cards using links to compatibility pages from the previous paragraph.

IMPORTANT! Do NOT update your GPU card driver at this step because with the high probability it will be replaced by the CUDA installation procedure. This will be the case even if your system contains the driver newer, than the one included in the CUDA installation. This guide will instruct you to update the driver at a later step.

CUDA 7.5

IMPORTANT. Currently CNTK is set to be built with CUDA 7.5. Building it with higher versions of CUDA may result in build errors.

Download and install the NVIDIA CUDA 7.5 Toolkit:

  • Download the required package from here
  • Run the installation procedure

IMPORTANT! CUDA installation will propose to install a certain version of the Graphics Driver. Accept this selection even if you have a newer driver installed. Otherwise the GPU Deployment Kit component required by CNTK will NOT be installed. You will install the latest Graphics Driver in the next section.

Make sure that the following CUDA environment variables are set to the correct path (the installer will create these for you). Default installation paths are assumed:

CUDA_PATH="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5"
CUDA_PATH_V7_5="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5"
Latest GPU card driver

Now install the latest driver for your GPU card:

  • Select your card and download the driver pack from here
  • Run the driver installation procedure
CUB

Get and install NVIDIA CUB.

IMPORTANT! Install NVIDIA CUB using the exact version specified below. This is necessary because it is expected by the CNTK build configuration program.

  • Download NVIDIA CUB v.1.4.1
  • Extract the archive to a folder on your local disk and set the environment variable CUB_PATHpointing to that location, e.g.:
setx CUB_PATH c:\src\cub-1.4.1\
  • Quick installation check. If you followed the instruction above and used the same paths, you should have the file cub.cuh at C:\src\cub-1.4.1\cub
cuDNN

Install NVIDIA CUDA Deep Neural Network library (cuDNN).

IMPORTANT! Install cuDNN using the exact version specified below. This is necessary because it is expected by the CNTK build configuration program.

  • Download the Windows version of cuDNN v4 using the following link
  • Extract the archive to a folder on your local disk, e.g. to c:\NVIDIA\cudnn-4.0 and set the environment variable CUDNN_PATH pointing to that location, e.g.:
setx CUDNN_PATH C:\NVIDIA\cudnn-4.0\cuda
  • Quick installation check. If you followed the instruction above and used the same paths, you should have the file cudnn.h at C:\NVIDIA\cudnn-4.0\cuda\include

This completes GPU Specific section


OPTIONAL. OpenCV

If you want to build the CNTK Image Reader, you need to install Open Source Computer Vision (OpenCV).

(See also the next section if you want the Image Reader to support ZIP file format)

Download and install version 3.0 for Windows.

Set the environment variable OPENCV_PATH pointing to the OpenCV build folder, e.g.

setx OPENCV_PATH C:\src\opencv\build

OPTIONAL. zlib and libzip

If you want to build the CNTK Image Reader, that supports ZIP File format, you need to installzlib and libzip libraries.

Please note, that you also need to install OpenCV to build CNTK Image Reader. See the previous section.

(The process described below is somewhat tedious and cumbersome. We currently are working on providing an easier option of enabling zlib and libzip and will publish it soon)*

We use the following installation paths in our instructions:

  • zlib sources: c:\zlib
  • libzip sources: c:\libzip
  • Build directory for zlib and libzip binaries: c:\zip

You can use any paths you like, but note the remark on target folder for binaries below

IMPORTANT! The following two aspects are important:

  • Build commands for zlib and libzip should use the same target folder for binaries (specified via-DCMAKE_INSTALL_PREFIX parameter in cmake command below)
  • Build order is important. You should build zlib first because libzip is dependent on it.
Command prompt environment for build

Use VS2013 x64 Native Tools Command Prompt for executing all commands described below. You will find the correspondent shortcut in

%ProgramFiles(x86)%\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts
Building zlib

Execute the following commands from VS2013 x64 Native Tools Command Prompt:

cd c:\zlib
mkdir build
cd build
cmake .. -G"Visual Studio 12 2013 Win64" -DCMAKE_INSTALL_PREFIX="C:\zip"
msbuild /P:Configuration=Release INSTALL.vcxproj
Building libzib

Execute the following commands from VS2013 x64 Native Tools Command Prompt:

cd c:\libzip
mkdir build
cd build
cmake .. -G"Visual Studio 12 2013 Win64" -DCMAKE_INSTALL_PREFIX="C:\zip"
msbuild libzip.sln /t:zip /P:Configuration=Release
cmake -DBUILD_TYPE=Release -P cmake_install.cmake

MSBuild command above may generate some warnings. It is expected and may be ignored.

The last cmake command from the list above will generate the following error:

CMake Error at src/cmake_install.cmake:34 (file):
  file INSTALL cannot find "C:/libzip/build/src/Release/zipcmp.exe".

It is expected and may be ignored - all required binaries (zip.dll and zlib.dll) should be already in C:\zip\bin

Preparing the environment
  • Go to C:\zip\bin and rename zlib.dll to zlib1.dll (see Question 2 in zlib DLL FAQ for details)
  • Set the following environment variable:
setx ZLIB_PATH c:\zip

*: Build instructions in this section are based on the information from this post

Getting CNTK Source code

Before proceeding further, please note, that if you plan on making modifications to the CNTK code you should read the information on Developing and Testing in this Wiki.

Use Git to clone the CNTK Repository and access the source code.

  • If you use a standalone client, open Git command prompt, go to your source code folder (we use c:\src for examples at this page) and execute the following command:
git clone https://github.com/Microsoft/cntk
  • Within Visual Studio use the following path for the Repository to clone:
https://github.com/Microsoft/cntk

IMPORTANT! The procedure above does not provide you with the access to 1-bit Stochastic Gradient Descent (1bit-SGD) and BlockMomentumSGD components. If you want to build CNTK with this functionality enabled, please read the instructions on this page and then proceed with the installation.

Building CNTK

Open the CNTK solution and select the desired configuration:

  • Right-click the CNTK Solution in Solution Explorer and select Properties
  • In the appeared window select Configuration Properties and press Configuration Manager... button
  • In Configuration Manager select the desired configuration:
    • Debug or Release
    • GPU or CPU-only. CPU-only configurations are explicitly named. All other configurations imply GPU usage (i.e. Release means Release. GPU enabled mode)
    • You should always select CPU-only configurations if you have NOT installed thecomponents required for GPU configurations

Build the CNTK solution.

Quick test of CNTK build functionality

To ensure that CNTK is working properly in your system, you can quickly run Simple2d examplefrom CNTK Examples set. This example trains a simple network and can be directed to use either CPU or GPU, which helps quickly ensure that CNTK is functioning properly.

Below we assume that the CNTK repository is cloned to c:\Repos\cntk and build\x64\releasewas used as a sub-directory for the build.

  • Open Command Prompt
  • Provide the path to the CNTK binaries (via Environment Variable or for Command Prompt session using the first command below) and switch to the Simple2d directory:
set PATH=C:\src\cntk\build\x64\release;%PATH%
cd C:\src\cntk\Examples\Other\Simple2d\Data

First try the example (note UNIX-style slashes in the config file path):

cntk configFile=../Config/Simple.cntk

If the sample runs, i.e. if there are no error messages, you will get an output related first to reading the configuration, followed by the output of the actual network training. Running the command a second time will report that the model has already been trained. To perform the training again, you must first remove the existing models by using the following command:

del ..\Output\Models\*.*
Trying CNTK with CPU

As seen previously, the Simple2d example produces an extensive output. Among this output there is the information regarding what processor was used for the Network Builder. If you perform the following command:

cntk configFile=../Config/Simple.cntk 1> out.txt 2>&1

and look for the string Builder Using in the resulting file out.txt you should be able to find this line

SimpleNetworkBuilder Using CPU

It tells us that CNTK was indeed using CPU.

Trying CNTK with GPU

If you built CNTK for GPU usage, try using GPU by executing the following command:

cntk configFile=../Config/Simple.cntk deviceId=auto 1> out.txt 2>&1

Look for the string Builder Using in the resulting file out.txt. In this case you should see:

SimpleNetworkBuilder Using GPU 0

Note that GPU id may be different. deviceId parameter defines what processor to use for Network Builder:

  • deviceId=-1 means use CPU. Default value
  • deviceId=X where X is an integer >=0 means use GPU X, i.e. deviceId=0 means GPU 0, etc.
  • deviceId=auto means use GPU, select GPU automatically

Contributing to CNTK code

If you plan modifications to the code you should read the information on Developing and Testing in this Wiki.

Next steps

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值