Skip to content

Commit

Permalink
move precise spike time offset from Event to Time class
Browse files Browse the repository at this point in the history
  • Loading branch information
C.A.P. Linssen committed Sep 10, 2024
1 parent 48b29ba commit ee38b27
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 62 deletions.
6 changes: 3 additions & 3 deletions models/cont_delay_synapse.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,16 @@ cont_delay_synapse< targetidentifierT >::send( Event& e, size_t t, const CommonS
if ( total_offset < Time::get_resolution().get_ms() )
{
e.set_delay_steps( get_delay_steps() );
e.set_offset( total_offset );
e.get_stamp().set_offset( total_offset );
}
else
{
e.set_delay_steps( get_delay_steps() - 1 );
e.set_offset( total_offset - Time::get_resolution().get_ms() );
e.get_stamp().set_offset( total_offset - Time::get_resolution().get_ms() );
}
e();
// reset offset to original value
e.set_offset( orig_event_offset );
e.get_stamp().set_offset( orig_event_offset );

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions models/iaf_bw_2001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ nest::iaf_bw_2001::update( Time const& origin, const long from, const long to )
S_.s_NMDA_pre += s_NMDA_delta;

SpikeEvent se;
se.set_offset( s_NMDA_delta );
se.get_stamp().set_offset( s_NMDA_delta );
kernel().event_delivery_manager.send( *this, se, lag );
}

Expand Down Expand Up @@ -509,7 +509,7 @@ nest::iaf_bw_2001::handle( SpikeEvent& e )
}
else
{
B_.spikes_[ rport - 1 ].add_value( steps, e.get_weight() * e.get_multiplicity() * e.get_offset() );
B_.spikes_[ rport - 1 ].add_value( steps, e.get_weight() * e.get_multiplicity() * e.get_stamp().get_offset() );
}
}

Expand Down
2 changes: 1 addition & 1 deletion models/iaf_chxk_2008.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ nest::iaf_chxk_2008::update( Time const& origin, const long from, const long to
set_spiketime( Time::step( origin.get_steps() + lag + 1 ) );

SpikeEvent se;
se.set_offset( dt );
se.get_stamp().set_offset( dt );
kernel().event_delivery_manager.send( *this, se, lag );
}

