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
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
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
44 changes: 26 additions & 18 deletions unitTests/testMemcpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void testAsyncMemcpy1D()
Array< int, 1, RAJA::PERM_I, std::ptrdiff_t, BUFFER_TYPE > y( x.size() );

camp::resources::Event e = memcpy( host, y.toSlice(), x.toSliceConst() );
host.wait_for( &e );
host.wait_for( e );

for( std::ptrdiff_t i = 0; i < x.size(); ++i )
{
Expand All @@ -78,7 +78,7 @@ void testAsyncMemcpy1D()
}

e = memcpy< 0, 0 >( host, y, {}, x.toViewConst(), {} );
host.wait_for( &e );
host.wait_for( e );

for( std::ptrdiff_t i = 0; i < x.size(); ++i )
{
Expand Down Expand Up @@ -162,7 +162,7 @@ void testMemcpyDevice()

forall< RAJA::cuda_exec< 32 > >( y.size(), [yPtr] LVARRAY_DEVICE ( std::ptrdiff_t const i )
{
PORTABLE_EXPECT_EQ( yPtr[ i ], i );
PORTABLE_DEVICE_EXPECT_EQ( yPtr[ i ], i );
yPtr[ i ] *= 2;
} );

Expand Down Expand Up @@ -194,7 +194,7 @@ void testMemcpyDevice()
template< template< typename > class BUFFER_TYPE >
void testAsyncMemcpyDevice()
{
camp::resources::Resource stream{ camp::resources::Cuda{} };
camp::resources::Resource stream{ camp::resources::Cuda::get_default() };

Array< int, 1, RAJA::PERM_I, std::ptrdiff_t, BUFFER_TYPE > x( 100 );

Expand All @@ -208,16 +208,18 @@ void testAsyncMemcpyDevice()
int * yPtr = y.data();

camp::resources::Event e = memcpy< 0, 0 >( stream, y.toView(), {}, x.toViewConst(), {} );
stream.wait_for( &e );
stream.wait_for( e );

forall< RAJA::cuda_exec< 32 > >( y.size(), [yPtr] LVARRAY_DEVICE ( std::ptrdiff_t const i )
RAJA::forall< RAJA::cuda_exec< 32 > >( stream.get< camp::resources::Cuda >(),
RAJA::TypedRangeSegment< std::ptrdiff_t >( 0, y.size() ),
[yPtr] LVARRAY_DEVICE ( std::ptrdiff_t const i )
{
PORTABLE_EXPECT_EQ( yPtr[ i ], i );
PORTABLE_DEVICE_EXPECT_EQ( yPtr[ i ], i );
yPtr[ i ] *= 2;
} );

e = memcpy< 0, 0 >( stream, x, {}, y.toViewConst(), {} );
stream.wait_for( &e );
stream.wait_for( e );

for( std::ptrdiff_t i = 0; i < x.size(); ++i )
{
Expand All @@ -229,13 +231,15 @@ void testAsyncMemcpyDevice()
y.move( MemorySpace::host );

ArrayView< int, 1, 0, std::ptrdiff_t, BUFFER_TYPE > const yView = y.toView();
forall< RAJA::cuda_exec< 32 > >( y.size(), [yView] LVARRAY_DEVICE ( std::ptrdiff_t const i )
RAJA::forall< RAJA::cuda_exec< 32 > >( stream.get< camp::resources::Cuda >(),
RAJA::TypedRangeSegment< std::ptrdiff_t >( 0, y.size() ),
[yView] LVARRAY_DEVICE ( std::ptrdiff_t const i )
{
yView[ i ] = -i;
} );

e = memcpy< 0, 0 >( stream, x, {}, y.toViewConst(), {} );
stream.wait_for( &e );
stream.wait_for( e );

for( std::ptrdiff_t i = 0; i < x.size(); ++i )
{
Expand All @@ -262,7 +266,7 @@ void testMemcpyDevice()

forall< RAJA::hip_exec< 32 > >( y.size(), [yPtr] LVARRAY_DEVICE ( std::ptrdiff_t const i )
{
PORTABLE_EXPECT_EQ( yPtr[ i ], i );
PORTABLE_DEVICE_EXPECT_EQ( yPtr[ i ], i );
yPtr[ i ] *= 2;
} );

Expand Down Expand Up @@ -294,7 +298,7 @@ void testMemcpyDevice()
template< template< typename > class BUFFER_TYPE >
void testAsyncMemcpyDevice()
{
camp::resources::Resource stream{ camp::resources::Hip{} };
camp::resources::Resource stream{ camp::resources::Hip::get_default() };

Array< int, 1, RAJA::PERM_I, std::ptrdiff_t, BUFFER_TYPE > x( 100 );

Expand All @@ -308,16 +312,18 @@ void testAsyncMemcpyDevice()
int * yPtr = y.data();

camp::resources::Event e = memcpy< 0, 0 >( stream, y.toView(), {}, x.toViewConst(), {} );
stream.wait_for( &e );
stream.wait_for( e );

forall< RAJA::hip_exec< 32 > >( y.size(), [yPtr] LVARRAY_DEVICE ( std::ptrdiff_t const i )
RAJA::forall< RAJA::hip_exec< 32 > >( stream.get< camp::resources::Hip >(),
RAJA::TypedRangeSegment< std::ptrdiff_t >( 0, y.size() ),
[yPtr] LVARRAY_DEVICE ( std::ptrdiff_t const i )
{
PORTABLE_EXPECT_EQ( yPtr[ i ], i );
PORTABLE_DEVICE_EXPECT_EQ( yPtr[ i ], i );
yPtr[ i ] *= 2;
} );

e = memcpy< 0, 0 >( stream, x, {}, y.toViewConst(), {} );
stream.wait_for( &e );
stream.wait_for( e );

for( std::ptrdiff_t i = 0; i < x.size(); ++i )
{
Expand All @@ -329,13 +335,15 @@ void testAsyncMemcpyDevice()
y.move( MemorySpace::host );

ArrayView< int, 1, 0, std::ptrdiff_t, BUFFER_TYPE > const yView = y.toView();
forall< RAJA::hip_exec< 32 > >( y.size(), [yView] LVARRAY_DEVICE ( std::ptrdiff_t const i )
RAJA::forall< RAJA::hip_exec< 32 > >( stream.get< camp::resources::Hip >(),
RAJA::TypedRangeSegment< std::ptrdiff_t >( 0, y.size() ),
[yView] LVARRAY_DEVICE ( std::ptrdiff_t const i )
{
yView[ i ] = -i;
} );

e = memcpy< 0, 0 >( stream, x, {}, y.toViewConst(), {} );
stream.wait_for( &e );
stream.wait_for( e );

for( std::ptrdiff_t i = 0; i < x.size(); ++i )
{
Expand Down
55 changes: 31 additions & 24 deletions unitTests/testStackArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,44 +175,51 @@ class StackArrayCaptureTest : public StackArrayTest< typename PERMUTATION_POLICY
/// This needs to use the parallelDevice policy because you can't nest host-device lambdas.
static void resizeMultipleInLambda()
{
INDEX_TYPE dims[ NDIM ];
for( int i = 0; i < NDIM; ++i )
{ dims[ i ] = 8; }
if constexpr ( std::is_same< POLICY, serialPolicy >::value )
{
GTEST_SKIP() << "Nested device lambdas are only supported by a device execution policy.";
return;
}
else
{
INDEX_TYPE dims[ NDIM ];
for( int i = 0; i < NDIM; ++i )
{ dims[ i ] = 8; }

INDEX_TYPE const capacity = CAPACITY;
forall< POLICY >( 10, [dims, capacity] LVARRAY_DEVICE ( int )
{
StackArray< int, NDIM, PERMUTATION, INDEX_TYPE, CAPACITY > array;
PORTABLE_EXPECT_EQ( array.size(), 0 );
PORTABLE_EXPECT_EQ( array.capacity(), capacity );
forall< POLICY >( 10, [dims] LVARRAY_DEVICE ( int )
{
StackArray< int, NDIM, PERMUTATION, INDEX_TYPE, CAPACITY > array;
PORTABLE_DEVICE_EXPECT_EQ( array.size(), 0 );
PORTABLE_DEVICE_EXPECT_EQ( array.capacity(), CAPACITY );

array.resize( NDIM, dims );
array.resize( NDIM, dims );

for( int i = 0; i < NDIM; ++i )
{ PORTABLE_EXPECT_EQ( array.size( i ), 8 ); }
for( int i = 0; i < NDIM; ++i )
{ PORTABLE_DEVICE_EXPECT_EQ( array.size( i ), 8 ); }

PORTABLE_EXPECT_EQ( array.size(), capacity );
PORTABLE_DEVICE_EXPECT_EQ( array.size(), CAPACITY );

forValuesInSliceWithIndices( array.toSlice(), SetValue() );
forValuesInSliceWithIndices( array.toSlice(), SetValue() );

array.resize( 2 );
array.resize( 2 );

PORTABLE_EXPECT_EQ( array.size( 0 ), 2 );
for( int i = 1; i < NDIM; ++i )
{ PORTABLE_EXPECT_EQ( array.size( i ), 8 ); }
PORTABLE_DEVICE_EXPECT_EQ( array.size( 0 ), 2 );
for( int i = 1; i < NDIM; ++i )
{ PORTABLE_DEVICE_EXPECT_EQ( array.size( i ), 8 ); }

PORTABLE_EXPECT_EQ( array.size(), array.capacity() / 4 );
PORTABLE_DEVICE_EXPECT_EQ( array.size(), array.capacity() / 4 );

forValuesInSliceWithIndices( array.toSlice(), CheckValue() );
} );
forValuesInSliceWithIndices( array.toSlice(), CheckValue() );
} );
}
}

template< typename _PERMUTATION=PERMUTATION >
static std::enable_if_t< typeManipulation::getDimension< _PERMUTATION > == 1 >
sizedConstructorInLambda()
{
INDEX_TYPE const capacity = CAPACITY;
forall< POLICY >( 10, [capacity] LVARRAY_DEVICE ( int )
forall< POLICY >( 10, [capacity] LVARRAY_HOST_DEVICE ( int )
{
StackArray< int, NDIM, PERMUTATION, INDEX_TYPE, CAPACITY > array( CAPACITY );
PORTABLE_EXPECT_EQ( array.capacity(), capacity );
Expand All @@ -227,7 +234,7 @@ class StackArrayCaptureTest : public StackArrayTest< typename PERMUTATION_POLICY
{
INDEX_TYPE const capacity = CAPACITY;
int const size = 8;
forall< POLICY >( 10, [capacity, size] LVARRAY_DEVICE ( int )
forall< POLICY >( 10, [capacity, size] LVARRAY_HOST_DEVICE ( int )
{
StackArray< int, NDIM, PERMUTATION, INDEX_TYPE, CAPACITY > array( size - 1, size );
PORTABLE_EXPECT_EQ( array.capacity(), capacity );
Expand All @@ -243,7 +250,7 @@ class StackArrayCaptureTest : public StackArrayTest< typename PERMUTATION_POLICY
{
INDEX_TYPE const capacity = CAPACITY;
int const size = 8;
forall< POLICY >( 10, [capacity, size] LVARRAY_DEVICE ( int )
forall< POLICY >( 10, [capacity, size] LVARRAY_HOST_DEVICE ( int )
{
StackArray< int, NDIM, PERMUTATION, INDEX_TYPE, CAPACITY > array( size - 2, size - 1, size );
PORTABLE_EXPECT_EQ( array.capacity(), capacity );
Expand Down
17 changes: 17 additions & 0 deletions unitTests/testTensorOpsCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,22 @@ randomValue( T const maxVal, std::mt19937_64 & gen )
} \
} while ( false )

#define CHECK_NEAR_2D( N, M, A, RESULT, EPSILON ) \
tensorOps::internal::checkSizes< N, M >( A ); \
tensorOps::internal::checkSizes< N, M >( RESULT ); \
do \
{ \
for( std::ptrdiff_t _i = 0; _i < N; ++_i ) \
{ \
for( std::ptrdiff_t _j = 0; _j < M; ++_j ) \
{ \
if( std::is_integral< std::remove_reference_t< decltype( A[ _i ][ _j ] ) > >::value ) \
{ PORTABLE_EXPECT_EQ( A[ _i ][ _j ], RESULT[ _i ][ _j ] ); } \
else \
{ PORTABLE_EXPECT_NEAR( A[ _i ][ _j ], RESULT[ _i ][ _j ], EPSILON ); } \
} \
} \
} while ( false )

} // namespace testing
} // namespace LvArray
4 changes: 2 additions & 2 deletions unitTests/testTensorOpsEigen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class TestEigendecomposition : public ::testing::Test
ArrayViewT< FLOAT const, 2, 1 > const eigenvalues = m_eigenvalues.toViewConst();
ArrayViewT< FLOAT, 2, 1 > const expectedEigenvalues = m_expectedEigenvalues.toView();
ArrayViewT< FLOAT const, 3, 2 > const eigenvectors = m_eigenvectors.toViewConst();
forall< serialPolicy >( matrices.size( 0 ), [=, &relativeDiffs] ( std::ptrdiff_t const i )
forall< serialPolicy >( matrices.size( 0 ), [=, &relativeDiffs, this] ( std::ptrdiff_t const i )
{
if( iteration > 0 )
{
Expand Down Expand Up @@ -174,7 +174,7 @@ class TestEigendecomposition : public ::testing::Test
ArrayViewT< FLOAT, 2, 1 > const eigenvalues = m_eigenvalues.toView();
ArrayViewT< FLOAT, 2, 1 > const expectedEigenvalues = m_expectedEigenvalues.toView();
ArrayViewT< FLOAT, 3, 2 > const eigenvectors = m_eigenvectors.toView();
forall< serialPolicy >( matrices.size( 0 ), [=] ( std::ptrdiff_t const i )
forall< serialPolicy >( matrices.size( 0 ), [=, this] ( std::ptrdiff_t const i )
{
// Since we're constructing the matrix we know the eigenvalues beforehand.
for( INDEX_TYPE j = 0; j < M; ++j )
Expand Down
Loading