GeNN  4.0.0
GPU enhanced Neuronal Networks (GeNN)
CodeGenerator Namespace Reference

Helper class for generating code - automatically inserts brackets, indents etc. More...

Namespaces

 CUDA
 
 SingleThreadedCPU
 

Classes

class  BackendBase
 
class  CodeStream
 
struct  FunctionTemplate
 
struct  NameIterCtx
 
struct  PreferencesBase
 Base class for backend preferences - can be accessed via a global in 'classic' C++ code generator. More...
 
class  StructNameConstIter
 Custom iterator for iterating through the containers of structs with 'name' members. More...
 
class  Substitutions
 
class  TeeBuf
 
class  TeeStream
 

Typedefs

typedef NameIterCtx< Models::Base::VarVecVarNameIterCtx
 
typedef NameIterCtx< Models::Base::DerivedParamVecDerivedParamNameIterCtx
 
typedef NameIterCtx< Models::Base::VarVecExtraGlobalParamNameIterCtx
 

Functions

void substitute (std::string &s, const std::string &trg, const std::string &rep)
 Tool for substituting strings in the neuron code strings or other templates. More...
 
bool regexVarSubstitute (std::string &s, const std::string &trg, const std::string &rep)
 Tool for substituting variable names in the neuron code strings or other templates using regular expressions. More...
 
bool regexFuncSubstitute (std::string &s, const std::string &trg, const std::string &rep)
 Tool for substituting function names in the neuron code strings or other templates using regular expressions. 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...
 
template<typename NameIter >
void name_substitutions (std::string &code, const std::string &prefix, NameIter namesBegin, NameIter namesEnd, const std::string &postfix="", const std::string &ext="")
 This function performs a list of name substitutions for variables in code snippets. More...
 
void name_substitutions (std::string &code, const std::string &prefix, const std::vector< std::string > &names, const std::string &postfix="", const std::string &ext="")
 This function performs a list of name substitutions for variables in code snippets. More...
 
template<class T , typename std::enable_if< std::is_floating_point< T >::value >::type * = nullptr>
void writePreciseString (std::ostream &os, T value)
 This function writes a floating point value to a stream -setting the precision so no digits are lost. More...
 
template<class T , typename std::enable_if< std::is_floating_point< T >::value >::type * = nullptr>
std::string writePreciseString (T value)
 This function writes a floating point value to a string - setting the precision so no digits are lost. More...
 
template<typename NameIter >
void value_substitutions (std::string &code, NameIter namesBegin, NameIter namesEnd, const std::vector< double > &values, const std::string &ext="")
 This function performs a list of value substitutions for parameters in code snippets. More...
 
void value_substitutions (std::string &code, const std::vector< std::string > &names, const std::vector< double > &values, const std::string &ext="")
 This function performs a list of value substitutions for parameters in code snippets. More...
 
std::string ensureFtype (const std::string &oldcode, const std::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 std::string &code, const std::string &codeName)
 This function checks for unknown variable definitions and returns a gennError if any are found. More...
 
void preNeuronSubstitutionsInSynapticCode (std::string &wCode, const SynapseGroupInternal &sg, const std::string &offset, const std::string &axonalDelayOffset, const std::string &postIdx, const std::string &devPrefix, const std::string &preVarPrefix="", const std::string &preVarSuffix="")
 suffix to be used for presynaptic variable accesses - typically combined with prefix to wrap in function call such as __ldg(&XXX) More...
 
