Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a3f5369
Fix issue: #3532
med-ayssar Jul 20, 2025
4271659
Make clang-format happy
med-ayssar Jul 20, 2025
25b7240
Make clang-format happy
med-ayssar Jul 20, 2025
7617de0
Avoid copies of Source
med-ayssar Jul 20, 2025
02c2055
Make clang-format happy #3
med-ayssar Jul 20, 2025
93a0798
Disable my Nvim clangformat-plugin
med-ayssar Jul 20, 2025
94cdccb
Use std::find_if instead of custom function
med-ayssar Sep 20, 2025
0015a85
Apply clang format
med-ayssar Sep 20, 2025
ae566f0
Merge branch 'master' into 3532
med-ayssar Sep 20, 2025
3454d36
Make clang happy again
med-ayssar Sep 20, 2025
bbf3baf
Use custom compare method for std::lower_bound
med-ayssar Sep 20, 2025
9c67d5a
Fix clang-format again
med-ayssar Sep 20, 2025
28e50b4
Fix format again
med-ayssar Sep 20, 2025
eead8c3
Fix space
med-ayssar Sep 20, 2025
d138558
Fix std::lower_bound comp predicate
med-ayssar Sep 20, 2025
e30af4f
Fix the logic behind std::lower_bound with deleted connection
med-ayssar Sep 21, 2025
8564c57
Fix indentation
med-ayssar Sep 21, 2025
ed28503
Adjust the function to be more compact and simpler
ayssar100 Sep 22, 2025
06e36f5
Fix compiler errors
med-ayssar Sep 22, 2025
7610668
Compare Iter with origin
med-ayssar Sep 22, 2025
e99e03c
Fix find_connection implementation for use_compressed_spike=OFF
med-ayssar Sep 24, 2025
f8170d5
Add pytest
med-ayssar Sep 24, 2025
007501f
Format files
med-ayssar Sep 24, 2025
a344c57
Fix copyright header
med-ayssar Sep 24, 2025
097babd
Sort imports
med-ayssar Sep 24, 2025
0c4048b
Add bit flag for disabled sources
med-ayssar Sep 25, 2025
52460b8
Activate Source again on changing node_id
med-ayssar Sep 25, 2025
b3941fe
Avoid double-delete of ptr
med-ayssar Sep 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libnestutil/nest_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ constexpr uint8_t NUM_BITS_PROCESSED_FLAG = 1U;
constexpr uint8_t NUM_BITS_MARKER_SPIKE_DATA = 2U;
constexpr uint8_t NUM_BITS_LAG = 14U;
constexpr uint8_t NUM_BITS_DELAY = 21U;
constexpr uint8_t NUM_BITS_NODE_ID = 62U;
constexpr uint8_t NUM_BITS_NODE_ID = 61U;

// Maximally allowed values for bitfields

Expand Down
10 changes: 8 additions & 2 deletions models/eprop_synapse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ Connector< eprop_synapse< TargetIdentifierPtrRport > >::~Connector()
{
for ( auto& c : C_ )
{
c.delete_optimizer();
if ( not c.is_disabled() )
{
c.delete_optimizer();
}
}
C_.clear();
}
Expand All @@ -136,7 +139,10 @@ Connector< eprop_synapse< TargetIdentifierIndex > >::~Connector()
{
for ( auto& c : C_ )
{
c.delete_optimizer();
if ( not c.is_disabled() )
{
c.delete_optimizer();
}
}
C_.clear();
}
Expand Down
10 changes: 8 additions & 2 deletions models/eprop_synapse_bsshslm_2020.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ Connector< eprop_synapse_bsshslm_2020< TargetIdentifierPtrRport > >::~Connector(
{
for ( auto& c : C_ )
{
c.delete_optimizer();
if ( not c.is_disabled() )
{
c.delete_optimizer();
}
}
C_.clear();
}
Expand All @@ -141,7 +144,10 @@ Connector< eprop_synapse_bsshslm_2020< TargetIdentifierIndex > >::~Connector()
{
for ( auto& c : C_ )
{
c.delete_optimizer();
if ( not c.is_disabled() )
{
c.delete_optimizer();
}
}
C_.clear();
}
Expand Down
41 changes: 29 additions & 12 deletions nestkernel/connection_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "kernel_manager.h"
#include "mpi_manager_impl.h"
#include "nest_names.h"
#include "nest_types.h"
#include "node.h"
#include "sonata_connector.h"
#include "stopwatch_impl.h"
Expand Down Expand Up @@ -786,7 +787,7 @@
}

void
nest::ConnectionManager::connect_sonata( const DictionaryDatum& graph_specs, const long hyberslab_size )

Check warning on line 790 in nestkernel/connection_manager.cpp

View workflow job for this annotation

GitHub Actions / build_linux (ubuntu-22.04, gcc, optimize, warning)

