Skip to content

Commit

Permalink
Merge pull request #515 from genn-team/override_max_connections
Browse files Browse the repository at this point in the history
Fix max connections issues
  • Loading branch information
neworderofjamie authored Apr 28, 2022
2 parents d941d60 + 17204e4 commit a53cbca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/genn/genn/code_generator/groupMerged.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1258,10 +1258,9 @@ boost::uuids::detail::sha1::digest_type SynapseGroupMergedBase::getHashDigest(Ro
// Update hash with number of neurons in pre and postsynaptic population
updateHash([](const SynapseGroupInternal &g) { return g.getSrcNeuronGroup()->getNumNeurons(); }, hash);
updateHash([](const SynapseGroupInternal &g) { return g.getTrgNeuronGroup()->getNumNeurons(); }, hash);
updateHash([](const SynapseGroupInternal &g) { return g.getMaxConnections(); }, hash);
updateHash([](const SynapseGroupInternal &g) { return g.getMaxSourceConnections(); }, hash);
// **NOTE** ideally we'd include the row stride but this needs a backend and it SHOULDN'T be necessary
// as I can't think of any way of changing this without changing the hash in other places


if(updateRole) {
// Update hash with weight update model parameters and derived parameters
updateHash([](const SynapseGroupInternal &g) { return g.getWUParams(); }, hash);
Expand Down
22 changes: 18 additions & 4 deletions src/genn/genn/synapseGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,15 @@ void SynapseGroup::setMaxConnections(unsigned int maxConnections)
}
else {
if(getMatrixType() & SynapseMatrixConnectivity::SPARSE) {
if(m_SparseConnectivityInitialiser.getSnippet()->getCalcMaxRowLengthFunc()) {
throw std::runtime_error("setMaxConnections: Synapse group already has max connections defined by sparse connectivity initialisation snippet.");
// If sparse connectivity initialiser provides a function to calculate max row length
auto calcMaxRowLengthFunc = m_SparseConnectivityInitialiser.getSnippet()->getCalcMaxRowLengthFunc();
if(calcMaxRowLengthFunc) {
// Call function and if max connections we specify is less than the bound imposed by the snippet, give error
auto connectivityMaxRowLength = calcMaxRowLengthFunc(getSrcNeuronGroup()->getNumNeurons(), getTrgNeuronGroup()->getNumNeurons(),
m_SparseConnectivityInitialiser.getParams());
if (maxConnections < connectivityMaxRowLength) {
throw std::runtime_error("setMaxConnections: max connections must be higher than that already specified by sparse connectivity initialisation snippet.");
}
}

m_MaxConnections = maxConnections;
Expand All @@ -168,8 +175,15 @@ void SynapseGroup::setMaxSourceConnections(unsigned int maxConnections)
}
else {
if(getMatrixType() & SynapseMatrixConnectivity::SPARSE) {
if(m_SparseConnectivityInitialiser.getSnippet()->getCalcMaxColLengthFunc()) {
throw std::runtime_error("setMaxSourceConnections: Synapse group already has max source connections defined by connectivity initialisation snippet.");
// If sparse connectivity initialiser provides a function to calculate max col length
auto calcMaxColLengthFunc = m_SparseConnectivityInitialiser.getSnippet()->getCalcMaxColLengthFunc();
if (calcMaxColLengthFunc) {
// Call function and if max connections we specify is less than the bound imposed by the snippet, give error
auto connectivityMaxColLength = calcMaxColLengthFunc(getSrcNeuronGroup()->getNumNeurons(), getTrgNeuronGroup()->getNumNeurons(),
m_SparseConnectivityInitialiser.getParams());
if (maxConnections < connectivityMaxColLength) {
throw std::runtime_error("setMaxSourceConnections: max source connections must be higher than that already specified by sparse connectivity initialisation snippet.");
}
}

m_MaxSourceConnections = maxConnections;
Expand Down

0 comments on commit a53cbca

Please sign in to comment.