Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# SPDX-License-Identifier: (BSD-3-Clause)
###################################################################################################

cmake_minimum_required( VERSION 3.9 )
cmake_minimum_required( VERSION 3.24 )

# Set version number
set( LVARRAY_VERSION_MAJOR 0 )
Expand Down Expand Up @@ -77,11 +77,11 @@ blt_list_append( TO lvarray_dependencies ELEMENTS chai IF ENABLE_CHAI )

blt_list_append( TO lvarray_dependencies ELEMENTS RAJA )

blt_list_append( TO lvarray_dependencies ELEMENTS umpire IF ENABLE_UMPIRE )
blt_list_append( TO lvarray_dependencies ELEMENTS umpire::umpire IF ENABLE_UMPIRE )

# Ignore umpire warnings as errors by using -isystem flag
if (ENABLE_UMPIRE)
blt_convert_to_system_includes(TARGET umpire)
blt_convert_to_system_includes(TARGET umpire::umpire)
endif()

blt_list_append( TO lvarray_dependencies ELEMENTS cuda IF ENABLE_CUDA )
Expand Down Expand Up @@ -116,5 +116,3 @@ endif()
if( ENABLE_DOCS )
add_subdirectory( docs )
endif()


2 changes: 1 addition & 1 deletion cmake/SetupTPL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if(ENABLE_UMPIRE)
find_package(umpire REQUIRED
PATHS ${UMPIRE_DIR})

set(thirdPartyLibs ${thirdPartyLibs} umpire)
set(thirdPartyLibs ${thirdPartyLibs} umpire::umpire)
else()
message(STATUS "Not using Umpire.")
endif()
Expand Down
27 changes: 21 additions & 6 deletions src/ArrayOfArraysView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,10 @@ class ArrayOfArraysView
{
INDEX_TYPE const curArraySize = sizeOfArray( array );
INDEX_TYPE const curArrayOffset = m_offsets[ array ];
arrayManipulation::uninitializedShiftUp( &buffer[ curArrayOffset ], curArraySize, capacityIncrease );
if( curArraySize > 0 )
{
arrayManipulation::uninitializedShiftUp( &buffer[ curArrayOffset ], curArraySize, capacityIncrease );
}
}
}
else
Expand All @@ -944,8 +947,11 @@ class ArrayOfArraysView
INDEX_TYPE const curArraySize = sizeOfArray( array );
INDEX_TYPE const curArrayOffset = m_offsets[ array ];
INDEX_TYPE shift = array > i ? capacityIncrease : 0;
arrayManipulation::uninitializedMove( &newBuffer[ curArrayOffset + shift ], curArraySize, &buffer[ curArrayOffset ] );
arrayManipulation::destroy( &buffer[ curArrayOffset ], curArraySize );
if( curArraySize > 0 )
{
arrayManipulation::uninitializedMove( &newBuffer[ curArrayOffset + shift ], curArraySize, &buffer[ curArrayOffset ] );
arrayManipulation::destroy( &buffer[ curArrayOffset ], curArraySize );
}
}

buffer.free();
Expand All @@ -968,14 +974,20 @@ class ArrayOfArraysView
[this, i, capacityDecrease, arrayOffset, newArraySize, prevArraySize] ( auto & buffer )
{
// Delete the values at the end of the array.
arrayManipulation::destroy( &buffer[ arrayOffset + newArraySize ], prevArraySize - newArraySize );
if( prevArraySize > newArraySize )
{
arrayManipulation::destroy( &buffer[ arrayOffset + newArraySize ], prevArraySize - newArraySize );
}

// Shift down the values of subsequent arrays.
for( INDEX_TYPE array = i + 1; array < m_numArrays; ++array )
{
INDEX_TYPE const curArraySize = sizeOfArray( array );
INDEX_TYPE const curArrayOffset = m_offsets[array];
arrayManipulation::uninitializedShiftDown( &buffer[ curArrayOffset ], curArraySize, capacityDecrease );
if( curArraySize > 0 )
{
arrayManipulation::uninitializedShiftDown( &buffer[ curArrayOffset ], curArraySize, capacityDecrease );
}
}
},
m_values, buffers ...
Expand Down Expand Up @@ -1056,7 +1068,10 @@ class ArrayOfArraysView
{
INDEX_TYPE const offset = m_offsets[ i ];
INDEX_TYPE const arraySize = sizeOfArray( i );
arrayManipulation::destroy( &buffer[ offset ], arraySize );
if( arraySize > 0 )
{
arrayManipulation::destroy( &buffer[ offset ], arraySize );
}
}
}
}, m_values, buffers ... );
Expand Down
9 changes: 8 additions & 1 deletion src/ArraySlice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,14 @@ class ArraySlice
operator[]( INDEX_TYPE const index ) const noexcept
{
ARRAY_SLICE_CHECK_BOUNDS( index );
return m_data[ indexing::ConditionalMultiply< USD == 0 >::multiply( index, m_strides[ 0 ] ) ];
if constexpr ( USD == 0 )
{
return m_data[ index ];
}
else
{
return m_data[ index * m_strides[ 0 ] ];
}
}

