GeNN  4.0.0
GPU enhanced Neuronal Networks (GeNN)
CodeGenerator::BackendBase Class Referenceabstract

#include <backendBase.h>

Inheritance diagram for CodeGenerator::BackendBase:
CodeGenerator::CUDA::Backend CodeGenerator::SingleThreadedCPU::Backend

Public Types

typedef std::function< void(CodeStream &, Substitutions &)> Handler
 
template<typename T >
using GroupHandler = std::function< void(CodeStream &, const T &, Substitutions &)>
 
typedef GroupHandler< NeuronGroupInternalNeuronGroupHandler
 Standard callback type which provides a CodeStream to write platform-independent code for the specified NeuronGroup to. More...
 
typedef GroupHandler< SynapseGroupInternalSynapseGroupHandler
 Standard callback type which provides a CodeStream to write platform-independent code for the specified SynapseGroup to. More...
 
typedef std::function< void(CodeStream &, const NeuronGroupInternal &, Substitutions &, NeuronGroupHandler, NeuronGroupHandler)> NeuronGroupSimHandler
 Callback function type for generation neuron group simulation code. More...
 

Public Member Functions

 BackendBase (int localHostID)
 
virtual ~BackendBase ()
 
virtual void genNeuronUpdate (CodeStream &os, const ModelSpecInternal &model, NeuronGroupSimHandler simHandler, NeuronGroupHandler wuVarUpdateHandler) const =0
 Generate platform-specific function to update the state of all neurons. More...
 
virtual void genSynapseUpdate (CodeStream &os, const ModelSpecInternal &model, SynapseGroupHandler wumThreshHandler, SynapseGroupHandler wumSimHandler, SynapseGroupHandler wumEventHandler, SynapseGroupHandler postLearnHandler, SynapseGroupHandler synapseDynamicsHandler) const =0
 Generate platform-specific function to update the state of all synapses. More...
 
virtual void genInit (CodeStream &os, const ModelSpecInternal &model, NeuronGroupHandler localNGHandler, NeuronGroupHandler remoteNGHandler, SynapseGroupHandler sgDenseInitHandler, SynapseGroupHandler sgSparseConnectHandler, SynapseGroupHandler sgSparseInitHandler) const =0
 
virtual void genDefinitionsPreamble (CodeStream &os) const =0
 Definitions is the usercode-facing header file for the generated code. This function generates a 'preamble' to this header file. More...
 
virtual void genDefinitionsInternalPreamble (CodeStream &os) const =0
 Definitions internal is the internal header file for the generated code. This function generates a 'preamble' to this header file. More...
 
virtual void genRunnerPreamble (CodeStream &os) const =0
 
virtual void genAllocateMemPreamble (CodeStream &os, const ModelSpecInternal &model) const =0
 
virtual void genStepTimeFinalisePreamble (CodeStream &os, const ModelSpecInternal &model) const =0
 After all timestep logic is complete. More...
 
virtual void genVariableDefinition (CodeStream &definitions, CodeStream &definitionsInternal, const std::string &type, const std::string &name, VarLocation loc) const =0
 
virtual void genVariableImplementation (CodeStream &os, const std::string &type, const std::string &name, VarLocation loc) const =0
 
virtual void genVariableAllocation (CodeStream &os, const std::string &type, const std::string &name, VarLocation loc, size_t count) const =0
 
virtual void genVariableFree (CodeStream &os, const std::string &name, VarLocation loc) const =0
 
virtual void genExtraGlobalParamDefinition (CodeStream &definitions, const std::string &type, const std::string &name, VarLocation loc) const =0
 
virtual void genExtraGlobalParamImplementation (CodeStream &os, const std::string &type, const std::string &name, VarLocation loc) const =0
 
virtual void genExtraGlobalParamAllocation (CodeStream &os, const std::string &type, const std::string &name, VarLocation loc) const =0
 
virtual void genExtraGlobalParamPush (CodeStream &os, const std::string &type, const std::string &name) const =0
 
virtual void genExtraGlobalParamPull (CodeStream &os, const std::string &type, const std::string &name) const =0
 
virtual void genPopVariableInit (CodeStream &os, VarLocation loc, const Substitutions &kernelSubs, Handler handler) const =0
 
virtual void genVariableInit (CodeStream &os, VarLocation loc, size_t count, const std::string &indexVarName, const Substitutions &kernelSubs, Handler handler) const =0
 
virtual void genSynapseVariableRowInit (CodeStream &os, VarLocation loc, const SynapseGroupInternal &sg, const Substitutions &kernelSubs, Handler handler) const =0
 
virtual void genVariablePush (CodeStream &os, const std::string &type, const std::string &name, bool autoInitialized, size_t count) const =0
 
virtual void genVariablePull (CodeStream &os, const std::string &type, const std::string &name, size_t count) const =0
 
virtual void genCurrentTrueSpikePush (CodeStream &os, const NeuronGroupInternal &ng) const =0
 
virtual void genCurrentTrueSpikePull (CodeStream &os, const NeuronGroupInternal &ng) const =0
 
virtual void genCurrentSpikeLikeEventPush (CodeStream &os, const NeuronGroupInternal &ng) const =0
 
virtual void genCurrentSpikeLikeEventPull (CodeStream &os, const NeuronGroupInternal &ng) const =0
 
virtual void genGlobalRNG (CodeStream &definitions, CodeStream &definitionsInternal, CodeStream &runner, CodeStream &allocations, CodeStream &free, const ModelSpecInternal &model) const =0
 
virtual void genPopulationRNG (CodeStream &definitions, CodeStream &definitionsInternal, CodeStream &runner, CodeStream &allocations, CodeStream &free, const std::string &name, size_t count) const =0
 
virtual void genTimer (CodeStream &definitions, CodeStream &definitionsInternal, CodeStream &runner, CodeStream &allocations, CodeStream &free, CodeStream &stepTimeFinalise, const std::string &name, bool updateInStepTime) const =0
 
virtual void genMakefilePreamble (std::ostream &os) const =0
 This function can be used to generate a preamble for the GNU makefile used to build. More...
 
virtual void genMakefileLinkRule (std::ostream &os) const =0
 
virtual void genMakefileCompileRule (std::ostream &os) const =0
 
virtual void genMSBuildConfigProperties (std::ostream &os) const =0
 
virtual void genMSBuildImportProps (std::ostream &os) const =0
 
virtual void genMSBuildItemDefinitions (std::ostream &os) const =0
 
virtual void genMSBuildCompileModule (const std::string &moduleName, std::ostream &os) const =0
 
virtual void genMSBuildImportTarget (std::ostream &os) const =0
 
virtual std::string getVarPrefix () const
 
virtual bool isGlobalRNGRequired (const ModelSpecInternal &model) const =0
 Different backends use different RNGs for different things. Does this one require a global RNG for the specified model? More...
 
virtual bool isSynRemapRequired () const =0
 
virtual bool isPostsynapticRemapRequired () const =0
 
void genVariablePushPull (CodeStream &push, CodeStream &pull, const std::string &type, const std::string &name, bool autoInitialized, size_t count) const
 Helper function to generate matching push and pull functions for a variable. More...
 
void genArray (CodeStream &definitions, CodeStream &definitionsInternal, CodeStream &runner, CodeStream &allocations, CodeStream &free, const std::string &type, const std::string &name, VarLocation loc, size_t count) const
 Helper function to generate matching definition, declaration, allocation and free code for an array. More...
 
void genScalar (CodeStream &definitions, CodeStream &definitionsInternal, CodeStream &runner, const std::string &type, const std::string &name, VarLocation loc) const
 Helper function to generate matching definition and declaration code for a scalar variable. More...
 
int getLocalHostID () const
 Gets ID of local host backend is building code for. More...
 

Member Typedef Documentation

◆ GroupHandler

template<typename T >
using CodeGenerator::BackendBase::GroupHandler = std::function <void(CodeStream &, const T &, Substitutions&)>

◆ Handler

◆ NeuronGroupHandler

Standard callback type which provides a CodeStream to write platform-independent code for the specified NeuronGroup to.

◆ NeuronGroupSimHandler

Callback function type for generation neuron group simulation code.

Provides additional callbacks to insert code to emit spikes

◆ SynapseGroupHandler

Standard callback type which provides a CodeStream to write platform-independent code for the specified SynapseGroup to.

Constructor & Destructor Documentation

◆ BackendBase()

CodeGenerator::BackendBase::BackendBase ( int  localHostID)
inline

◆ ~BackendBase()

virtual CodeGenerator::BackendBase::~BackendBase ( )
inlinevirtual

Member Function Documentation

◆ genAllocateMemPreamble()

virtual void CodeGenerator::BackendBase::genAllocateMemPreamble ( CodeStream os,
const ModelSpecInternal model 
) const
pure virtual

