Skip to content

Comments

Automate detection of homogeneous parameters#646

Merged
neworderofjamie merged 8 commits intomasterfrom
improved_heterogeneity
Jan 6, 2025
Merged

Automate detection of homogeneous parameters#646
neworderofjamie merged 8 commits intomasterfrom
improved_heterogeneity

Conversation

@neworderofjamie
Copy link
Contributor

@neworderofjamie neworderofjamie commented Dec 3, 2024

One of the really awkward things with the initial implementation of merging groups was that we had to add a manual mechanism for detecting whether parameters (and derived parameters) were heterogeneous across the merged group or not and handle them separately. With the improved type information present in GeNN 5, it was always on my todo list to simplify and automate it so it could be applied to 'internal' parameters like number of neurons etc.

In EnvironmentGroupMergedField::addField, we now just check that the type is const, numeric and the values match (this is the key thing as, in GeNN 4, all fields basically were just strings) and if their value is the same for all groups that are being merged together, we just substitute a constant. This means for models which don't really benefit from merging i.e. ones with a small number of populations, the code will be as efficient as it was before merging was added and this removes a load of ugly boilerplate.

For example, after this change, generated code for a merged neuron update group with one 256 neuron group in looks like:

if(id >= 768 && id < 1024) {
     const unsigned int lid = id - 768;
     struct MergedNeuronUpdateGroup2 *group = &d_mergedNeuronUpdateGroup2[0]; 
     {
        const unsigned int batchOffset = 256u * batch;
        if(lid < 256u) {
             // **DO STUFF**
        }
    }
}

rather than:

if(id >= 768 && id < 1024) {
    const unsigned int lid = id - 768;
    struct MergedNeuronUpdateGroup1 *group = &d_mergedNeuronUpdateGroup2[0]; 
    {
        const unsigned int batchOffset = group->numNeurons * batch;
        if(lid < group->numNeurons) {
            // **DO STUFF**
        }
    }
}

* Added helper to check for existence of fields rather than using old heterogeneity-testing boilerplate
* Requires generating code so call code generator (with neverRebuild=true so no files get written)
* Fixed various models that don't actually compile
@codecov
Copy link

codecov bot commented Jan 3, 2025

Codecov Report

Attention: Patch coverage is 93.49593% with 8 lines in your changes missing coverage. Please review.

Project coverage is 88.94%. Comparing base (ea3f9ab) to head (ebdeeac).
Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
include/genn/genn/code_generator/environment.h 90.24% 4 Missing ⚠️
src/genn/genn/code_generator/backendBase.cc 88.23% 2 Missing ⚠️
...enn/genn/code_generator/customUpdateGroupMerged.cc 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #646      +/-   ##
==========================================
+ Coverage   87.83%   88.94%   +1.11%     
==========================================
  Files         104      106       +2     
  Lines       14104    14786     +682     
==========================================
+ Hits        12388    13152     +764     
+ Misses       1716     1634      -82     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@neworderofjamie neworderofjamie marked this pull request as ready for review January 3, 2025 15:06
Copy link
Member

@tnowotny tnowotny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sensible.

@neworderofjamie neworderofjamie merged commit e7f6c9d into master Jan 6, 2025
2 checks passed
@neworderofjamie neworderofjamie deleted the improved_heterogeneity branch January 6, 2025 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants