From a744f036b86665788c7d985cae7562305072f06a Mon Sep 17 00:00:00 2001 From: wrtobin Date: Thu, 22 Jun 2023 14:22:37 -0700 Subject: [PATCH] wip --- src/coreComponents/LvArray | 2 +- .../dataRepository/BufferOps.hpp | 124 +++++++++- .../dataRepository/BufferOps_inline.hpp | 220 ++++++++++++++---- src/coreComponents/dataRepository/Wrapper.hpp | 30 +-- .../dataRepository/wrapperHelpers.hpp | 13 ++ .../fileIO/timeHistory/PackCollection.cpp | 17 +- src/docs/doxygen/GeosxConfig.hpp | 10 +- 7 files changed, 331 insertions(+), 85 deletions(-) diff --git a/src/coreComponents/LvArray b/src/coreComponents/LvArray index 76dcda0e716..0699503c8a2 160000 --- a/src/coreComponents/LvArray +++ b/src/coreComponents/LvArray @@ -1 +1 @@ -Subproject commit 76dcda0e71678598ef76b9fd7bc5a1b28f5e13e1 +Subproject commit 0699503c8a2e1cae5f1e16887443e1ff86906ee3 diff --git a/src/coreComponents/dataRepository/BufferOps.hpp b/src/coreComponents/dataRepository/BufferOps.hpp index f277f3c19a2..55326e66e56 100644 --- a/src/coreComponents/dataRepository/BufferOps.hpp +++ b/src/coreComponents/dataRepository/BufferOps.hpp @@ -38,12 +38,11 @@ template< typename T > struct is_host_packable_helper; - template< typename T > constexpr bool is_host_packable_scalar = std::is_trivial< T >::value || std::is_arithmetic< T >::value; -/// Whether an object itself is packable +/// Whether an object of type T is itself packable template< typename T > constexpr bool is_host_packable_object = is_host_packable_scalar< T > || traits::is_tensorT< T > || @@ -53,7 +52,6 @@ template< typename T > constexpr bool is_container = !is_host_packable_object< T >; - /// Whether an object is an lvarray array/arrayview/arrayslice/arrayofarrays which ultimately contains packable objects when fully indexed template< typename > constexpr bool is_host_packable_array = false; @@ -71,7 +69,6 @@ template< typename T > constexpr bool is_host_packable_array< ArrayOfArrays< T > > = is_host_packable_helper< T >::value; - /// Whether an object is an lvarray sortedarray which contains packable objects template< typename > constexpr bool is_host_packable_set = false; @@ -80,7 +77,6 @@ template< typename T > constexpr bool is_host_packable_set< SortedArray< T > > = is_host_packable_helper< T >::value; - /// Whether an object is a map for which the keys and values are packable objects template< typename > constexpr bool is_host_packable_map = false; @@ -90,8 +86,6 @@ constexpr bool is_host_packable_map< mapBase< T_KEY, T_VAL, SORTED > > = is_host is_host_packable_helper< T_VAL >::value; - - template< typename T > struct is_host_packable_helper { @@ -120,69 +114,139 @@ constexpr bool is_host_packable_map_by_index< mapBase< T_KEY, T_VAL, SORTED > > is_host_packable_by_index< T_VAL >; - //------------------------------------------------------------------------------ // Pack(buffer,var) +//------------------------------------------------------------------------------ +template< bool DO_PACKING, typename T > +typename std::enable_if< is_host_packable_scalar< T >, localIndex >::type +PackData( buffer_unit_type * & buffer, + T const & var ); + //------------------------------------------------------------------------------ template< bool DO_PACKING, typename T > typename std::enable_if< is_host_packable_scalar< T >, localIndex >::type Pack( buffer_unit_type * & buffer, T const & var ); +//------------------------------------------------------------------------------ +template< bool DO_PACKING > +localIndex +PackData( buffer_unit_type * & buffer, + const string & var ); + //------------------------------------------------------------------------------ template< bool DO_PACKING > localIndex Pack( buffer_unit_type * & buffer, const string & var ); +//------------------------------------------------------------------------------ +template< bool DO_PACKING, typename T > +localIndex +PackData( buffer_unit_type * & buffer, + SortedArray< T > const & var ); + //------------------------------------------------------------------------------ template< bool DO_PACKING, typename T > localIndex Pack( buffer_unit_type * & buffer, SortedArray< T > const & var ); +//------------------------------------------------------------------------------ +template< bool DO_PACKING, typename T > +typename std::enable_if< traits::is_tensorT< T >, localIndex >::type +PackData( buffer_unit_type * & buffer, + T const & var ); + //------------------------------------------------------------------------------ template< bool DO_PACKING, typename T > typename std::enable_if< traits::is_tensorT< T >, localIndex >::type Pack( buffer_unit_type * & buffer, T const & var ); +//------------------------------------------------------------------------------ +template< bool DO_PACKING, typename T, int NDIM, int USD > +typename std::enable_if< is_host_packable< T >, localIndex >::type +PackData( buffer_unit_type * & buffer, + ArrayView< T, NDIM, USD > const & var ); + //------------------------------------------------------------------------------ template< bool DO_PACKING, typename T, int NDIM, int USD > typename std::enable_if< is_host_packable< T >, localIndex >::type Pack( buffer_unit_type * & buffer, ArrayView< T, NDIM, USD > const & var ); +//------------------------------------------------------------------------------ +template< bool DO_PACKING, typename T > +localIndex +PackData( buffer_unit_type * & buffer, + ArrayOfArrays< T > const & var ); + //------------------------------------------------------------------------------ template< bool DO_PACKING, typename T > localIndex Pack( buffer_unit_type * & buffer, ArrayOfArrays< T > const & var ); +//------------------------------------------------------------------------------ +template< bool DO_PACKING, typename T > +localIndex +PackData( buffer_unit_type * & buffer, + ArrayOfSets< T > const & var ); + //------------------------------------------------------------------------------ template< bool DO_PACKING, typename T > localIndex Pack( buffer_unit_type * & buffer, ArrayOfSets< T > const & var ); +//------------------------------------------------------------------------------ +template< bool DO_PACKING, typename MAP_TYPE > +typename std::enable_if< is_host_packable_map< MAP_TYPE >, localIndex >::type +PackData( buffer_unit_type * & buffer, + MAP_TYPE const & var ); + //------------------------------------------------------------------------------ template< bool DO_PACKING, typename MAP_TYPE > typename std::enable_if< is_host_packable_map< MAP_TYPE >, localIndex >::type Pack( buffer_unit_type * & buffer, MAP_TYPE const & var ); +//------------------------------------------------------------------------------ +template< bool DO_PACKING, typename T_FIRST, typename T_SECOND > +localIndex +PackData( buffer_unit_type * & buffer, + std::pair< T_FIRST, T_SECOND > const & var ); + //------------------------------------------------------------------------------ template< bool DO_PACKING, typename T_FIRST, typename T_SECOND > localIndex Pack( buffer_unit_type * & buffer, std::pair< T_FIRST, T_SECOND > const & var ); +//------------------------------------------------------------------------------ +template< bool DO_PACKING, typename T > +localIndex +PackData( buffer_unit_type * & buffer, + InterObjectRelation< T > const & var ); + //------------------------------------------------------------------------------ template< bool DO_PACKING, typename T > localIndex Pack( buffer_unit_type * & buffer, InterObjectRelation< T > const & var ); +//------------------------------------------------------------------------------ +// fallthrough-implementation +template< bool DO_PACKING, typename T > +typename std::enable_if< !is_host_packable< T >, localIndex >::type +PackData( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ), + T const & GEOS_UNUSED_PARAM( var ) ) +{ + GEOS_ERROR( "Trying to pack data type ("< @@ -197,12 +261,25 @@ Pack( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ), //------------------------------------------------------------------------------ // PackArray(buffer,var,length) //------------------------------------------------------------------------------ +template< bool DO_PACKING, typename T, typename INDEX_TYPE > +typename std::enable_if< std::is_trivial< T >::value, localIndex >::type +PackPointerData( buffer_unit_type * & buffer, + T const * const GEOS_RESTRICT var, + INDEX_TYPE const length ); + template< bool DO_PACKING, typename T, typename INDEX_TYPE > typename std::enable_if< std::is_trivial< T >::value, localIndex >::type PackPointer( buffer_unit_type * & buffer, T const * const GEOS_RESTRICT var, INDEX_TYPE const length ); +//------------------------------------------------------------------------------ +template< bool DO_PACKING, typename T, typename INDEX_TYPE > +typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type +PackPointerData( buffer_unit_type * & buffer, + T const * const GEOS_RESTRICT var, + INDEX_TYPE const length ); + //------------------------------------------------------------------------------ template< bool DO_PACKING, typename T, typename INDEX_TYPE > typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type @@ -227,6 +304,12 @@ PackArray( buffer_unit_type * & buffer, //------------------------------------------------------------------------------ // PackByIndex(buffer,var,indices) //------------------------------------------------------------------------------ +template< bool DO_PACKING, typename T, int NDIM, int USD, typename T_indices > +typename std::enable_if< is_host_packable< T >, localIndex >::type +PackDataByIndex( buffer_unit_type * & buffer, + ArrayView< T, NDIM, USD > const & var, + const T_indices & indices ); + template< bool DO_PACKING, typename T, int NDIM, int USD, typename T_indices > typename std::enable_if< is_host_packable< T >, localIndex >::type PackByIndex( buffer_unit_type * & buffer, @@ -234,12 +317,23 @@ PackByIndex( buffer_unit_type * & buffer, const T_indices & indices ); //------------------------------------------------------------------------------ +template< bool DO_PACKING, typename T, typename T_indices > +localIndex PackDataByIndex( buffer_unit_type * & buffer, + ArrayOfArrays< T > const & var, + T_indices const & indices ); + template< bool DO_PACKING, typename T, typename T_indices > localIndex PackByIndex( buffer_unit_type * & buffer, ArrayOfArrays< T > const & var, T_indices const & indices ); //------------------------------------------------------------------------------ +template< bool DO_PACKING, typename MAP_TYPE, typename T_INDICES > +typename std::enable_if< is_host_packable_map_by_index< MAP_TYPE >, localIndex >::type +PackDataByIndex( buffer_unit_type * & buffer, + MAP_TYPE const & var, + T_INDICES const & indices ); + template< bool DO_PACKING, typename MAP_TYPE, typename T_INDICES > typename std::enable_if< is_host_packable_map_by_index< MAP_TYPE >, localIndex >::type PackByIndex( buffer_unit_type * & buffer, @@ -247,6 +341,17 @@ PackByIndex( buffer_unit_type * & buffer, T_INDICES const & indices ); //------------------------------------------------------------------------------ +template< bool DO_PACKING, typename T, typename T_INDICES > +typename std::enable_if< !is_host_packable_by_index< T > && !is_host_packable_map_by_index< T >, localIndex >::type +PackDataByIndex( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ), + T const & GEOS_UNUSED_PARAM( var ), + T_INDICES const & GEOS_UNUSED_PARAM( indices ) ) +{ + GEOS_ERROR( "Trying to pack data type ("< typename std::enable_if< !is_host_packable_by_index< T > && !is_host_packable_map_by_index< T >, localIndex >::type PackByIndex( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ), @@ -366,21 +471,18 @@ UnpackByIndex( buffer_unit_type const * & buffer, ArrayView< T, NDIM, USD > const & var, const T_indices & indices ); -//------------------------------------------------------------------------------ template< typename T, typename T_indices > localIndex UnpackByIndex( buffer_unit_type const * & buffer, ArrayOfArrays< T > & var, T_indices const & indices ); -//------------------------------------------------------------------------------ template< typename MAP_TYPE, typename T_INDICES > typename std::enable_if< is_host_packable_map_by_index< MAP_TYPE >, localIndex >::type UnpackByIndex( buffer_unit_type const * & buffer, MAP_TYPE & map, T_INDICES const & indices ); -//------------------------------------------------------------------------------ template< typename T, typename T_INDICES > typename std::enable_if< !is_host_packable_by_index< T > && !is_host_packable_map_by_index< T >, localIndex >::type UnpackByIndex( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ), diff --git a/src/coreComponents/dataRepository/BufferOps_inline.hpp b/src/coreComponents/dataRepository/BufferOps_inline.hpp index 30640acd476..5b3226f61a3 100644 --- a/src/coreComponents/dataRepository/BufferOps_inline.hpp +++ b/src/coreComponents/dataRepository/BufferOps_inline.hpp @@ -32,7 +32,7 @@ namespace bufferOps template< bool DO_PACKING, typename T > typename std::enable_if< is_host_packable_scalar< T >, localIndex >::type -Pack( buffer_unit_type * & buffer, T const & var ) +PackData( buffer_unit_type * & buffer, T const & var ) { localIndex const sizeOfPackedChars = sizeof(T); if( DO_PACKING ) @@ -43,53 +43,44 @@ Pack( buffer_unit_type * & buffer, T const & var ) return sizeOfPackedChars; } -template< bool DO_PACKING, typename T, typename INDEX_TYPE > -typename std::enable_if< std::is_trivial< T >::value, localIndex >::type -Pack( buffer_unit_type * & buffer, T const * const GEOS_RESTRICT var, INDEX_TYPE const length ) + +template< bool DO_PACKING, typename T > +typename std::enable_if< is_host_packable_scalar< T >, localIndex >::type +Pack( buffer_unit_type * & buffer, T const & var ) { - localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length ); + return PackData< DO_PACKING >( buffer, var ); +} - sizeOfPackedChars += length * sizeof(T); +template< bool DO_PACKING > +localIndex PackData( buffer_unit_type * & buffer, const string & var ) +{ + localIndex sizeOfPackedChars = 0; + const string::size_type varSize = var.size(); if( DO_PACKING ) { - memcpy( buffer, var, length * sizeof(T) ); - buffer += length * sizeof(T); + memcpy( buffer, var.data(), varSize ); + buffer += varSize; } - + sizeOfPackedChars += varSize; return sizeOfPackedChars; } -template< typename T, typename INDEX_TYPE > -typename std::enable_if< std::is_trivial< T >::value, localIndex >::type -Unpack( buffer_unit_type const * & buffer, T * const GEOS_RESTRICT var, INDEX_TYPE const expectedLength ) -{ - INDEX_TYPE length; - localIndex sizeOfUnpackedChars = Unpack( buffer, length ); - - GEOS_ASSERT_MSG( length == expectedLength, "expectedLength != length: " << - expectedLength << " != " << length ); - GEOS_DEBUG_VAR( expectedLength ); - - memcpy( var, buffer, length * sizeof(T) ); - sizeOfUnpackedChars += length * sizeof(T); - buffer += length * sizeof(T); - - return sizeOfUnpackedChars; -} - template< bool DO_PACKING > localIndex Pack( buffer_unit_type * & buffer, const string & var ) { const string::size_type varSize = var.size(); localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, varSize ); + return sizeOfPackedChars + PackData< DO_PACKING >( buffer, var ); +} - if( DO_PACKING ) +template< bool DO_PACKING, typename T > +localIndex PackData( buffer_unit_type * & buffer, SortedArray< T > const & var ) +{ + localIndex sizeOfPackedChars = 0; + for( T const & val : var ) { - memcpy( buffer, var.data(), varSize ); - buffer += varSize; + sizeOfPackedChars += Pack< DO_PACKING >( buffer, val ); } - - sizeOfPackedChars += varSize; return sizeOfPackedChars; } @@ -98,18 +89,32 @@ localIndex Pack( buffer_unit_type * & buffer, SortedArray< T > const & var ) { const localIndex length = LvArray::integerConversion< localIndex >( var.size() ); localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length ); - for( T const & val : var ) - { - sizeOfPackedChars += Pack< DO_PACKING >( buffer, val ); - } + return sizeOfPackedChars + PackData< DO_PACKING >( buffer, var ); +} + +template< bool DO_PACKING, typename T, int SIZE > +localIndex PackData( buffer_unit_type * & buffer, Tensor< T, SIZE > const & var ) +{ + localIndex sizeOfPackedChars = 0; + sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, var.data, SIZE ); return sizeOfPackedChars; } template< bool DO_PACKING, typename T, int SIZE > localIndex Pack( buffer_unit_type * & buffer, Tensor< T, SIZE > const & var ) +{ + return PackData< DO_PACKING >( buffer, var ); +} + +template< bool DO_PACKING, typename T, int NDIM, int USD > +typename std::enable_if< is_host_packable< T >, localIndex >::type +PackData( buffer_unit_type * & buffer, + ArrayView< T, NDIM, USD > const & var ) { localIndex sizeOfPackedChars = 0; - sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, var.data, SIZE ); + const localIndex length = var.size(); + T const * const data = var.data(); + sizeOfPackedChars += PackPointerData< DO_PACKING >( buffer, data, length ); return sizeOfPackedChars; } @@ -121,8 +126,20 @@ Pack( buffer_unit_type * & buffer, localIndex sizeOfPackedChars = PackPointer< DO_PACKING >( buffer, var.dims(), NDIM ); sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, var.strides(), NDIM ); const localIndex length = var.size(); - T const * const data = var.data(); - sizeOfPackedChars += PackPointer< DO_PACKING >( buffer, data, length ); + sizeOfPackedChars += PackData< DO_PACKING >( buffer, length ); + return sizeOfPackedChars + PackData< DO_PACKING >( buffer, var ); +} + +template< bool DO_PACKING, typename T > +localIndex PackData( buffer_unit_type * & buffer, + ArrayOfArrays< T > const & var ) +{ + localIndex sizeOfPackedChars = 0; + for( localIndex a=0; a( buffer, data, var.sizeOfArray( a ) ); + } return sizeOfPackedChars; } @@ -141,6 +158,19 @@ localIndex Pack( buffer_unit_type * & buffer, return sizeOfPackedChars; } +template< bool DO_PACKING, typename T > +localIndex PackData( buffer_unit_type * & buffer, + ArrayOfSets< T > const & var ) +{ + localIndex sizeOfPackedChars = 0; + for( localIndex a=0; a( buffer, data, var.sizeOfSet( a ) ); + } + return sizeOfPackedChars; +} + template< bool DO_PACKING, typename T > localIndex Pack( buffer_unit_type * & buffer, ArrayOfSets< T > const & var ) @@ -156,6 +186,19 @@ localIndex Pack( buffer_unit_type * & buffer, return sizeOfPackedChars; } +template< bool DO_PACKING, typename MAP_TYPE > +typename std::enable_if< is_host_packable_map< MAP_TYPE >, localIndex >::type +PackData( buffer_unit_type * & buffer, MAP_TYPE const & var ) +{ + localIndex sizeOfPackedChars = 0; + for( typename MAP_TYPE::const_iterator i = var.begin(); i != var.end(); ++i ) + { + sizeOfPackedChars += PackData< DO_PACKING >( buffer, i->first ); + sizeOfPackedChars += PackData< DO_PACKING >( buffer, i->second ); + } + return sizeOfPackedChars; +} + template< bool DO_PACKING, typename MAP_TYPE > typename std::enable_if< is_host_packable_map< MAP_TYPE >, localIndex >::type Pack( buffer_unit_type * & buffer, MAP_TYPE const & var ) @@ -170,6 +213,15 @@ Pack( buffer_unit_type * & buffer, MAP_TYPE const & var ) return sizeOfPackedChars; } +template< bool DO_PACKING, typename T_FIRST, typename T_SECOND > +localIndex +PackData( buffer_unit_type * & buffer, std::pair< T_FIRST, T_SECOND > const & var ) +{ + localIndex sizeOfPackedChars = PackData< DO_PACKING >( buffer, var.first ); + sizeOfPackedChars += PackData< DO_PACKING >( buffer, var.second ); + return sizeOfPackedChars; +} + template< bool DO_PACKING, typename T_FIRST, typename T_SECOND > localIndex Pack( buffer_unit_type * & buffer, std::pair< T_FIRST, T_SECOND > const & var ) @@ -179,6 +231,12 @@ Pack( buffer_unit_type * & buffer, std::pair< T_FIRST, T_SECOND > const & var ) return sizeOfPackedChars; } +template< bool DO_PACKING, typename T > +localIndex PackData( buffer_unit_type * & buffer, InterObjectRelation< T > const & var ) +{ + return PackData< DO_PACKING >( buffer, static_cast< T const & >(var)); +} + template< bool DO_PACKING, typename T > localIndex Pack( buffer_unit_type * & buffer, InterObjectRelation< T > const & var ) { @@ -188,12 +246,12 @@ localIndex Pack( buffer_unit_type * & buffer, InterObjectRelation< T > const & v //------------------------------------------------------------------------------ // PackArray(buffer,var,length) //------------------------------------------------------------------------------ + template< bool DO_PACKING, typename T, typename INDEX_TYPE > typename std::enable_if< std::is_trivial< T >::value, localIndex >::type -PackPointer( buffer_unit_type * & buffer, T const * const GEOS_RESTRICT var, INDEX_TYPE const length ) +PackPointerData( buffer_unit_type * & buffer, T const * const GEOS_RESTRICT var, INDEX_TYPE const length ) { - localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length ); - sizeOfPackedChars += length * sizeof(T); + localIndex sizeOfPackedChars = length * sizeof(T); if( DO_PACKING ) { memcpy( buffer, var, length * sizeof(T) ); @@ -202,6 +260,29 @@ PackPointer( buffer_unit_type * & buffer, T const * const GEOS_RESTRICT var, IND return sizeOfPackedChars; } +template< bool DO_PACKING, typename T, typename INDEX_TYPE > +typename std::enable_if< std::is_trivial< T >::value, localIndex >::type +PackPointer( buffer_unit_type * & buffer, T const * const GEOS_RESTRICT var, INDEX_TYPE const length ) +{ + localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length ); + return sizeOfPackedChars + PackPointerData< DO_PACKING >( buffer, var, length ); +} + +template< bool DO_PACKING, typename T, typename INDEX_TYPE > +typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type +PackPointerData( buffer_unit_type * & buffer, + T const * const GEOS_RESTRICT var, + INDEX_TYPE const length ) + +{ + localIndex sizeOfPackedChars = 0; + for( INDEX_TYPE a = 0; a < length; ++a ) + { + sizeOfPackedChars += PackData< DO_PACKING >( buffer, var[ a ] ); + } + return sizeOfPackedChars; +} + template< bool DO_PACKING, typename T, typename INDEX_TYPE > typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type PackPointer( buffer_unit_type * & buffer, @@ -214,7 +295,6 @@ PackPointer( buffer_unit_type * & buffer, { sizeOfPackedChars += Pack< DO_PACKING >( buffer, var[ a ] ); } - return sizeOfPackedChars; } @@ -255,6 +335,26 @@ PackArray( buffer_unit_type * & buffer, //------------------------------------------------------------------------------ // PackByIndex(buffer,var,indices) //------------------------------------------------------------------------------ + +template< bool DO_PACKING, typename T, int NDIM, int USD, typename T_indices > +typename std::enable_if< is_host_packable< T >, localIndex >::type +PackDataByIndex( buffer_unit_type * & buffer, + ArrayView< T, NDIM, USD > const & var, + const T_indices & indices ) +{ + localIndex sizeOfPackedChars = 0; + for( localIndex a = 0; a < indices.size(); ++a ) + { + LvArray::forValuesInSlice( var[ indices[ a ] ], + [&sizeOfPackedChars, &buffer]( T const & value ) + { + sizeOfPackedChars += PackData< DO_PACKING >( buffer, value ); + } + ); + } + return sizeOfPackedChars; +} + template< bool DO_PACKING, typename T, int NDIM, int USD, typename T_indices > typename std::enable_if< is_host_packable< T >, localIndex >::type PackByIndex( buffer_unit_type * & buffer, @@ -274,6 +374,20 @@ PackByIndex( buffer_unit_type * & buffer, return sizeOfPackedChars; } +template< bool DO_PACKING, typename T, typename T_indices > +localIndex PackDataByIndex( buffer_unit_type * & buffer, + ArrayOfArrays< T > const & var, + T_indices const & indices ) +{ + localIndex sizeOfPackedChars = 0; + for( localIndex a = 0; a < indices.size(); ++a ) + { + T const * const data = var[indices[a]]; + sizeOfPackedChars += PackPointerData< DO_PACKING >( buffer, data, var.sizeOfArray( indices[a] ) ); + } + return sizeOfPackedChars; +} + template< bool DO_PACKING, typename T, typename T_indices > localIndex PackByIndex( buffer_unit_type * & buffer, ArrayOfArrays< T > const & var, @@ -290,18 +404,33 @@ localIndex PackByIndex( buffer_unit_type * & buffer, return sizeOfPackedChars; } +template< bool DO_PACKING, typename MAP_TYPE, typename T_INDICES > +typename std::enable_if< is_host_packable_map_by_index< MAP_TYPE >, localIndex >::type +PackDataByIndex( buffer_unit_type * & buffer, + MAP_TYPE const & var, + T_INDICES const & indices ) +{ + localIndex sizeOfPackedChars = 0; + for( typename MAP_TYPE::const_iterator i = var.begin(); i != var.end(); ++i ) + { + sizeOfPackedChars += PackData< DO_PACKING >( buffer, i->first ); + sizeOfPackedChars += PackDataByIndex< DO_PACKING >( buffer, i->second, indices ); + } + return sizeOfPackedChars; +} + template< bool DO_PACKING, typename MAP_TYPE, typename T_INDICES > typename std::enable_if< is_host_packable_map_by_index< MAP_TYPE >, localIndex >::type PackByIndex( buffer_unit_type * & buffer, MAP_TYPE const & var, - T_INDICES const & packIndices ) + T_INDICES const & indices ) { const typename MAP_TYPE::size_type length = var.size(); localIndex sizeOfPackedChars = Pack< DO_PACKING >( buffer, length ); for( typename MAP_TYPE::const_iterator i = var.begin(); i != var.end(); ++i ) { sizeOfPackedChars += Pack< DO_PACKING >( buffer, i->first ); - sizeOfPackedChars += PackByIndex< DO_PACKING >( buffer, i->second, packIndices ); + sizeOfPackedChars += PackByIndex< DO_PACKING >( buffer, i->second, indices ); } return sizeOfPackedChars; } @@ -475,7 +604,6 @@ UnpackPointer( buffer_unit_type const * & buffer, localIndex sizeOfUnpackedChars = Unpack( buffer, length ); GEOS_ASSERT_EQ( length, expectedLength ); GEOS_DEBUG_VAR( expectedLength ); - for( INDEX_TYPE a=0; a::value, "should only be instantiated for the wrapped type!" ); - auto const & ref = reference(); - if( ref.getPreviousSpace() == LvArray::MemorySpace::host && ref.checkTouch() ) + if( reference().getPreviousSpace() == LvArray::MemorySpace::host ) { // a type with the mem-space functions, that is not packable on device (e.g. array ), should never be moved to device, // so it should always have previousSpace == host and checkTouch == true, and we can then host-pack it if possible (should always be possible) @@ -809,8 +808,7 @@ class Wrapper final : public WrapperBase isPackableByIndexImpl( ) const { static_assert( std::is_same< T, U >::value, "should only be instantiated for the wrapped type!" ); - auto const & ref = reference(); - if( ref.getPreviousSpace() == LvArray::MemorySpace::host && ref.checkTouch() ) + if( reference().getPreviousSpace() == LvArray::MemorySpace::host ) { return bufferOps::is_host_packable_by_index< U >; } @@ -863,8 +861,7 @@ class Wrapper final : public WrapperBase unpackImpl( buffer_unit_type const * & buffer, bool withMetadata, parallelDeviceEvents & events ) { static_assert( std::is_same< T, U >::value, "should only be instantiated for the wrapped type!" ); - auto const & ref = reference(); - if( ref.getPreviousSpace() == LvArray::MemorySpace::host && ref.checkTouch() ) + if( reference().getPreviousSpace() == LvArray::MemorySpace::host ) { return unpackHostImpl( buffer, withMetadata, events ); } @@ -917,8 +914,7 @@ class Wrapper final : public WrapperBase unpackByIndexImpl( buffer_unit_type const * & buffer, arrayView1d< localIndex const > const & unpackIndices, bool withMetadata, parallelDeviceEvents & events ) { static_assert( std::is_same< T, U >::value, "should only be instantiated for the wrapped type!" ); - auto const & ref = reference(); - if( ref.getPreviousSpace() == LvArray::MemorySpace::host && ref.checkTouch() ) + if( reference().getPreviousSpace() == LvArray::MemorySpace::host ) { return unpackByIndexHostImpl( buffer, unpackIndices, withMetadata, events ); } @@ -967,8 +963,12 @@ class Wrapper final : public WrapperBase if( withMetadata ) { packedSize += bufferOps::Pack< DO_PACKING >( buffer, getName() ); + packedSize += bufferOps::Pack< DO_PACKING >( buffer, *m_data ); + } + else + { + packedSize += bufferOps::PackData< DO_PACKING >( buffer, *m_data ); } - packedSize += bufferOps::Pack< DO_PACKING >( buffer, *m_data ); return packedSize; } @@ -979,8 +979,7 @@ class Wrapper final : public WrapperBase bool withMetadata, parallelDeviceEvents & events ) const { - auto const & ref = reference(); - if( ref.getPreviousSpace() == LvArray::MemorySpace::host && ref.checkTouch() ) + if( reference().getPreviousSpace() == LvArray::MemorySpace::host ) { return packHostImpl< DO_PACKING >( buffer, withMetadata, events ); } @@ -1042,8 +1041,12 @@ class Wrapper final : public WrapperBase if( withMetadata ) { packedSize += bufferOps::Pack< DO_PACKING >( buffer, getName() ); + packedSize += wrapperHelpers::PackByIndex< DO_PACKING >( buffer, *m_data, packList ); + } + else + { + packedSize += wrapperHelpers::PackDataByIndex< DO_PACKING >( buffer, *m_data, packList ); } - packedSize += wrapperHelpers::PackByIndex< DO_PACKING >( buffer, *m_data, packList ); return packedSize; } @@ -1056,8 +1059,7 @@ class Wrapper final : public WrapperBase parallelDeviceEvents & events ) const { static_assert( std::is_same< T, U >::value, "should only be instantiated for the wrapped type!" ); - auto const & ref = reference(); - if( ref.getPreviousSpace() == LvArray::MemorySpace::host && ref.checkTouch() ) + if( reference().getPreviousSpace() == LvArray::MemorySpace::host ) { return packByIndexHostImpl< DO_PACKING >( buffer, packList, withMetadata, events ); } diff --git a/src/coreComponents/dataRepository/wrapperHelpers.hpp b/src/coreComponents/dataRepository/wrapperHelpers.hpp index 659d3063468..84d96565e27 100644 --- a/src/coreComponents/dataRepository/wrapperHelpers.hpp +++ b/src/coreComponents/dataRepository/wrapperHelpers.hpp @@ -726,6 +726,19 @@ UnpackByIndex( buffer_unit_type const * &, T &, IDX & ) return 0; } +template< bool DO_PACKING, typename T, typename IDX > +inline std::enable_if_t< bufferOps::is_host_packable_by_index< T >, localIndex > +PackDataByIndex( buffer_unit_type * & buffer, T & var, IDX & idx ) +{ return bufferOps::PackDataByIndex< DO_PACKING >( buffer, var, idx ); } + +template< bool DO_PACKING, typename T, typename IDX > +inline std::enable_if_t< !bufferOps::is_host_packable_by_index< T >, localIndex > +PackDataByIndex( buffer_unit_type * &, T &, IDX & ) +{ + GEOS_ERROR( "Trying to pack data type (" << LvArray::system::demangleType< T >() << ") by index. Operation not supported." ); + return 0; +} + template< bool DO_PACKING, typename T > inline std::enable_if_t< bufferOps::is_container< T > || bufferOps::is_device_packable< T >, localIndex > diff --git a/src/coreComponents/fileIO/timeHistory/PackCollection.cpp b/src/coreComponents/fileIO/timeHistory/PackCollection.cpp index e92291fcd2b..c02da54c12e 100644 --- a/src/coreComponents/fileIO/timeHistory/PackCollection.cpp +++ b/src/coreComponents/fileIO/timeHistory/PackCollection.cpp @@ -119,18 +119,19 @@ void PackCollection::updateSetsIndices( DomainPartition const & domain ) return omb; }; - Group const * targetGrp = this->getTargetObject( domain, m_objectPath ); - WrapperBase const & targetField = targetGrp->getWrapperBase( m_fieldName ); - GEOS_ERROR_IF( !targetField.isPackable( ), GEOS_FMT( "The object targeted for collection ({}: {}, {}: {}) must be packable in its last modified memory space!", - viewKeysStruct::objectPathString(), - m_objectPath, - viewKeysStruct::fieldNameString(), - m_fieldName ) ); - // If no set or "all" is specified we retrieve the entire field. // If sets are specified we retrieve the field only from those sets. bool const collectAll = this->collectAll(); + Group const * targetGrp = this->getTargetObject( domain, m_objectPath ); + WrapperBase const & targetField = targetGrp->getWrapperBase( m_fieldName ); + GEOS_ERROR_IF( !( (!m_targetIsMeshObject && collectAll) ? targetField.isPackable( ) : targetField.isPackableByIndex()), + GEOS_FMT( "The object targeted for collection ({}: {}, {}: {}) must be packable in its last modified memory space!", + viewKeysStruct::objectPathString(), + m_objectPath, + viewKeysStruct::fieldNameString(), + m_fieldName ) ); + // In the wake of previous trick about `m_setNames`, another small trick not to compute the real set names if they are not needed. // This is questionable but lets me define `setNames` as `const` variable. // Note that the third operator will be evaluated iff `collectAll` is `false` (C++ paragraph 6.5.15). diff --git a/src/docs/doxygen/GeosxConfig.hpp b/src/docs/doxygen/GeosxConfig.hpp index 04b69853fd4..54412c1b918 100644 --- a/src/docs/doxygen/GeosxConfig.hpp +++ b/src/docs/doxygen/GeosxConfig.hpp @@ -33,10 +33,10 @@ #define GEOSX_USE_OPENMP /// Enables use of CUDA (CMake option ENABLE_CUDA) -/* #undef GEOS_USE_CUDA */ +#define GEOS_USE_CUDA /// Enables use of CUDA NVToolsExt (CMake option ENABLE_CUDA_NVTOOLSEXT) -/* #undef GEOS_USE_CUDA_NVTOOLSEXT */ +#define GEOS_USE_CUDA_NVTOOLSEXT /// Enables use of HIP (CMake option ENABLE_HIP) /* #undef GEOS_USE_HIP */ @@ -69,7 +69,7 @@ /// Parsed hypre version information #define HYPRE_VERSION_MAJOR 2 /// Parsed hypre version information - #define HYPRE_VERSION_MINOR 28 + #define HYPRE_VERSION_MINOR 27 /// Parsed hypre version information #define HYPRE_VERSION_PATCH 0 #endif @@ -81,7 +81,7 @@ /// Denotes HYPRE using HIP #define GEOS_USE_HYPRE_HIP 2 /// Macro determining what parellel interface hypre is using -#define GEOS_USE_HYPRE_DEVICE GEOS_USE_HYPRE_CPU +#define GEOS_USE_HYPRE_DEVICE GEOS_USE_HYPRE_CUDA /// Enables use of SuperLU_dist library through HYPRE (CMake option ENABLE_SUPERLU_DIST) #define GEOSX_USE_SUPERLU_DIST @@ -171,7 +171,7 @@ #define Python3_VERSION 3.10.8 /// Version information for CUDAToolkit -/* #undef CUDAToolkit_VERSION */ +#define CUDAToolkit_VERSION 11.6.112 #if defined(GEOS_USE_CUDA) || defined(GEOS_USE_HIP) // This needs to be placed into this header in order to appropriately replace