NEST main@caf0ae8
 
Loading...
Searching...
No Matches
slice_ring_buffer.h
Go to the documentation of this file.
1/*
2 * slice_ring_buffer.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef SLICE_RING_BUFFER_H
24#define SLICE_RING_BUFFER_H
25
26// C++ includes:
27#include <algorithm>
28#include <cassert>
29#include <functional>
30#include <vector>
31
32// Generated includes:
33#include "config.h"
34
35// Includes from nestkernel:
36#include "kernel_manager.h"
37#include "nest_types.h"
38
39namespace nest
40{
41
63{
64public:
66
75 void add_spike( const long rel_delivery, const long stamp, const double ps_offset, const double weight );
76
84 void add_refractory( const long stamp, const double ps_offset );
85
89 void prepare_delivery();
90
94 void discard_events();
95
114 bool get_next_spike( const long req_stamp,
115 bool accumulate_simultaneous,
116 double& ps_offset,
117 double& weight,
118 bool& end_of_refract );
119
123 void clear();
124
128 void resize();
129
130private:
135 {
136 SpikeInfo( long stamp, double ps_offset, double weight );
137
138 bool operator<( const SpikeInfo& b ) const;
139 bool operator<=( const SpikeInfo& b ) const;
140 bool operator>( const SpikeInfo& b ) const;
141
142 // data elements must not be const, since heap implementation
143 // in DEC STL uses operator=().
144 long stamp_; //<! spike's time stamp
145 double ps_offset_; //<! spike offset is PS sense
146 double weight_; //<! spike weight
147 };
148
150 std::vector< std::vector< SpikeInfo > > queue_;
151
153 std::vector< SpikeInfo >* deliver_;
154
156};
157
158inline void
159SliceRingBuffer::add_spike( const long rel_delivery, const long stamp, const double ps_offset, const double weight )
160{
161 const long idx = kernel().event_delivery_manager.get_slice_modulo( rel_delivery );
162 assert( static_cast< size_t >( idx ) < queue_.size() );
163 assert( ps_offset >= 0 );
164
165 queue_[ idx ].push_back( SpikeInfo( stamp, ps_offset, weight ) );
166}
167
168inline void
169SliceRingBuffer::add_refractory( const long stamp, const double ps_offset )
170{
171 // We require that only one refractory-return pseudo-event is stored per
172 // time step.
173 //
174 // We guard against violation using assert(): refract_.stamp_ must
175 // be equal to the marker value for non-refractoriness. All else would mean
176 // that a refractory neuron fired.
177 assert( refract_.stamp_ == std::numeric_limits< long >::max() );
178
179 refract_.stamp_ = stamp;
180 refract_.ps_offset_ = ps_offset;
181}
182
183inline bool
185 bool accumulate_simultaneous,
186 double& ps_offset,
187 double& weight,
188 bool& end_of_refract )
189{
190 end_of_refract = false;
191 if ( deliver_->empty() or refract_ <= deliver_->back() )
192 {
193 if ( refract_.stamp_ == req_stamp )
194 { // if relies on stamp_==long::max() if not refractory
195 // return from refractoriness
196 ps_offset = refract_.ps_offset_;
197 weight = 0;
198 end_of_refract = true;
199
200 // mark as non-refractory
201 refract_.stamp_ = std::numeric_limits< long >::max();
202 return true;
203 }
204 else
205 {
206 return false;
207 }
208 }
209 else if ( deliver_->back().stamp_ == req_stamp )
210 {
211 // we have an event to deliver
212 ps_offset = deliver_->back().ps_offset_;
213 weight = deliver_->back().weight_;
214 deliver_->pop_back();
215
216 if ( accumulate_simultaneous )
217 {
218 // add weights of all spikes with same stamp and offset
219 while (
220 not deliver_->empty() and deliver_->back().ps_offset_ == ps_offset and deliver_->back().stamp_ == req_stamp )
221 {
222 weight += deliver_->back().weight_;
223 deliver_->pop_back();
224 }
225 }
226
227 return true;
228 }
229 else
230 {
231 // ensure that we are not blocked by spike from the past, cf #404
232 assert( deliver_->back().stamp_ > req_stamp );
233 return false;
234 }
235}
236
237inline SliceRingBuffer::SpikeInfo::SpikeInfo( long stamp, double ps_offset, double weight )
238 : stamp_( stamp )
239 , ps_offset_( ps_offset )
240 , weight_( weight )
241{
242}
243
244inline bool
246{
247 return stamp_ == b.stamp_ ? ps_offset_ > b.ps_offset_ : stamp_ < b.stamp_;
248}
249
250inline bool
252{
253 return not( *this > b );
254}
255
256inline bool
258{
259 return stamp_ == b.stamp_ ? ps_offset_ < b.ps_offset_ : stamp_ > b.stamp_;
260}
261
262} // namespace nest
263
264#endif /* #ifndef SLICE_RING_BUFFER_H */
long get_slice_modulo(long d)
Index to slice-based buffer.
Definition event_delivery_manager.h:537
Queue for all spikes arriving into a neuron.
Definition slice_ring_buffer.h:63
void discard_events()
Discard all events in current slice.
Definition slice_ring_buffer.cpp:81
SliceRingBuffer()
Definition slice_ring_buffer.cpp:32
bool get_next_spike(const long req_stamp, bool accumulate_simultaneous, double &ps_offset, double &weight, bool &end_of_refract)
Return next spike.
Definition slice_ring_buffer.h:184
void prepare_delivery()
Prepare for spike delivery in current slice by sorting.
Definition slice_ring_buffer.cpp:71
std::vector< SpikeInfo > * deliver_
slot to deliver from
Definition slice_ring_buffer.h:153
std::vector< std::vector< SpikeInfo > > queue_
entire queue, one slot per min_delay block within max_delay
Definition slice_ring_buffer.h:150
void clear()
Clear buffer.
Definition slice_ring_buffer.cpp:62
void add_spike(const long rel_delivery, const long stamp, const double ps_offset, const double weight)
Add spike to queue.
Definition slice_ring_buffer.h:159
SpikeInfo refract_
pseudo-event for return from refractoriness
Definition slice_ring_buffer.h:155
void add_refractory(const long stamp, const double ps_offset)
Add refractory event to queue.
Definition slice_ring_buffer.h:169
void resize()
Resize the buffer according to min_delay and max_delay.
Definition slice_ring_buffer.cpp:38
EventDeliveryManager event_delivery_manager
Definition kernel_manager.h:241
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
KernelManager & kernel()
Definition kernel_manager.h:311
Information about spike.
Definition slice_ring_buffer.h:135
double ps_offset_
Definition slice_ring_buffer.h:145
bool operator<=(const SpikeInfo &b) const
Definition slice_ring_buffer.h:251
bool operator<(const SpikeInfo &b) const
Definition slice_ring_buffer.h:245
double weight_
Definition slice_ring_buffer.h:146
long stamp_
Definition slice_ring_buffer.h:144
bool operator>(const SpikeInfo &b) const
Definition slice_ring_buffer.h:257
SpikeInfo(long stamp, double ps_offset, double weight)
Definition slice_ring_buffer.h:237