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

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

Namespaces

 CUDA
 
 OpenCL
 
 PresynapticUpdateStrategySIMT
 
 SingleThreadedCPU
 

Classes

class  BackendBase
 
class  BackendSIMT
 Base class for Single Instruction Multiple Thread style backends. More...
 
class  CodeStream
 
class  CustomUpdateGroupMerged
 
class  CustomUpdateHostReductionGroupMerged
 
class  CustomUpdateHostReductionGroupMergedBase
 
class  CustomUpdateInitGroupMerged
 
class  CustomUpdateInitGroupMergedBase
 
class  CustomUpdateTransposeWUGroupMerged
 
class  CustomUpdateWUGroupMerged
 
class  CustomUpdateWUGroupMergedBase
 
class  CustomWUUpdateHostReductionGroupMerged
 
class  CustomWUUpdateInitGroupMerged
 
class  CustomWUUpdateSparseInitGroupMerged
 
class  GroupMerged
 
class  MemAlloc
 
class  ModelSpecMerged
 
class  NeuronGroupMergedBase
 
class  NeuronInitGroupMerged
 
class  NeuronPrevSpikeTimeUpdateGroupMerged
 
class  NeuronSpikeQueueUpdateGroupMerged
 
class  NeuronUpdateGroupMerged
 
class  PostsynapticUpdateGroupMerged
 
struct  PreferencesBase
 Base class for backend preferences - can be accessed via a global in 'classic' C++ code generator. More...
 
class  PresynapticUpdateGroupMerged
 
class  Substitutions
 
class  SupportCodeMerged
 
class  SynapseConnectivityHostInitGroupMerged
 
class  SynapseConnectivityInitGroupMerged
 
class  SynapseDendriticDelayUpdateGroupMerged
 
class  SynapseDynamicsGroupMerged
 
class  SynapseGroupMergedBase
 
class  SynapseInitGroupMerged
 
class  SynapseSparseInitGroupMerged
 
class  TeeBuf
 
class  TeeStream
 

Typedefs

using KernelBlockSize = std::array< size_t, KernelMax >
 Array of block sizes for each kernel. More...
 

Enumerations

enum  Kernel {
  KernelNeuronUpdate, KernelPresynapticUpdate, KernelPostsynapticUpdate, KernelSynapseDynamicsUpdate,
  KernelInitialize, KernelInitializeSparse, KernelNeuronSpikeQueueUpdate, KernelNeuronPrevSpikeTimeUpdate,
  KernelSynapseDendriticDelayUpdate, KernelCustomUpdate, KernelCustomTransposeUpdate, KernelMax
}
 Kernels generated by SIMT backends. More...
 

Functions

std::ostream & operator<< (std::ostream &out, const MemAlloc &m)
 
std::istream & operator>> (std::istream &in, MemAlloc &m)
 
GENN_EXPORT 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...
 
GENN_EXPORT 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...
 
GENN_EXPORT 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...
 
GENN_EXPORT 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...
 
size_t ceilDivide (size_t numerator, size_t denominator)
 Divide two integers, rounding up i.e. effectively taking ceil. More...
 
size_t padSize (size_t size, size_t blockSize)
 Pad an integer to a multiple of another. More...
 
GENN_EXPORT void genTypeRange (CodeStream &os, const std::string &precision, const std::string &prefix)
 
GENN_EXPORT 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...
 
GENN_EXPORT std::string getReductionInitialValue (const BackendBase &backend, VarAccessMode access, const std::string &type)
 Get the initial value to start reduction operations from. More...
 
GENN_EXPORT std::string getReductionOperation (const std::string &reduction, const std::string &value, VarAccessMode access, const std::string &type)
 Generate a reduction operation to reduce value into reduction. More...
 
GENN_EXPORT 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...
 
GENN_EXPORT std::string disambiguateNamespaceFunction (const std::string supportCode, const std::string code, std::string namespaceName)
 This function substitutes function names in a code with namespace as prefix of the function name for backends that do not support namespaces by checking that the function indeed exists in the support code and returns the substituted code. More...
 
