Skip to content

Setup CNTK with script on Windows

Wolfgang Manousek edited this page Jan 10, 2017 · 15 revisions

If you want to build CNTK from source code and want to use the Developer Install script, this page is for you.

If you are looking for any other kind of support in setting up a CNTK build environment or installing CNTK on your system, you should go here instead.

For Your Consideration

Here are recommendations to make sure you can build CNTK successfully:

  • The system locale on the build machine should be set to a language with a 'latin' based character set.
  • Avoid extremely long path names. The build procedure uses copy-operations (XCOPY) that can run into problems with path expression with over 256 characters in length.

64-bit OS

CNTK requires a 64-bit Windows installation. We tested the build process on Windows 8.1, Windows 10, and Windows Server 2012 R2 and later. Other environments are not officially supported. For compatibility issues check CNTK Production Build and Test configuration.

Preparation

There are steps required to create a CNTK CNTK development environment on your machine:

  • Installation of required tools
    • Visual Studion 2015 Update 3
    • NVIDIA Cuda 8
    • Git
    • Clone the CNTK Source code
  • Running the developer installation script
  • Building tools
  • Building CNTK

This page will walk you through all these steps. The script driven installation will create a development environment with all optional components, including NVIDIA tools, the Python environment, OpenCV and compression libraries.

Installation of required tools

Visual Studio 2015 Update 3

Install Microsoft Visual Studio 2015.3 for Windows. A link to the download can be found here. Please install Visual Studio 2015, not a previous version or the 2017-Preview! The Community Version of Visual Studion 2015 is sufficient to build CNTK.

During the installation process please select custom installation:

im1

On the feature selection screen make sure you add 'Common Tools for Visual C++ 2015' to your installation:

im1

Pre-Existing Visual Studio 2015 installation

If you already have VS 2015 installed, make sure you are on Update 3. See the Help->About menu to display the version number like "Version 14.0.25431.01 Update 3".

You are also required to have the 'Common Tools for Visual C++ 2015' installed on your system. To check open the Windows "Control Panel -> Programs -> Programs and Features' and select 'Microsoft Visual Studio Enterprise 2015 with Updates' from the list of installed programs. This will start the Visual Studio setup again and allows you to make sure the 'Common Tools for Visual C++ 2015' feature is installed on your system (see picture above).

NVIDIA Cuda 8

Important In case you have a first-time Visual Studio 2015 installation as described above, you will need to install NVIDIA Cuda 8 now, even if you have already an existing installation of Cuda 8! The NVIDIA Cuda 8 installation adds support to the NVIDIA development tools to the Visual Studio environment, which is required to build CNTK successfully.

CNTK is set to build with Cuda 8.0. Download and install the NVIDIA Cuda 8.0 Toolkit:

  • Download the required package from this download page
  • Run the installation procedure (Choose the 'Express Install Option' if the choice is presented)

Note: In case you don't have a system with a NVidia Cuda 8 compatible graphics card, the Cuda installer will issue a warning. Please continue the installer if you receive this warning, the Cuda tools will be installed, and you are able to build a NVIDIA Gpu enabled version of CNTK on your system.

Git

Git is required to clone the CNTK code base. There are various Git client tools available, and you can also work with Git directly from inside Visual Studio. Here we assume you installed Git for Windows. We assume you installed Git using the default options in the Git installer (Especially 'Use Git from the Windows Command Prompt' and with the option "Checkout Windows-style, commit UNIX-style line endings" at the "Configuring line endings" prompt enabled.

Clone the CNTK source code

We will create a clone of the CNTK source code in the c:\repos\CNTK. If you prefer a different location you will need to adjust the commands accordingly.

Open a standard windows command shell, and execute these command

c: && md \repos && cd \repos
git clone https://github.com/Microsoft/cntk
cd cntk
git submodule update --init Source/Multiverso

Running the developer installation script

The developer installation script is a Powershell script which will install all additional required and optional tools to build CNTK on your system. It will also create the required environment setting on your system. Once the script is started no additional user input is necessary, although you will require to acknowledge the installation of programs, depending on your 'User Account Control' setting.

By default Powershell doesn't allow the execution of any scripts. To allow execution of the installation script start Powershell from a standard Windows command shell by:

start powershell -executionpolicy remotesigned

Assuming that you cloned the CNTK source code into the c:\repos\cntk directory, change inside the Powershell session into the directory with the install script inside the cloned CNTK repository and start the installer in that directory:

cd C:\repos\cntk\Tools\devInstall\Windows
.\DevInstall.ps1

The script will inspect your system and determine the pre-requisites which are missing. You will be notified about the proposed installation steps. At this point you are running in a demo mode - NO changes to your system are being performed.

If you are satisfied with the proposed changes, you can proceed to the actual installation. The installation script supports several command line options. get-help .\install.ps1 will give you a list over the available option. At this point it is recommended to start the installation by adding the -Execute parameter:

.\install.ps1 -execute

The script will download needed components from the web, therefore a connection to the Internet is required. It will execute these components, and according to the setting of UAC (User Account Control) on your system, you will be asked to acknowledge the execution and installtion of these components.

Depending on the speed of your system, your Internet connection and the required components to install, the whole process can take up to 20 minutes. Especially the Anaconda3 install is very time consuming without any progress indication, please be patient.

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 the components required for GPU configurations
  • IMPORTANT! When you open CNTK Solution for the 1st time Debug_CpuOnly build configuration is selected by default. If you do NOT perform the steps above and just build the solution, you will get a debug build, and your GPU will not be used

Build the CNTK solution.

Quick test of CNTK build functionality

To ensure that CNTK is working properly in your system, you can quickly run an example from the Hello World - Logistic Regression tutorial. 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\release was 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 change to the Tutorials\HelloWorld-LogisticRegression directory:
set PATH=C:\repos\cntk\x64\release;%PATH%
cd C:\repos\cntk\Tutorials\HelloWorld-LogisticRegression

First try the example:

cntk configFile=lr_bs.cntk makeMode=false

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.

Trying CNTK with GPU

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

cntk configFile=lr_bs.cntk makeMode=false deviceId=auto

Near the beginning of the output you should see a line confirming a GPU was used:

Model has 9 nodes. Using GPU 0.

Note that GPU ID may be different. The deviceId parameter defines what processor to use for computation.

  • 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

Debugging CNTK source code in Visual Studio

To debug the source code in CNTK with Visual Studio, follow the steps [here](Debugging CNTK source code in Visual Studio).

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

Clone this wiki locally