Commit 559c9f5c authored by Vít Hanousek's avatar Vít Hanousek
Browse files

Merge branch 'develop' into MIC-devel

parents 7f3b651c 9e6fe9a8
Loading
Loading
Loading
Loading
+54 −48
Original line number Diff line number Diff line
@@ -49,13 +49,8 @@

namespace TNL {

/***
 * Use the lazy mode if you do not want to call the object constructor in the
 * shared pointer constructor. You may call it later via the method recreate.
 */
template< typename Object,
          typename Device = typename Object::DeviceType,
          bool lazy = false >
          typename Device = typename Object::DeviceType >
class SharedPointer
{
   static_assert( ! std::is_same< Device, void >::value, "The device cannot be void. You need to specify the device explicitly in your code." );
@@ -64,8 +59,8 @@ class SharedPointer
/****
 * Specialization for Devices::Host
 */
template< typename Object, bool lazy >
class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer
template< typename Object >
class SharedPointer< Object, Devices::Host > : public SmartPointer
{
   private:
      // Convenient template alias for controlling the selection of copy- and
@@ -77,14 +72,14 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer
                                      std::is_same< typename std::remove_cv< Object >::type, Object_ >::value >;

      // friend class will be needed for templated assignment operators
      template< typename Object_, typename Device_, bool lazy_ >
      template< typename Object_, typename Device_ >
      friend class SharedPointer;

   public:

      typedef Object ObjectType;
      typedef Devices::Host DeviceType;
      typedef SharedPointer< Object, Devices::Host, lazy > ThisType;
      typedef SharedPointer< Object, Devices::Host > ThisType;

      template< typename... Args >
      explicit  SharedPointer( Args... args )
@@ -93,7 +88,6 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer
#ifdef TNL_DEBUG_SHARED_POINTERS
         std::cerr << "Creating shared pointer to " << demangle(typeid(ObjectType).name()) << std::endl;
#endif
         if( ! lazy )
         this->allocate( args... );
      }

@@ -105,9 +99,9 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer
      }

      // conditional constructor for non-const -> const data
      template< typename Object_, bool lazy_,
      template< typename Object_,
                typename = typename Enabler< Object_ >::type >
      SharedPointer( const SharedPointer< Object_, DeviceType, lazy_ >& pointer )
      SharedPointer( const SharedPointer< Object_, DeviceType >& pointer )
      : pd( (PointerData*) pointer.pd )
      {
         this->pd->counter += 1;
@@ -121,9 +115,9 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer
      }

      // conditional constructor for non-const -> const data
      template< typename Object_, bool lazy_,
      template< typename Object_,
                typename = typename Enabler< Object_ >::type >
      SharedPointer( SharedPointer< Object_, DeviceType, lazy_ >&& pointer )
      SharedPointer( SharedPointer< Object_, DeviceType >&& pointer )
      : pd( (PointerData*) pointer.pd )
      {
         pointer.pd = nullptr;
@@ -203,9 +197,9 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer
      }

      // conditional operator for non-const -> const data
      template< typename Object_, bool lazy_,
      template< typename Object_,
                typename = typename Enabler< Object_ >::type >
      const ThisType& operator=( const SharedPointer< Object_, DeviceType, lazy_ >& ptr )
      const ThisType& operator=( const SharedPointer< Object_, DeviceType >& ptr )
      {
         this->free();
         this->pd = (PointerData*) ptr.pd;
@@ -223,9 +217,9 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer
      }

      // conditional operator for non-const -> const data
      template< typename Object_, bool lazy_,
      template< typename Object_,
                typename = typename Enabler< Object_ >::type >
      const ThisType& operator=( SharedPointer< Object_, DeviceType, lazy_ >&& ptr )
      const ThisType& operator=( SharedPointer< Object_, DeviceType >&& ptr )
      {
         this->free();
         this->pd = (PointerData*) ptr.pd;
@@ -238,6 +232,11 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer
         return true;
      }
      
      void clear()
      {
         this->free();
      }