template<typename P , typename D , typename V , typename S >
void neuronSubstitutionsInSynapticCode (CodeGenerator::Substitutions &substitutions, const NeuronGroupInternal *archetypeNG, const std::string &delayOffset, const std::string &sourceSuffix, const std::string &destSuffix, const std::string &varPrefix, const std::string &varSuffix, bool useLocalNeuronVars, P isParamHeterogeneousFn, D isDerivedParamHeterogeneousFn, V getVarIndexFn, S getPrevSpikeTimeIndexFn)
 Function for performing the code and value substitutions necessary to insert neuron related variables, parameters, and extraGlobal parameters into synaptic code. More...
 
template<typename G , typename K >
bool isKernelSizeHeterogeneous (const G *group, size_t dimensionIndex, K getKernelSizeFn)
 
template<typename G , typename K >
std::string getKernelSize (const G *group, size_t dimensionIndex, K getKernelSizeFn)
 
template<typename G , typename K >
void genKernelIndex (const G *group, std::ostream &os, const CodeGenerator::Substitutions &subs, K getKernelSizeFn)
 
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 void generateMakefile (std::ostream &os, const BackendBase &backend, const std::vector< std::string > &moduleNames)
 
GENN_EXPORT std::pair< std::vector< std::string >, MemAllocgenerateAll (const ModelSpecInternal &model, const BackendBase &backend, const filesystem::path &sharePath, const filesystem::path &outputPath, bool forceRebuild=false)
 
GENN_EXPORT void generateNeuronUpdate (const filesystem::path &outputPath, const ModelSpecMerged &modelMerged, const BackendBase &backend, const std::string &suffix="")
 
GENN_EXPORT void generateCustomUpdate (const filesystem::path &outputPath, const ModelSpecMerged &modelMerged, const BackendBase &backend, const std::string &suffix="")
 
GENN_EXPORT void generateSynapseUpdate (const filesystem::path &outputPath, const ModelSpecMerged &modelMerged, const BackendBase &backend, const std::string &suffix="")
 
GENN_EXPORT void generateInit (const filesystem::path &outputPath, const ModelSpecMerged &modelMerged, const BackendBase &backend, const std::string &suffix="")
 
GENN_EXPORT void generateMSBuild (std::ostream &os, const ModelSpecInternal &model, const BackendBase &backend, const std::string &projectGUID, const std::vector< std::string > &moduleNames)
 
GENN_EXPORT MemAlloc generateRunner (const filesystem::path &outputPath, const ModelSpecMerged &modelMerged, const BackendBase &backend, const std::string &suffix="")
 
GENN_EXPORT void generateSupportCode (const filesystem::path &outputPath, const ModelSpecMerged &modelMerged, const std::string &suffix="")
 

Detailed Description

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

Very thin wrapper around a number of groups which have been merged together.

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

Typedef Documentation

◆ KernelBlockSize

using CodeGenerator::KernelBlockSize = typedef std::array<size_t, KernelMax>

Array of block sizes for each kernel.

Enumeration Type Documentation

◆ Kernel

Kernels generated by SIMT backends.

Enumerator
KernelNeuronUpdate 
KernelPresynapticUpdate 
KernelPostsynapticUpdate 
KernelSynapseDynamicsUpdate 
KernelInitialize 
KernelInitializeSparse 
KernelNeuronSpikeQueueUpdate 
KernelNeuronPrevSpikeTimeUpdate 
KernelSynapseDendriticDelayUpdate 
KernelCustomUpdate 
KernelCustomTransposeUpdate 
KernelMax 

Function Documentation

◆ ceilDivide()

size_t CodeGenerator::ceilDivide ( size_t  numerator,
size_t  denominator 
)
inline

Divide two integers, rounding up i.e. effectively taking ceil.

◆ 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.

◆ disambiguateNamespaceFunction()

std::string CodeGenerator::disambiguateNamespaceFunction ( const std::string  supportCode,
const std::string  code,
std::string  namespaceName 
)

This function substitutes function names in a code with namespace as prefix of the function name for backends that do not support namespaces by checking that the function indeed exists in the support code and returns the substituted code.

