GeNN  4.9.0
GPU enhanced Neuronal Networks (GeNN)
Variable initialisation

Neuron, weight update, postsynaptic and custom update models all have state variables which GeNN can automatically initialise.

Previously we have shown variables being initialised to constant values such as:

or initialised using one of a number of predefined variable initialisation snippets:

For example, to initialise a parameter using values drawn from the normal distribution:

Defining a new variable initialisation snippet

Similarly to neuron, weight update and postsynaptic models, new variable initialisation snippets can be created by simply defining a class in the model description. For example, when initialising excitatory (positive) synaptic weights with a normal distribution they should be clipped at 0 so the long tail of the normal distribution doesn't result in negative weights. This could be implemented using the following variable initialisation snippet which redraws until samples are within the desired bounds:

Within the snippet of code specified using the , when initialisising neuron and postaynaptic model state variables , the $(id) variable can be used to access the id of the neuron being initialised. Similarly, when initialising weight update model state variables, the $(id_pre) and $(id_post) variables can used to access the ids of the pre and postsynaptic neurons connected by the synapse being initialised.

Variable locations

Once you have defined how your variables are going to be initialised you need to configure where they will be allocated. By default memory is allocated for variables on both the GPU and the host. However, the following alternative 'variable locations' are available:

  • VarLocation::DEVICE - Variables are only allocated on the GPU, saving memory but meaning that they can't easily be copied to the host - best for internal state variables.
  • VarLocation::HOST_DEVICE - Variables are allocated on both the GPU and the host - the default.
  • VarLocation::HOST_DEVICE_ZERO_COPY - Variables are allocated as 'zero-copy' memory accessible to the host and GPU - useful on devices such as Jetson TX1 where physical memory is shared between the GPU and CPU.
Note
'Zero copy' memory is only supported on newer embedded systems such as the Jetson TX1 where there is no physical seperation between GPU and host memory and thus the same block of memory can be shared between them.

These modes can be set as a model default using ModelSpec::setDefaultVarLocation or on a per-variable basis using one of the following functions:


Previous | Top | Next