From 12d52b65375e5dba5b63611e93082ec3a151f280 Mon Sep 17 00:00:00 2001 From: Stefan Eilemann Date: Fri, 3 Jun 2016 14:09:09 +0200 Subject: [PATCH 1/2] Cleanup --- brion/plugin/compartmentReportHDF5.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/brion/plugin/compartmentReportHDF5.cpp b/brion/plugin/compartmentReportHDF5.cpp index 54166d9..a5cfac1 100644 --- a/brion/plugin/compartmentReportHDF5.cpp +++ b/brion/plugin/compartmentReportHDF5.cpp @@ -456,10 +456,9 @@ bool CompartmentReportHDF5::writeCompartments( const uint32_t gid, boost::scoped_array< float > mapping( new float[compCount] ); size_t i = 0; for( size_t j = 0; j < counts.size(); ++j ) - { for( size_t k = 0; k < counts[j]; ++k ) mapping[i++] = j; - } + dataset.write( mapping.get(), H5::PredType::NATIVE_FLOAT ); return true; } From d98d3c2cdc252d5813e9a396ad2085ce4f6caac5 Mon Sep 17 00:00:00 2001 From: Stefan Eilemann Date: Mon, 13 Jun 2016 16:03:35 +0200 Subject: [PATCH 2/2] Implement (mem)cache for synapse files --- .gitsubprojects | 8 ++++---- brion/synapse.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++-- tests/synapse.cpp | 2 +- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/.gitsubprojects b/.gitsubprojects index 86088f6..d50f3ea 100644 --- a/.gitsubprojects +++ b/.gitsubprojects @@ -1,5 +1,5 @@ # -*- mode: cmake -*- -git_subproject(Servus https://github.com/HBPVIS/Servus.git 62873a5) -git_subproject(Lunchbox https://github.com/Eyescale/Lunchbox.git b990d7f) -git_subproject(vmmlib https://github.com/Eyescale/vmmlib.git f6fda2d) -git_subproject(MVDTool https://github.com/BlueBrain/MVDTool.git f6af9a4) +git_subproject(Servus https://github.com/HBPVIS/Servus.git 134b674) +git_subproject(Lunchbox https://github.com/Eyescale/Lunchbox.git 440fded) +git_subproject(vmmlib https://github.com/Eyescale/vmmlib.git 10d93e6) +git_subproject(MVDTool https://github.com/BlueBrain/MVDTool.git 03d8138) diff --git a/brion/synapse.cpp b/brion/synapse.cpp index d563cd8..cd09a10 100644 --- a/brion/synapse.cpp +++ b/brion/synapse.cpp @@ -1,4 +1,6 @@ -/* Copyright (c) 2013-2015, EPFL/Blue Brain Project + +/* Copyright (c) 2013-2016, EPFL/Blue Brain Project + * bbp-open-source@googlegroups.com * Daniel Nachbaur * * This file is part of Brion @@ -27,13 +29,21 @@ #include #include #include +#include #include +#include #include + namespace brion { namespace detail { +namespace +{ +static lunchbox::a_ssize_t _cacheHits; +static lunchbox::a_ssize_t _cacheMiss; +} struct Dataset { @@ -49,6 +59,8 @@ class SynapseFile : public boost::noncopyable { public: explicit SynapseFile( const std::string& source ) + : _cache( lunchbox::PersistentMap::createCache( )) + , _cacheKey( fs::canonical( fs::path( source )).generic_string( )) { lunchbox::ScopedWrite mutex( detail::_hdf5Lock ); @@ -92,8 +104,32 @@ class SynapseFile : public boost::noncopyable if( !bits.any( )) return SynapseMatrix(); - lunchbox::ScopedWrite mutex( detail::_hdf5Lock ); + std::string cacheKey; + if( _cache ) + { + cacheKey = _cacheKey + "/" + lexical_cast< std::string >( gid ) + + "/" + lexical_cast< std::string >( attributes ); + const std::string& cached = (*_cache)[ cacheKey ]; + if( !cached.empty( )) + { + if( (++_cacheHits % 5000) == 0 ) + LBDEBUG << int( float( _cacheHits ) / + float( _cacheHits+_cacheMiss )*100.f + .5f ) + << "% cache hit rate" << std::endl; + + const size_t dim0 = cached.size() / bits.count() / + sizeof( float ); + SynapseMatrix values( boost::extents[ dim0 ][ bits.count( )]); + ::memcpy( values.data(), cached.data(), cached.size( )); + return values; + } + if( (++_cacheMiss % 5000) == 0 ) + LBDEBUG << int( float( _cacheHits ) / + float( _cacheHits + _cacheMiss ) * 100.f + .5f ) + << "% cache hit rate" << std::endl; + } + lunchbox::ScopedWrite mutex( detail::_hdf5Lock ); Dataset dataset; if( !_openDataset( gid, dataset )) return SynapseMatrix(); @@ -116,6 +152,9 @@ class SynapseFile : public boost::noncopyable dataset.dataset.read( values.data(), H5::PredType::NATIVE_FLOAT, targetspace, dataset.dataspace ); + if( _cache ) + _cache->insert( cacheKey, values.data(), + dataset.dims[0] * bits.count() * sizeof( float )); return values; } @@ -192,6 +231,8 @@ class SynapseFile : public boost::noncopyable } private: + lunchbox::PersistentMapPtr _cache; + std::string _cacheKey; H5::H5File _file; size_t _numAttributes; }; diff --git a/tests/synapse.cpp b/tests/synapse.cpp index f2c8c8f..ed030ef 100644 --- a/tests/synapse.cpp +++ b/tests/synapse.cpp @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE( perf ) const brion::Synapse synapseFile( path.string( )); brion::GIDSet gids; - for( uint32_t i = 1; i <= 1000; ++ i) + for( uint32_t i = 1; i <= 1000; ++i ) gids.insert( i ); namespace bp = boost::posix_time;