◆ 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::pair< std::vector< std::string >, MemAlloc > CodeGenerator::generateAll ( const ModelSpecInternal model,
const BackendBase backend,
const filesystem::path &  sharePath,
const filesystem::path &  outputPath,
bool  forceRebuild = false 
)

◆ generateCustomUpdate()

void CodeGenerator::generateCustomUpdate ( const filesystem::path &  outputPath,
const ModelSpecMerged modelMerged,
const BackendBase backend,
const std::string &  suffix = "" 
)

◆ generateInit()

void CodeGenerator::generateInit ( const filesystem::path &  outputPath,
const ModelSpecMerged modelMerged,
const BackendBase backend,
const std::string &  suffix = "" 
)

◆ generateMakefile()

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

◆ generateMSBuild()

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

◆ generateNeuronUpdate()

void CodeGenerator::generateNeuronUpdate ( const filesystem::path &  outputPath,
const ModelSpecMerged modelMerged,
const BackendBase backend,
const std::string &  suffix = "" 
)

◆ generateRunner()

MemAlloc CodeGenerator::generateRunner ( const filesystem::path &  outputPath,
const ModelSpecMerged modelMerged,
const BackendBase backend,
const std::string &  suffix = "" 
)

◆ generateSupportCode()

void CodeGenerator::generateSupportCode ( const filesystem::path &  outputPath,
const ModelSpecMerged modelMerged,
const std::string &  suffix = "" 
)

◆ generateSynapseUpdate()

void CodeGenerator::generateSynapseUpdate ( const filesystem::path &  outputPath,
const ModelSpecMerged modelMerged,
const BackendBase backend,
const std::string &  suffix = "" 
)

◆ genKernelIndex()

template<typename G , typename K >
void CodeGenerator::genKernelIndex ( const G *  group,
std::ostream &  os,
const CodeGenerator::Substitutions subs,
getKernelSizeFn 
)

◆ genTypeRange()

void CodeGenerator::genTypeRange ( CodeStream os,
const std::string &  precision,
const std::string &  prefix 
)

◆ getKernelSize()

template<typename G , typename K >
std::string CodeGenerator::getKernelSize ( const G *  group,
size_t  dimensionIndex,
getKernelSizeFn 
)

◆ getReductionInitialValue()

std::string CodeGenerator::getReductionInitialValue ( const BackendBase backend,
VarAccessMode  access,
const std::string &  type 
)

Get the initial value to start reduction operations from.

◆ getReductionOperation()

std::string CodeGenerator::getReductionOperation ( const std::string &  reduction,
const std::string &  value,
VarAccessMode  access,
const std::string &  type 
)

Generate a reduction operation to reduce value into reduction.

◆ isKernelSizeHeterogeneous()

template<typename G , typename K >
bool CodeGenerator::isKernelSizeHeterogeneous ( const G *  group,
size_t  dimensionIndex,
getKernelSizeFn 
)

◆ neuronSubstitutionsInSynapticCode()

template<typename P , typename D , typename V , typename S >
void CodeGenerator::neuronSubstitutionsInSynapticCode ( CodeGenerator::Substitutions substitutions,
const NeuronGroupInternal archetypeNG,
const std::string &  delayOffset,
const std::string &  sourceSuffix,
const std::string &  destSuffix,
const std::string &  varPrefix,
const std::string &  varSuffix,
bool  useLocalNeuronVars,
isParamHeterogeneousFn,
isDerivedParamHeterogeneousFn,
getVarIndexFn,
getPrevSpikeTimeIndexFn 
)

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

◆ operator<<() [1/3]

std::ostream& CodeGenerator::operator<< ( std::ostream &  out,
const MemAlloc m 
)
inline

◆ operator<<() [2/3]

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

◆ operator<<() [3/3]

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

◆ operator>>()

std::istream& CodeGenerator::operator>> ( std::istream &  in,
MemAlloc m 
)
inline

◆ padSize()

size_t CodeGenerator::padSize ( size_t  size,
size_t  blockSize 
)
inline

Pad an integer to a multiple of another.

◆ 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.