Commit f4b47d49 authored by Christian Godenschwager's avatar Christian Godenschwager
Browse files

Move Index calculation into Layout class

parent 4879c734
......@@ -31,6 +31,7 @@
#include "lbm/list/CellCounters.h"
#include "lbm/list/List.h"
#include "lbm/list/ListCommunication.h"
#include "lbm/list/ListSIMDKernel.h"
#include "lbm/list/ListKernel.h"
#include "lbm/list/ListPressureBoundary.h"
#include "lbm/list/ListVTK.h"
......@@ -201,7 +202,7 @@ int main( int argc, char **argv )
auto blocks = bfc.createStructuredBlockForest( blockSize );
// Setup block data
typedef lbm::List< MyLatticeModel, lbm::LayoutFIdx<64> > MyList;
typedef lbm::List< MyLatticeModel, lbm::LayoutSoA< MyLatticeModel::Stencil > > MyList;
BlockDataID pdfListId = lbm::addListToStorage< MyList >( blocks, "LBM list (FIdx)", latticeModel );
BlockDataID inflowPressureBoundaryHandling = lbm::addListPressureBoundaryToStorage< MyList >( pdfListId, blocks, "inflowBoundaryHandling" );
......@@ -267,6 +268,7 @@ int main( int argc, char **argv )
// LBM Sweep
timeloop.add() << Sweep( lbm::ListDefaultTRTSweep< MyList >( pdfListId ), "ListSIMD2SplitTRTSweep" );
//timeloop.add() << Sweep( lbm::ListSIMD2SplitTRTSweep< MyList, 128 >( pdfListId ), "ListSIMD2SplitTRTSweep" );
// VTK Output
......
......@@ -56,13 +56,50 @@
namespace walberla {
namespace lbm {
struct LayoutIdxF { static const uint_t alignment = 1; };
template< typename Stencil, typename Index_T = walberla::uint32_t >
struct LayoutAoS
{
constexpr LayoutAoS() = delete;
constexpr uint_t alignment() { return uint_t(1); }
constexpr static Index_T getPDFIdx( const uint_t idx, const uint_t f, const uint_t /*N*/ ) { return numeric_cast<Index_T>( idx * Stencil::Size + f ); }
constexpr static Index_T getPullIdxIdx( const uint_t idx, const stencil::Direction d, const uint_t /*N*/ )
{
WALBERLA_ASSERT_UNEQUAL( d, stencil::C );
WALBERLA_ASSERT_UNEQUAL( Stencil::idx[d], stencil::INVALID_DIR );
const uint_t f = Stencil::idx[d] - Stencil::noCenterFirstIdx;
return numeric_cast<Index_T>( idx * ( Stencil::Size - Stencil::noCenterFirstIdx ) + f );
}
constexpr static const real_t *& incPtr( const real_t *& p ) { p += Stencil::Size; return p; }
constexpr static real_t *& incPtr( real_t *& p ) { p += Stencil::Size; return p; }
constexpr static Index_T & incIdx( Index_T & idx ) { idx += numeric_cast<Index_T>( Stencil::Size ); return idx; }
};
template< uint_t ALIGNMENT = 64 >
struct LayoutFIdx
template< typename Stencil, typename Index_T = walberla::uint32_t, uint_t ALIGNMENT = 64 >
struct LayoutSoA
{
static_assert( ( ( ALIGNMENT & ( ALIGNMENT - uint_t( 1 ) ) ) == 0 ) && ( ALIGNMENT >= uint_t(1) ), "The alignment for the list layout has to a power of two!" );
static const uint_t alignment = ALIGNMENT;
constexpr LayoutSoA() = delete;
constexpr static uint_t alignment() { return ALIGNMENT; }
constexpr static Index_T getPDFIdx( const uint_t idx, const uint_t f, const uint_t N ) { return numeric_cast<Index_T>( f * N + idx ); }
constexpr static Index_T getPullIdxIdx( const uint_t idx, const stencil::Direction d, const uint_t N )
{
WALBERLA_ASSERT_UNEQUAL( d, stencil::C );
WALBERLA_ASSERT_UNEQUAL( Stencil::idx[d], stencil::INVALID_DIR );
const uint_t f = Stencil::idx[d] - Stencil::noCenterFirstIdx;
return numeric_cast<Index_T>( f * N + idx );
}
constexpr static const real_t *& incPtr( const real_t *& p ) { ++p; return p; }
constexpr static real_t *& incPtr( real_t *& p ) { ++p; return p; }
constexpr static Index_T & incIdx( Index_T & idx ) { ++idx; return idx; }
};
struct CellToIdxOrdering
......@@ -86,14 +123,10 @@ public:
void init( const std::vector<Cell> & fluidCells, const real_t rho = 1, const Vector3<real_t> velocity = Vector3<real_t>() );
static inline real_t *& incPtr( real_t *& p ) { return incPtr( p, Layout() ); }
static inline const real_t *& incPtr( const real_t *& p ) { return incPtr( p, Layout() ); }
static inline Index_T & incIdx( Index_T & idx ) { return incIdx( idx, Layout() ); }
static inline real_t *& incPtr( real_t *& p ) { return Layout_T::incPtr( p ); }
static inline const real_t *& incPtr( const real_t *& p ) { return Layout_T::incPtr( p ); }
static bool hasIdxFLayout() { return hasIdxFLayout( Layout() ); }
static bool hasFIdxLayout() { return hasFIdxLayout( Layout() ); }
static inline Index_T & incIdx( Index_T & idx ) { return Layout_T::incIdx( idx ); }
const LatticeModel_T & latticeModel() const { return latticeModel_; }
LatticeModel_T & latticeModel() { return latticeModel_; }
......@@ -152,13 +185,13 @@ public:
WALBERLA_FORCE_INLINE( const Index_T & getPullIdx( const uint_t idx, const stencil::Direction d ) const );
WALBERLA_FORCE_INLINE( const Index_T & getPullIdx( const Cell & cell, const stencil::Direction d ) const ) { return getPullIdx( getIdx( cell ), d ); }
WALBERLA_FORCE_INLINE( Index_T getPDFIdx( const uint_t idx, const uint_t f ) const ) { return getPDFIdx( idx, f, Layout() ); }
WALBERLA_FORCE_INLINE( Index_T getPDFIdx( const uint_t idx, const uint_t f ) const ) { return Layout_T::getPDFIdx( idx, f, numFluidCellsPadded_ ); }
WALBERLA_FORCE_INLINE( Index_T getPDFIdx( const Cell & cell, const uint_t f ) const ) { return getPDFIdx( getIdx( cell ), f ); }
WALBERLA_FORCE_INLINE( Index_T getPDFIdx( const uint_t idx, const stencil::Direction d ) const ) { WALBERLA_ASSERT_UNEQUAL( Stencil::idx[d], stencil::INVALID_DIR ); return getPDFIdx( idx, Stencil::idx[d] ); }
WALBERLA_FORCE_INLINE( Index_T getPDFIdx( const Cell & cell, const stencil::Direction d ) const ) { return getPDFIdx( getIdx( cell ), d ); }
WALBERLA_FORCE_INLINE( Index_T getPullIdxIdx( const uint_t idx, const stencil::Direction d ) const ) { return getPullIdxIdx( idx, d, Layout() ); }
WALBERLA_FORCE_INLINE( Index_T getPullIdxIdx( const uint_t idx, const stencil::Direction d ) const ) { return Layout_T::getPullIdxIdx( idx, d, numFluidCellsPadded_ ); }
WALBERLA_FORCE_INLINE( Index_T getPullIdxIdx( const Cell & cell, const stencil::Direction d ) const ) { return getPullIdxIdx( getIdx( cell ), d ); }
Vector3<real_t> getVelocity( uint_t idx ) const;
......@@ -201,43 +234,15 @@ protected:
void setPullIdx( const uint_t idx, const stencil::Direction d, const Index_T pdfIdx );
void setPullIdx( const Cell & cell, const stencil::Direction d, const Index_T pdfIdx ) { setPullIdx( getIdx( cell ), d, pdfIdx ); }
Index_T getPDFIdx( const uint_t idx, const uint_t f, LayoutIdxF ) const;
template <uint_t ALIGNMENT>
Index_T getPDFIdx( const uint_t idx, const uint_t f, LayoutFIdx< ALIGNMENT > ) const;
static inline real_t *& incPtr( real_t *& p, LayoutIdxF ) { p += Stencil::Size; return p; }
template <uint_t ALIGNMENT>
static inline real_t *& incPtr( real_t *& p, LayoutFIdx< ALIGNMENT > ) { ++p; return p; }
static inline const real_t *& incPtr( const real_t *& p, LayoutIdxF ) { p += Stencil::Size; return p; }
template <uint_t ALIGNMENT>
static inline const real_t *& incPtr( const real_t *& p, LayoutFIdx< ALIGNMENT > ) { ++p; return p; }
static inline Index_T & incIdx( Index_T & idx, LayoutIdxF ) { idx += numeric_cast<Index_T>( Stencil::Size ); return idx; }
template <uint_t ALIGNMENT>
static inline Index_T & incIdx( Index_T & idx, LayoutFIdx< ALIGNMENT > ) { ++idx; return idx; }
Index_T getPullIdxIdx( const uint_t idx, const stencil::Direction d, LayoutIdxF ) const;
template <uint_t ALIGNMENT>
Index_T getPullIdxIdx( const uint_t idx, const stencil::Direction d, LayoutFIdx< ALIGNMENT > ) const;
static bool hasIdxFLayout( LayoutIdxF ) { return true; }
static bool hasFIdxLayout( LayoutIdxF ) { return false; }
template <uint_t ALIGNMENT>
static bool hasIdxFLayout( LayoutFIdx< ALIGNMENT > ) { return false; }
template <uint_t ALIGNMENT>
static bool hasFIdxLayout( LayoutFIdx< ALIGNMENT > ) { return true; }
LatticeModel_T latticeModel_;
uint_t numFluidCellsPadded_;
std::vector< real_t, simd::aligned_allocator< real_t, Layout_T::alignment > > pdfs_;
std::vector< real_t, simd::aligned_allocator< real_t, Layout_T::alignment > > tmpPdfs_;
std::vector< real_t, simd::aligned_allocator< real_t, Layout_T::alignment() > > pdfs_;
std::vector< real_t, simd::aligned_allocator< real_t, Layout_T::alignment() > > tmpPdfs_;
std::vector< Index_T, simd::aligned_allocator< Index_T, Layout_T::alignment > > pullIdxs_;
std::vector< Index_T, simd::aligned_allocator< Index_T, Layout_T::alignment() > > pullIdxs_;
std::vector< Cell > idxToCell_;
std::vector< std::pair< Cell, uint_t > > cellToIdx_;
......@@ -266,7 +271,7 @@ void List<LatticeModel_T, Layout_T, Index_T>::init( const std::vector<Cell> & fl
// Allocate Fluid PDFs
uint_t alignedStepSize = std::max( uint_t(1), Layout_T::alignment / sizeof( real_t ) );
uint_t alignedStepSize = std::max( uint_t(1), Layout_T::alignment() / sizeof( real_t ) );
if( ( fluidCells.size() % alignedStepSize ) == 0 )
numFluidCellsPadded_ = fluidCells.size();
else
......@@ -368,24 +373,6 @@ void List<LatticeModel_T, Layout_T, Index_T>::setEquilibrium( const real_t rho,
}
template< typename LatticeModel_T, typename Layout_T, typename Index_T >
Index_T List<LatticeModel_T, Layout_T, Index_T>::getPDFIdx( const uint_t idx, const uint_t f, LayoutIdxF ) const
{
return numeric_cast<Index_T>( idx * Stencil::Size + f );
}
template< typename LatticeModel_T, typename Layout_T, typename Index_T >
template< uint_t ALIGNMENT >
Index_T List<LatticeModel_T, Layout_T, Index_T>::getPDFIdx( const uint_t idx, const uint_t f, LayoutFIdx< ALIGNMENT > ) const
{
return numeric_cast<Index_T>( f * numFluidCellsPadded_ + idx );
}
template< typename LatticeModel_T, typename Layout_T, typename Index_T >
Vector3<real_t> List<LatticeModel_T, Layout_T, Index_T>::getVelocity( uint_t idx ) const
{
......@@ -415,33 +402,6 @@ real_t List<LatticeModel_T, Layout_T, Index_T>::getDensity( uint_t idx ) const
return rho;
}
template< typename LatticeModel_T, typename Layout_T, typename Index_T >
Index_T List<LatticeModel_T, Layout_T, Index_T>::getPullIdxIdx( const uint_t idx, const stencil::Direction d, LayoutIdxF ) const
{
WALBERLA_ASSERT_UNEQUAL( d, stencil::C );
WALBERLA_ASSERT_UNEQUAL( Stencil::idx[d], stencil::INVALID_DIR );
const uint_t f = Stencil::idx[d] - Stencil::noCenterFirstIdx;
return numeric_cast<Index_T>( idx * ( Stencil::Size - Stencil::noCenterFirstIdx ) + f );
}
template< typename LatticeModel_T, typename Layout_T, typename Index_T >
template< uint_t ALIGNMENT >
Index_T List<LatticeModel_T, Layout_T, Index_T>::getPullIdxIdx( const uint_t idx, const stencil::Direction d, LayoutFIdx< ALIGNMENT > ) const
{
WALBERLA_ASSERT_UNEQUAL( d, stencil::C );
WALBERLA_ASSERT_UNEQUAL( Stencil::idx[d], stencil::INVALID_DIR );
const uint_t f = Stencil::idx[d] - Stencil::noCenterFirstIdx;
return numeric_cast<Index_T>( f * numFluidCellsPadded_ + idx );
}
template< typename LatticeModel_T, typename Layout_T, typename Index_T >
const Index_T & List<LatticeModel_T, Layout_T, Index_T>::getPullIdx( const uint_t idx, const stencil::Direction d ) const
{
......@@ -458,9 +418,6 @@ void List<LatticeModel_T, Layout_T, Index_T>::setPullIdx( const uint_t idx, cons
template< typename LatticeModel_T, typename Layout_T, typename Index_T >
bool List<LatticeModel_T, Layout_T, Index_T>::operator==( const List<LatticeModel_T, Layout_T> & other ) const
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment