Skip to content

Commit

Permalink
Fix bug when indexing StateMonitor with [:3] type idnexing
Browse files Browse the repository at this point in the history
Fixes #50. Issue was the same as in PR brian-team/brian2#1119. We need
to update the monitor's `N` variable on CUDA side and we need to update
the device variable since it is copied to the host variable in
`write_arrays()`. And we need to use `WRITES_TO_READ_ONLY_VARIABLES`,
otherwise `N` will be cached in brian2 and not loaded after simulation.
  • Loading branch information
denisalevi committed Aug 6, 2021
1 parent 1a18f3f commit 28d7fd8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions brian2cuda/templates/statemonitor.cu
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ if (_num__array_{{owner.name}}__indices > 1024)
// inefficient, can we keep the t values on the host instead? Do we need them
// on the device?
dev_dynamic_array_{{owner.name}}_t.push_back({{owner.clock.name}}.t[0]);
// Update size variables for Python side indexing to work
// (Note: Need to update device variable which will be copied to host in write_arrays())
// TODO: This is one cudaMemcpy per time step, this should be done only once in the last
// time step, fix when fixing the statemonitor (currently only works for <=1024 threads)
_array_{{owner.name}}_N[0] += 1;
CUDA_SAFE_CALL(
cudaMemcpy(dev_array_{{owner.name}}_N, _array_{{owner.name}}_N, sizeof(int32_t),
cudaMemcpyHostToDevice)
);

int num_iterations = {{owner.clock.name}}.i_end;
int current_iteration = {{owner.clock.name}}.timestep[0];
Expand Down

0 comments on commit 28d7fd8

Please sign in to comment.