when using brian2cuda, same modification on main.cu will leads to the following errors when running the 2nd iteration:
98.989 s (98%) simulated in 1m 10s, estimated 1s remaining.
100.000 s (100%) simulated in 1m 10s
Starting simulation at t=100.000 s for duration 100.000 s
ERROR: cudaMemcpy( &_num_events, &_eventspace[_num_spikespace - 1], sizeof(int32_t), cudaMemcpyDeviceToHost ) failed at code_objects/spikemonitor_codeobject.cu:395 : an illegal memory access was encountered
terminate called after throwing an instance of 'thrust::system::system_error'
what(): device free failed: driver shutting down
Is there a way to allow brian2cuda to run in a loop? The reason for question is that I’m looping over a large sample of stimuli and run, e.g. 100*ms, for each stimulus.
That said, this will be quite inefficient if you do it for many runs, due to a number of duplicated code files that have to be compiled. How are you changing the stimuli between the runs, actually? In most cases, there is no need to use multiple runs to deal with multiple stimuli, you can usually have a single run and switch stimuli via a TimedArray or a run_regularly statement: Input stimuli — Brian 2 2.5.1 documentation
When going through a loop of samples, I need to rerun a sample with different condition, e.g. stimulus rate, until the condition is satisfied before moving to the next sample. This is what we discussed in this thread:
One other option would be to use this slightly hacky approach here (the second, “sequential” script):
You do a run, check the results, change some parameter of the model, and then run the model again, without recompiling anything. This means that each run starts again from 0s, but that might not be a problem for you? You can keep, e.g., synaptic weights if you use the same mechanism to initialize them, and then set them for each run with the previous run’s values.
Hi @DavidKing2020 . Yes, this is correct, it will use 15Hz. The initialize_parameter/set_parameter_value function directly set the values in the generated C++ code which is only executed when you call run. Before that, the code on the Python side does not know what the value will be. The solution in my gist is a bit hacky, there would be ways to make this work in a more intuitive way.
However, I am not 100% sure whether it will correctly broadcast the scalar value to an array here. To be on the safe side, try to always set the array with the size of the group, e.g. here you’d use initialize_parameter(input.rates, np.ones(N)*15*Hz).