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

#include <backendBase.h>

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

Classes

struct  ReductionTarget
 Simple struct to hold reduction targets. More...
 

Public Types

typedef std::function< void(CodeStream &)> HostHandler
 
typedef std::function< void(CodeStream &, Substitutions &)> Handler
 
template<typename T >
using GroupHandler = std::function< void(CodeStream &, const T &, Substitutions &)>
 
typedef std::vector< std::pair< std::string, size_t > > MemorySpaces
 Vector of prefixes required to allocate in memory space and size of memory space. More...
 

Public Member Functions

 BackendBase (const std::string &scalarType, const PreferencesBase &preferences)
 
virtual ~BackendBase ()
 
virtual void genNeuronUpdate (CodeStream &os, const ModelSpecMerged &modelMerged, HostHandler preambleHandler, HostHandler pushEGPHandler) const =0
 Generate platform-specific function to update the state of all neurons. More...
 
virtual void genSynapseUpdate (CodeStream &os, const ModelSpecMerged &modelMerged, HostHandler preambleHandler, HostHandler pushEGPHandler) const =0
 Generate platform-specific function to update the state of all synapses. More...
 
virtual void genCustomUpdate (CodeStream &os, const ModelSpecMerged &modelMerged, HostHandler preambleHandler, HostHandler pushEGPHandler) const =0
 Generate platform-specific functions to perform custom updates. More...
 
virtual void genInit (CodeStream &os, const ModelSpecMerged &modelMerged, HostHandler preambleHandler, HostHandler initPushEGPHandler, HostHandler initSparsePushEGPHandler) const =0
 Generate platform-specific function to initialise model. More...
 
virtual size_t getSynapticMatrixRowStride (const SynapseGroupInternal &sg) const =0
 Gets the stride used to access synaptic matrix rows, taking into account sparse data structure, padding etc. More...
 
virtual void genDefinitionsPreamble (CodeStream &os, const ModelSpecMerged &modelMerged) 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 ModelSpecMerged &modelMerged) 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 ModelSpecMerged &modelMerged, const MemAlloc &memAlloc) const =0
 
virtual void genAllocateMemPreamble (CodeStream &os, const ModelSpecMerged &modelMerged, const MemAlloc &memAlloc) const =0
 
virtual void genFreeMemPreamble (CodeStream &os, const ModelSpecMerged &modelMerged) const =0
 
virtual void genStepTimeFinalisePreamble (CodeStream &os, const ModelSpecMerged &modelMerged) 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, MemAlloc &memAlloc) const =0
 
virtual void genVariableFree (CodeStream &os, const std::string &name, VarLocation loc) const =0
 
virtual void genExtraGlobalParamDefinition (CodeStream &definitions, CodeStream &definitionsInternal, 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 std::string &countVarName="count", const std::string &prefix="") const =0
 
virtual void genExtraGlobalParamPush (CodeStream &os, const std::string &type, const std::string &name, VarLocation loc, const std::string &countVarName="count", const std::string &prefix="") const =0
 
virtual void genExtraGlobalParamPull (CodeStream &os, const std::string &type, const std::string &name, VarLocation loc, const std::string &countVarName="count", const std::string &prefix="") const =0
 
virtual void genMergedExtraGlobalParamPush (CodeStream &os, const std::string &suffix, size_t mergedGroupIdx, const std::string &groupIdx, const std::string &fieldName, const std::string &egpName) const =0
 Generate code for pushing an updated EGP value into the merged group structure on 'device'. More...
 
virtual std::string getMergedGroupFieldHostType (const std::string &type) const =0
 When generating function calls to push to merged groups, backend without equivalent of Unified Virtual Addressing e.g. OpenCL 1.2 may use different types on host. More...
 
virtual std::string getMergedGroupSimRNGType () const =0
 When generating merged structures what type to use for simulation RNGs. More...
 
virtual void genPopVariableInit (CodeStream &os, const Substitutions &kernelSubs, Handler handler) const =0
 
virtual void genVariableInit (CodeStream &os, const std::string &count, const std::string &indexVarName, const Substitutions &kernelSubs, Handler handler) const =0
 
virtual void genSparseSynapseVariableRowInit (CodeStream &os, const Substitutions &kernelSubs, Handler handler) const =0
 
virtual void genDenseSynapseVariableRowInit (CodeStream &os, const Substitutions &kernelSubs, Handler handler) const =0
 
virtual void genKernelSynapseVariableInit (CodeStream &os, const SynapseInitGroupMerged &sg, const Substitutions &kernelSubs, Handler handler) const =0
 
virtual void genKernelCustomUpdateVariableInit (CodeStream &os, const CustomWUUpdateInitGroupMerged &cu, const Substitutions &kernelSubs, Handler handler) const =0
 
virtual void genVariablePush (CodeStream &os, const std::string &type, const std::string &name, VarLocation loc, bool autoInitialized, size_t count) const =0
 Generate code for pushing a variable to the 'device'. More...
 
virtual void genVariablePull (CodeStream &os, const std::string &type, const std::string &name, VarLocation loc, size_t count) const =0
 Generate code for pulling a variable from the 'device'. More...
 
virtual void genCurrentVariablePush (CodeStream &os, const NeuronGroupInternal &ng, const std::string &type, const std::string &name, VarLocation loc, unsigned int batchSize) const =0
 Generate code for pushing a variable's value in the current timestep to the 'device'. More...
 
virtual void genCurrentVariablePull (CodeStream &os, const NeuronGroupInternal &ng, const std::string &type, const std::string &name, VarLocation loc, unsigned int batchSize) const =0
 Generate code for pulling a variable's value in the current timestep from the 'device'. More...
 
virtual void genCurrentTrueSpikePush (CodeStream &os, const NeuronGroupInternal &ng, unsigned int batchSize) const =0
 Generate code for pushing true spikes emitted by a neuron group in the current timestep to the 'device'. More...
 
virtual void genCurrentTrueSpikePull (CodeStream &os, const NeuronGroupInternal &ng, unsigned int batchSize) const =0
 Generate code for pulling true spikes emitted by a neuron group in the current timestep from the 'device'. More...
 
virtual void genCurrentSpikeLikeEventPush (CodeStream &os, const NeuronGroupInternal &ng, unsigned int batchSize) const =0
 Generate code for pushing spike-like events emitted by a neuron group in the current timestep to the 'device'. More...
 
virtual void genCurrentSpikeLikeEventPull (CodeStream &os, const NeuronGroupInternal &ng, unsigned int batchSize) const =0
 Generate code for pulling spike-like events emitted by a neuron group in the current timestep from the 'device'. More...
 
virtual void genGlobalDeviceRNG (CodeStream &definitions, CodeStream &definitionsInternal, CodeStream &runner, CodeStream &allocations, CodeStream &free, MemAlloc &memAlloc) const =0
 Generate a single RNG instance. More...
 
virtual void genPopulationRNG (CodeStream &definitions, CodeStream &definitionsInternal, CodeStream &runner, CodeStream &allocations, CodeStream &free, const std::string &name, size_t count, MemAlloc &memAlloc) const =0
 Generate an RNG with a state per population member. More...
 
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 genReturnFreeDeviceMemoryBytes (CodeStream &os) const =0
 Generate code to return amount of free 'device' memory in bytes. More...
 
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 getAllocateMemParams (const ModelSpecMerged &) const
 Get backend-specific allocate memory parameters. More...
 
virtual std::vector< filesystem::path > getFilesToCopy (const ModelSpecMerged &) const
 Get list of files to copy into generated code. More...
 
virtual std::string getDeviceVarPrefix () const
 
virtual std::string getHostVarPrefix () const
 
virtual std::string getPointerPrefix () const
 Different backends may have different or no pointer prefix (e.g. __global for OpenCL) More...
 
virtual bool isDeviceScalarRequired () const =0
 Should 'scalar' variables be implemented on device or can host variables be used directly? More...
 
virtual bool isGlobalHostRNGRequired (const ModelSpecMerged &modelMerged) const =0
 Different backends use different RNGs for different things. Does this one require a global host RNG for the specified model? More...
 
virtual bool isGlobalDeviceRNGRequired (const ModelSpecMerged &modelMerged) const =0
 Different backends use different RNGs for different things. Does this one require a global device RNG for the specified model? More...
 
virtual bool isPopulationRNGRequired () const =0
 Different backends use different RNGs for different things. Does this one require population RNGs? More...
 
virtual bool isPopulationRNGInitialisedOnDevice () const =0
 Different backends seed RNGs in different ways. Does this one initialise population RNGS on device? More...
 
virtual bool isPostsynapticRemapRequired () const =0
 Different backends may implement synaptic plasticity differently. Does this one require a postsynaptic remapping data structure? More...
 
virtual bool isHostReductionRequired () const =0
 Backends which support batch-parallelism might require an additional host reduction phase after reduction kernels. More...
 
virtual size_t getDeviceMemoryBytes () const =0
 How many bytes of memory does 'device' have. More...
 
virtual MemorySpaces getMergedGroupMemorySpaces (const ModelSpecMerged &modelMerged) const =0
 
virtual bool supportsNamespace () const =0
 Does this backend support namespaces i.e. can C++ implementation of support functions be used. More...
 
virtual boost::uuids::detail::sha1::digest_type getHashDigest () const =0
 Get hash digest of this backends identification and the preferences it has been configured with. More...
 
void genVariablePushPull (CodeStream &push, CodeStream &pull, const std::string &type, const std::string &name, VarLocation loc, bool autoInitialized, size_t count) const
 Helper function to generate matching push and pull functions for a variable. More...
 
void genCurrentVariablePushPull (CodeStream &push, CodeStream &pull, const NeuronGroupInternal &ng, const std::string &type, const std::string &name, VarLocation loc, unsigned int batchSize) const
 Helper function to generate matching push and pull functions for the current state of 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, MemAlloc &memAlloc) const
 Helper function to generate matching definition, declaration, allocation and free code for an array. More...
 
size_t getSize (const std::string &type) const
 Get the size of the type. More...
 
std::string getLowestValue (const std::string &type) const
 Get the lowest value of a type. More...
 
std::string getScalarAddressPrefix () const
 Get the prefix for accessing the address of 'scalar' variables. More...
 
bool areSixtyFourBitSynapseIndicesRequired (const SynapseGroupMergedBase &sg) const
 
const PreferencesBasegetPreferences () const
 
template<typename T >
const T & getPreferences () const
 

Protected Member Functions

void addType (const std::string &type, size_t size, const std::string &lowestValue="")
 
void setPointerBytes (size_t pointerBytes)
 
void genNeuronIndexCalculation (CodeStream &os, const NeuronUpdateGroupMerged &ng, unsigned int batchSize) const
 
void genSynapseIndexCalculation (CodeStream &os, const SynapseGroupMergedBase &sg, unsigned int batchSize) const
 
void genCustomUpdateIndexCalculation (CodeStream &os, const CustomUpdateGroupMerged &cu) const
 
std::vector< ReductionTargetgenInitReductionTargets (CodeStream &os, const CustomUpdateGroupMerged &cg, const std::string &idx="") const
 
std::vector< ReductionTargetgenInitReductionTargets (CodeStream &os, const CustomUpdateWUGroupMerged &cg, const std::string &idx="") const
 

Member Typedef Documentation

◆ GroupHandler

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

◆ Handler

◆ HostHandler

typedef std::function<void(CodeStream &)> CodeGenerator::BackendBase::HostHandler

◆ MemorySpaces

typedef std::vector<std::pair<std::string, size_t> > CodeGenerator::BackendBase::MemorySpaces

