8 #include <unordered_map> 15 #include <plog/Severity.h> 124 m_HostBytes += rhs.m_HostBytes;
125 m_DeviceBytes += rhs.m_DeviceBytes;
126 m_ZeroCopyBytes += rhs.m_ZeroCopyBytes;
140 MemAlloc(
size_t hostBytes,
size_t deviceBytes,
size_t zeroCopyBytes)
141 : m_HostBytes(hostBytes), m_DeviceBytes(deviceBytes), m_ZeroCopyBytes(zeroCopyBytes)
149 size_t m_DeviceBytes;
150 size_t m_ZeroCopyBytes;
161 out << m.m_HostBytes <<
" " << m.m_DeviceBytes <<
" " << m.m_ZeroCopyBytes;
168 in >> m.m_DeviceBytes;
169 in >> m.m_ZeroCopyBytes;
184 typedef std::function<void(CodeStream &, Substitutions&)>
Handler;
187 using GroupHandler = std::function <void(CodeStream &, const T &, Substitutions&)> ;
204 HostHandler preambleHandler, HostHandler pushEGPHandler)
const = 0;
212 HostHandler preambleHandler, HostHandler pushEGPHandler)
const = 0;
220 HostHandler preambleHandler, HostHandler pushEGPHandler)
const = 0;
229 HostHandler preambleHandler, HostHandler initPushEGPHandler, HostHandler initSparsePushEGPHandler)
const = 0;
255 virtual void genVariableDefinition(
CodeStream &definitions,
CodeStream &definitionsInternal,
const std::string &type,
const std::string &name,
VarLocation loc)
const = 0;
256 virtual void genVariableImplementation(
CodeStream &os,
const std::string &type,
const std::string &name,
VarLocation loc)
const = 0;
257 virtual void genVariableAllocation(
CodeStream &os,
const std::string &type,
const std::string &name,
VarLocation loc,
size_t count,
MemAlloc &memAlloc)
const = 0;
260 virtual void genExtraGlobalParamDefinition(
CodeStream &definitions,
CodeStream &definitionsInternal,
const std::string &type,
const std::string &name,
VarLocation loc)
const = 0;
261 virtual void genExtraGlobalParamImplementation(
CodeStream &os,
const std::string &type,
const std::string &name,
VarLocation loc)
const = 0;
262 virtual void genExtraGlobalParamAllocation(
CodeStream &os,
const std::string &type,
const std::string &name,
263 VarLocation loc,
const std::string &countVarName =
"count",
const std::string &prefix =
"")
const = 0;
264 virtual void genExtraGlobalParamPush(
CodeStream &os,
const std::string &type,
const std::string &name,
265 VarLocation loc,
const std::string &countVarName =
"count",
const std::string &prefix =
"")
const = 0;
266 virtual void genExtraGlobalParamPull(
CodeStream &os,
const std::string &type,
const std::string &name,
267 VarLocation loc,
const std::string &countVarName =
"count",
const std::string &prefix =
"")
const = 0;
270 virtual void genMergedExtraGlobalParamPush(
CodeStream &os,
const std::string &suffix,
size_t mergedGroupIdx,
271 const std::string &groupIdx,
const std::string &fieldName,
272 const std::string &egpName)
const = 0;
275 virtual std::string getMergedGroupFieldHostType(
const std::string &type)
const = 0;
278 virtual std::string getMergedGroupSimRNGType()
const = 0;
281 virtual void genVariableInit(
CodeStream &os,
const std::string &count,
const std::string &indexVarName,
283 virtual void genSparseSynapseVariableRowInit(
CodeStream &os,
const Substitutions &kernelSubs, Handler handler)
const = 0;
284 virtual void genDenseSynapseVariableRowInit(
CodeStream &os,
const Substitutions &kernelSubs, Handler handler)
const = 0;
289 virtual void genVariablePush(
CodeStream &os,
const std::string &type,
const std::string &name,
VarLocation loc,
bool autoInitialized,
size_t count)
const = 0;
292 virtual void genVariablePull(
CodeStream &os,
const std::string &type,
const std::string &name,
VarLocation loc,
size_t count)
const = 0;
296 const std::string &name,
VarLocation loc,
unsigned int batchSize)
const = 0;
300 const std::string &name,
VarLocation loc,
unsigned int batchSize)
const = 0;
321 CodeStream &free,
const std::string &name,
size_t count,
MemAlloc &memAlloc)
const = 0;
324 CodeStream &stepTimeFinalise,
const std::string &name,
bool updateInStepTime)
const = 0;
327 virtual void genReturnFreeDeviceMemoryBytes(
CodeStream &os)
const = 0;
330 virtual void genMakefilePreamble(std::ostream &os)
const = 0;
334 virtual void genMakefileLinkRule(std::ostream &os)
const = 0;
338 virtual void genMakefileCompileRule(std::ostream &os)
const = 0;
343 virtual void genMSBuildConfigProperties(std::ostream &os)
const = 0;
344 virtual void genMSBuildImportProps(std::ostream &os)
const = 0;
349 virtual void genMSBuildItemDefinitions(std::ostream &os)
const = 0;
350 virtual void genMSBuildCompileModule(
const std::string &moduleName, std::ostream &os)
const = 0;
351 virtual void genMSBuildImportTarget(std::ostream &os)
const = 0;
372 virtual bool isDeviceScalarRequired()
const = 0;
375 virtual bool isGlobalHostRNGRequired(
const ModelSpecMerged &modelMerged)
const = 0;
378 virtual bool isGlobalDeviceRNGRequired(
const ModelSpecMerged &modelMerged)
const = 0;
381 virtual bool isPopulationRNGRequired()
const = 0;
384 virtual bool isPopulationRNGInitialisedOnDevice()
const = 0;
387 virtual bool isPostsynapticRemapRequired()
const = 0;
390 virtual bool isHostReductionRequired()
const = 0;
393 virtual size_t getDeviceMemoryBytes()
const = 0;
398 virtual MemorySpaces getMergedGroupMemorySpaces(
const ModelSpecMerged &modelMerged)
const = 0;
401 virtual bool supportsNamespace()
const = 0;
404 virtual boost::uuids::detail::sha1::digest_type getHashDigest()
const = 0;
411 const std::string &type,
const std::string &name,
VarLocation loc,
bool autoInitialized,
size_t count)
const 413 genVariablePush(push, type, name, loc, autoInitialized, count);
414 genVariablePull(pull, type, name, loc, count);
419 const std::string &name,
VarLocation loc,
unsigned int batchSize)
const 421 genCurrentVariablePush(push, ng, type, name, loc, batchSize);
422 genCurrentVariablePull(pull, ng, type, name, loc, batchSize);
427 const std::string &type,
const std::string &name,
VarLocation loc,
size_t count,
MemAlloc &memAlloc)
const 429 genVariableDefinition(definitions, definitionsInternal, type +
"*", name, loc);
430 genVariableImplementation(runner, type +
"*", name, loc);
431 genVariableFree(free, name, loc);
432 genVariableAllocation(allocations, type, name, loc, count, memAlloc);
436 size_t getSize(
const std::string &type)
const;
439 std::string getLowestValue(
const std::string &type)
const;
444 return isDeviceScalarRequired() ? getDeviceVarPrefix() : (
"&" + getDeviceVarPrefix());
452 const T &
getPreferences()
const {
return static_cast<const T &
>(m_Preferences); }
462 : name(n), type(t), access(a), index(i)
475 void addType(
const std::string &type,
size_t size,
const std::string &lowestValue =
"")
477 m_Types.emplace(std::piecewise_construct, std::forward_as_tuple(type),
478 std::forward_as_tuple(size, lowestValue));
483 m_PointerBytes = pointerBytes;
504 template<
typename G,
typename R>
505 std::vector<ReductionTarget> genInitReductionTargets(
CodeStream &os,
const G &cg,
const std::string &idx, R getVarRefIndexFn)
const 508 std::vector<ReductionTarget> reductionTargets;
509 const auto *cm = cg.getArchetype().getCustomUpdateModel();
510 for (
const auto &v : cm->getVars()) {
520 const auto modelVarRefs = cm->getVarRefs();
521 const auto &varRefs = cg.getArchetype().getVarReferences();
522 for (
size_t i = 0; i < varRefs.size(); i++) {
523 const auto varRef = varRefs.at(i);
524 const auto modelVarRef = modelVarRefs.at(i);
528 os << modelVarRef.type <<
" lr" << modelVarRef.name <<
" = " <<
getReductionInitialValue(*
this, modelVarRef.access, modelVarRef.type) <<
";" << std::endl;
529 reductionTargets.emplace_back(modelVarRef.name, modelVarRef.type, modelVarRef.access,
530 getVarRefIndexFn(varRef, idx));
533 return reductionTargets;
541 size_t m_PointerBytes;
545 std::unordered_map<std::string, std::pair<size_t, std::string>> m_Types;
Definition: neuronGroupInternal.h:9
std::string getScalarAddressPrefix() const
Get the prefix for accessing the address of 'scalar' variables.
Definition: backendBase.h:442
VarAccessMode
Supported combination of VarAccessModeAttribute.
Definition: varAccess.h:19
size_t getHostMBytes() const
Definition: backendBase.h:116
size_t getDeviceBytes() const
Definition: backendBase.h:114
VarLocation
< Flags defining which memory space variables should be allocated in
Definition: variableMode.h:10
Definition: initGroupMerged.h:298
Definition: customUpdateGroupMerged.h:12
Definition: groupMerged.h:1021
std::ostream & operator<<(std::ostream &out, const MemAlloc &m)
Definition: backendBase.h:159
void addType(const std::string &type, size_t size, const std::string &lowestValue="")
Definition: backendBase.h:475
const std::string index
Definition: backendBase.h:469
bool automaticCopy
If backend/device supports it, copy data automatically when required rather than requiring push and p...
Definition: backendBase.h:71
ReductionTarget(const std::string &n, const std::string &t, VarAccessMode a, const std::string &i)
Definition: backendBase.h:461
#define GENN_EXPORT
Definition: gennExport.h:13
Definition: synapseUpdateGroupMerged.h:85
size_t getDeviceMBytes() const
Definition: backendBase.h:117
Base class for backend preferences - can be accessed via a global in 'classic' C++ code generator...
Definition: backendBase.h:58
static MemAlloc host(size_t hostBytes)
Definition: backendBase.h:134
bool generateExtraGlobalParamPull
Should GeNN generate pull functions for extra global parameters? These are very rarely used...
Definition: backendBase.h:77
Definition: modelSpecMerged.h:31
Helper class for generating code - automatically inserts brackets, indents etc.
Definition: backendBase.h:30
bool generateEmptyStatePushPull
Should GeNN generate empty state push and pull functions.
Definition: backendBase.h:74
size_t getZeroCopyBytes() const
Definition: backendBase.h:115
Definition: initGroupMerged.h:386
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...
Definition: backendBase.h:418
std::vector< std::pair< std::string, size_t > > MemorySpaces
Vector of prefixes required to allocate in memory space and size of memory space. ...
Definition: backendBase.h:190
Definition: synapseGroupInternal.h:9
std::istream & operator>>(std::istream &in, MemAlloc &m)
Definition: backendBase.h:165
Definition: codeStream.h:21
bool enableBitmaskOptimisations
Definition: backendBase.h:68
Definition: backendBase.h:107
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...
Definition: backendBase.h:426
Definition: substitutions.h:21
VarAccessMode getVarAccessMode(VarAccess type)
Definition: varAccess.h:74
const T & getPreferences() const
Definition: backendBase.h:452
Definition: synapseUpdateGroupMerged.h:52
Definition: initGroupMerged.h:132
void updateHash(const T &value, boost::uuids::detail::sha1 &hash)
Hash arithmetic types and enums.
Definition: gennUtils.h:128
static MemAlloc zero()
Definition: backendBase.h:133
Definition: initGroupMerged.h:11
Definition: backendBase.h:176
static MemAlloc zeroCopy(size_t zeroCopyBytes)
Definition: backendBase.h:137
std::function< void(CodeStream &)> HostHandler
Definition: backendBase.h:182
bool debugCode
Generate code with debug symbols.
Definition: backendBase.h:64
Definition: initGroupMerged.h:329
std::string userCxxFlagsGNU
C++ compiler options to be used for building all host side code (used for unix based platforms) ...
Definition: backendBase.h:84
Simple struct to hold reduction targets.
Definition: backendBase.h:459
Definition: customUpdateInternal.h:41
virtual std::string getHostVarPrefix() const
Definition: backendBase.h:366
Definition: neuronUpdateGroupMerged.h:11
void updateHash(boost::uuids::detail::sha1 &hash) const
Definition: backendBase.h:92
Definition: initGroupMerged.h:164
static MemAlloc device(size_t deviceBytes)
Definition: backendBase.h:136
Definition: initGroupMerged.h:100
const VarAccessMode access
Definition: backendBase.h:468
Definition: customUpdateGroupMerged.h:125
void setPointerBytes(size_t pointerBytes)
Definition: backendBase.h:481
std::function< void(CodeStream &, const T &, Substitutions &)> GroupHandler
Definition: backendBase.h:187
size_t getZeroCopyMBytes() const
Definition: backendBase.h:118
virtual ~BackendBase()
Definition: backendBase.h:193
plog::Severity logLevel
Logging level to use for code generation.
Definition: backendBase.h:90
std::string userNvccFlagsGNU
NVCC compiler options they may want to use for all GPU code (used for unix based platforms) ...
Definition: backendBase.h:87
virtual std::string getPointerPrefix() const
Different backends may have different or no pointer prefix (e.g. __global for OpenCL) ...
Definition: backendBase.h:369
Definition: customUpdateInternal.h:9
MemAlloc & operator+=(const MemAlloc &rhs)
Definition: backendBase.h:123
bool includeModelNameInDLL
Definition: backendBase.h:81
const std::string name
Definition: backendBase.h:466
virtual std::string getAllocateMemParams(const ModelSpecMerged &) const
Get backend-specific allocate memory parameters.
Definition: backendBase.h:354
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.
Definition: backendBase.h:410
VarAccessDuplication getVarAccessDuplication(VarAccess type)
Definition: varAccess.h:79
This variable is read-write.
Definition: synapseUpdateGroupMerged.h:15
size_t getHostBytes() const
Definition: backendBase.h:113
const std::string type
Definition: backendBase.h:467
GENN_EXPORT std::string getReductionInitialValue(const BackendBase &backend, VarAccessMode access, const std::string &type)
Get the initial value to start reduction operations from.
Definition: codeGenUtils.cc:470
static MemAlloc hostDevice(size_t bytes)
Definition: backendBase.h:135
Definition: customUpdateGroupMerged.h:94
virtual std::string getDeviceVarPrefix() const
Definition: backendBase.h:362
virtual std::vector< filesystem::path > getFilesToCopy(const ModelSpecMerged &) const
Get list of files to copy into generated code.
Definition: backendBase.h:358
std::function< void(CodeStream &, Substitutions &)> Handler
Definition: backendBase.h:184
bool optimizeCode
Generate speed-optimized code, potentially at the expense of floating-point accuracy.
Definition: backendBase.h:61
m
Definition: genn_model.py:117
const PreferencesBase & getPreferences() const
Definition: backendBase.h:449