void postNeuronSubstitutionsInSynapticCode (std::string &wCode, const SynapseGroupInternal &sg, const std::string &offset, const std::string &backPropDelayOffset, const std::string &preIdx, const std::string &devPrefix, const std::string &postVarPrefix="", const std::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 neuronSubstitutionsInSynapticCode (std::string &wCode, const SynapseGroupInternal &sg, const std::string &preIdx, const std::string &postIdx, const std::string &devPrefix, double dt, const std::string &preVarPrefix="", const std::string &preVarSuffix="", const std::string &postVarPrefix="", const std::string &postVarSuffix="")
 Function for performing the code and value substitutions necessary to insert neuron related variables, parameters, and extraGlobal parameters into synaptic code. More...
 
GENN_EXPORT std::ostream & operator<< (std::ostream &s, const CodeStream::OB &ob)
 
GENN_EXPORT std::ostream & operator<< (std::ostream &s, const CodeStream::CB &cb)
 
GENN_EXPORT std::vector< std::string > generateAll (const ModelSpecInternal &model, const BackendBase &backend, const filesystem::path &outputPath, bool standaloneModules=false)
 
void generateInit (CodeStream &os, const ModelSpecInternal &model, const BackendBase &backend, bool standaloneModules)
 
void GENN_EXPORT generateMakefile (std::ostream &os, const BackendBase &backend, const std::vector< std::string > &moduleNames)
 
void GENN_EXPORT generateMPI (CodeStream &os, const ModelSpecInternal &model, const BackendBase &backend, bool standaloneModules)
 A function that generates predominantly MPI infrastructure code. More...
 
void GENN_EXPORT generateMSBuild (std::ostream &os, const BackendBase &backend, const std::string &projectGUID, const std::vector< std::string > &moduleNames)
 
void generateNeuronUpdate (CodeStream &os, const ModelSpecInternal &model, const BackendBase &backend, bool standaloneModules)
 
void generateRunner (CodeStream &definitions, CodeStream &definitionsInternal, CodeStream &runner, const ModelSpecInternal &model, const BackendBase &backend, int localHostID)
 
void generateSupportCode (CodeStream &os, const ModelSpecInternal &model)
 
void generateSynapseUpdate (CodeStream &os, const ModelSpecInternal &model, const BackendBase &backend, bool standaloneModules)
 

Detailed Description

Helper class for generating code - automatically inserts brackets, indents etc.

Based heavily on: https://stackoverflow.com/questions/15053753/writing-a-manipulator-for-a-custom-stream-class

Typedef Documentation

◆ DerivedParamNameIterCtx

◆ ExtraGlobalParamNameIterCtx

◆ VarNameIterCtx

Function Documentation

◆ checkUnreplacedVariables()

void CodeGenerator::checkUnreplacedVariables ( const std::string &  code,
const std::string &  codeName 
)

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

◆ ensureFtype()

std::string CodeGenerator::ensureFtype ( const std::string &  oldcode,
const std::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 CodeGenerator::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))

◆ generateAll()

std::vector< std::string > CodeGenerator::generateAll ( const ModelSpecInternal model,
const BackendBase backend,
const filesystem::path &  outputPath,
bool  standaloneModules = false 
)

◆ generateInit()

void CodeGenerator::generateInit ( CodeStream os,
const ModelSpecInternal model,
const BackendBase backend,
bool  standaloneModules 
)

◆ generateMakefile()

void CodeGenerator::generateMakefile ( std::ostream &  os,
const BackendBase backend,
const std::vector< std::string > &  moduleNames 
)

◆ generateMPI()

void CodeGenerator::generateMPI ( CodeStream os,
const ModelSpecInternal model,
const BackendBase backend,
bool  standaloneModules 
)

A function that generates predominantly MPI infrastructure code.

In this function MPI infrastructure code are generated, including: MPI send and receive functions.

◆ generateMSBuild()

void CodeGenerator::generateMSBuild ( std::ostream &  os,
const BackendBase backend,
const std::string &  projectGUID,
const std::vector< std::string > &  moduleNames 
)

◆ generateNeuronUpdate()

void CodeGenerator::generateNeuronUpdate ( CodeStream os,
const ModelSpecInternal model,
const BackendBase backend,
bool  standaloneModules 
)

◆ generateRunner()

void CodeGenerator::generateRunner ( CodeStream definitions,
CodeStream definitionsInternal,
CodeStream runner,
const ModelSpecInternal model,
const BackendBase backend,
int  localHostID 
)

◆ generateSupportCode()

