Skip to content

genn-team/genn

Repository files navigation

Build Statuscodecov.io DOI Dockerhub Neuromorphic Computing

GPU-enhanced Neuronal Networks (GeNN)

GeNN is a GPU-enhanced Neuronal Network simulation environment based on code generation for NVIDIA CUDA and AMD HIP.

Installation

Pre-installation

C/C++ Compiler and system dependencies

Install the C++ compiler on the machine, if not already present.

Windows native
Linux or Windows with WSL 2
  • On Linux, the GNU Compiler Collection (GCC) 7.5 or above is required. This can be obtained from your Linux distribution repository, for example on Ubuntu by running sudo apt-get install g++
  • Install the development version of libffi. For example, on Ubuntu you can do this by running sudo apt-get install libffi-dev.

CUDA (NVIDIA GPU only)

  • If your machine has an NVIDIA GPU and you haven't installed CUDA already, obtain a fresh installation of the NVIDIA CUDA toolkit from https://developer.nvidia.com/cuda-downloads
  • Be sure to pick CUDA and C++ compiler versions which are compatible - the latest C++ compiler is not necessarily be compatible with the latest CUDA toolkit.
  • 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 running echo %CUDA_PATH% in a commmand prompt.
    • On Linux, you need to set CUDA_PATH manually using export CUDA_PATH=/usr/local/cuda, assuming CUDA is installed in /usr/local/cuda (the standard location on Ubuntu Linux). To make any of these changes persistent, add this command to your login script (e.g. .profile or .bashrc).

HIP (AMD or NVIDIA GPU)

  • If your machine has an AMD GPU and you haven't installed HIP yet, follow the instructions at https://rocm.docs.amd.com/projects/HIP/en/latest/install/install.html.
  • Set the HIP_PATH variable manually using export HIP_PATH=/opt/rocm, assuming HIP is installed using the official installer.
  • Specify your platform with export HIP_PLATFORM='amd' if you wish to use an AMD GPU or export HIP_PLATFORM='nvidia' if you wish to use HIP with an NVIDIA GPU
  • To make any of these changes persistent, these commands should be added to your login script (e.g. .profile or .bashrc).

Installation

In order to install GeNN on Windows you need to run the following commands from a command prompt with the Visual Studio environment variables correctly configured. Typically this is added to the start menu during Visual Studio installataion and is called something like "x64 Native Tools Command Prompt for VS 2022". Once installation is complete, GeNN can be used from a normal command prompt.

Using pip

The easiest way to install GeNN is directly from github using pip. First of all make sure pip is up to date using : pip install -U pip Then, to install the latest development version you can use: pip install https://github.com/genn-team/genn/archive/refs/heads/master.zip or, to install the 5.4.0 release, you can use: pip install https://github.com/genn-team/genn/archive/refs/tags/5.4.0.zip.

Editable with pip

If you want to develop GeNN yourself or run userprojects from the GeNN repository, it is helpful to create an 'editable' install. The easiest way to do this to first 'clone' GeNN from github using git clone https://github.com/genn-team/genn.git. Then, navigate to the GeNN directory and install using pip install -e .. If you wish to install the additional dependencies needed to run the userprojects, you can do so using pip install -e .[userproject].

setup.py (LEGACY)

Although it is not recommended, in order to build special development versions you sometimes need to install the old fashioned way!

  1. Manually install PyGeNN's build dependencies using pip i.e. pip install pybind11 psutil pkgconfig setuptools>=61.
  2. Clone GeNN using git i.e. using git clone https://github.com/genn-team/genn.git
  3. From the GeNN directory, build PyGeNN using python setup.py develop. You can build a debug version of GeNN with python setup.py build_ext --debug develop.

Docker

You can also use GeNN through our CUDA-enabled docker container which comes with GeNN pre-installed. To work with such CUDA-enabled containers, you need to first install CUDA on your host system as described above and then install docker and the NVIDIA Container Toolkit as described in https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker. You can then build the GeNN container yourself or download it from Dockerhub.

Building the container

The following command can be used from the GeNN source directory to build the GeNN container:

make docker-build

This builds a container tagged as genn:latest so, to use this container rather than downloading the prebuild one from dockerhub, just replace gennteam/genn:latest with genn:latest in the following instructions. By default, the container image is based off the Ubuntu 20.04 image with CUDA 11.5 provided by NVIDIA but, if you want to use a different base image, for example to use the container on a machine with an older version of CUDA, you can invoke docker build directly and specify a different tag (listed on https://gitlab.com/nvidia/container-images/cuda/blob/master/doc/supported-tags.md) via the BASE build argument. For example to build using CUDA 11.3 you could run:

docker build  --build-arg BASE=11.3.0-devel-ubuntu20.04 -t genn:latest_cuda_11_3 .

Interactive mode

If you wish to use GeNN or PyGeNN interactively, you can launch a bash shell in the GeNN container using the following command:

docker run -it --gpus=all gennteam/genn:latest

You can also provide a final argument to launch a different executable e.g. /bin/sh to launch a dash shell. NOTE PyGeNN is installed in the system Python 3 environment, the interpreter for which is launched with python3 (rather than just python) on Ubuntu 20.04.

Accessing your files

When using the GeNN container you often want to access files on your host system. This can be easily achieved by using the -v option to mount a local directory into the container. For example:

docker run -it --gpus=all -v $HOME:/local_home gennteam/genn:latest

mounts the local user's home directory into /local_home within the container. However, all of the commands provided by the GeNN container operate using a non-elevated, internal user called 'genn' who, by default, won't have the correct permissions to create files in volumes mounted into the container. This can be resolved by setting the LOCAL_USER_ID and LOCAL_GROUP_ID environment variables when running the container like:

docker run -it --gpus=all -e LOCAL_USER_ID=`id -u $USER` -e LOCAL_GROUP_ID=`id -g $USER` -v $HOME:/local_home gennteam/genn:latest

which will ensure that that 'genn' user has the same UID and GID as the local user, meaning that they will have the same permissions to access the files mounted into /local_home.

Running Jupyter Notebooks

A Jupyter Notebook environment running in the container can be launched using the notebook command. Typically, you would combine this with the -p 8080:8080 option to 'publish' port 8080, allowing the notebook server to be accessed on the host. By default, notebooks are created in the home directory of the 'genn' user inside the container. However, to create notebooks which persist beyond the lifetime of the container, the notebook command needs to be combined with the options discussed previously. For example:

docker run --gpus=all -p 8080:8080 -e LOCAL_USER_ID=`id -u $USER` -e LOCAL_GROUP_ID=`id -g $USER` -v $HOME:/local_home gennteam/genn:latest notebook /local_home

will create notebooks in the current users home directory.

Running PyGeNN scripts

Assuming they have no additional dependencies, PyGeNN scripts can be run directly using the container with the script command. As scripts are likely to be located outside of the container, the script command is often combined with the options discussed previously. For example, to run a script called test.py in your home directory, the script command could be invoked with:

docker run --gpus=all -e LOCAL_USER_ID=`id -u $USER` -e LOCAL_GROUP_ID=`id -g $USER` -v $HOME:/local_home gennteam/genn:latest script /local_home/test.py

Usage

Sample projects

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

In order to get a quick start and run one of the the provided example models, navigate to the userproject directory, and run the python script with --help to see what options are available.

For more details on how to use GeNN, please see documentation.

About

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

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

 
 
 

Contributors