Commit a556f79e authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Removed HostType and CudaType aliases in containers, matrices and grids

They are not suitable for more than 2 devices/execution types; their design
breaks the Open-Closed Principle. Instead, a type template "Self" was
created, which allows to change any template parameter.
parent d81d168e
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -73,8 +73,8 @@ benchmarkSpmvCuda( Benchmark& benchmark,
{
   using RealType = typename Matrix::RealType;
   using IndexType = typename Matrix::IndexType;
   using CudaMatrix = typename Matrix::CudaType;
   using CudaVector = typename Vector::CudaType;
   using CudaMatrix = typename Matrix::template Self< RealType, Devices::Cuda >;
   using CudaVector = typename Vector::template Self< typename Vector::RealType, Devices::Cuda >;

   CudaVector cuda_x;
   cuda_x = x;
@@ -125,8 +125,8 @@ benchmarkDistributedSpmvCuda( Benchmark& benchmark,
{
   using RealType = typename Matrix::RealType;
   using IndexType = typename Matrix::IndexType;
   using CudaMatrix = typename Matrix::CudaType;
   using CudaVector = typename Vector::CudaType;
   using CudaMatrix = typename Matrix::template Self< RealType, Devices::Cuda >;
   using CudaVector = typename Vector::template Self< typename Vector::RealType, Devices::Cuda >;

   CudaVector cuda_x;
   cuda_x = x;
+6 −4
Original line number Diff line number Diff line
@@ -119,8 +119,8 @@ benchmarkIterativeSolvers( Benchmark& benchmark,
                           const Vector& b )
{
#ifdef HAVE_CUDA
   using CudaMatrix = typename Matrix::CudaType;
   using CudaVector = typename Vector::CudaType;
   using CudaMatrix = typename Matrix::template Self< typename Matrix::RealType, Devices::Cuda >;
   using CudaVector = typename Vector::template Self< typename Vector::RealType, Devices::Cuda >;

   CudaVector cuda_x0, cuda_b;
   cuda_x0 = x0;
@@ -461,9 +461,11 @@ struct LinearSolversBenchmark
         SharedPointer< CSR > matrixCopy;
         Matrices::copySparseMatrix( *matrixCopy, *matrixPointer );

         SharedPointer< typename CSR::CudaType > cuda_matrixCopy;
         using CudaCSR = Matrices::CSR< RealType, Devices::Cuda, IndexType >;
         using CudaVector = typename VectorType::template Self< RealType, Devices::Cuda >;
         SharedPointer< CudaCSR > cuda_matrixCopy;
         *cuda_matrixCopy = *matrixCopy;
         typename VectorType::CudaType cuda_x0, cuda_b;
         CudaVector cuda_x0, cuda_b;
         cuda_x0.setLike( x0 );
         cuda_b.setLike( b );
         cuda_x0 = x0;
+2 −1
Original line number Diff line number Diff line
@@ -52,7 +52,8 @@ template< typename Array >
void expect_eq( Array& a, Array& b )
{
   if( std::is_same< typename Array::DeviceType, TNL::Devices::Cuda >::value ) {
      typename Array::HostType a_host, b_host;
      using HostArray = typename Array::template Self< typename Array::ValueType, TNL::Devices::Host >;
      HostArray a_host, b_host;
      a_host = a;
      b_host = b;
      expect_eq_chunked( a_host, b_host );
+2 −1
Original line number Diff line number Diff line
@@ -54,7 +54,8 @@ template< typename Array >
void expect_eq( Array& a, Array& b )
{
   if( std::is_same< typename Array::DeviceType, TNL::Devices::Cuda >::value ) {
      typename Array::HostType a_host, b_host;
      using HostArray = typename Array::template Self< typename Array::ValueType, TNL::Devices::Host >;
      HostArray a_host, b_host;
      a_host = a;
      b_host = b;
      expect_eq_chunked( a_host, b_host );
+9 −11
Original line number Diff line number Diff line
@@ -73,7 +73,6 @@ template< typename Value,
class Array
{
   public:

      /**
       * \brief Type of elements stored in this array.
       */
@@ -98,16 +97,6 @@ class Array
       */
      using AllocatorType = Allocator;

      /**
       * \brief Defines the same array type but allocated on host (CPU).
       */
      using HostType = Array< Value, TNL::Devices::Host, Index >;

      /**
       * \brief Defines the same array type but allocated on CUDA device (GPU).
       */
      using CudaType = Array< Value, TNL::Devices::Cuda, Index >;

      /**
       * \brief Compatible ArrayView type.
       */
@@ -118,6 +107,15 @@ class Array
       */
      using ConstViewType = ArrayView< std::add_const_t< Value >, Device, Index >;

      /**
       * \brief A template which allows to quickly obtain an \ref Array type with changed template parameters.
       */
      template< typename _Value,
                typename _Device = Device,
                typename _Index = Index,
                typename _Allocator = typename Allocators::Default< _Device >::template Allocator< _Value > >
      using Self = Array< _Value, _Device, _Index, _Allocator >;


      /**
       * \brief Constructs an empty array with zero size.
Loading