Skip to content

Commit

Permalink
WIP on new layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
klevzoff committed Aug 28, 2023
1 parent bc43fa5 commit 6074837
Show file tree
Hide file tree
Showing 48 changed files with 2,975 additions and 1,356 deletions.
16 changes: 8 additions & 8 deletions benchmarks/benchmarkArray1DR2TensorMultiplicationKernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ namespace benchmarking
RAJA_OUTER_LOOP( N, INNER_LOOP( a_ijl, b_ilk, c_ijk ) )


template< typename VALUE_TYPE_CONST, int USD >
template< typename VALUE_TYPE_CONST, typename LAYOUT, std::enable_if_t< LAYOUT::NDIM == 2 >* = nullptr >
inline LVARRAY_HOST_DEVICE constexpr
void R2TensorMultiplyFortran( LvArray::ArraySlice< VALUE_TYPE_CONST, 2, USD, INDEX_TYPE > const a,
LvArray::ArraySlice< VALUE_TYPE_CONST, 2, USD, INDEX_TYPE > const b,
LvArray::ArraySlice< VALUE_TYPE, 2, USD, INDEX_TYPE > const c )
void R2TensorMultiplyFortran( LvArray::ArraySlice2< VALUE_TYPE_CONST, LAYOUT > const a,
LvArray::ArraySlice2< VALUE_TYPE_CONST, LAYOUT > const b,
LvArray::ArraySlice2< VALUE_TYPE, LAYOUT > const c )
{ INNER_LOOP( a( j, l ), b( l, k ), c( j, k ) ) }

template< typename VALUE_TYPE_CONST, int USD >
template< typename VALUE_TYPE_CONST, typename LAYOUT, std::enable_if_t< LAYOUT::NDIM == 2 >* = nullptr >
RAJA_INLINE LVARRAY_HOST_DEVICE constexpr
void R2TensorMultiplySubscript( LvArray::ArraySlice< VALUE_TYPE_CONST, 2, USD, INDEX_TYPE > const a,
LvArray::ArraySlice< VALUE_TYPE_CONST, 2, USD, INDEX_TYPE > const b,
LvArray::ArraySlice< VALUE_TYPE, 2, USD, INDEX_TYPE > const c )
void R2TensorMultiplySubscript( LvArray::ArraySlice2< VALUE_TYPE_CONST, LAYOUT > const a,
LvArray::ArraySlice2< VALUE_TYPE_CONST, LAYOUT > const b,
LvArray::ArraySlice2< VALUE_TYPE, LAYOUT > const c )
{ INNER_LOOP( a[ j ][ l ], b[ l ][ k ], c[ j ][ k ] ) }


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace benchmarking