unused parameter ‘hyberslab_size’ [-Wunused-parameter]

Check warning on line 790 in nestkernel/connection_manager.cpp

View workflow job for this annotation

GitHub Actions / build_linux (ubuntu-22.04, gcc, optimize, warning)

unused parameter ‘graph_specs’ [-Wunused-parameter]

Check warning on line 790 in nestkernel/connection_manager.cpp

View workflow job for this annotation

GitHub Actions / build_linux (ubuntu-22.04, gcc, boost, optimize, warning)

unused parameter ‘hyberslab_size’ [-Wunused-parameter]

Check warning on line 790 in nestkernel/connection_manager.cpp

View workflow job for this annotation

GitHub Actions / build_linux (ubuntu-22.04, gcc, boost, optimize, warning)

unused parameter ‘graph_specs’ [-Wunused-parameter]

Check warning on line 790 in nestkernel/connection_manager.cpp

View workflow job for this annotation

GitHub Actions / build_linux (ubuntu-22.04, gcc, openmp, python, gsl, ltdl, boost, optimize, warning)

unused parameter ‘hyberslab_size’ [-Wunused-parameter]

Check warning on line 790 in nestkernel/connection_manager.cpp

View workflow job for this annotation

GitHub Actions / build_linux (ubuntu-22.04, gcc, openmp, python, gsl, ltdl, boost, optimize, warning)