      ~SharedPointer()
      {
         this->free();
@@ -284,8 +283,8 @@ class SharedPointer< Object, Devices::Host, lazy > : public SmartPointer
/****
 * Specialization for CUDA
 */
template< typename Object, bool lazy >
class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer
template< typename Object >
class SharedPointer< Object, Devices::Cuda > : public SmartPointer
{
   private:
      // Convenient template alias for controlling the selection of copy- and
@@ -297,21 +296,20 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer
                                      std::is_same< typename std::remove_cv< Object >::type, Object_ >::value >;

      // friend class will be needed for templated assignment operators
      template< typename Object_, typename Device_, bool lazy_ >
      template< typename Object_, typename Device_ >
      friend class SharedPointer;

   public:

      typedef Object ObjectType;
      typedef Devices::Cuda DeviceType;
      typedef SharedPointer< Object, Devices::Cuda, lazy > ThisType;
      typedef SharedPointer< Object, Devices::Cuda > ThisType;

      template< typename... Args >
      explicit  SharedPointer( Args... args )
      : pd( nullptr ),
        cuda_pointer( nullptr )
      {
         if( ! lazy )
         this->allocate( args... );
      }

@@ -324,9 +322,9 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer
      }

      // conditional constructor for non-const -> const data
      template< typename Object_, bool lazy_,
      template< typename Object_,
                typename = typename Enabler< Object_ >::type >
      SharedPointer( const SharedPointer< Object_, DeviceType, lazy_ >& pointer )
      SharedPointer( const SharedPointer< Object_, DeviceType >& pointer )
      : pd( (PointerData*) pointer.pd ),
        cuda_pointer( pointer.cuda_pointer )
      {
@@ -343,9 +341,9 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer
      }

      // conditional constructor for non-const -> const data
      template< typename Object_, bool lazy_,
      template< typename Object_,
                typename = typename Enabler< Object_ >::type >
      SharedPointer( SharedPointer< Object_, DeviceType, lazy_ >&& pointer )
      SharedPointer( SharedPointer< Object_, DeviceType >&& pointer )
      : pd( (PointerData*) pointer.pd ),
        cuda_pointer( pointer.cuda_pointer )
      {
@@ -452,9 +450,9 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer
      }

      // conditional operator for non-const -> const data
      template< typename Object_, bool lazy_,
      template< typename Object_,
                typename = typename Enabler< Object_ >::type >
      const ThisType& operator=( const SharedPointer< Object_, DeviceType, lazy_ >& ptr )
      const ThisType& operator=( const SharedPointer< Object_, DeviceType >& ptr )
      {
         this->free();
         this->pd = (PointerData*) ptr.pd;
@@ -481,9 +479,9 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer
      }

      // conditional operator for non-const -> const data
      template< typename Object_, bool lazy_,
      template< typename Object_,
                typename = typename Enabler< Object_ >::type >
      const ThisType& operator=( SharedPointer< Object_, DeviceType, lazy_ >&& ptr )
      const ThisType& operator=( SharedPointer< Object_, DeviceType >&& ptr )
      {
         this->free();
         this->pd = (PointerData*) ptr.pd;
@@ -521,6 +519,11 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer
#endif
      }
      
      void clear()
      {
         this->free();
      }      

      ~SharedPointer()
      {
         this->free();
@@ -606,13 +609,12 @@ class SharedPointer< Object, Devices::Cuda, lazy > : public SmartPointer
      Object* cuda_pointer;
};


#ifdef HAVE_MIC
/****
 * Specialization for MIC
 */
template< typename Object, bool lazy >
class SharedPointer< Object, Devices::MIC, lazy > : public SmartPointer
template< typename Object>
class SharedPointer< Object, Devices::MIC > : public SmartPointer
{
   private:
      // Convenient template alias for controlling the selection of copy- and
@@ -624,21 +626,20 @@ class SharedPointer< Object, Devices::MIC, lazy > : public SmartPointer
                                      std::is_same< typename std::remove_cv< Object >::type, Object_ >::value >;

      // friend class will be needed for templated assignment operators
      template< typename Object_, typename Device_, bool lazy_ >
      template< typename Object_, typename Device_>
      friend class SharedPointer;

   public:

      typedef Object ObjectType;
      typedef Devices::MIC DeviceType;
      typedef SharedPointer< Object, Devices::MIC, lazy > ThisType;
      typedef SharedPointer< Object, Devices::MIC> ThisType;

      template< typename... Args >
      explicit  SharedPointer( Args... args )
      : pd( nullptr ),
        mic_pointer( nullptr )
      {
         if( ! lazy )
            this->allocate( args... );
      }

@@ -651,9 +652,9 @@ class SharedPointer< Object, Devices::MIC, lazy > : public SmartPointer
      }

      // conditional constructor for non-const -> const data
      template< typename Object_, bool lazy_,
      template< typename Object_,
                typename = typename Enabler< Object_ >::type >
      SharedPointer( const SharedPointer< Object_, DeviceType, lazy_ >& pointer )
      SharedPointer( const SharedPointer< Object_, DeviceType >& pointer )
      : pd( (PointerData*) pointer.pd ),
        mic_pointer( pointer.mic_pointer )
      {
@@ -670,9 +671,9 @@ class SharedPointer< Object, Devices::MIC, lazy > : public SmartPointer
      }

      // conditional constructor for non-const -> const data
      template< typename Object_, bool lazy_,
      template< typename Object_,
                typename = typename Enabler< Object_ >::type >
      SharedPointer( SharedPointer< Object_, DeviceType, lazy_ >&& pointer )
      SharedPointer( SharedPointer< Object_, DeviceType >&& pointer )
      : pd( (PointerData*) pointer.pd ),
        mic_pointer( pointer.mic_pointer )
      {
@@ -779,9 +780,9 @@ class SharedPointer< Object, Devices::MIC, lazy > : public SmartPointer
      }

      // conditional operator for non-const -> const data
      template< typename Object_, bool lazy_,
      template< typename Object_,
                typename = typename Enabler< Object_ >::type >
      const ThisType& operator=( const SharedPointer< Object_, DeviceType, lazy_ >& ptr )
      const ThisType& operator=( const SharedPointer< Object_, DeviceType >& ptr )
      {
         this->free();
         this->pd = (PointerData*) ptr.pd;
@@ -808,9 +809,9 @@ class SharedPointer< Object, Devices::MIC, lazy > : public SmartPointer
      }

      // conditional operator for non-const -> const data
      template< typename Object_, bool lazy_,
      template< typename Object_,
                typename = typename Enabler< Object_ >::type >
      const ThisType& operator=( SharedPointer< Object_, DeviceType, lazy_ >&& ptr )
      const ThisType& operator=( SharedPointer< Object_, DeviceType >&& ptr )
      {
         this->free();
         this->pd = (PointerData*) ptr.pd;
@@ -843,6 +844,11 @@ class SharedPointer< Object, Devices::MIC, lazy > : public SmartPointer
         return false; //??
      }
      
      void clear()
      {
         this->free();
      }

      ~SharedPointer()
      {
         this->free();
+2 −2
Original line number Diff line number Diff line
@@ -39,8 +39,8 @@ class BICGStab : public Object,
   typedef typename Matrix::DeviceType DeviceType;
   typedef Matrix MatrixType;
   typedef Preconditioner PreconditionerType;
   typedef SharedPointer< const MatrixType, DeviceType, true > MatrixPointer;
   typedef SharedPointer< const PreconditionerType, DeviceType, true > PreconditionerPointer;
   typedef SharedPointer< const MatrixType, DeviceType > MatrixPointer;
   typedef SharedPointer< const PreconditionerType, DeviceType > PreconditionerPointer;

   BICGStab();

+5 −0
Original line number Diff line number Diff line
@@ -26,6 +26,11 @@ template< typename Matrix,
          typename Preconditioner >
BICGStab< Matrix, Preconditioner > :: BICGStab()
{
   /****
    * Clearing the shared pointer means that there is no
    * preconditioner set.
    */
   this->preconditioner.clear();   
}

template< typename Matrix,
+2 −2
Original line number Diff line number Diff line
@@ -38,8 +38,8 @@ class CG : public Object,
   typedef typename Matrix::DeviceType DeviceType;
   typedef Matrix MatrixType;
   typedef Preconditioner PreconditionerType;
   typedef SharedPointer< const MatrixType, DeviceType, true > MatrixPointer;
   typedef SharedPointer< const PreconditionerType, DeviceType, true > PreconditionerPointer;
   typedef SharedPointer< const MatrixType, DeviceType > MatrixPointer;
   typedef SharedPointer< const PreconditionerType, DeviceType > PreconditionerPointer;


   CG();
+5 −0
Original line number Diff line number Diff line
@@ -18,6 +18,11 @@ template< typename Matrix,
          typename Preconditioner >
CG< Matrix, Preconditioner > :: CG()
{
   /****
    * Clearing the shared pointer means that there is no
    * preconditioner set.
    */
   this->preconditioner.clear();   
}

template< typename Matrix,
Loading