Expand Down
4 changes: 2 additions & 2 deletions models/iaf_psc_alpha_ps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ nest::iaf_psc_alpha_ps::emit_spike_( Time const& origin, const long lag, const d
// send spike
set_spiketime( Time::step( S_.last_spike_step_ ), S_.last_spike_offset_ );
SpikeEvent se;
se.set_offset( S_.last_spike_offset_ );
se.get_stamp().set_offset( S_.last_spike_offset_ );
kernel().event_delivery_manager.send( *this, se, lag );

return;
Expand All @@ -569,7 +569,7 @@ nest::iaf_psc_alpha_ps::emit_instant_spike_( Time const& origin, const long lag,
// send spike
set_spiketime( Time::step( S_.last_spike_step_ ), S_.last_spike_offset_ );
SpikeEvent se;
se.set_offset( S_.last_spike_offset_ );
se.get_stamp().set_offset( S_.last_spike_offset_ );
kernel().event_delivery_manager.send( *this, se, lag );

return;
Expand Down
4 changes: 2 additions & 2 deletions models/iaf_psc_delta_ps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ nest::iaf_psc_delta_ps::emit_spike_( Time const& origin, const long lag, const d
// send spike
set_spiketime( Time::step( S_.last_spike_step_ ), S_.last_spike_offset_ );
SpikeEvent se;
se.set_offset( S_.last_spike_offset_ );
se.get_stamp().set_offset( S_.last_spike_offset_ );
kernel().event_delivery_manager.send( *this, se, lag );
}

Expand All @@ -500,7 +500,7 @@ nest::iaf_psc_delta_ps::emit_instant_spike_( Time const& origin, const long lag,
// send spike
set_spiketime( Time::step( S_.last_spike_step_ ), S_.last_spike_offset_ );
SpikeEvent se;
se.set_offset( S_.last_spike_offset_ );
se.get_stamp().set_offset( S_.last_spike_offset_ );
kernel().event_delivery_manager.send( *this, se, lag );
}

Expand Down
4 changes: 2 additions & 2 deletions models/iaf_psc_exp_ps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ nest::iaf_psc_exp_ps::emit_spike_( const Time& origin, const long lag, const dou
set_spiketime( Time::step( S_.last_spike_step_ ), S_.last_spike_offset_ );
SpikeEvent se;

se.set_offset( S_.last_spike_offset_ );
se.get_stamp().set_offset( S_.last_spike_offset_ );
kernel().event_delivery_manager.send( *this, se, lag );
}

Expand All @@ -537,7 +537,7 @@ nest::iaf_psc_exp_ps::emit_instant_spike_( const Time& origin, const long lag, c
set_spiketime( Time::step( S_.last_spike_step_ ), S_.last_spike_offset_ );
SpikeEvent se;

se.set_offset( S_.last_spike_offset_ );
se.get_stamp().set_offset( S_.last_spike_offset_ );
kernel().event_delivery_manager.send( *this, se, lag );
}

Expand Down
4 changes: 2 additions & 2 deletions models/iaf_psc_exp_ps_lossless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ nest::iaf_psc_exp_ps_lossless::emit_spike_( const Time& origin, const long lag,
set_spiketime( Time::step( S_.last_spike_step_ ), S_.last_spike_offset_ );
SpikeEvent se;

se.set_offset( S_.last_spike_offset_ );
se.get_stamp().set_offset( S_.last_spike_offset_ );
kernel().event_delivery_manager.send( *this, se, lag );
}

Expand All @@ -580,7 +580,7 @@ nest::iaf_psc_exp_ps_lossless::emit_instant_spike_( const Time& origin, const lo
set_spiketime( Time::step( S_.last_spike_step_ ), S_.last_spike_offset_ );
SpikeEvent se;

se.set_offset( S_.last_spike_offset_ );
se.get_stamp().set_offset( S_.last_spike_offset_ );
kernel().event_delivery_manager.send( *this, se, lag );
}

Expand Down
4 changes: 2 additions & 2 deletions models/iaf_tum_2000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ nest::iaf_tum_2000::update( const Time& origin, const long from, const long to )

// send spike with datafield
SpikeEvent se;
se.set_offset( delta_y_tsp );
se.get_stamp().set_offset( delta_y_tsp );
kernel().event_delivery_manager.send( *this, se, lag );
}

Expand Down Expand Up @@ -458,7 +458,7 @@ nest::iaf_tum_2000::handle( SpikeEvent& e )

if ( e.get_rport() == 1 )
{
s *= e.get_offset();
s *= e.get_stamp().get_offset();
}

// separate buffer channels for excitatory and inhibitory inputs
Expand Down
2 changes: 1 addition & 1 deletion models/parrot_neuron_ps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ parrot_neuron_ps::update( Time const& origin, long const from, long const to )
// send spike
SpikeEvent se;
se.set_multiplicity( multiplicity );
se.set_offset( ev_offset );
se.get_stamp().set_offset( ev_offset );
kernel().event_delivery_manager.send( *this, se, lag );

for ( unsigned long i = 0; i < multiplicity; ++i )
Expand Down
2 changes: 1 addition & 1 deletion models/poisson_generator_ps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ nest::poisson_generator_ps::event_hook( DSSpikeEvent& e )
while ( nextspk.first <= V_.t_max_active_ )
{
e.set_stamp( nextspk.first );
e.set_offset( nextspk.second );
e.get_stamp().set_offset( nextspk.second );
e.get_receiver().handle( e );

// Draw time of next spike
Expand Down
2 changes: 1 addition & 1 deletion models/spike_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ nest::spike_generator::update( Time const& sliceT0, const long from, const long

if ( P_.precise_times_ )
{
se->set_offset( P_.spike_offsets_[ S_.position_ ] );
se->get_stamp().set_offset( P_.spike_offsets_[ S_.position_ ] );
}

if ( not P_.spike_multiplicities_.empty() )
Expand Down
2 changes: 1 addition & 1 deletion models/spike_train_injector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ spike_train_injector::update( Time const& sliceT0, const long from, const long t

if ( P_.precise_times_ )
{
se.set_offset( P_.spike_offsets_[ S_.position_ ] );
se.get_stamp().set_offset( P_.spike_offsets_[ S_.position_ ] );
}

if ( not P_.spike_multiplicities_.empty() )
Expand Down
44 changes: 29 additions & 15 deletions nestkernel/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,6 @@ class Event
*/
void set_sender_node_id_info( const size_t tid, const synindex syn_id, const size_t lcid );

/**
* Return time stamp of the event.
*
* The stamp denotes the time when the event was created.
*/
Time const& get_stamp() const;

/**
* Set the time stamp of the event.
* The time stamp refers to the time when the event
* was created.
*/
void set_stamp( Time const& );

/**
* Return transmission delay of the event.
*
Expand All @@ -195,11 +181,12 @@ class Event

/**
* Set the transmission delay of the event.
*
* The delay refers to the time until the event is
* expected to arrive at the receiver.
* @param d delay
*/
void set_delay_steps( delay d );
void set_delay_steps( long d );

/**
* Relative spike delivery time in steps.
Expand Down Expand Up @@ -297,7 +284,28 @@ class Event
*/
bool is_valid() const;

/**
* Return time stamp of the event.
*
* The stamp denotes the time when the event was created.
*/
Time const& get_stamp() const;

/**
* Return time stamp of the event.
*
* The stamp denotes the time when the event was created.
*/
Time& get_stamp();

/**
* Set the time stamp of the event.
*
* The time stamp refers to the time when the event
* was created.
*/
void set_stamp( Time const& );

protected:
size_t sender_node_id_; //!< node ID of sender or 0
SpikeData sender_spike_data_; //!< spike data of sender node, in some cases required to retrieve node ID
Expand Down Expand Up @@ -931,6 +939,12 @@ Event::get_stamp() const
return stamp_;
}

inline Time&
Event::get_stamp()
{
return stamp_;
}

inline void
Event::set_stamp( Time const& s )
{
Expand Down
8 changes: 4 additions & 4 deletions nestkernel/event_delivery_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ EventDeliveryManager::deliver_events_( const size_t tid, const std::vector< Spik
{
const SpikeDataT& spike_data = recv_buffer[ rank * spike_buffer_size_per_rank + i * SPIKES_PER_BATCH + j ];
se_batch[ j ].set_stamp( prepared_timestamps[ spike_data.get_lag() ] );
se_batch[ j ].set_offset( spike_data.get_offset() );
se_batch[ j ].get_stamp().set_offset( spike_data.get_offset() );
tid_batch[ j ] = spike_data.get_tid();
syn_id_batch[ j ] = spike_data.get_syn_id();
lcid_batch[ j ] = spike_data.get_lcid();
Expand All @@ -689,7 +689,7 @@ EventDeliveryManager::deliver_events_( const size_t tid, const std::vector< Spik
const SpikeDataT& spike_data =
recv_buffer[ rank * spike_buffer_size_per_rank + num_batches * SPIKES_PER_BATCH + j ];
se_batch[ j ].set_stamp( prepared_timestamps[ spike_data.get_lag() ] );
se_batch[ j ].set_offset( spike_data.get_offset() );
se_batch[ j ].get_stamp().set_offset( spike_data.get_offset() );
tid_batch[ j ] = spike_data.get_tid();
syn_id_batch[ j ] = spike_data.get_syn_id();
lcid_batch[ j ] = spike_data.get_lcid();
Expand All @@ -712,7 +712,7 @@ EventDeliveryManager::deliver_events_( const size_t tid, const std::vector< Spik
const SpikeDataT& spike_data = recv_buffer[ rank * spike_buffer_size_per_rank + i * SPIKES_PER_BATCH + j ];

se_batch[ j ].set_stamp( prepared_timestamps[ spike_data.get_lag() ] );
se_batch[ j ].set_offset( spike_data.get_offset() );
se_batch[ j ].get_stamp().set_offset( spike_data.get_offset() );

syn_id_batch[ j ] = spike_data.get_syn_id();
// for compressed spikes lcid holds the index in the
Expand Down Expand Up @@ -750,7 +750,7 @@ EventDeliveryManager::deliver_events_( const size_t tid, const std::vector< Spik
const SpikeDataT& spike_data =
recv_buffer[ rank * spike_buffer_size_per_rank + num_batches * SPIKES_PER_BATCH + j ];
se_batch[ j ].set_stamp( prepared_timestamps[ spike_data.get_lag() ] );
se_batch[ j ].set_offset( spike_data.get_offset() );
se_batch[ j ].get_stamp().set_offset( spike_data.get_offset() );
syn_id_batch[ j ] = spike_data.get_syn_id();
// for compressed spikes lcid holds the index in the
// compressed_spike_data structure
Expand Down
50 changes: 27 additions & 23 deletions nestkernel/nest_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,29 @@ class Time
public:
static tic_t compute_max();

/////////////////////////////////////////////////////////////
// Offset
/////////////////////////////////////////////////////////////

/**
* Return the creation time offset of the Event.
* Each Event carries the exact time of creation. This
* time need not coincide with an integral multiple of the
* temporal resolution. Rather, Events may be created at any point
* in time.
*/
double get_offset() const;

/**
* Set the creation time of the Event.
* Each Event carries the exact time of creation in realtime. This
* time need not coincide with an integral multiple of the
* temporal resolution. Rather, Events may be created at any point
* in time.
* @param t Creation time in realtime. t has to be in [0, h).
*/
void set_offset( double t );

/////////////////////////////////////////////////////////////
// The data
/////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -213,29 +236,6 @@ class Time
friend Time operator*( const Time& t, long factor );
friend std::ostream&( ::operator<< )( std::ostream&, const Time& );

/////////////////////////////////////////////////////////////
// Offset
/////////////////////////////////////////////////////////////

/**
* Return the creation time offset of the Event.
* Each Event carries the exact time of creation. This
* time need not coincide with an integral multiple of the
* temporal resolution. Rather, Events may be created at any point
* in time.
*/
double get_offset() const;

/**
* Set the creation time of the Event.
* Each Event carries the exact time of creation in realtime. This
* time need not coincide with an integral multiple of the
* temporal resolution. Rather, Events may be created at any point
* in time.
* @param t Creation time in realtime. t has to be in [0, h).
*/
void set_offset( double t );

/////////////////////////////////////////////////////////////
// Limits for time, including infinity definitions
/////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -339,26 +339,30 @@ class Time
: tics( ( time_abs( t.t ) < LIM_MAX.tics ) ? t.t
: ( t.t < 0 ) ? LIM_NEG_INF.tics
: LIM_POS_INF.tics )
, offset_( 0. )
{
}

Time( step t )
: tics( ( time_abs( t.t ) < LIM_MAX.steps ) ? t.t * Range::TICS_PER_STEP
: ( t.t < 0 ) ? LIM_NEG_INF.tics
: LIM_POS_INF.tics )
, offset_( 0. )
{
}

Time( ms t )
: tics( ( time_abs( t.t ) < LIM_MAX.ms ) ? static_cast< tic_t >( t.t * Range::TICS_PER_MS + 0.5 )
: ( t.t < 0 ) ? LIM_NEG_INF.tics
: LIM_POS_INF.tics )
, offset_( 0. )
{
}

static tic_t fromstamp( ms_stamp );
Time( ms_stamp t )
: tics( fromstamp( t ) )
, offset_( 0. )
{
}

Expand Down

0 comments on commit ee38b27

Please sign in to comment.