GeNN  3.3.0
GPU enhanced Neuronal Networks (GeNN)
codeGenUtils.cc File Reference
#include "codeGenUtils.h"
#include <regex>
#include <cstring>
#include "modelSpec.h"
#include "standardSubstitutions.h"
#include "utils.h"

Enumerations

enum  MathsFunc
 

Functions

void substitute (string &s, const string &trg, const string &rep)
 Tool for substituting strings in the neuron code strings or other templates. More...
 
bool regexVarSubstitute (string &s, const string &trg, const string &rep)
 Tool for substituting variable names in the neuron code strings or other templates using regular expressions. More...
 
bool regexFuncSubstitute (string &s, const string &trg, const string &rep)
 Tool for substituting function names in the neuron code strings or other templates using regular expressions. More...
 
bool isRNGRequired (const std::string &code)
 Does the code string contain any functions requiring random number generator. More...
 
bool isInitRNGRequired (const std::vector< NewModels::VarInit > &varInitialisers, const std::vector< VarMode > &varModes, VarInit initLocation)
 Does the model with the vectors of variable initialisers and modes require an RNG for the specified init mode. More...
 
void functionSubstitute (std::string &code, const std::string &funcName, unsigned int numParams, const std::string &replaceFuncTemplate)
 This function substitutes function calls in the form: More...
 
void functionSubstitutions (std::string &code, const std::string &ftype, const std::vector< FunctionTemplate > functions)
 This function performs a list of function substitutions in code snipped. More...
 
string ensureFtype (const string &oldcode, const string &type)
 This function implements a parser that converts any floating point constant in a code snippet to a floating point constant with an explicit precision (by appending "f" or removing it). More...
 
void checkUnreplacedVariables (const string &code, const string &codeName)
 This function checks for unknown variable definitions and returns a gennError if any are found. More...
 
uint32_t hashString (const std::string &string)
 This function returns the 32-bit hash of a string - because these are used across MPI nodes which may have different libstdc++ it would be risky to use std::hash. More...
 
void preNeuronSubstitutionsInSynapticCode (string &wCode, const SynapseGroup *sg, const string &offset, const string &axonalDelayOffset, const string &preIdx, const string &devPrefix, const string &preVarPrefix, const string &preVarSuffix)
 Function for performing the code and value substitutions necessary to insert neuron related variables, parameters, and extraGlobal parameters into synaptic code. More...
 
void postNeuronSubstitutionsInSynapticCode (string &wCode, const SynapseGroup *sg, const string &offset, const string &backPropDelayOffset, const string &postIdx, const string &devPrefix, const string &postVarPrefix, const string &postVarSuffix)
 suffix to be used for postsynaptic variable accesses - typically combined with prefix to wrap in function call such as __ldg(&XXX) More...
 
void neuron_substitutions_in_synaptic_code (string &wCode, const SynapseGroup *sg, const string &preIdx, const string &postIdx, const string &devPrefix, double dt, const string &preVarPrefix, const string &preVarSuffix, const string &postVarPrefix, const string &postVarSuffix)
 Function for performing the code and value substitutions necessary to insert neuron related variables, parameters, and extraGlobal parameters into synaptic code. More...
 

Enumeration Type Documentation

◆ MathsFunc

enum MathsFunc

Function Documentation

◆ checkUnreplacedVariables()

void checkUnreplacedVariables ( const string &  code,
const string &  codeName 
)

This function checks for unknown variable definitions and returns a gennError if any are found.

◆ ensureFtype()

string ensureFtype ( const string &  oldcode,
const string &  type 
)

This function implements a parser that converts any floating point constant in a code snippet to a floating point constant with an explicit precision (by appending "f" or removing it).

◆ functionSubstitute()

void functionSubstitute ( std::string &  code,
const std::string &  funcName,
unsigned int  numParams,
const std::string &  replaceFuncTemplate 
)

This function substitutes function calls in the form:

$(functionName, parameter1, param2Function(0.12, "string"))

with replacement templates in the form:

actualFunction(CONSTANT, $(0), $(1))

◆ functionSubstitutions()

void functionSubstitutions ( std::string &  code,
const std::string &  ftype,
const std::vector< FunctionTemplate functions 
)

This function performs a list of function substitutions in code snipped.

◆ hashString()

uint32_t hashString ( const std::string &  string)

This function returns the 32-bit hash of a string - because these are used across MPI nodes which may have different libstdc++ it would be risky to use std::hash.

https://stackoverflow.com/questions/19411742/what-is-the-default-hash-function-used-in-c-stdunordered-map suggests that libstdc++ uses MurmurHash2 so this seems as good a bet as any MurmurHash2, by Austin Appleby It has a few limitations -

  1. It will not work incrementally.
  2. It will not produce the same results on little-endian and big-endian machines.