// Sphinx start after vector
void NaiveNodeToElemMapConstruction::
vector( ArrayView< INDEX_TYPE const, 2, 1, INDEX_TYPE, DEFAULT_BUFFER > const & elementToNodeMap,
vector( ArrayView< INDEX_TYPE const, 2, RAJA::PERM_IJ, INDEX_TYPE, DEFAULT_BUFFER > const & elementToNodeMap,
std::vector< std::vector< INDEX_TYPE > > & nodeToElementMap,
INDEX_TYPE const numNodes )
{
Expand All @@ -33,7 +33,7 @@ void NaiveNodeToElemMapConstruction::

// Sphinx start after naive
void NaiveNodeToElemMapConstruction::
naive( ArrayView< INDEX_TYPE const, 2, 1, INDEX_TYPE, DEFAULT_BUFFER > const & elementToNodeMap,
naive( ArrayView< INDEX_TYPE const, 2, RAJA::PERM_IJ, INDEX_TYPE, DEFAULT_BUFFER > const & elementToNodeMap,
ArrayOfArrays< INDEX_TYPE, INDEX_TYPE, DEFAULT_BUFFER > & nodeToElementMap,
INDEX_TYPE const numNodes )
{
Expand All @@ -52,7 +52,7 @@ void NaiveNodeToElemMapConstruction::
// Sphinx start after overAllocation
template< typename POLICY >
void NodeToElemMapConstruction< POLICY >::
overAllocation( ArrayView< INDEX_TYPE const, 2, 1, INDEX_TYPE, DEFAULT_BUFFER > const & elementToNodeMap,
overAllocation( ArrayView< INDEX_TYPE const, 2, RAJA::PERM_IJ, INDEX_TYPE, DEFAULT_BUFFER > const & elementToNodeMap,
ArrayOfArrays< INDEX_TYPE, INDEX_TYPE, DEFAULT_BUFFER > & nodeToElementMap,
INDEX_TYPE const numNodes,
INDEX_TYPE const maxNodeElements )
Expand Down Expand Up @@ -83,7 +83,7 @@ overAllocation( ArrayView< INDEX_TYPE const, 2, 1, INDEX_TYPE, DEFAULT_BUFFER >
// Sphinx start after resizeFromCapacities
template< typename POLICY >
void NodeToElemMapConstruction< POLICY >::
resizeFromCapacities( ArrayView< INDEX_TYPE const, 2, 1, INDEX_TYPE, DEFAULT_BUFFER > const & elementToNodeMap,
resizeFromCapacities( ArrayView< INDEX_TYPE const, 2, RAJA::PERM_IJ, INDEX_TYPE, DEFAULT_BUFFER > const & elementToNodeMap,
ArrayOfArrays< INDEX_TYPE, INDEX_TYPE, DEFAULT_BUFFER > & nodeToElementMap,
INDEX_TYPE const numNodes )
{
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/benchmarkHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ using ArrayT = LvArray::Array< T, typeManipulation::getDimension< PERMUTATION >,
template< typename T, typename PERMUTATION >
using ArrayViewT = LvArray::ArrayView< T,
typeManipulation::getDimension< PERMUTATION >,
typeManipulation::getStrideOneDimension( PERMUTATION {} ),
PERMUTATION,
INDEX_TYPE,
DEFAULT_BUFFER >;

Expand Down Expand Up @@ -145,8 +145,8 @@ inline std::uint_fast64_t getSeed()
}


template< typename T, int NDIM, int USD >
void initialize( ArraySlice< T, NDIM, USD, INDEX_TYPE > const slice, int & iter )
template< typename T, typename LAYOUT >
void initialize( ArraySlice2< T, LAYOUT > const slice, int & iter )
{
++iter;
std::mt19937_64 gen( iter * getSeed() );
Expand All @@ -171,7 +171,7 @@ RajaView< T, PERMUTATION > makeRajaView( ArrayT< T, PERMUTATION > const & array

for( int i = 0; i < NDIM; ++i )
{
sizes[ i ] = array.dims()[ i ];
sizes[ i ] = array.size( i );
}

constexpr std::array< camp::idx_t, NDIM > const permutation = RAJA::as_array< PERMUTATION >::get();
Expand Down
21 changes: 10 additions & 11 deletions examples/exampleArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ TEST( Array, permutations )
LvArray::MallocBuffer > array( 3, 4, 5 );

// Index 0 has the largest stride while index 2 has unit stride.
EXPECT_EQ( array.strides()[ 0 ], array.size( 2 ) * array.size( 1 ) );
EXPECT_EQ( array.strides()[ 1 ], array.size( 2 ) );
EXPECT_EQ( array.strides()[ 2 ], 1 );
EXPECT_EQ( array.stride< 0 >(), array.size( 2 ) * array.size( 1 ) );
EXPECT_EQ( array.stride< 1 >(), array.size( 2 ) );
EXPECT_EQ( array.stride< 2 >(), 1 );

int const * const pointer = array.data();
for( std::ptrdiff_t i = 0; i < array.size( 0 ); ++i )
Expand All @@ -134,9 +134,9 @@ TEST( Array, permutations )
LvArray::MallocBuffer > array( 3, 4, 5 );

// Index 0 has the unit stride while index 2 has the largest stride.
EXPECT_EQ( array.strides()[ 0 ], 1 );
EXPECT_EQ( array.strides()[ 1 ], array.size( 0 ) );
EXPECT_EQ( array.strides()[ 2 ], array.size( 0 ) * array.size( 1 ) );
EXPECT_EQ( array.stride< 0 >(), 1 );
EXPECT_EQ( array.stride< 1 >(), array.size( 0 ) );
EXPECT_EQ( array.stride< 2 >(), array.size( 0 ) * array.size( 1 ) );

int const * const pointer = array.data();
for( std::ptrdiff_t i = 0; i < array.size( 0 ); ++i )
Expand Down Expand Up @@ -223,8 +223,7 @@ TEST( Array, resizeSingleDimension )
}

// Shrink the second dimension from 6 to 3;
array.setSingleParameterResizeIndex( 1 );
array.resize( 3 );
array.resizeDimension< 1 >( 3 );
for( std::ptrdiff_t i = 0; i < array.size( 0 ); ++i )
{
for( std::ptrdiff_t j = 0; j < array.size( 1 ); ++j )
Expand Down Expand Up @@ -254,23 +253,23 @@ TEST( Array, arrayView )
// Create a view.
LvArray::ArrayView< int,
2,
0,
camp::idx_seq< 1, 0 >,
std::ptrdiff_t,
LvArray::MallocBuffer > const view = array;
EXPECT_EQ( view.data(), array.data() );

// Create a view with const values.
LvArray::ArrayView< int const,
2,
0,
camp::idx_seq< 1, 0 >,
std::ptrdiff_t,
LvArray::MallocBuffer > const viewConst = array.toViewConst();
EXPECT_EQ( viewConst.data(), array.data() );

// Copy a view.
LvArray::ArrayView< int,
2,
0,
camp::idx_seq< 1, 0 >,
std::ptrdiff_t,
LvArray::MallocBuffer > const viewCopy = view;
EXPECT_EQ( viewCopy.data(), array.data() );
Expand Down
Loading

0 comments on commit 6074837

Please sign in to comment.