Vector of prefixes required to allocate in memory space and size of memory space.

Constructor & Destructor Documentation

◆ BackendBase()

CodeGenerator::BackendBase::BackendBase ( const std::string &  scalarType,
const PreferencesBase preferences 
)

◆ ~BackendBase()

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

Member Function Documentation

◆ addType()

void CodeGenerator::BackendBase::addType ( const std::string &  type,
size_t  size,
const std::string &  lowestValue = "" 
)
inlineprotected

◆ areSixtyFourBitSynapseIndicesRequired()

bool CodeGenerator::BackendBase::areSixtyFourBitSynapseIndicesRequired ( const SynapseGroupMergedBase sg) const

◆ genAllocateMemPreamble()

virtual void CodeGenerator::BackendBase::genAllocateMemPreamble ( CodeStream os,
const ModelSpecMerged modelMerged,
const MemAlloc memAlloc 
) 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, CodeGenerator::OpenCL::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,
MemAlloc memAlloc 
) 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,
unsigned int  batchSize 
) const
pure virtual

Generate code for pulling spike-like events emitted by a neuron group in the current timestep from the 'device'.

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

◆ genCurrentSpikeLikeEventPush()

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

Generate code for pushing spike-like events emitted by a neuron group in the current timestep to the 'device'.

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

◆ genCurrentTrueSpikePull()

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

Generate code for pulling true spikes emitted by a neuron group in the current timestep from the 'device'.

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

◆ genCurrentTrueSpikePush()

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

Generate code for pushing true spikes emitted by a neuron group in the current timestep to the 'device'.

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

◆ genCurrentVariablePull()

virtual void CodeGenerator::BackendBase::genCurrentVariablePull ( CodeStream os,
const NeuronGroupInternal ng,
const std::string &  type,
const std::string &  name,
VarLocation  loc,
unsigned int  batchSize 
) const
pure virtual

Generate code for pulling a variable's value in the current timestep from the 'device'.

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

◆ genCurrentVariablePush()

virtual void CodeGenerator::BackendBase::genCurrentVariablePush ( CodeStream os,
const NeuronGroupInternal ng,
const std::string &  type,
const std::string &  name,
VarLocation  loc,
unsigned int  batchSize 
) const
pure virtual

Generate code for pushing a variable's value in the current timestep to the 'device'.

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

◆ genCurrentVariablePushPull()

void CodeGenerator::BackendBase::genCurrentVariablePushPull ( CodeStream push,
CodeStream pull,
const NeuronGroupInternal ng,
const std::string &  type,
const std::string &  name,
VarLocation  loc,
unsigned int  batchSize 
) const
inline

Helper function to generate matching push and pull functions for the current state of a variable.

◆ genCustomUpdate()

virtual void CodeGenerator::BackendBase::genCustomUpdate ( CodeStream os,
const ModelSpecMerged modelMerged,
HostHandler  preambleHandler,
HostHandler  pushEGPHandler 
) const
pure virtual

Generate platform-specific functions to perform custom updates.

Parameters
osCodeStream to write function to
modelMergedmerged model to generate code for
preambleHandlercallback to write functions for pushing extra-global parameters
pushEGPHandlercallback to write required extra-global parameter pushing code to start of customUpdate function

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

◆ genCustomUpdateIndexCalculation()

void CodeGenerator::BackendBase::genCustomUpdateIndexCalculation ( CodeStream os,
const CustomUpdateGroupMerged cu 
) const
protected

◆ genDefinitionsInternalPreamble()

virtual void CodeGenerator::BackendBase::genDefinitionsInternalPreamble ( CodeStream os,
const ModelSpecMerged modelMerged 
) 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, CodeGenerator::OpenCL::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ genDefinitionsPreamble()

virtual void CodeGenerator::BackendBase::genDefinitionsPreamble ( CodeStream os,
const ModelSpecMerged modelMerged 
) 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, CodeGenerator::OpenCL::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ genDenseSynapseVariableRowInit()

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