/**
Expand Down
24 changes: 20 additions & 4 deletions src/ArrayView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,18 @@ class ArrayView
operator[]( INDEX_TYPE const index ) const & noexcept
{
ARRAY_SLICE_CHECK_BOUNDS( index );
return ArraySlice< T, NDIM-1, USD-1, INDEX_TYPE >( data() + indexing::ConditionalMultiply< USD == 0 >::multiply( index, m_strides[ 0 ] ),
m_dims.data + 1,
m_strides.data + 1 );
if constexpr ( USD == 0 )
{
return ArraySlice< T, NDIM-1, USD-1, INDEX_TYPE >( data() + index,
m_dims.data + 1,
m_strides.data + 1 );
}
else
{
return ArraySlice< T, NDIM-1, USD-1, INDEX_TYPE >( data() + index * m_strides[ 0 ],
m_dims.data + 1,
m_strides.data + 1 );
}
}

/**
Expand All @@ -531,7 +540,14 @@ class ArrayView
operator[]( INDEX_TYPE const index ) const & noexcept
{
ARRAY_SLICE_CHECK_BOUNDS( index );
return data()[ indexing::ConditionalMultiply< USD == 0 >::multiply( index, m_strides[ 0 ] ) ];
if constexpr ( USD == 0 )
{
return data()[ index ];
}
else
{
return data()[ index * m_strides[ 0 ] ];
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ChaiBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class ChaiBuffer
ChaiBuffer( ChaiBuffer< U > const & src ):
m_pointer( reinterpret_cast< T * >( src.data() ) ),
m_capacity( typeManipulation::convertSize< T, U >( src.capacity() ) ),
m_pointerRecord( &src.pointerRecord() )
m_pointerRecord( src.data() == nullptr ? nullptr : &src.pointerRecord() )
{}

/**
Expand Down
22 changes: 19 additions & 3 deletions src/indexing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,16 @@ multiplyAll( T const * const LVARRAY_RESTRICT values )
template< int USD, typename INDEX_TYPE, typename INDEX >
LVARRAY_HOST_DEVICE inline constexpr
INDEX_TYPE getLinearIndex( INDEX_TYPE const * const LVARRAY_RESTRICT strides, INDEX const index )
{ return ConditionalMultiply< USD == 0 >::multiply( index, strides[ 0 ] ); }
{
if constexpr ( USD == 0 )
{
return index;
}
else
{
return index * strides[ 0 ];
}
}

/**
* @tparam USD The unit stride dimension of strides.
Expand All @@ -122,8 +131,15 @@ template< int USD, typename INDEX_TYPE, typename INDEX, typename ... REMAINING_I
LVARRAY_HOST_DEVICE inline constexpr
INDEX_TYPE getLinearIndex( INDEX_TYPE const * const LVARRAY_RESTRICT strides, INDEX const index, REMAINING_INDICES const ... indices )
{
return ConditionalMultiply< USD == 0 >::multiply( index, strides[ 0 ] ) +
getLinearIndex< USD - 1, INDEX_TYPE, REMAINING_INDICES... >( strides + 1, indices ... );
if constexpr ( USD == 0 )
{
return index + getLinearIndex< USD - 1, INDEX_TYPE, REMAINING_INDICES... >( strides + 1, indices ... );
}
else
{
return index * strides[ 0 ] +
getLinearIndex< USD - 1, INDEX_TYPE, REMAINING_INDICES... >( strides + 1, indices ... );
}
}

/// @return A string representing an empty set of indices.
Expand Down
12 changes: 7 additions & 5 deletions src/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,17 @@ static void stringToArray( Array< T, NDIM, PERMUTATION, INDEX_TYPE, BUFFER_TYPE

// we also need to add a ' ' in front of any '}' otherwise the
// stringstream::operator>> will grab the }
for( std::string::size_type a=0; a<valueString.size(); ++a )
std::string valueStringWithSpaces;
valueStringWithSpaces.reserve( valueString.size() + numClose );
for( char const c : valueString )
{
if( valueString[a] == '}' )
if( c == '}' )
{
valueString.insert( a, " " );
++a;
valueStringWithSpaces.push_back( ' ' );
}
valueStringWithSpaces.push_back( c );
}
std::istringstream strstream( valueString );
std::istringstream strstream( valueStringWithSpaces );
// this recursively reads the values from the stringstream
internal::StringToArrayHelper< T, INDEX_TYPE >::Read( array.toSlice(), array.dims(), strstream );
}
Expand Down
15 changes: 15 additions & 0 deletions src/umpireInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ namespace umpireInterface

void copy( void * const dstPointer, void * const srcPointer, std::size_t const size )
{
if( size == 0 )
{
return;
}

#if defined( LVARRAY_USE_UMPIRE )
umpire::ResourceManager & rm = umpire::ResourceManager::getInstance();
if( rm.hasAllocator( dstPointer ) && rm.hasAllocator( srcPointer ) )
Expand All @@ -40,6 +45,11 @@ void copy( void * const dstPointer, void * const srcPointer, std::size_t const s
camp::resources::Event copy( void * const dstPointer, void * const srcPointer,
camp::resources::Resource & resource, std::size_t const size )
{
if( size == 0 )
{
return resource.get_event();
}

#if defined( LVARRAY_USE_UMPIRE )
umpire::ResourceManager & rm = umpire::ResourceManager::getInstance();

Expand All @@ -64,6 +74,11 @@ camp::resources::Event copy( void * const dstPointer, void * const srcPointer,

void memset( void * const dstPointer, int const val, std::size_t const size )
{
if( size == 0 )
{
return;
}

#if defined( LVARRAY_USE_UMPIRE )
umpire::ResourceManager & rm = umpire::ResourceManager::getInstance();
if( rm.hasAllocator( dstPointer ) )
Expand Down
6 changes: 3 additions & 3 deletions unitTests/testArray1DOfArray1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class Array1DOfArray1DOfArrayView2DTest : public ::testing::Test
{
for( IndexType c = 0; c < nestedView[ i ][ j ].size( 1 ); ++c )
{
PORTABLE_EXPECT_EQ( nestedView[ i ][ j ]( r, c ), deviceTouchedValue( i, j, r, c ) );
PORTABLE_EXPECT_NEAR( nestedView[ i ][ j ]( r, c ), deviceTouchedValue( i, j, r, c ), T( 1e-12 ) );
}
}
}
Expand Down Expand Up @@ -423,7 +423,7 @@ class Array1DOfArray1DOfArrayView2DTest : public ::testing::Test
{
for( IndexType c = 0; c < nestedView[ i ][ j ].size( 1 ); ++c )
{
PORTABLE_EXPECT_EQ( nestedView[ i ][ j ]( r, c ), initialValue( i, j, r, c ) );
PORTABLE_EXPECT_NEAR( nestedView[ i ][ j ]( r, c ), initialValue( i, j, r, c ), T( 1e-12 ) );
}
}
}
Expand All @@ -440,7 +440,7 @@ class Array1DOfArray1DOfArrayView2DTest : public ::testing::Test
{
for( IndexType c = 0; c < nestedView[ i ][ j ].size( 1 ); ++c )
{
PORTABLE_EXPECT_EQ( nestedView[ i ][ j ]( r, c ), hostTouchedValue( i, j, r, c ) );
PORTABLE_EXPECT_NEAR( nestedView[ i ][ j ]( r, c ), hostTouchedValue( i, j, r, c ), T( 1e-12 ) );
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions unitTests/testArrayView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ class ArrayViewPolicyTest : public ArrayViewTest< typename ARRAY_POLICY_PAIR::fi
array->template setValues< POLICY >( value );

ViewTypeConst const view = array->toViewConst();
forall< POLICY >( array->size(), [view, value] LVARRAY_HOST_DEVICE ( INDEX_TYPE const i )
forall< POLICY >( array->size(), [view] LVARRAY_HOST_DEVICE ( INDEX_TYPE const i )
{
PORTABLE_EXPECT_EQ( view.data()[ i ], value );
PORTABLE_EXPECT_EQ( view.data()[ i ], T( 3.14 ) );
} );

EXPECT_EQ( array->size(), totalSize );
Expand Down
2 changes: 1 addition & 1 deletion unitTests/testMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ struct TestMath2 : public ::testing::Test
}
};

#if defined( LVARRAY_USE_CUDA ) || defined( LVARRAY_USE_HIP )
#if defined( LVARRAY_USE_CUDA )

using TestMath2Types = ::testing::Types<
std::pair< __half2, parallelDevicePolicy< 32 > >
Expand Down
Loading