◆ isInitRNGRequired()

bool isInitRNGRequired ( const std::vector< NewModels::VarInit > &  varInitialisers,
const std::vector< VarMode > &  varModes,
VarInit  initLocation 
)

Does the model with the vectors of variable initialisers and modes require an RNG for the specified init mode.

Does the model with the vectors of variable initialisers and modes require an RNG for the specified init location i.e. host or device.

◆ isRNGRequired()

bool isRNGRequired ( const std::string &  code)

Does the code string contain any functions requiring random number generator.

◆ neuron_substitutions_in_synaptic_code()

void neuron_substitutions_in_synaptic_code ( string &  wCode,
const SynapseGroup sg,
const string &  preIdx,
const string &  postIdx,
const string &  devPrefix,
double  dt,
const string &  preVarPrefix = "",
const string &  preVarSuffix = "",
const string &  postVarPrefix = "",
const string &  postVarSuffix = "" 
)

Function for performing the code and value substitutions necessary to insert neuron related variables, parameters, and extraGlobal parameters into synaptic code.

suffix to be used for postsynaptic variable accesses - typically combined with prefix to wrap in function call such as __ldg(&XXX)

Parameters
wCodethe code string to work on
sgthe synapse group connecting the pre and postsynaptic neuron populations whose parameters might need to be substituted
preIdxindex of the pre-synaptic neuron to be accessed for _pre variables; differs for different Span)
postIdxindex of the post-synaptic neuron to be accessed for _post variables; differs for different Span)
devPrefixdevice prefix, "dd_" for GPU, nothing for CPU
dtsimulation timestep (ms)
preVarPrefixprefix to be used for presynaptic variable accesses - typically combined with suffix to wrap in function call such as __ldg(&XXX)
preVarSuffixsuffix to be used for presynaptic variable accesses - typically combined with prefix to wrap in function call such as __ldg(&XXX)
postVarPrefixprefix to be used for postsynaptic variable accesses - typically combined with suffix to wrap in function call such as __ldg(&XXX)
postVarSuffixsuffix to be used for postsynaptic variable accesses - typically combined with prefix to wrap in function call such as __ldg(&XXX)

◆ postNeuronSubstitutionsInSynapticCode()

void postNeuronSubstitutionsInSynapticCode ( string &  wCode,
const SynapseGroup sg,
const string &  offset,
const string &  backPropDelayOffset,
const string &  postIdx,
const string &  devPrefix,
const string &  postVarPrefix,
const string &  postVarSuffix 
)

suffix to be used for postsynaptic variable accesses - typically combined with prefix to wrap in function call such as __ldg(&XXX)

Parameters
wCodethe code string to work on
devPrefixdevice prefix, "dd_" for GPU, nothing for CPU
postVarPrefixprefix to be used for postsynaptic variable accesses - typically combined with suffix to wrap in function call such as __ldg(&XXX)
postVarSuffixsuffix to be used for postsynaptic variable accesses - typically combined with prefix to wrap in function call such as __ldg(&XXX)

◆ preNeuronSubstitutionsInSynapticCode()

void preNeuronSubstitutionsInSynapticCode ( string &  wCode,
const SynapseGroup sg,
const string &  offset,
const string &  axonalDelayOffset,
const string &  preIdx,
const string &  devPrefix,
const string &  preVarPrefix,
const string &  preVarSuffix 
)

Function for performing the code and value substitutions necessary to insert neuron related variables, parameters, and extraGlobal parameters into synaptic code.

suffix to be used for presynaptic variable accesses - typically combined with prefix to wrap in function call such as __ldg(&XXX)

Parameters
wCodethe code string to work on
devPrefixdevice prefix, "dd_" for GPU, nothing for CPU
preVarPrefixprefix to be used for presynaptic variable accesses - typically combined with suffix to wrap in function call such as __ldg(&XXX)
preVarSuffixsuffix to be used for presynaptic variable accesses - typically combined with prefix to wrap in function call such as __ldg(&XXX)

◆ regexFuncSubstitute()

bool regexFuncSubstitute ( string &  s,
const string &  trg,
const string &  rep 
)

Tool for substituting function names in the neuron code strings or other templates using regular expressions.

◆ regexVarSubstitute()

bool regexVarSubstitute ( string &  s,
const string &  trg,
const string &  rep 
)

Tool for substituting variable names in the neuron code strings or other templates using regular expressions.

◆ substitute()

void substitute ( string &  s,
const string &  trg,
const string &  rep 
)

Tool for substituting strings in the neuron code strings or other templates.