◆ genExtraGlobalParamAllocation()

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

◆ genExtraGlobalParamDefinition()

virtual void CodeGenerator::BackendBase::genExtraGlobalParamDefinition ( CodeStream definitions,
CodeStream definitionsInternal,
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,
VarLocation  loc,
const std::string &  countVarName = "count",
const std::string &  prefix = "" 
) const
pure virtual

◆ genExtraGlobalParamPush()

virtual void CodeGenerator::BackendBase::genExtraGlobalParamPush ( CodeStream os,
const std::string &  type,
const std::string &  name,
VarLocation  loc,
const std::string &  countVarName = "count",
const std::string &  prefix = "" 
) const
pure virtual

◆ genFreeMemPreamble()

virtual void CodeGenerator::BackendBase::genFreeMemPreamble ( CodeStream os,
const ModelSpecMerged modelMerged 
) const
pure virtual

Free memory is called by usercode to free all memory allocatd by GeNN and should only ever be called once. This function generates a 'preamble' to this function, for example to free backend-specific objects

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

◆ genGlobalDeviceRNG()

virtual void CodeGenerator::BackendBase::genGlobalDeviceRNG ( CodeStream definitions,
CodeStream definitionsInternal,
CodeStream runner,
CodeStream allocations,
CodeStream free,
MemAlloc memAlloc 
) const
pure virtual

Generate a single RNG instance.

On single-threaded platforms this can be a standard RNG like M.T. but, on parallel platforms, it is likely to be a counter-based RNG

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

◆ genInit()

virtual void CodeGenerator::BackendBase::genInit ( CodeStream os,
const ModelSpecMerged modelMerged,
HostHandler  preambleHandler,
HostHandler  initPushEGPHandler,
HostHandler  initSparsePushEGPHandler 
) const
pure virtual

Generate platform-specific function to initialise model.

Parameters
osCodeStream to write function to
modelMergedmerged model to generate code for
preambleHandlercallback to write functions for pushing extra-global parameters
initPushEGPHandlercallback to write required extra-global parameter pushing code to start of initialize function
initSparsePushEGPHandlercallback to write required extra-global parameter pushing code to start of initializeSparse function

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

◆ genInitReductionTargets() [1/2]

std::vector< BackendBase::ReductionTarget > CodeGenerator::BackendBase::genInitReductionTargets ( CodeStream os,
const CustomUpdateGroupMerged cg,
const std::string &  idx = "" 
) const
protected

Helper function to generate initialisation code for any reduction operations carried out be custom update group. Returns vector of ReductionTarget structs, providing all information to write back reduction results to memory

◆ genInitReductionTargets() [2/2]

std::vector< BackendBase::ReductionTarget > CodeGenerator::BackendBase::genInitReductionTargets ( CodeStream os,
const CustomUpdateWUGroupMerged cg,
const std::string &  idx = "" 
) const
protected

Helper function to generate initialisation code for any reduction operations carried out be custom weight update group. //! Returns vector of ReductionTarget structs, providing all information to write back reduction results to memory

◆ genKernelCustomUpdateVariableInit()

virtual void CodeGenerator::BackendBase::genKernelCustomUpdateVariableInit ( CodeStream os,
const CustomWUUpdateInitGroupMerged cu,
const Substitutions kernelSubs,
Handler  handler 
) const
pure virtual

◆ genKernelSynapseVariableInit()

virtual void CodeGenerator::BackendBase::genKernelSynapseVariableInit ( CodeStream os,
const SynapseInitGroupMerged sg,
const Substitutions kernelSubs,
Handler  handler 
) 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, CodeGenerator::OpenCL::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, CodeGenerator::OpenCL::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, CodeGenerator::OpenCL::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ genMergedExtraGlobalParamPush()

