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

Fixed nasty race condition #414

Merged
merged 6 commits into from
Apr 21, 2021
Merged

Fixed nasty race condition #414

merged 6 commits into from
Apr 21, 2021

Conversation

neworderofjamie
Copy link
Contributor

@neworderofjamie neworderofjamie commented Apr 21, 2021

In #376 I added support for tracking 'previous' spike times. However, this generated preNeuronResetKernel code like this:

if(lid < group->spkCnt[0]) {
    group->prevST[group->spk[lid]] = t - DT;
}
        
if(lid == 0) {
    group->spkCnt[0] = 0;
}

Which has a nasty race condition in that the spike count may have been reset by the time other blocks try and access it. Presumably, this wasn't hit in our tests or the Pavlovian conditioning model because they were small enough that the whole kernel ran simultaneously. Better performing (this adds approximately 1.5 microseconds per-timestep to the Pavlovian conditioning model), more complex solutions might be possible but for now I've just split the two stages into two separate kernels which has had the side benefit of tidying up several nasty bits of the previous implementation)

@codecov
Copy link

codecov bot commented Apr 21, 2021

Codecov Report

Merging #414 (b8ad859) into master (f4240a5) will decrease coverage by 0.02%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #414      +/-   ##
==========================================
- Coverage   87.13%   87.10%   -0.03%     
==========================================
  Files          78       78              
  Lines       15245    15309      +64     
==========================================
+ Hits        13283    13335      +52     
- Misses       1962     1974      +12     
Impacted Files Coverage Δ
src/genn/backends/single_threaded_cpu/backend.cc 56.35% <47.82%> (-0.02%) ⬇️
src/genn/genn/code_generator/backendSIMT.cc 96.42% <74.02%> (-0.09%) ⬇️
include/genn/genn/code_generator/backendSIMT.h 98.48% <100.00%> (-0.05%) ⬇️
include/genn/genn/code_generator/groupMerged.h 91.15% <100.00%> (+0.08%) ⬆️
include/genn/genn/code_generator/modelSpecMerged.h 98.78% <100.00%> (+0.01%) ⬆️
src/genn/backends/cuda/backend.cc 87.85% <100.00%> (+0.17%) ⬆️
src/genn/backends/cuda/optimiser.cc 77.73% <100.00%> (-0.10%) ⬇️
src/genn/backends/opencl/backend.cc 91.11% <100.00%> (+0.19%) ⬆️
src/genn/genn/code_generator/generateRunner.cc 95.99% <100.00%> (+0.01%) ⬆️
src/genn/genn/code_generator/groupMerged.cc 87.04% <100.00%> (+0.14%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f4240a5...b8ad859. Read the comment docs.

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.

Classic trap. Glad you spotted it. Trying to think of more efficient solutions but coming up blank atm.

@neworderofjamie
Copy link
Contributor Author

Sadly not the cause of the bug that led me to fix it but hey 😄

@neworderofjamie neworderofjamie merged commit aa456d2 into master Apr 21, 2021
@neworderofjamie neworderofjamie deleted the fix_prev_st_race branch April 21, 2021 18:44
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