Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate detection of homogeneous parameters #646

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

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**
        }
    }
}

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.

1 participant