SpikeMonitor fails for multiple runs
denisalevi opened this issue · 1 comments
The brian2.tests.test_spikegenerator:test_spikegenerator_change_period
currently fails because the SpikeMonitor does not correctly record the spikes during the second run
call.
I think the reason is that in main.cu
, the monitor data is copied from the device to the host. But that happens for both spikemonitor codeobjects after the second run call (there is one per run call, which operate on the same data structures). I think one is overwriting the spikes of the other instead of appending them in the result array. Is looks something like this
// second network run here
network.clear();
network.add(&defaultclock, _run_random_number_buffer);
network.add(&defaultclock, _run_spikegeneratorgroup_codeobject_1);
network.add(&defaultclock, _run_spikemonitor_codeobject_1);
CUDA_SAFE_CALL(cudaProfilerStart());
network.run(0.01, NULL, 10.0);
random_number_buffer.run_finished();
CUDA_SAFE_CALL(cudaDeviceSynchronize());
CUDA_SAFE_CALL(cudaProfilerStop());
// XXX: Copy second run's spike data first
_copyToHost_spikemonitor_codeobject_1();
_debugmsg_spikemonitor_codeobject_1();
// XXX: Copy first run's spike data afterwards, which might overwrite the first?
_copyToHost_spikemonitor_codeobject();
_debugmsg_spikemonitor_codeobject();
Same happens for test_spikegenerator_change_spikes, even if I add a different spikemonitor for each run. The test only passes if I also remove the previous spikemonitor from the network. before running again.
For each separate SpikeMonitor
, there is a separate spikemonitor codeobject with separate data. And for each run
with the same SpikeMonitor
, there is a new spikemonitor
codeobject with the same data.