Allocate memory is the first function in GeNN generated code called by usercode and it should only ever be called once. Therefore it's a good place for any global initialisation. This function generates a 'preamble' to this function.

Implemented in CodeGenerator::CUDA::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ genArray()

void CodeGenerator::BackendBase::genArray ( CodeStream definitions,
CodeStream definitionsInternal,
CodeStream runner,
CodeStream allocations,
CodeStream free,
const std::string &  type,
const std::string &  name,
VarLocation  loc,
size_t  count 
) const
inline

Helper function to generate matching definition, declaration, allocation and free code for an array.

◆ genCurrentSpikeLikeEventPull()

virtual void CodeGenerator::BackendBase::genCurrentSpikeLikeEventPull ( CodeStream os,
const NeuronGroupInternal ng 
) const
pure virtual

◆ genCurrentSpikeLikeEventPush()

virtual void CodeGenerator::BackendBase::genCurrentSpikeLikeEventPush ( CodeStream os,
const NeuronGroupInternal ng 
) const
pure virtual

◆ genCurrentTrueSpikePull()

virtual void CodeGenerator::BackendBase::genCurrentTrueSpikePull ( CodeStream os,
const NeuronGroupInternal ng 
) const
pure virtual

◆ genCurrentTrueSpikePush()

virtual void CodeGenerator::BackendBase::genCurrentTrueSpikePush ( CodeStream os,
const NeuronGroupInternal ng 
) const
pure virtual

◆ genDefinitionsInternalPreamble()

virtual void CodeGenerator::BackendBase::genDefinitionsInternalPreamble ( CodeStream os) const
pure virtual

Definitions internal is the internal header file for the generated code. This function generates a 'preamble' to this header file.

This will only be included by the platform-specific compiler used to build this backend so can include platform-specific types or headers

Implemented in CodeGenerator::CUDA::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ genDefinitionsPreamble()

virtual void CodeGenerator::BackendBase::genDefinitionsPreamble ( CodeStream os) const
pure virtual

Definitions is the usercode-facing header file for the generated code. This function generates a 'preamble' to this header file.

This will be included from a standard C++ compiler so shouldn't include any platform-specific types or headers

Implemented in CodeGenerator::CUDA::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ genExtraGlobalParamAllocation()

virtual void CodeGenerator::BackendBase::genExtraGlobalParamAllocation ( CodeStream os,
const std::string &  type,
const std::string &  name,
VarLocation  loc 
) const
pure virtual

◆ genExtraGlobalParamDefinition()

virtual void CodeGenerator::BackendBase::genExtraGlobalParamDefinition ( CodeStream definitions,
const std::string &  type,
const std::string &  name,
VarLocation  loc 
) const
pure virtual

◆ genExtraGlobalParamImplementation()

virtual void CodeGenerator::BackendBase::genExtraGlobalParamImplementation ( CodeStream os,
const std::string &  type,
const std::string &  name,
VarLocation  loc 
) const
pure virtual

◆ genExtraGlobalParamPull()

virtual void CodeGenerator::BackendBase::genExtraGlobalParamPull ( CodeStream os,
const std::string &  type,
const std::string &  name 
) const
pure virtual

◆ genExtraGlobalParamPush()

virtual void CodeGenerator::BackendBase::genExtraGlobalParamPush ( CodeStream os,
const std::string &  type,
const std::string &  name 
) const
pure virtual

◆ genGlobalRNG()

virtual void CodeGenerator::BackendBase::genGlobalRNG ( CodeStream definitions,
CodeStream definitionsInternal,
CodeStream runner,
CodeStream allocations,
CodeStream free,
const ModelSpecInternal model 
) const
pure virtual

◆ genInit()

virtual void CodeGenerator::BackendBase::genInit ( CodeStream os,
const ModelSpecInternal model,
NeuronGroupHandler  localNGHandler,
NeuronGroupHandler  remoteNGHandler,
SynapseGroupHandler  sgDenseInitHandler,
SynapseGroupHandler  sgSparseConnectHandler,
SynapseGroupHandler  sgSparseInitHandler 
) const
pure virtual

◆ genMakefileCompileRule()

virtual void CodeGenerator::BackendBase::genMakefileCompileRule ( std::ostream &  os) const
pure virtual

