namespace CodeGenerator¶
Overview¶
Helper class for generating code - automatically inserts brackets, indents etc. More…
namespace CodeGenerator { // namespaces namespace CodeGenerator::CUDA; namespace CodeGenerator::CUDA::Optimiser; namespace CodeGenerator::CUDA::PresynapticUpdateStrategy; namespace CodeGenerator::CUDA::Utils; namespace CodeGenerator::SingleThreadedCPU; namespace CodeGenerator::SingleThreadedCPU::Optimiser; // typedefs typedef NameIterCtx<Models::Base::VarVec> VarNameIterCtx; typedef NameIterCtx<Snippet::Base::EGPVec> EGPNameIterCtx; typedef NameIterCtx<Snippet::Base::DerivedParamVec> DerivedParamNameIterCtx; typedef NameIterCtx<Snippet::Base::ParamValVec> ParamValIterCtx; // structs struct FunctionTemplate; template <typename Container> struct NameIterCtx; struct PreferencesBase; // classes class BackendBase; class CodeStream; class MemAlloc; template <typename BaseIter> class StructNameConstIter; class Substitutions; class TeeBuf; class TeeStream; // global functions void substitute(std::string& s, const std::string& trg, const std::string& rep); bool regexVarSubstitute(std::string& s, const std::string& trg, const std::string& rep); bool regexFuncSubstitute(std::string& s, const std::string& trg, const std::string& rep); void functionSubstitute( std::string& code, const std::string& funcName, unsigned int numParams, const std::string& replaceFuncTemplate ); 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 = "" ); void name_substitutions( std::string& code, const std::string& prefix, const std::vector<std::string>& names, const std::string& postfix = "", const std::string& ext = "" ); template < class T, typename std::enable_if< std::is_floating_point< T >::value >::type * = nullptr > void writePreciseString( std::ostream& os, T value ); template < class T, typename std::enable_if< std::is_floating_point< T >::value >::type * = nullptr > std::string writePreciseString(T value); template <typename NameIter> void value_substitutions( std::string& code, NameIter namesBegin, NameIter namesEnd, const std::vector<double>& values, const std::string& ext = "" ); void value_substitutions( std::string& code, const std::vector<std::string>& names, const std::vector<double>& values, const std::string& ext = "" ); std::string ensureFtype(const std::string& oldcode, const std::string& type); void checkUnreplacedVariables(const std::string& code, const std::string& codeName); 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 = "" ); 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 = "" ); 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 = "" ); 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); 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 ); MemAlloc 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 ); } // namespace CodeGenerator
Detailed Documentation¶
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
Global 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.
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.
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.
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))
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.
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.
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.
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.
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.
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.
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).
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.
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)
Function for performing the code and value substitutions necessary to insert neuron related variables, parameters, and extraGlobal parameters into synaptic code.
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)
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.
suffix to be used for postsynaptic variable accesses - typically combined with prefix to wrap in function call such as __ldg(&XXX)
void GENN_EXPORT 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.