void CodeGenerator::generateSupportCode ( CodeStream os,
const ModelSpecInternal model 
)

◆ generateSynapseUpdate()

void CodeGenerator::generateSynapseUpdate ( CodeStream os,
const ModelSpecInternal model,
const BackendBase backend,
bool  standaloneModules 
)

◆ name_substitutions() [1/2]

template<typename NameIter >
void CodeGenerator::name_substitutions ( std::string &  code,
const std::string &  prefix,
NameIter  namesBegin,
NameIter  namesEnd,
const std::string &  postfix = "",
const std::string &  ext = "" 
)
inline

This function performs a list of name substitutions for variables in code snippets.

◆ name_substitutions() [2/2]

void CodeGenerator::name_substitutions ( std::string &  code,
const std::string &  prefix,
const std::vector< std::string > &  names,
const std::string &  postfix = "",
const std::string &  ext = "" 
)
inline

This function performs a list of name substitutions for variables in code snippets.

◆ neuronSubstitutionsInSynapticCode()

void CodeGenerator::neuronSubstitutionsInSynapticCode ( std::string &  wCode,
const SynapseGroupInternal sg,
const std::string &  preIdx,
const std::string &  postIdx,
const std::string &  devPrefix,
double  dt,
const std::string &  preVarPrefix = "",
const std::string &  preVarSuffix = "",
const std::string &  postVarPrefix = "",
const std::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)

◆ operator<<() [1/2]

std::ostream & CodeGenerator::operator<< ( std::ostream &  s,
const CodeStream::OB ob 
)

◆ operator<<() [2/2]

std::ostream & CodeGenerator::operator<< ( std::ostream &  s,
const CodeStream::CB cb 
)

◆ postNeuronSubstitutionsInSynapticCode()

void CodeGenerator::postNeuronSubstitutionsInSynapticCode ( std::string &  wCode,
const SynapseGroupInternal sg,
const std::string &  offset,
const std::string &  backPropDelayOffset,
const std::string &  preIdx,
const std::string &  devPrefix,
const std::string &  postVarPrefix = "",
const std::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 CodeGenerator::preNeuronSubstitutionsInSynapticCode ( std::string &  wCode,
const SynapseGroupInternal sg,
const std::string &  offset,
const std::string &  axonalDelayOffset,
const std::string &  postIdx,
const std::string &  devPrefix,
const std::string &  preVarPrefix = "",
const std::string &  preVarSuffix = "" 
)

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

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

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 CodeGenerator::regexFuncSubstitute ( std::string &  s,
const std::string &  trg,
const std::string &  rep 
)

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

◆ regexVarSubstitute()

bool CodeGenerator::regexVarSubstitute ( std::string &  s,
const std::string &  trg,
const std::string &  rep 
)

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

◆ substitute()

void CodeGenerator::substitute ( std::string &  s,
const std::string &  trg,
const std::string &  rep 
)

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

◆ value_substitutions() [1/2]

template<typename NameIter >
void CodeGenerator::value_substitutions ( std::string &  code,
NameIter  namesBegin,
NameIter  namesEnd,
const std::vector< double > &  values,
const std::string &  ext = "" 
)
inline

This function performs a list of value substitutions for parameters in code snippets.

◆ value_substitutions() [2/2]

void CodeGenerator::value_substitutions ( std::string &  code,
const std::vector< std::string > &  names,
const std::vector< double > &  values,
const std::string &  ext = "" 
)
inline

This function performs a list of value substitutions for parameters in code snippets.

◆ writePreciseString() [1/2]

template<class T , typename std::enable_if< std::is_floating_point< T >::value >::type * = nullptr>
void CodeGenerator::writePreciseString ( std::ostream &  os,
value 
)

This function writes a floating point value to a stream -setting the precision so no digits are lost.

◆ writePreciseString() [2/2]

template<class T , typename std::enable_if< std::is_floating_point< T >::value >::type * = nullptr>
std::string CodeGenerator::writePreciseString ( value)

This function writes a floating point value to a string - setting the precision so no digits are lost.