4 #include <unordered_map> 42 EGPField(
size_t m,
const std::string &t,
const std::string &f)
43 : mergedGroupIndex(m), type(t), fieldName(f) {}
60 if(other.
type < type) {
63 else if(type < other.
type) {
84 MergedEGP(
size_t m,
size_t g,
const std::string &t,
const std::string &f)
85 :
EGPField(m, t, f), groupIndex(g) {}
197 boost::uuids::detail::sha1::digest_type getHashDigest(
const BackendBase &backend)
const;
200 boost::uuids::detail::sha1::digest_type getNeuronUpdateArchetypeHashDigest()
const;
203 boost::uuids::detail::sha1::digest_type getSynapseUpdateArchetypeHashDigest()
const;
206 boost::uuids::detail::sha1::digest_type getCustomUpdateArchetypeHashDigest()
const;
209 boost::uuids::detail::sha1::digest_type getInitArchetypeHashDigest()
const;
212 bool anyPointerEGPs()
const;
225 for(
const auto &e : m_MergedEGPs) {
227 const auto groupEGPs = e.second.equal_range(T::name);
228 for(
auto g = groupEGPs.first; g != groupEGPs.second; ++g) {
232 std::to_string(g->second.groupIndex),
233 g->second.fieldName, e.first);
245 std::set<EGPField> mergedGroupFields;
246 for(
const auto &e : m_MergedEGPs) {
248 const auto groupEGPs = e.second.equal_range(T::name);
251 std::transform(groupEGPs.first, groupEGPs.second, std::inserter(mergedGroupFields, mergedGroupFields.end()),
252 [](
const MergedEGPMap::value_type::second_type::value_type &g)
259 return mergedGroupFields;
266 if(!groups.empty()) {
268 const auto mergedGroupFields = getMergedGroupFields<T>();
270 os <<
"// ------------------------------------------------------------------------" << std::endl;
271 os <<
"// merged extra global parameter functions" << std::endl;
272 os <<
"// ------------------------------------------------------------------------" << std::endl;
274 for(
auto f : mergedGroupFields) {
278 os <<
"void pushMerged" << T::name << f.mergedGroupIndex << f.fieldName <<
"ToDevice(unsigned int idx, " << backend.
getMergedGroupFieldHostType(f.type) <<
" value)";
294 void genMergedStructures(
CodeStream &os,
const BackendBase &backend,
const std::vector<T> &mergedGroups)
const 297 for(
const auto &g : mergedGroups) {
298 g.generateStruct(os, backend, T::name);
302 template<
typename Group,
typename MergedGroup,
typename D>
304 const std::vector<std::reference_wrapper<const Group>> &unmergedGroups,
305 std::vector<MergedGroup> &mergedGroups, D getHashDigest)
308 std::unordered_map<boost::uuids::detail::sha1::digest_type,
309 std::vector<std::reference_wrapper<const Group>>,
313 for(
const auto &g : unmergedGroups) {
314 protoMergedGroups[(g.get().*getHashDigest)()].push_back(g);
318 mergedGroups.reserve(protoMergedGroups.size());
322 for(
const auto &p : protoMergedGroups) {
327 for(
const auto &f : mergedGroups.back().getFields()) {
329 if(std::get<3>(f) == MergedGroup::FieldType::PointerEGP || std::get<3>(f) == MergedGroup::FieldType::ScalarEGP)
332 for(
size_t groupIndex = 0; groupIndex < mergedGroups.back().getGroups().size(); groupIndex++) {
333 const auto &g = mergedGroups.back().getGroups()[groupIndex];
338 m_MergedEGPs[std::get<2>(f)(g, groupIndex)].emplace(
339 std::piecewise_construct,
340 std::forward_as_tuple(MergedGroup::name),
341 std::forward_as_tuple(i, groupIndex, std::get<0>(f), std::get<1>(f)));
350 template<
typename Group,
typename MergedGroup,
typename F,
typename U>
352 const std::map<std::string, Group> &groups, std::vector<MergedGroup> &mergedGroups,
356 std::vector<std::reference_wrapper<const Group>> unmergedGroups;
357 for(
const auto &g : groups) {
358 if(filter(g.second)) {
359 unmergedGroups.emplace_back(std::cref(g.second));
364 createMergedGroupsHash(model, backend, unmergedGroups, mergedGroups, updateHash);
374 std::vector<NeuronUpdateGroupMerged> m_MergedNeuronUpdateGroups;
377 std::vector<PresynapticUpdateGroupMerged> m_MergedPresynapticUpdateGroups;
380 std::vector<PostsynapticUpdateGroupMerged> m_MergedPostsynapticUpdateGroups;
383 std::vector<SynapseDynamicsGroupMerged> m_MergedSynapseDynamicsGroups;
386 std::vector<NeuronInitGroupMerged> m_MergedNeuronInitGroups;
389 std::vector<CustomUpdateInitGroupMerged> m_MergedCustomUpdateInitGroups;
392 std::vector<CustomWUUpdateInitGroupMerged> m_MergedCustomWUUpdateInitGroups;
395 std::vector<SynapseInitGroupMerged> m_MergedSynapseInitGroups;
398 std::vector<SynapseConnectivityInitGroupMerged> m_MergedSynapseConnectivityInitGroups;
401 std::vector<SynapseSparseInitGroupMerged> m_MergedSynapseSparseInitGroups;
404 std::vector<CustomWUUpdateSparseInitGroupMerged> m_MergedCustomWUUpdateSparseInitGroups;
407 std::vector<NeuronSpikeQueueUpdateGroupMerged> m_MergedNeuronSpikeQueueUpdateGroups;
410 std::vector<NeuronPrevSpikeTimeUpdateGroupMerged> m_MergedNeuronPrevSpikeTimeUpdateGroups;
413 std::vector<SynapseDendriticDelayUpdateGroupMerged> m_MergedSynapseDendriticDelayUpdateGroups;
416 std::vector<SynapseConnectivityHostInitGroupMerged> m_MergedSynapseConnectivityHostInitGroups;
419 std::vector<CustomUpdateGroupMerged> m_MergedCustomUpdateGroups;
422 std::vector<CustomUpdateWUGroupMerged> m_MergedCustomUpdateWUGroups;
425 std::vector<CustomUpdateTransposeWUGroupMerged> m_MergedCustomUpdateTransposeWUGroups;
428 std::vector<CustomUpdateHostReductionGroupMerged> m_MergedCustomUpdateHostReductionGroups;
431 std::vector<CustomWUUpdateHostReductionGroupMerged> m_MergedCustomWUUpdateHostReductionGroups;
449 MergedEGPMap m_MergedEGPs;
const std::string & getNeuronUpdateSupportCodeNamespace(const std::string &code) const
Definition: modelSpecMerged.h:190
const std::string & getPostsynapticDynamicsSupportCodeNamespace(const std::string &code) const
Definition: modelSpecMerged.h:191
void genPostsynapticDynamicsSupportCode(CodeStream &os, bool supportsNamespace=true) const
Definition: modelSpecMerged.h:185
void genMergedSynapseInitGroupStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:170
const std::string fieldName
Definition: modelSpecMerged.h:47
void genSynapseDynamicsSupportCode(CodeStream &os, bool supportsNamespace=true) const
Definition: modelSpecMerged.h:188
const std::vector< SynapseConnectivityHostInitGroupMerged > & getMergedSynapseConnectivityHostInitGroups() const
Get merged synapse groups which require host code to initialise their synaptic connectivity.
Definition: modelSpecMerged.h:146
void genMergedCustomWUUpdateSparseInitGroupStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:173
void genPresynapticUpdateSupportCode(CodeStream &os, bool supportsNamespace=true) const
Definition: modelSpecMerged.h:186
void genPostsynapticUpdateSupportCode(CodeStream &os, bool supportsNamespace=true) const
Definition: modelSpecMerged.h:187
const std::vector< SynapseInitGroupMerged > & getMergedSynapseInitGroups() const
Get merged synapse groups with dense connectivity which require initialisation.
Definition: modelSpecMerged.h:125
const std::vector< CustomUpdateHostReductionGroupMerged > & getMergedCustomUpdateHostReductionGroups() const
Get merged custom update groups where host reduction needs to be performed.
Definition: modelSpecMerged.h:158
void genMergedSynapseSparseInitGroupStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:172
const std::vector< NeuronSpikeQueueUpdateGroupMerged > & getMergedNeuronSpikeQueueUpdateGroups() const
Get merged neuron groups which require their spike queues updating.
Definition: modelSpecMerged.h:137
const std::vector< NeuronUpdateGroupMerged > & getMergedNeuronUpdateGroups() const
Get merged neuron groups which require updating.
Definition: modelSpecMerged.h:104
void genMergedNeuronUpdateGroupStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:163
const std::vector< NeuronInitGroupMerged > & getMergedNeuronInitGroups() const
Get merged neuron groups which require initialisation.
Definition: modelSpecMerged.h:116
void genMergedSynapseDynamicsGroupStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:166
const std::vector< SynapseDynamicsGroupMerged > & getMergedSynapseDynamicsGroups() const
Get merged synapse groups which require synapse dynamics.
Definition: modelSpecMerged.h:113
#define GENN_EXPORT
Definition: gennExport.h:13
std::set< EGPField > getMergedGroupFields() const
Definition: modelSpecMerged.h:242
EGPField(size_t m, const std::string &t, const std::string &f)
Definition: modelSpecMerged.h:42
void genMergedNeuronInitGroupStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:167
const std::vector< SynapseConnectivityInitGroupMerged > & getMergedSynapseConnectivityInitGroups() const
Get merged synapse groups which require connectivity initialisation.
Definition: modelSpecMerged.h:128
const std::vector< SynapseDendriticDelayUpdateGroupMerged > & getMergedSynapseDendriticDelayUpdateGroups() const
Get merged synapse groups which require their dendritic delay updating.
Definition: modelSpecMerged.h:143
void genMergedGroupPush(CodeStream &os, const std::vector< T > &groups, const BackendBase &backend) const
Definition: modelSpecMerged.h:263
const std::vector< NeuronPrevSpikeTimeUpdateGroupMerged > & getMergedNeuronPrevSpikeTimeUpdateGroups() const
Get merged neuron groups which require their previous spike times updating.
Definition: modelSpecMerged.h:140
void genMergedCustomWUUpdateInitGroupStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:169
void genMergedSynapseConnectivityInitGroupStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:171
const std::string type
Definition: modelSpecMerged.h:46
Definition: modelSpecMerged.h:31
Helper class for generating code - automatically inserts brackets, indents etc.
Definition: backendBase.h:30
void genMergedCustomUpdateInitGroupStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:168
const size_t mergedGroupIndex
Definition: modelSpecMerged.h:45
Immutable structure for tracking where an extra global variable ends up after merging.
Definition: modelSpecMerged.h:82
void genMergedCustomUpdateHostReductionStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:181
void genMergedCustomWUUpdateHostReductionStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:182
const std::vector< CustomUpdateGroupMerged > & getMergedCustomUpdateGroups() const
Get merged custom updates of variables.
Definition: modelSpecMerged.h:149
void genMergedCustomUpdateTransposeWUStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:180
void genMergedCustomUpdateStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:178
Definition: codeStream.h:21
const MergedEGPDestinations & getMergedEGPDestinations(const std::string &name, const BackendBase &backend) const
Get the map of destinations within the merged data structures for a particular extra global parameter...
Definition: modelSpecMerged.h:215
const std::string & getSynapseDynamicsSupportCodeNamespace(const std::string &code) const
Definition: modelSpecMerged.h:194
std::unordered_multimap< std::string, MergedEGP > MergedEGPDestinations
Map of original extra global param names to their locations within merged structures.
Definition: modelSpecMerged.h:94
const size_t groupIndex
Definition: modelSpecMerged.h:87
std::map< std::string, MergedEGPDestinations > MergedEGPMap
Definition: modelSpecMerged.h:95
void updateHash(const T &value, boost::uuids::detail::sha1 &hash)
Hash arithmetic types and enums.
Definition: gennUtils.h:128
void genScalarEGPPush(CodeStream &os, const BackendBase &backend) const
Generate calls to update all target merged groups.
Definition: modelSpecMerged.h:222
const std::vector< CustomUpdateInitGroupMerged > & getMergedCustomUpdateInitGroups() const
Get merged custom update groups which require initialisation.
Definition: modelSpecMerged.h:119
Definition: backendBase.h:176
Functor for generating a hash suitable for use in std::unordered_map etc (i.e. size_t size) from a SH...
Definition: gennUtils.h:170
GENN_EXPORT bool isTypePointer(const std::string &type)
Function to determine whether a string containing a type is a pointer.
Definition: gennUtils.cc:75
const ModelSpecInternal & getModel() const
Get underlying, unmerged model.
Definition: modelSpecMerged.h:101
const std::string & getPostsynapticUpdateSupportCodeNamespace(const std::string &code) const
Definition: modelSpecMerged.h:193
void genMergedNeuronSpikeQueueUpdateStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:174
std::string getTimePrecision() const
Gets the floating point numerical precision used to represent time.
Definition: modelSpec.cc:50
const std::vector< PresynapticUpdateGroupMerged > & getMergedPresynapticUpdateGroups() const
Get merged synapse groups which require presynaptic updates.
Definition: modelSpecMerged.h:107
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'...
const std::vector< SynapseSparseInitGroupMerged > & getMergedSynapseSparseInitGroups() const
Get merged synapse groups with sparse connectivity which require initialisation.
Definition: modelSpecMerged.h:131
const std::vector< CustomUpdateWUGroupMerged > & getMergedCustomUpdateWUGroups() const
Get merged custom updates of weight update model variables.
Definition: modelSpecMerged.h:152
Immutable structure for tracking fields of merged group structure containing EGPs.
Definition: modelSpecMerged.h:40
const std::vector< CustomWUUpdateInitGroupMerged > & getMergedCustomWUUpdateInitGroups() const
Get merged custom updategroups with dense connectivity which require initialisation.
Definition: modelSpecMerged.h:122
Definition: modelSpecInternal.h:10
void genMergedCustomUpdateWUStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:179
void genMergedPresynapticUpdateGroupStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:164
virtual std::string getMergedGroupFieldHostType(const std::string &type) const =0
When generating function calls to push to merged groups, backend without equivalent of Unified Virtua...
void genNeuronUpdateGroupSupportCode(CodeStream &os, bool supportsNamespace=true) const
Definition: modelSpecMerged.h:184
void genMergedPostsynapticUpdateGroupStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:165
const std::vector< CustomWUUpdateHostReductionGroupMerged > & getMergedCustomWUUpdateHostReductionGroups() const
Get merged custom weight update groups where host reduction needs to be performed.
Definition: modelSpecMerged.h:161
MergedEGP(size_t m, size_t g, const std::string &t, const std::string &f)
Definition: modelSpecMerged.h:84
const std::string & getPrecision() const
Gets the floating point numerical precision.
Definition: modelSpec.h:291
const std::vector< CustomUpdateTransposeWUGroupMerged > & getMergedCustomUpdateTransposeWUGroups() const
Get merged custom weight update groups where transpose needs to be calculated.
Definition: modelSpecMerged.h:155
virtual std::string getDeviceVarPrefix() const
Definition: backendBase.h:362
Definition: supportCodeMerged.h:15
const std::vector< CustomWUUpdateSparseInitGroupMerged > & getMergedCustomWUUpdateSparseInitGroups() const
Get merged custom update groups with sparse connectivity which require initialisation.
Definition: modelSpecMerged.h:134
const std::vector< PostsynapticUpdateGroupMerged > & getMergedPostsynapticUpdateGroups() const
Get merged synapse groups which require postsynaptic updates.
Definition: modelSpecMerged.h:110
m
Definition: genn_model.py:117
const std::string & getPresynapticUpdateSupportCodeNamespace(const std::string &code) const
Definition: modelSpecMerged.h:192
void genMergedSynapseDendriticDelayUpdateStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:176
Definition: codeStream.h:94
void genMergedNeuronPrevSpikeTimeUpdateStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:175
void genMergedSynapseConnectivityHostInitStructs(CodeStream &os, const BackendBase &backend) const
Definition: modelSpecMerged.h:177