The GNU make build system uses 'pattern rules' (https://www.gnu.org/software/make/manual/html_node/Pattern-Intro.html) to build backend modules into objects. This function should generate a GNU make pattern rule capable of building each module (i.e. compiling .cc file $< into .o file $@).

Implemented in CodeGenerator::CUDA::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ genMakefileLinkRule()

virtual void CodeGenerator::BackendBase::genMakefileLinkRule ( std::ostream &  os) const
pure virtual

The GNU make build system will populate a variable called with a list of objects to link. This function should generate a GNU make rule to build these objects into a shared library.

Implemented in CodeGenerator::CUDA::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ genMakefilePreamble()

virtual void CodeGenerator::BackendBase::genMakefilePreamble ( std::ostream &  os) const
pure virtual

This function can be used to generate a preamble for the GNU makefile used to build.

Implemented in CodeGenerator::CUDA::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ genMSBuildCompileModule()

virtual void CodeGenerator::BackendBase::genMSBuildCompileModule ( const std::string &  moduleName,
std::ostream &  os 
) const
pure virtual

◆ genMSBuildConfigProperties()

virtual void CodeGenerator::BackendBase::genMSBuildConfigProperties ( std::ostream &  os) const
pure virtual

In MSBuild, 'properties' are used to configure global project settings e.g. whether the MSBuild project builds a static or dynamic library This function can be used to add additional XML properties to this section.

see https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-properties for more information.

Implemented in CodeGenerator::CUDA::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ genMSBuildImportProps()

virtual void CodeGenerator::BackendBase::genMSBuildImportProps ( std::ostream &  os) const
pure virtual

◆ genMSBuildImportTarget()

virtual void CodeGenerator::BackendBase::genMSBuildImportTarget ( std::ostream &  os) const
pure virtual

◆ genMSBuildItemDefinitions()

virtual void CodeGenerator::BackendBase::genMSBuildItemDefinitions ( std::ostream &  os) const
pure virtual

In MSBuild, the 'item definitions' are used to override the default properties of 'items' such as <ClCompile> or <Link>. This function should generate XML to correctly configure the 'items' required to build the generated code, taking into account etc.

see https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-items#item-definitions for more information.

Implemented in CodeGenerator::CUDA::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ genNeuronUpdate()

virtual void CodeGenerator::BackendBase::genNeuronUpdate ( CodeStream os,
const ModelSpecInternal model,
NeuronGroupSimHandler  simHandler,
NeuronGroupHandler  wuVarUpdateHandler 
) const
pure virtual

Generate platform-specific function to update the state of all neurons.

Parameters
osCodeStream to write function to
modelmodel to generate code for
simHandlercallback to write platform-independent code to update an individual NeuronGroup
wuVarUpdateHandlercallback to write platform-independent code to update pre and postsynaptic weight update model variables when neuron spikes

Implemented in CodeGenerator::CUDA::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ genPopulationRNG()

virtual void CodeGenerator::BackendBase::genPopulationRNG ( CodeStream definitions,
CodeStream definitionsInternal,
CodeStream runner,
CodeStream allocations,
CodeStream free,
const std::string &  name,
size_t  count 
) const
pure virtual

◆ genPopVariableInit()

virtual void CodeGenerator::BackendBase::genPopVariableInit ( CodeStream os,
VarLocation  loc,
const Substitutions kernelSubs,
Handler  handler 
) const
pure virtual

◆ genRunnerPreamble()

virtual void CodeGenerator::BackendBase::genRunnerPreamble ( CodeStream os) const
pure virtual

◆ genScalar()

void CodeGenerator::BackendBase::genScalar ( CodeStream definitions,
CodeStream definitionsInternal,
CodeStream runner,
const std::string &  type,
const std::string &  name,
VarLocation  loc 
) const
inline

Helper function to generate matching definition and declaration code for a scalar variable.

◆ genStepTimeFinalisePreamble()

virtual void CodeGenerator::BackendBase::genStepTimeFinalisePreamble ( CodeStream os,
const ModelSpecInternal model 
) const
pure virtual

After all timestep logic is complete.

Implemented in CodeGenerator::CUDA::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ genSynapseUpdate()

virtual void CodeGenerator::BackendBase::genSynapseUpdate ( CodeStream os,
const ModelSpecInternal model,
SynapseGroupHandler  wumThreshHandler,
SynapseGroupHandler  wumSimHandler,
SynapseGroupHandler  wumEventHandler,
SynapseGroupHandler  postLearnHandler,
SynapseGroupHandler  synapseDynamicsHandler 
) const
pure virtual

Generate platform-specific function to update the state of all synapses.

Parameters
osCodeStream to write function to
modelmodel to generate code for
wumThreshHandlercallback to write platform-independent code to update an individual NeuronGroup
wumSimHandlercallback to write platform-independent code to process presynaptic spikes. "id_pre", "id_post" and "id_syn" variables; and either "addToInSynDelay" or "addToInSyn" function will be provided to callback via Substitutions.
wumEventHandlercallback to write platform-independent code to process presynaptic spike-like events. "id_pre", "id_post" and "id_syn" variables; and either "addToInSynDelay" or "addToInSyn" function will be provided to callback via Substitutions.
postLearnHandlercallback to write platform-independent code to process postsynaptic spikes. "id_pre", "id_post" and "id_syn" variables will be provided to callback via Substitutions.
synapseDynamicsHandlercallback to write platform-independent code to update time-driven synapse dynamics. "id_pre", "id_post" and "id_syn" variables; and either "addToInSynDelay" or "addToInSyn" function will be provided to callback via Substitutions.

Implemented in CodeGenerator::CUDA::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ genSynapseVariableRowInit()

virtual void CodeGenerator::BackendBase::genSynapseVariableRowInit ( CodeStream os,
VarLocation  loc,
const SynapseGroupInternal sg,
const Substitutions kernelSubs,
Handler  handler 
) const
pure virtual

◆ genTimer()

virtual void CodeGenerator::BackendBase::genTimer ( CodeStream definitions,
CodeStream definitionsInternal,
CodeStream runner,
CodeStream allocations,
CodeStream free,
CodeStream stepTimeFinalise,
const std::string &  name,
bool  updateInStepTime 
) const
pure virtual

◆ genVariableAllocation()

virtual void CodeGenerator::BackendBase::genVariableAllocation ( CodeStream os,
const std::string &  type,
const std::string &  name,
VarLocation  loc,
size_t  count 
) const
pure virtual

◆ genVariableDefinition()

virtual void CodeGenerator::BackendBase::genVariableDefinition ( CodeStream definitions,
CodeStream definitionsInternal,
const std::string &  type,
const std::string &  name,
VarLocation  loc 
) const
pure virtual

◆ genVariableFree()

virtual void CodeGenerator::BackendBase::genVariableFree ( CodeStream os,
const std::string &  name,
VarLocation  loc 
) const
pure virtual

◆ genVariableImplementation()

virtual void CodeGenerator::BackendBase::genVariableImplementation ( CodeStream os,
const std::string &  type,
const std::string &  name,
VarLocation  loc 
) const
pure virtual

◆ genVariableInit()

virtual void CodeGenerator::BackendBase::genVariableInit ( CodeStream os,
VarLocation  loc,
size_t  count,
const std::string &  indexVarName,
const Substitutions kernelSubs,
Handler  handler 
) const
pure virtual

◆ genVariablePull()

virtual void CodeGenerator::BackendBase::genVariablePull ( CodeStream os,
const std::string &  type,
const std::string &  name,
size_t  count 
) const
pure virtual

◆ genVariablePush()

virtual void CodeGenerator::BackendBase::genVariablePush ( CodeStream os,
const std::string &  type,
const std::string &  name,
bool  autoInitialized,
size_t  count 
) const
pure virtual

◆ genVariablePushPull()

void CodeGenerator::BackendBase::genVariablePushPull ( CodeStream push,
CodeStream pull,
const std::string &  type,
const std::string &  name,
bool  autoInitialized,
size_t  count 
) const
inline

Helper function to generate matching push and pull functions for a variable.

◆ getLocalHostID()

int CodeGenerator::BackendBase::getLocalHostID ( ) const
inline

Gets ID of local host backend is building code for.

◆ getVarPrefix()

virtual std::string CodeGenerator::BackendBase::getVarPrefix ( ) const
inlinevirtual

When backends require separate 'device' and 'host' versions of variables, they are identified with a prefix. This function returns this prefix so it can be used in otherwise platform-independent code.

Reimplemented in CodeGenerator::CUDA::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ isGlobalRNGRequired()

virtual bool CodeGenerator::BackendBase::isGlobalRNGRequired ( const ModelSpecInternal model) const
pure virtual

Different backends use different RNGs for different things. Does this one require a global RNG for the specified model?

Implemented in CodeGenerator::CUDA::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ isPostsynapticRemapRequired()

virtual bool CodeGenerator::BackendBase::isPostsynapticRemapRequired ( ) const
pure virtual

◆ isSynRemapRequired()

virtual bool CodeGenerator::BackendBase::isSynRemapRequired ( ) const
pure virtual

The documentation for this class was generated from the following file: