Commit 51ea61b0 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Transfering of Mesh to GPU

parent 8f29cea1
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -23,12 +23,13 @@
#include <TNL/Meshes/MeshDetails/traits/MeshTraits.h>
#include <TNL/Meshes/MeshDetails/layers/MeshStorageLayer.h>
#include <TNL/Meshes/MeshDetails/config/MeshConfigValidator.h>
#include <TNL/Meshes/MeshDetails/layers/MeshEntityStorageRebinder.h>

namespace TNL {
namespace Meshes {

template< typename MeshConfig > class MeshInitializer;
template< typename Mesh, typename DimensionTag, typename SuperdimensionTag >
struct MeshEntityStorageRebinderDivisor;


template< typename MeshConfig, typename Device, typename MeshType >
@@ -73,6 +74,15 @@ class Mesh
      template< int Dimension >
      using EntityType = typename EntityTraits< Dimension >::EntityType;

      // constructors
      Mesh() = default;

      explicit Mesh( const Mesh& mesh );

      template< typename Device_ >
      Mesh( const Mesh< MeshConfig, Device_ >& mesh );


      static constexpr int getMeshDimension();

      // types of common entities
@@ -101,9 +111,11 @@ class Mesh
      GlobalIndexType getEntitiesCount() const;

      template< int Dimension >
      __cuda_callable__
      EntityType< Dimension >& getEntity( const GlobalIndexType& entityIndex );

      template< int Dimension >
      __cuda_callable__
      const EntityType< Dimension >& getEntity( const GlobalIndexType& entityIndex ) const;


@@ -112,9 +124,11 @@ class Mesh
      GlobalIndexType getEntitiesCount() const;

      template< typename EntityType >
      __cuda_callable__
      EntityType& getEntity( const GlobalIndexType& entityIndex );

      template< typename EntityType >
      __cuda_callable__
      const EntityType& getEntity( const GlobalIndexType& entityIndex ) const;


@@ -142,7 +156,7 @@ class Mesh
      friend MeshInitializer< MeshConfig >;

      template< typename Mesh, typename DimensionTag, typename SuperdimensionTag >
      friend struct MeshEntityStorageRebinderWorker;
      friend struct MeshEntityStorageRebinderDivisor;
};

template< typename MeshConfig, typename Device >
+3 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#pragma once

#include <TNL/Assert.h>
#include <TNL/Devices/Cuda.h>

namespace TNL {
namespace Meshes {
@@ -36,6 +37,7 @@ public:
      return this->id;
   }

   __cuda_callable__
   bool operator==( const MeshEntityIndex& id ) const
   {
      return ( this->id == id.id );
@@ -54,6 +56,7 @@ template<>
class MeshEntityIndex< void >
{
public:
   __cuda_callable__
   bool operator==( const MeshEntityIndex& id ) const
   {
      return true;
+107 −0
Original line number Diff line number Diff line
@@ -21,6 +21,60 @@
namespace TNL {
namespace Meshes {

template< typename MeshConfig,
          typename Device,
          typename EntityTopology >
MeshEntity< MeshConfig, Device, EntityTopology >::
MeshEntity( const MeshEntity& entity )
   : MeshSubentityAccess< MeshConfig, Device, EntityTopology >( entity ),
     MeshSuperentityAccess< MeshConfig, Device, EntityTopology >( entity ),
     MeshEntityIndex< typename MeshConfig::IdType >( entity )
{
}

template< typename MeshConfig,
          typename Device,
          typename EntityTopology >
   template< typename Device_ >
MeshEntity< MeshConfig, Device, EntityTopology >::
MeshEntity( const MeshEntity< MeshConfig, Device_, EntityTopology >& entity )
   // no cross-device copy of subentities and superentities here - Mesh constructor has to rebind pointers
   // TODO: check this
   : MeshEntityIndex< typename MeshConfig::IdType >( entity )
{
}

template< typename MeshConfig,
          typename Device,
          typename EntityTopology >
__cuda_callable__
MeshEntity< MeshConfig, Device, EntityTopology >& 
MeshEntity< MeshConfig, Device, EntityTopology >::
operator=( const MeshEntity& entity )
{
   MeshSubentityAccess< MeshConfig, Device, EntityTopology >::operator=( entity );
   MeshSuperentityAccess< MeshConfig, Device, EntityTopology >::operator=( entity );
   MeshEntityIndex< typename MeshConfig::IdType >::operator=( entity );
   return *this;
}

template< typename MeshConfig,
          typename Device,
          typename EntityTopology >
      template< typename Device_ >
__cuda_callable__
MeshEntity< MeshConfig, Device, EntityTopology >& 
MeshEntity< MeshConfig, Device, EntityTopology >::
operator=( const MeshEntity< MeshConfig, Device_, EntityTopology >& entity )
{
   // no cross-device copy here - Mesh::operator= has to rebind pointers
   // TODO: check this
//   MeshSubentityAccess< MeshConfig, Device, EntityTopology >::operator=( entity );
//   MeshSuperentityAccess< MeshConfig, Device, EntityTopology >::operator=( entity );
   MeshEntityIndex< typename MeshConfig::IdType >::operator=( entity );
   return *this;
}

template< typename MeshConfig,
          typename Device,
          typename EntityTopology >
@@ -82,6 +136,7 @@ print( std::ostream& str ) const
template< typename MeshConfig,
          typename Device,
          typename EntityTopology >
__cuda_callable__
bool
MeshEntity< MeshConfig, Device, EntityTopology >::
operator==( const MeshEntity& entity ) const
@@ -94,6 +149,7 @@ operator==( const MeshEntity& entity ) const
template< typename MeshConfig,
          typename Device,
          typename EntityTopology >
__cuda_callable__
bool
MeshEntity< MeshConfig, Device, EntityTopology >::
operator!=( const MeshEntity& entity ) const
@@ -138,6 +194,53 @@ getVertexIndex( const LocalIndexType localIndex ) const
/****
 * Vertex entity specialization
 */
template< typename MeshConfig, typename Device >
MeshEntity< MeshConfig, Device, MeshVertexTopology >::
MeshEntity( const MeshEntity& entity )
   : MeshSuperentityAccess< MeshConfig, Device, MeshVertexTopology >( entity ),
     MeshEntityIndex< typename MeshConfig::IdType >( entity )
{
   setPoint( entity.getPoint() );
}

template< typename MeshConfig, typename Device >
   template< typename Device_ >
MeshEntity< MeshConfig, Device, MeshVertexTopology >::
MeshEntity( const MeshEntity< MeshConfig, Device_, MeshVertexTopology >& entity )
   // no cross-device copy of superentities here - Mesh constructor has to rebind pointers
   // TODO: check this
   : MeshEntityIndex< typename MeshConfig::IdType >( entity )
{
   setPoint( entity.getPoint() );
}

template< typename MeshConfig, typename Device >
__cuda_callable__
MeshEntity< MeshConfig, Device, MeshVertexTopology >& 
MeshEntity< MeshConfig, Device, MeshVertexTopology >::
operator=( const MeshEntity& entity )
{
   MeshSuperentityAccess< MeshConfig, Device, MeshVertexTopology >::operator=( entity );
   MeshEntityIndex< typename MeshConfig::IdType >::operator=( entity );
   setPoint( entity.getPoint() );
   return *this;
}

template< typename MeshConfig, typename Device >
      template< typename Device_ >
__cuda_callable__
MeshEntity< MeshConfig, Device, MeshVertexTopology >& 
MeshEntity< MeshConfig, Device, MeshVertexTopology >::
operator=( const MeshEntity< MeshConfig, Device_, MeshVertexTopology >& entity )
{
   // no cross-device copy of subentities and superentities here - Mesh::operator= has to rebind pointers
   // TODO: check this
//   MeshSuperentityAccess< MeshConfig, Device, EntityTopology >::operator=( entity );
   MeshEntityIndex< typename MeshConfig::IdType >::operator=( entity );
   setPoint( entity.getPoint() );
   return *this;
}

template< typename MeshConfig, typename Device >
String
MeshEntity< MeshConfig, Device, MeshVertexTopology >::
@@ -187,6 +290,7 @@ print( std::ostream& str ) const
}

template< typename MeshConfig, typename Device >
__cuda_callable__
bool
MeshEntity< MeshConfig, Device, MeshVertexTopology >::
operator==( const MeshEntity& entity ) const
@@ -197,6 +301,7 @@ operator==( const MeshEntity& entity ) const
}

template< typename MeshConfig, typename Device >
__cuda_callable__
bool
MeshEntity< MeshConfig, Device, MeshVertexTopology >::
operator!=( const MeshEntity& entity ) const
@@ -213,6 +318,7 @@ getEntityDimension()
}

template< typename MeshConfig, typename Device >
__cuda_callable__
typename MeshEntity< MeshConfig, Device, MeshVertexTopology >::PointType
MeshEntity< MeshConfig, Device, MeshVertexTopology >::
getPoint() const
@@ -221,6 +327,7 @@ getPoint() const
}

template< typename MeshConfig, typename Device >
__cuda_callable__
void
MeshEntity< MeshConfig, Device, MeshVertexTopology >::
setPoint( const PointType& point )
+28 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#pragma once

#include <TNL/Meshes/Mesh.h>
#include <TNL/Meshes/MeshDetails/layers/MeshEntityStorageRebinder.h>
#include <TNL/Meshes/MeshDetails/initializer/MeshInitializer.h>

namespace TNL {
@@ -35,6 +36,28 @@ init( typename MeshTraitsType::PointArrayType& points,
}


template< typename MeshConfig, typename Device >
Mesh< MeshConfig, Device >::
Mesh( const Mesh& mesh )
   : StorageBaseType( mesh )
{
   // update pointers from entities into the subentity and superentity storage networks
   MeshEntityStorageRebinder< Mesh< MeshConfig, Device > >::exec( *this );
}

template< typename MeshConfig, typename Device >
   template< typename Device_ >
Mesh< MeshConfig, Device >::
Mesh( const Mesh< MeshConfig, Device_ >& mesh )
   // clang complains that subclass cannot be cast to its private/protected base type,
   // but for some reason it works fine for the non-template copy-constructor
//   : StorageBaseType( *static_cast< const MeshStorageLayers< MeshConfig, Device_ >* >( &mesh ) )
   : StorageBaseType( *( (const MeshStorageLayers< MeshConfig, Device_ >*) &mesh ) )
{
   // update pointers from entities into the subentity and superentity storage networks
   MeshEntityStorageRebinder< Mesh< MeshConfig, Device > >::exec( *this );
}

template< typename MeshConfig, typename Device >
constexpr int
Mesh< MeshConfig, Device >::
@@ -96,6 +119,7 @@ getEntitiesCount() const

template< typename MeshConfig, typename Device >
   template< int Dimension >
__cuda_callable__
typename Mesh< MeshConfig, Device >::template EntityType< Dimension >&
Mesh< MeshConfig, Device >::
getEntity( const GlobalIndexType& entityIndex )
@@ -106,6 +130,7 @@ getEntity( const GlobalIndexType& entityIndex )

template< typename MeshConfig, typename Device >
   template< int Dimension >
__cuda_callable__
const typename Mesh< MeshConfig, Device >::template EntityType< Dimension >&
Mesh< MeshConfig, Device >::
getEntity( const GlobalIndexType& entityIndex ) const
@@ -127,6 +152,7 @@ getEntitiesCount() const

template< typename MeshConfig, typename Device >
   template< typename Entity >
__cuda_callable__
Entity&
Mesh< MeshConfig, Device >::
getEntity( const GlobalIndexType& entityIndex )
@@ -136,6 +162,7 @@ getEntity( const GlobalIndexType& entityIndex )

template< typename MeshConfig, typename Device >
   template< typename Entity >
__cuda_callable__
const Entity&
Mesh< MeshConfig, Device >::
getEntity( const GlobalIndexType& entityIndex ) const
@@ -171,7 +198,7 @@ load( File& file )
   }
   // TODO: this could be done from the storage layer
   // update pointers from entities into the subentity and superentity storage networks
   MeshEntityStorageRebinder< Mesh< MeshConfig > >::exec( *this );
   MeshEntityStorageRebinder< Mesh< MeshConfig, Device > >::exec( *this );
   return true;
}

+43 −0
Original line number Diff line number Diff line
@@ -32,6 +32,45 @@ public:
   using BoundaryTagsArray = typename MeshTraitsType::BoundaryTagsArrayType;
   using OrderingArray     = typename MeshTraitsType::GlobalIndexOrderingArrayType;

   MeshBoundaryTagsLayer() = default;

   explicit MeshBoundaryTagsLayer( const MeshBoundaryTagsLayer& other )
   {
      operator=( other );
   }

   template< typename Device_ >
   MeshBoundaryTagsLayer( const MeshBoundaryTagsLayer< MeshConfig, Device_, DimensionTag >& other )
   {
      operator=( other );
   }

   MeshBoundaryTagsLayer& operator=( const MeshBoundaryTagsLayer& other )
   {
      // TODO: throw exception if allocation fails
      boundaryTags.setLike( other.boundaryTags );
      boundaryIndices.setLike( other.boundaryIndices );
      interiorIndices.setLike( other.interiorIndices );
      boundaryTags = other.boundaryTags;
      boundaryIndices = other.boundaryIndices;
      interiorIndices = other.interiorIndices;
      return *this;
   }

   template< typename Device_ >
   MeshBoundaryTagsLayer& operator=( const MeshBoundaryTagsLayer< MeshConfig, Device_, DimensionTag >& other )
   {
      // TODO: throw exception if allocation fails
      boundaryTags.setLike( other.boundaryTags );
      boundaryIndices.setLike( other.boundaryIndices );
      interiorIndices.setLike( other.interiorIndices );
      boundaryTags = other.boundaryTags;
      boundaryIndices = other.boundaryIndices;
      interiorIndices = other.interiorIndices;
      return *this;
   }


   bool setNumberOfEntities( const GlobalIndexType& entitiesCount )
   {
      return boundaryTags.setSize( entitiesCount );
@@ -153,6 +192,10 @@ private:
   BoundaryTagsArray boundaryTags;
   OrderingArray boundaryIndices;
   OrderingArray interiorIndices;

   // friend class is needed for templated assignment operators
   template< typename MeshConfig_, typename Device_, typename DimensionTag_, bool TagStorage_ >
   friend class MeshBoundaryTagsLayer;
};

template< typename MeshConfig,
Loading