virtual void CodeGenerator::BackendBase::genMergedExtraGlobalParamPush ( CodeStream os,
const std::string &  suffix,
size_t  mergedGroupIdx,
const std::string &  groupIdx,
const std::string &  fieldName,
const std::string &  egpName 
) const
pure virtual

Generate code for pushing an updated EGP value into the merged group structure on 'device'.

Implemented in CodeGenerator::CUDA::Backend, CodeGenerator::OpenCL::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, CodeGenerator::OpenCL::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, CodeGenerator::OpenCL::Backend, and CodeGenerator::SingleThreadedCPU::Backend.

◆ genNeuronIndexCalculation()

void CodeGenerator::BackendBase::genNeuronIndexCalculation ( CodeStream os,
const NeuronUpdateGroupMerged ng,
unsigned int  batchSize 
) const
protected

◆ genNeuronUpdate()

virtual void CodeGenerator::BackendBase::genNeuronUpdate ( CodeStream os,
const ModelSpecMerged modelMerged,
HostHandler  preambleHandler,
HostHandler  pushEGPHandler 
) const
pure virtual

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

Parameters
osCodeStream to write function to
modelMergedmerged model to generate code for
preambleHandlercallback to write functions for pushing extra-global parameters
pushEGPHandlercallback to write required extra-global parameter pushing code to start of neuronUpdate function

Implemented in CodeGenerator::CUDA::Backend, CodeGenerator::OpenCL::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,
MemAlloc memAlloc 
) const
pure virtual

Generate an RNG with a state per population member.

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

◆ genPopVariableInit()

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

◆ genReturnFreeDeviceMemoryBytes()

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

Generate code to return amount of free 'device' memory in bytes.

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

◆ genRunnerPreamble()

virtual void CodeGenerator::BackendBase::genRunnerPreamble ( CodeStream os,
const ModelSpecMerged modelMerged,
const MemAlloc memAlloc 
) const
pure virtual

◆ genSparseSynapseVariableRowInit()

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

◆ genStepTimeFinalisePreamble()

virtual void CodeGenerator::BackendBase::genStepTimeFinalisePreamble ( CodeStream os,
const ModelSpecMerged modelMerged 
) const
pure virtual

◆ genSynapseIndexCalculation()

void CodeGenerator::BackendBase::genSynapseIndexCalculation ( CodeStream os,
const SynapseGroupMergedBase sg,
unsigned int  batchSize 
) const
protected

◆ genSynapseUpdate()

virtual void CodeGenerator::BackendBase::genSynapseUpdate ( CodeStream os,
const ModelSpecMerged modelMerged,
HostHandler  preambleHandler,
HostHandler  pushEGPHandler 
) const
pure virtual

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

Parameters
osCodeStream to write function to
modelMergedmerged model to generate code for
preambleHandlercallback to write functions for pushing extra-global parameters
pushEGPHandlercallback to write required extra-global parameter pushing code to start of synapseUpdate function

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

◆ 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,
MemAlloc memAlloc 
) 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,
const std::string &  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,
VarLocation  loc,
size_t  count 
) const
pure virtual

Generate code for pulling a variable from the 'device'.

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

◆ genVariablePush()

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

Generate code for pushing a variable to the 'device'.

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

◆ genVariablePushPull()

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

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

◆ getAllocateMemParams()

virtual std::string CodeGenerator::BackendBase::getAllocateMemParams ( const ModelSpecMerged ) const
inlinevirtual

Get backend-specific allocate memory parameters.

Reimplemented in CodeGenerator::CUDA::Backend.

◆ getDeviceMemoryBytes()

virtual size_t CodeGenerator::BackendBase::getDeviceMemoryBytes ( ) const
pure virtual

How many bytes of memory does 'device' have.

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

◆ getDeviceVarPrefix()

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

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

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

◆ getFilesToCopy()

virtual std::vector<filesystem::path> CodeGenerator::BackendBase::getFilesToCopy ( const ModelSpecMerged ) const
inlinevirtual

