GeNN  3.3.0
GPU enhanced Neuronal Networks (GeNN)
Variable initialisation

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

Note
In previous versions of GeNN, weight update models state variables for synapse populations with sparse connectivity were not automatically initialised. This behaviour remains the default, but by setting this can be overriden.

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

0.0529324, // 1 - prob. for Na channel activation m
...
);

state variables can also be left uninitialised leaving it up to the user code to initialise them:

uninitialisedVar(), // 1 - prob. for Na channel activation m
...
);

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:

InitVarSnippet::Normal::ParamValues params(
0.05, // 0 - mean
0.01); // 1 - standard deviation
initVar<InitVarSnippet::Normal>(params), // 1 - prob. for Na channel activation m
...
);

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:

class NormalPositive : public InitVarSnippet::Base
{
public:
DECLARE_SNIPPET(NormalPositive, 2);
"scalar normal;"
"do\n"
"{\n"
" normal = $(mean) + ($(gennrand_normal) * $(sd));\n"
"} while (normal < 0.0);\n"
"$(value) = normal;\n");
SET_PARAM_NAMES({"mean", "sd"});
};
IMPLEMENT_SNIPPET(NormalPositive);

Within the snippet of code specified using the SET_CODE() macro, 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 initialisation modes

Once you have defined how your variables are going to be initialised you need to configure where they will be initialised and allocated. By default memory is allocated for variables on both the GPU and the host; and variables are initialised on the host as described in section Variable initialisation and then uploaded to the GPU. However, variable initialisation can also be offloaded to the GPU, potentially reducing the time spent both calculating the initial values and uploading them. To enable this functionality the following alternative modes of operation are available:

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 global default using GENN_PREFERENCES::defaultVarMode or on a per-variable basis using one of the following functions:


Previous | Top | Next