Skip to content

Commit

Permalink
Merge pull request #538 from genn-team/windows_path_gui
Browse files Browse the repository at this point in the history
Encourage use of Windows path GUI
  • Loading branch information
neworderofjamie authored Aug 31, 2022
2 parents b5e0c36 + 04e0176 commit 206b436
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 111 deletions.
241 changes: 180 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,89 +4,206 @@

GeNN is a GPU-enhanced Neuronal Network simulation environment based on code generation for Nvidia CUDA.

## INSTALLING GeNN
## Installation

These instructions are for installing the release obtained from https://github.com/genn-team/genn/releases. For full instructions and cloning git branches of the project, see the documentation available at http://genn-team.github.io/genn/
You can download GeNN either as a zip file of a stable release or a
snapshot of the most recent stable version or the unstable development
version using the Git version control system.

### WINDOWS INSTALL
### Downloading a release
Point your browser to https://github.com/genn-team/genn/releases
and download a release from the list by clicking the relevant source
code button. After downloading continue to install GeNN as described in the [GitHub installing section](#installing-genn) below.

1. Download and unpack GeNN.zip to a convenient location, then download and install the Microsoft Visual C++ compiler and IDE from: http://www.visualstudio.com/en-us/downloads. Be sure to select the 'Desktop development with C++' configuration' and the 'Windows 8.1 SDK' and 'Windows Universal CRT' individual components. If your machine has an NVIDIA GPU, then download and install a compatible version of the Nvidia CUDA toolkit from: https://developer.nvidia.com/cuda-downloads. Note that the latest version of Visual Studio is not necessarily compatible with the latest version of the CUDA toolkit.
### Obtaining a Git snapshot

2. Ensure that the `CUDA_PATH` environment variable is defined and points to the location of the Nvidia CUDA toolkit installation; and that the CUDA `bin` directory is included in the path. These can be checked by using: `ECHO %CUDA_PATH%` and `ECHO %PATH%` respectively (although they are usully set automatically by the CUDA installer on Windows systems). If not, correct this using: `SETX CUDA_PATH "[drive]\Program Files\NVIDIA GPU Computing Toolkit\CUDA[version]"` and `SETX PATH "%PATH%;%CUDA_PATH%`.

3. Add the `bin` sub-directory of the directory in which GeNN is located to your `PATH` variable. For example, if you extracted GeNN to `c:\Users\me\GeNN`, use: `SETX PATH "c:\Users\me\GeNN\bin;%PATH%"`.

4. To access a developer command prompt, use the shortcut link in: start menu -\> all programs -\> Microsoft Visual Studio -\> Visual Studio Tools -\> x64 Native Tools Command Prompt which will launch an instance of cmd.exe with a build environment already set up. Alternatively, from any cmd console window, run the vscvsrsall.bat script under the Visual C++ directory before compiling any projects.

This completes the installation. Note that the command window must be restarted to initialise the variables set using the `SETX` command.

### LINUX / MAC INSTALL

1. Unpack GeNN.zip in a convenient location, then download and install a compatible version of the Nvidia CUDA toolkit from: https://developer.nvidia.com/cuda-downloads and the GNU GCC compiler collection and GNU Make build environment if it is not already present on the system. Note that the latest versions of GCC / Clang / Linux are not necessarily compatible with the latest version of the CUDA toolkit.

2. Ensure that the environment variable `CUDA_PATH` is set to the location of your Nvidia CUDA toolkit installation and that the CUDA binary directory is in your path.
For example, if your CUDA toolkit was installed to `/usr/local/cuda`, you can use:
```sh
echo "export CUDA_PATH=/usr/local/cuda" >> ~/.bash_profile
echo "export PATH=$PATH:$CUDA_PATH/bin" >> ~/.bash_profile
```

4. Add GeNN's `bin` directory to your $PATH variable. For example, if you extracted GeNN to `/home/me/genn`, you can use: `echo "export PATH=$PATH:/home/me/genn/bin" >> ~/.bash_profile`

This completes the installation. Note that you must either logout and in again or run `source ~/.bash_profile` for the changes to `.bash_profile` to take effect.

### ARCH LINUX INSTALL
For Arch Linux there are GeNN packages available [from the AUR](https://aur.archlinux.org/packages/?O=0&K=genn).

Install with your AUR helper of choice, like so:
```sh
yay -S genn
If it is not yet installed on your system, download and install Git
(http://git-scm.com/). Then clone the GeNN repository from Github
```bash
git clone https://github.com/genn-team/genn.git
```

If you do not want CUDA support (i.e. if you don't have an NVIDIA GPU), there is a CPU-only version of the package:
```sh
yay -S genn_cpu_only
```

## USING GeNN

### SAMPLE PROJECTS

At the moment, the following example projects are provided with GeNN:
The github url of GeNN in the command above can be copied from the
HTTPS clone URL displayed on the GeNN Github page (https://github.com/genn-team/genn).

This will clone the entire repository, including all open branches.
By default git will check out the master branch which contains the
source version upon which the next release will be based. There are other
branches in the repository that are used for specific development
purposes and are opened and closed without warning.

### Installing GeNN

Installing GeNN comprises a few simple steps [^1] to create the GeNN
development environment:

[^1]: While GeNN models are normally simulated using CUDA on NVIDIA GPUs, if you want to use GeNN on a machine without an NVIDIA GPU, you can skip steps v and vi and use GeNN in "CPU_ONLY" mode.

1. If you have downloaded a zip file, unpack GeNN.zip in a convenient
location. Otherwise enter the directory where you downloaded the Git
repository.

2. Add GeNN's 'bin' directory to your path, e.g. if you are running Linux or Mac OS X and extracted/downloaded GeNN to
``$HOME/GeNN``, this can be done with:
```bash
export PATH=$PATH:$HOME/GeNN/bin
```
to make this change persistent, this can be added to your login script (e.g. `.profile` or `.bashrc`) using your favourite text editor or with:
```bash
echo "export PATH=$PATH:$CUDA_PATH/bin" >> ~/.bash_profile
```
If you are using Windows, the easiest way to modify the path is
by using the 'Environment variables' GUI, which can be accessed by clicking start and searching for
(by starting to type) 'Edit environment variables for your account'.
In the upper 'User variables' section, scroll down until you see 'Path',
select it and click 'Edit'.
Now add a new directory to the path by clicking 'New' in the 'Edit environment variable' window e.g.:
![Screenshot of windows edit environment variable window](/doxygen/images/path_windows.png)
if GeNN is installed in a sub-directory of your home directory (``%USERPROFILE%`` is an environment variable which points to the current user's home directory) called ``genn``.
3. Install the C++ compiler on the machine, if not already present.
For Windows, download Microsoft Visual Studio Community Edition from
https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx.
When installing Visual Studio, one should select the 'Desktop
development with C++' configuration.
Mac users should download and set up Xcode from
https://developer.apple.com/xcode/index.html
, Linux users should install the GNU compiler collection gcc and g++
from their Linux distribution repository, or alternatively from
https://gcc.gnu.org/index.html
4. If your machine has a GPU and you haven't installed CUDA already,
obtain a fresh installation of the NVIDIA CUDA toolkit from
https://developer.nvidia.com/cuda-downloads
Again, be sure to pick CUDA and C++ compiler versions which are compatible
with each other. The latest C++ compiler need not necessarily be
compatible with the latest CUDA toolkit.

5. GeNN uses the ``CUDA_PATH`` environment variable to determine which
version of CUDA to build against. On Windows, this is set automatically when
installing CUDA. However, if you choose, you can verify which version is
selected by looking for the ``CUDA_PATH`` environment variable in the lower 'System variables' section of the GUI you used to configure the path:
![Screenshot of windows edit environment variable window](/doxygen/images/cuda_path_windows.png)
here, CUDA 10.1 and 11.4 are installed and CUDA 11.4 is selected via ``CUDA_PATH``.
However, on Linux and Mac you need to set ``CUDA_PATH`` manually with:
```bash
export CUDA_PATH=/usr/local/cuda
```
assuming CUDA is installed in /usr/local/cuda (the standard location
on Ubuntu Linux). Again, to make this change persistent, this can
be added to your login script (e.g. ``.profile`` or ``.bashrc``)

This normally completes the installation. Windows users must close
and reopen their command window so changes to the path take effect.

If you are using GeNN in Windows, the Visual Studio development
environment must be set up within every instance of the CMD.EXE command
window used. One can open an instance of CMD.EXE with the development
environment already set up by navigating to Start - All Programs -
Microsoft Visual Studio - Visual Studio Tools - x64 Native Tools Command Prompt. You may also wish to
create a shortcut for this tool on the desktop, for convenience.

## Usage

### Sample projects

At the moment, the following C++ example projects are provided with GeNN:

- Self-organisation with STDP in the locust olfactory system \([Nowotny et al. 2005][@Nowotnyetal2005]\):
- with all-to-all connectivity, using built-in neuron and synapse models \(for benchmarks see [Yavuz et al. 2016][@Yavuzetal2016]\)
- with sparse connectivity for some synapses, using user-defined neuron-and synapse models \(for benchmarks see [Yavuz et al. 2016][@Yavuzetal2016]\)
- using INDIVIDUALID scheme
- using delayed synapses
- using BITMASK connectivity
- using synapses with axonal delays
- Pulse-coupled network of Izhikevich neurons \([Izhikevich 2003][@Izhikevich2003]\) (for benchmarks see [Yavuz et al. 2016][@Yavuzetal2016])

- Genetic algorithm for tracking parameters in a Hodgkin-Huxley model cell

- Classifier based on an abstraction of the insect olfactory system \([Schmuker et al. 2014][@Schmukeretal2014]\)

- Cortical microcircuit model \([Potjans et al. 2014][@Potjans2014]\)

- Toy examples:
- Single neuron population of Izhikevich neuron(s) receiving Poisson spike trains as input
- Single neuron population of Izhikevich neuron(s) with no synapses
- Network of Izhikevich neurons with delayed synapses

In order to get a quick start and run one of the the provided example models, navigate to one of the example project directories in the userproject sub-directory, and then follow the instructions in the README file contained within.

## SIMULATING A NEW MODEL

The sample projects listed above are already quite highly integrated examples. If one was to use the library for GPU code generation of their own model, the following would be done:

1. The model in question is defined in a file, say `Model1.cc`.

2. This file needs to
- include `modelSpec.h`
- contains the model's definition in the form of a function `void modelDefinition(NNmodel &model)` (`MBody1.cc`) shows a typical example)

3. The programmer defines their own modeling code along similar lines as `MBody1Sim.cc`, etcetera. In this code,
- they define input patterns (e.g. for Poisson neurons like in the example)
- they use `stepTime();` to run one time step on whatever backend the model was built using.
- they use functions like `copyStateFromDevice();` etcetera to obtain results from GPU calculations.
- the simulation code is then produced in the following two steps: `genn-buildmodel.[sh|bat] ./modelFile.cc` and `make clean && make`
## Simulating a new model

The sample projects listed above are already quite highly integrated examples. If you wanted to use GeNN to develop a new C++ model, you would do the following:

1. The neuronal network of interest is defined in a model definition file,
e.g. ``Example1.cc``.

2. Within the the model definition file ``Example1.cc``, the following tasks
need to be completed:

1. The GeNN file ``modelSpec.h`` needs to be included,
```c++
#include "modelSpec.h"
```

2. The values for initial variables and parameters for neuron and synapse
populations need to be defined, e.g.
```c++
NeuronModels::PoissonNew::ParamValues poissonParams(
10.0); // 0 - firing rate
```
would define the (homogeneous) parameters for a population of Poisson
neurons [^2].
[^2]: The number of required parameters and their meaning is defined by the
neuron or synapse type. Refer to the [User manual](https://genn-team.github.io/genn/documentation/4/html/dc/d05/UserManual.html) for details. We recommend, however, to use comments like
in the above example to achieve maximal clarity of each parameter's
meaning.
If heterogeneous parameter values are required for a particular
population of neurons (or synapses), they need to be defined as "variables"
rather than parameters. See the [User manual](https://genn-team.github.io/genn/documentation/4/html/dc/d05/UserManual.html) for how to define new neuron (or synapse) types and the [Variable initialisation](https://genn-team.github.io/genn/documentation/4/html/d4/dc6/sectVariableInitialisation.html) section for more information on
initialising these variables to hetererogenous values.
3. The actual network needs to be defined in the form of a function
``modelDefinition`` [^3], i.e.
```c++
void modelDefinition(ModelSpec &model);
```
[^3]: The name ``modelDefinition`` and its parameter of type ``ModelSpec&``
are fixed and cannot be changed if GeNN is to recognize it as a
model definition.
4. Inside ``modelDefinition()``, The time step ``DT`` needs to be defined, e.g.
```c++
model.setDT(0.1);
```
\note
All provided examples and pre-defined model elements in GeNN work with
units of mV, ms, nF and uS. However, the choice of units is entirely
left to the user if custom model elements are used.
[MBody1.cc](userproject/MBody1_project/model/MBody1.cc) shows a typical example of a model definition function. In
its core it contains calls to ``ModelSpec::addNeuronPopulation`` and
``ModelSpec::addSynapsePopulation`` to build up the network. For a full range
of options for defining a network, refer to the [User manual](https://genn-team.github.io/genn/documentation/4/html/dc/d05/UserManual.html).
3. The programmer defines their own "simulation" code similar to
the code in [MBody1Sim.cc](userproject/MBody1_project/model/MBody1Sim.cc). In this code,
1. They can manually define the connectivity matrices between neuron groups.
Refer to the \ref subsect34 section for the required format of
connectivity matrices for dense or sparse connectivities.
2. They can define input patterns or individual initial values for neuron and
/ or synapse variables.
\note
The initial values or initialisation "snippets" given in the ``modelDefinition`` are automatically applied.
3. They use ``stepTime()`` to run one time step on either the CPU or GPU depending on the options passed to genn-buildmodel.
4. They use functions like ``copyStateFromDevice()`` etc to transfer the
results from GPU calculations to the main memory of the host computer
for further processing.
5. They analyze the results. In the most simple case this could just be
writing the relevant data to output files.
For more details on how to use GeNN, please see [documentation](http://genn-team.github.io/genn/).
Expand All @@ -97,6 +214,8 @@ If you use GeNN in your work, please cite "Yavuz, E., Turner, J. and Nowotny, T.
[@Nowotnyetal2005]: https://doi.org/10.1007/s00422-005-0019-7 "Nowotny, T., Huerta, R., Abarbanel, H. D. & Rabinovich, M. I. Self-organization in the olfactory system: one shot odor recognition in insects. Biological cybernetics 93, 436–446 (2005)"
[@Potjans2014]: https://doi.org/10.1093/cercor/bhs358 "Potjans, T. C., & Diesmann, M. The Cell-Type Specific Cortical Microcircuit: Relating Structure and Activity in a Full-Scale Spiking Network Model. Cerebral Cortex, 24(3), 785–806 (2014)"
[@Schmukeretal2014]: https://doi.org/10.1073/pnas.1303053111 "Schmuker, M., Pfeil, T. and Nawrot, M.P. A neuromorphic network for generic multivariate data classification. Proceedings of the National Academy of Sciences, 111(6), pp.2081-2086 (2014)"
[@Yavuzetal2016]: https://doi.org/10.1038%2Fsrep18854 "Yavuz, E., Turner, J. and Nowotny, T. GeNN: a code generation framework for accelerated brain simulations. Scientific reports, 6. (2016)"
Loading

0 comments on commit 206b436

Please sign in to comment.