unused parameter ‘graph_specs’ [-Wunused-parameter]
{
#ifdef HAVE_HDF5
kernel().node_manager.update_thread_local_node_data();
Expand Down Expand Up @@ -978,21 +979,37 @@
{
// lcid will hold the position of the /first/ connection from node
// snode_id to any local node, or be invalid
size_t lcid = source_table_.find_first_source( tid, syn_id, snode_id );
if ( lcid == invalid_index )
{
return invalid_index;
}

// lcid will hold the position of the /first/ connection from node
// snode_id to node tnode_id, or be invalid
lcid = connections_[ tid ][ syn_id ]->find_first_target( tid, lcid, tnode_id );
if ( lcid != invalid_index )
if ( use_compressed_spikes() )
{
size_t source_index = source_table_.find_first_source( tid, syn_id, snode_id, use_compressed_spikes() );
if ( source_index == invalid_index )
{
return invalid_index;
}

// lcid will hold the position of the /first/ connection from node
// snode_id to node tnode_id, or be invalid
size_t lcid =
connections_[ tid ][ syn_id ]->find_first_target( tid, source_index, tnode_id, use_compressed_spikes() );

return lcid;
}
else
{
size_t lcid = connections_[ tid ][ syn_id ]->find_first_target( tid, 0, tnode_id, use_compressed_spikes() );
if ( lcid == invalid_index )
{
return invalid_index;
}

std::vector< size_t > lcids {};
connections_[ tid ][ syn_id ]->get_source_lcids( tid, tnode_id, lcids );
size_t source_index = source_table_.select_source_lcid_from_list( tid, snode_id, syn_id, lcids );

return lcid;
return source_index;
}
return invalid_index;
}

void
Expand All @@ -1003,7 +1020,7 @@
{
assert( syn_id != invalid_synindex );

const size_t lcid = find_connection( tid, syn_id, snode_id, tnode_id );
const auto lcid = find_connection( tid, syn_id, snode_id, tnode_id );

if ( lcid == invalid_index ) // this function should only be called
// with a valid connection
Expand Down Expand Up @@ -1428,7 +1445,7 @@
{
for ( size_t i = 0; i < sources.size(); ++i )
{
const size_t start_lcid = source_table_.find_first_source( tid, syn_id, sources[ i ] );
const size_t start_lcid = source_table_.find_first_source( tid, syn_id, sources[ i ], use_compressed_spikes() );
if ( start_lcid != invalid_index )
{
connections_[ tid ][ syn_id ]->get_target_node_ids( tid, start_lcid, post_synaptic_element, targets[ i ] );
Expand Down
12 changes: 9 additions & 3 deletions nestkernel/connector_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ class ConnectorBase
* where the node_id of the target matches target_node_id. If there are no matches,
* the function returns invalid_index.
*/
virtual size_t find_first_target( const size_t tid, const size_t start_lcid, const size_t target_node_id ) const = 0;
virtual size_t find_first_target( const size_t tid,
const size_t start_lcid,
const size_t target_node_id,
bool use_compressed_spikes = false ) const = 0;

/**
* Return lcid of first connection where the node ID of the target
Expand Down Expand Up @@ -464,7 +467,10 @@ class Connector : public ConnectorBase
}

size_t
find_first_target( const size_t tid, const size_t start_lcid, const size_t target_node_id ) const override
find_first_target( const size_t tid,
const size_t start_lcid,
const size_t target_node_id,
bool use_compressed_spikes = false ) const override
{
size_t lcid = start_lcid;
while ( true )
Expand All @@ -474,7 +480,7 @@ class Connector : public ConnectorBase
return lcid;
}

if ( not C_[ lcid ].source_has_more_targets() )
if ( not C_[ lcid ].source_has_more_targets() and use_compressed_spikes )
{
return invalid_index;
}
Expand Down
9 changes: 7 additions & 2 deletions nestkernel/source.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Source
bool processed_ : 1; //!< whether this target has already been moved
//!< to the MPI buffer
bool primary_ : 1;
bool disabled_ : 1;

public:
Source();
Expand All @@ -62,6 +63,7 @@ class Source
void set_processed( const bool processed );
bool is_processed() const;


/**
* Sets whether Source is primary.
*/
Expand Down Expand Up @@ -91,13 +93,15 @@ inline Source::Source()
: node_id_( 0 )
, processed_( false )
, primary_( true )
, disabled_( false )
{
}

inline Source::Source( const uint64_t node_id, const bool is_primary )
: node_id_( node_id )
, processed_( false )
, primary_( is_primary )
, disabled_( false )
{
assert( node_id <= MAX_NODE_ID );
}
Expand All @@ -107,6 +111,7 @@ Source::set_node_id( const uint64_t node_id )
{
assert( node_id <= MAX_NODE_ID );
node_id_ = node_id;
disabled_ = false;
}

inline uint64_t
Expand Down Expand Up @@ -142,13 +147,13 @@ Source::is_primary() const
inline void
Source::disable()
{
node_id_ = DISABLED_NODE_ID;
disabled_ = true;
}

inline bool
Source::is_disabled() const
{
return node_id_ == DISABLED_NODE_ID;
return disabled_;
}

inline bool
Expand Down
69 changes: 54 additions & 15 deletions nestkernel/source_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
// C++ includes:
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <utility>
#include <vector>

// Includes from nestkernel:
Expand Down Expand Up @@ -300,7 +303,15 @@ class SourceTable
* Finds the first entry in sources_ at the given thread id and
* synapse type that is equal to snode_id.
*/
size_t find_first_source( const size_t tid, const synindex syn_id, const size_t snode_id ) const;
size_t find_first_source( const size_t tid,
const synindex syn_id,
const size_t snode_id,
bool using_compressed_spikes = false ) const;

size_t select_source_lcid_from_list( const size_t tid,
const size_t snode_id,
const size_t syn_id,
const std::vector< size_t >& lcids ) const;

/**
* Marks entry in sources_ at given position as disabled.
Expand Down Expand Up @@ -469,29 +480,57 @@ SourceTable::no_targets_to_process( const size_t tid )
current_positions_[ tid ].syn_id = -1;
current_positions_[ tid ].lcid = -1;
}
inline size_t
SourceTable::select_source_lcid_from_list( const size_t tid,
const size_t snode_id,
const size_t syn_id,
const std::vector< size_t >& lcids ) const
{
for ( const auto& lcid : lcids )
{
auto sources = sources_[ tid ][ syn_id ];
if ( lcid < sources.size() and sources[ lcid ].get_node_id() == snode_id )
{
return lcid;
}
}
return invalid_lcid;
}

inline size_t
SourceTable::find_first_source( const size_t tid, const synindex syn_id, const size_t snode_id ) const
SourceTable::find_first_source( const size_t tid,
const synindex syn_id,
const size_t snode_id,
bool using_compressed_spikes /* default = false */ ) const
{
// binary search in sorted sources
const BlockVector< Source >::const_iterator begin = sources_[ tid ][ syn_id ].begin();
const BlockVector< Source >::const_iterator end = sources_[ tid ][ syn_id ].end();
BlockVector< Source >::const_iterator it = std::lower_bound( begin, end, Source( snode_id, true ) );

// source found by binary search could be disabled, iterate through
// sources until a valid one is found
while ( it != end )

const auto source_begin = sources_[ tid ][ syn_id ].begin();
const auto source_end = sources_[ tid ][ syn_id ].end();

const Source selected_source { snode_id, /* is_primary */ true };

auto find_source_lcid = [ &source_begin ]( auto begin, auto end, const Source& value ) -> size_t
{
if ( it->get_node_id() == snode_id and not it->is_disabled() )
auto iter = std::find_if( begin,
end,
[ &value ]( const Source& src ) { return src.get_node_id() == value.get_node_id() and not src.is_disabled(); } );
if ( iter != end )
{
const size_t lcid = it - begin;
const size_t lcid = iter - source_begin;
return lcid;
}
++it;
// no enabled entry with this snode ID found
return invalid_index;
};

auto iter = source_begin;

if ( using_compressed_spikes )
{
iter = std::lower_bound( iter, source_end, selected_source );
}

// no enabled entry with this snode ID found
return invalid_index;
return find_source_lcid( iter, source_end, selected_source );
}

inline void
Expand Down
Loading
Loading