From d55d1aa4d7c782d1dc1be60ef241c74b46186988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Catherine=20Sch=C3=B6fmann?= Date: Sat, 24 Feb 2024 01:59:37 +0100 Subject: [PATCH 1/3] Attempt cache thrashing fix --- nestkernel/connection_manager.cpp | 2 +- nestkernel/connection_manager.h | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/nestkernel/connection_manager.cpp b/nestkernel/connection_manager.cpp index 7345f07193..bc050ff78a 100644 --- a/nestkernel/connection_manager.cpp +++ b/nestkernel/connection_manager.cpp @@ -131,7 +131,7 @@ nest::ConnectionManager::initialize( const bool reset_kernel ) std::vector< DelayChecker > tmp( kernel().vp_manager.get_num_threads() ); delay_checkers_.swap( tmp ); - std::vector< std::vector< size_t > > tmp2( kernel().vp_manager.get_num_threads(), std::vector< size_t >() ); + std::vector> tmp2( kernel().vp_manager.get_num_threads(), aligned_vector() ); num_connections_.swap( tmp2 ); } diff --git a/nestkernel/connection_manager.h b/nestkernel/connection_manager.h index 315e2a1305..84e6516547 100644 --- a/nestkernel/connection_manager.h +++ b/nestkernel/connection_manager.h @@ -30,6 +30,11 @@ #include "manager_interface.h" #include "stopwatch.h" +#ifdef HAVE_BOOST +#include +#include +#endif + // Includes from nestkernel: #include "conn_builder.h" #include "connection_id.h" @@ -52,6 +57,15 @@ namespace nest { + +#ifdef HAVE_BOOST + template + using aligned_vector = std::vector< T, boost::alignment::aligned_allocator >; +#else + template + using aligned_vector = std::vector; +#endif + class GenericConnBuilderFactory; class spikecounter; class Node; @@ -633,7 +647,8 @@ class ConnectionManager : public ManagerInterface * A structure to count the number of synapses of a specific * type. Arranged in a 2d structure: threads|synapsetypes. */ - std::vector< std::vector< size_t > > num_connections_; + + std::vector> num_connections_; DictionaryDatum connruledict_; //!< Dictionary for connection rules. From 720e9d9422fda124a5b4e5e9b8b5482a43497377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Catherine=20Sch=C3=B6fmann?= Date: Sat, 24 Feb 2024 19:41:42 +0100 Subject: [PATCH 2/3] Run clang-format --- nestkernel/connection_manager.cpp | 2 +- nestkernel/connection_manager.h | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/nestkernel/connection_manager.cpp b/nestkernel/connection_manager.cpp index bc050ff78a..1042b45122 100644 --- a/nestkernel/connection_manager.cpp +++ b/nestkernel/connection_manager.cpp @@ -131,7 +131,7 @@ nest::ConnectionManager::initialize( const bool reset_kernel ) std::vector< DelayChecker > tmp( kernel().vp_manager.get_num_threads() ); delay_checkers_.swap( tmp ); - std::vector> tmp2( kernel().vp_manager.get_num_threads(), aligned_vector() ); + std::vector< aligned_vector< size_t > > tmp2( kernel().vp_manager.get_num_threads(), aligned_vector< size_t >() ); num_connections_.swap( tmp2 ); } diff --git a/nestkernel/connection_manager.h b/nestkernel/connection_manager.h index 84e6516547..fb33d9688b 100644 --- a/nestkernel/connection_manager.h +++ b/nestkernel/connection_manager.h @@ -31,8 +31,8 @@ #include "stopwatch.h" #ifdef HAVE_BOOST -#include #include +#include #endif // Includes from nestkernel: @@ -59,11 +59,12 @@ namespace nest { #ifdef HAVE_BOOST - template - using aligned_vector = std::vector< T, boost::alignment::aligned_allocator >; +template < typename T > +using aligned_vector = + std::vector< T, boost::alignment::aligned_allocator< T, std::hardware_destructive_interference_size > >; #else - template - using aligned_vector = std::vector; +template < typename T > +using aligned_vector = std::vector< T >; #endif class GenericConnBuilderFactory; @@ -648,7 +649,7 @@ class ConnectionManager : public ManagerInterface * type. Arranged in a 2d structure: threads|synapsetypes. */ - std::vector> num_connections_; + std::vector< aligned_vector< size_t > > num_connections_; DictionaryDatum connruledict_; //!< Dictionary for connection rules. From 46d21cfe3efff85a2173946ffea3dd892414fc40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Catherine=20Sch=C3=B6fmann?= Date: Sat, 24 Feb 2024 20:32:59 +0100 Subject: [PATCH 3/3] Add feature version test --- nestkernel/connection_manager.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nestkernel/connection_manager.h b/nestkernel/connection_manager.h index fb33d9688b..512af11ab5 100644 --- a/nestkernel/connection_manager.h +++ b/nestkernel/connection_manager.h @@ -31,6 +31,11 @@ #include "stopwatch.h" #ifdef HAVE_BOOST +#ifdef __cpp_lib_hardware_interference_size +using std::hardware_destructive_interference_size; +#else +constexpr std::size_t hardware_destructive_interference_size = 64; +#endif #include #include #endif @@ -61,7 +66,7 @@ namespace nest #ifdef HAVE_BOOST template < typename T > using aligned_vector = - std::vector< T, boost::alignment::aligned_allocator< T, std::hardware_destructive_interference_size > >; + std::vector< T, boost::alignment::aligned_allocator< T, hardware_destructive_interference_size > >; #else template < typename T > using aligned_vector = std::vector< T >;