CNS: Cortical Network Simulator Programming Guide - Installation

Note: CNS is designed to run on a GPU, but can also run without one (much more slowly). These instructions are written assuming you have a GPU. If you don't, skip any steps written in italics and also read this section.

Installation Menu

  1. Requirements
    1. Recently Tested Configurations
  2. Preparing Your Computer
  3. Installing Core CNS
  4. Installing Packages
  5. Running Without a GPU


  • Linux, Windows, or Mac OS. (Note: CNS is not developed or tested on the Mac. Build scripts for Mac have been provided by users.)
  • MATLAB 2009b or higher.
  • CUDA 4.1 or 5.0.
  • A C++ compiler compatible with all the above.
    • Build scripts assume gcc for Linux or Mac and Visual Studio for Windows.
    • (Linux or Mac only.) For CNS to control multiple GPUs from one instance of MATLAB, and to run models asynchronously, your compiler must have the <pthread.h> library.
  • An NVIDIA GPU that supports the CUDA API.

Recently Tested Configurations


  • Ubuntu 10.04 64-bit
  • MATLAB 2010b
  • CUDA 4.1 or 5.0
  • GCC 4.4.3


  • Windows 7 64-bit
  • MATLAB 2010b
  • CUDA 4.1
  • Microsoft Visual C++ 2010

Preparing Your Computer

  1. Make sure MATLAB's "mex" command can find your C++ compiler. You can set this up in MATLAB with the command "mex -setup".


  2. Make sure the CUDA driver and CUDA toolkit (both version 4.1 or 5.0) are installed. If you need to install them, install the driver first. Note that CNS does not require the CUDA SDK.


  3. (Linux only.) Consider setting your GPU(s) to "exclusive access" mode to ensure that they will only allow one model at a time to run. Usually, trying to run multiple models on one GPU results in out-of-GPU-memory errors. Setting exclusive access avoids this. In multi-GPU systems, this setting also allows CNS to automatically select a GPU that isn't being used. Under other operating systems, GPU selection must currently be managed manually. See the NVIDIA documentation for how to specify exclusive access under Linux.


  4. (Linux or Mac only.) Make sure you have the C shell installed.


  5. Make sure that on operating system startup:


    • the system path contains the path to the NVIDIA compiler (nvcc). On Linux this is by default "/usr/local/cuda/bin".
    • the "mex" command works from the operating system command line. This may involve adding something to your system path.


  6. (Linux or Mac only.) Make sure that on operating system startup:


    • the environment variable "LD_LIBRARY_PATH" contains the path to the NVIDIA libraries. In Linux this is by default "/usr/local/cuda/lib".

Installing Core CNS

  1. Unpack the archive file and move the "cns" directory to wherever you will be using it.


  2. Make sure the settings in one of these files (the one corresponding to your OS) are correct for your computer:
  3. (Linux or Mac only.) Make sure the following permissions are set:


    • all files under "cns/scripts" are executable.
    • it is possible to create new files in "cns" or subdirectories.


  4. Make sure the "cns" directory and its subdirectories will be in your MATLAB path on startup. One way to do this is to call "cns/cns_path.m" from your "startup.m" file.


  5. (In MATLAB.) Create binaries by running:


  6. (In MATLAB.) Compile the demo package using the command:

    cns_build demopkg

  7. (In MATLAB.) Run the demo package by typing "demopkg_run". If everything is working, MATLAB should output the following messages:
    Defining a network model....
    Building the model (platform: GPU)....
    Reading a test image and loading it into the model....
    Running the model and retrieving result....
    Elapsed time is ??? seconds.
    Plotting result....
    Releasing model resources....

    and you should also see the following figure:

Installing Packages

Perform the following instructions for any packages you intend to use with CNS.

  1. Unpack the archive file and move the package directory to where you will be using it.


  2. (Linux or Mac only.) Make sure permissions are set so that it is possible to create new files in the package directory.


  3. Make sure the package directory and any subdirectories are in your MATLAB path.


  4. Compile the package using the command "cns_build package", where package is the package name. Normally this will be the same as the directory name. All file names in the package directory also start with the package name.

Note: if you change anything in a package directory, you must re-run the above cns_build command.


Running Without a GPU

If you need to run CNS without a GPU, do the following.

  • Skip any installation steps written in italics above.


  • Set CUDA = 0 in one of these files (the one corresponding to your OS):
  • In any script that calls cns('init'), you must use the 'cpu' (or 'debug') option. This includes the demopkg_run script mentioned above.