Get list of files to copy into generated code.

Paths should be relative to share/genn/backends/

Reimplemented in CodeGenerator::OpenCL::Backend.

◆ getHashDigest()

virtual boost::uuids::detail::sha1::digest_type CodeGenerator::BackendBase::getHashDigest ( ) const
pure virtual

Get hash digest of this backends identification and the preferences it has been configured with.

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

◆ getHostVarPrefix()

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

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

Reimplemented in CodeGenerator::OpenCL::Backend.

◆ getLowestValue()

std::string CodeGenerator::BackendBase::getLowestValue ( const std::string &  type) const

Get the lowest value of a type.

◆ getMergedGroupFieldHostType()

virtual std::string CodeGenerator::BackendBase::getMergedGroupFieldHostType ( const std::string &  type) const
pure virtual

When generating function calls to push to merged groups, backend without equivalent of Unified Virtual Addressing e.g. OpenCL 1.2 may use different types on host.

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

◆ getMergedGroupMemorySpaces()

virtual MemorySpaces CodeGenerator::BackendBase::getMergedGroupMemorySpaces ( const ModelSpecMerged modelMerged) const
pure virtual

Some backends will have additional small, fast, memory spaces for read-only data which might Be well-suited to storing merged group structs. This method returns the prefix required to Place arrays in these and their size in preferential order

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

◆ getMergedGroupSimRNGType()

virtual std::string CodeGenerator::BackendBase::getMergedGroupSimRNGType ( ) const
pure virtual

When generating merged structures what type to use for simulation RNGs.

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

◆ getPointerPrefix()

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

Different backends may have different or no pointer prefix (e.g. __global for OpenCL)

Reimplemented in CodeGenerator::OpenCL::Backend.

◆ getPreferences() [1/2]

const PreferencesBase& CodeGenerator::BackendBase::getPreferences ( ) const
inline

◆ getPreferences() [2/2]

template<typename T >
const T& CodeGenerator::BackendBase::getPreferences ( ) const
inline

◆ getScalarAddressPrefix()

std::string CodeGenerator::BackendBase::getScalarAddressPrefix ( ) const
inline

Get the prefix for accessing the address of 'scalar' variables.

◆ getSize()

size_t CodeGenerator::BackendBase::getSize ( const std::string &  type) const

Get the size of the type.

◆ getSynapticMatrixRowStride()

virtual size_t CodeGenerator::BackendBase::getSynapticMatrixRowStride ( const SynapseGroupInternal sg) const
pure virtual

Gets the stride used to access synaptic matrix rows, taking into account sparse data structure, padding etc.

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

◆ isDeviceScalarRequired()

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

Should 'scalar' variables be implemented on device or can host variables be used directly?

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

◆ isGlobalDeviceRNGRequired()

virtual bool CodeGenerator::BackendBase::isGlobalDeviceRNGRequired ( const ModelSpecMerged modelMerged) const
pure virtual

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

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

◆ isGlobalHostRNGRequired()

virtual bool CodeGenerator::BackendBase::isGlobalHostRNGRequired ( const ModelSpecMerged modelMerged) const
pure virtual

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

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

◆ isHostReductionRequired()

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

Backends which support batch-parallelism might require an additional host reduction phase after reduction kernels.

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

◆ isPopulationRNGInitialisedOnDevice()

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

Different backends seed RNGs in different ways. Does this one initialise population RNGS on device?

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

◆ isPopulationRNGRequired()

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

Different backends use different RNGs for different things. Does this one require population RNGs?

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

◆ isPostsynapticRemapRequired()

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

Different backends may implement synaptic plasticity differently. Does this one require a postsynaptic remapping data structure?

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

◆ setPointerBytes()

void CodeGenerator::BackendBase::setPointerBytes ( size_t  pointerBytes)
inlineprotected

◆ supportsNamespace()

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

Does this backend support namespaces i.e. can C++ implementation of support functions be used.

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


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