From b06136b9dfd99b592cfd88cdff659b966c54ee7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Oberhuber?= <oberhuber.tomas@gmail.com> Date: Thu, 27 Feb 2020 16:32:37 +0100 Subject: [PATCH] Added use of MatrixInfo to SpMV benchmark. --- src/Benchmarks/SpMV/spmv.h | 6 +- src/TNL/Containers/Segments/CSR.h | 2 + src/TNL/Containers/Segments/CSR.hpp | 10 +++ src/TNL/Containers/Segments/CSRView.h | 2 + src/TNL/Containers/Segments/CSRView.hpp | 9 +++ src/TNL/Containers/Segments/Ellpack.h | 3 +- src/TNL/Containers/Segments/Ellpack.hpp | 12 ++++ src/TNL/Containers/Segments/EllpackView.h | 2 + src/TNL/Containers/Segments/EllpackView.hpp | 11 +++ src/TNL/Containers/Segments/SlicedEllpack.h | 2 + src/TNL/Containers/Segments/SlicedEllpack.hpp | 12 ++++ .../Containers/Segments/SlicedEllpackView.h | 2 + .../Containers/Segments/SlicedEllpackView.hpp | 11 +++ src/TNL/Matrices/MatrixInfo.h | 69 ++++++++++++++++--- 14 files changed, 139 insertions(+), 14 deletions(-) diff --git a/src/Benchmarks/SpMV/spmv.h b/src/Benchmarks/SpMV/spmv.h index e3a1ae047e..02a26854dc 100644 --- a/src/Benchmarks/SpMV/spmv.h +++ b/src/Benchmarks/SpMV/spmv.h @@ -25,6 +25,7 @@ #include <TNL/Matrices/Legacy/BiEllpack.h> #include <TNL/Matrices/MatrixReader.h> +#include <TNL/Matrices/MatrixInfo.h> #include <TNL/Matrices/SparseMatrix.h> #include <TNL/Matrices/MatrixType.h> @@ -160,7 +161,7 @@ benchmarkSpMV( Benchmark& benchmark, { "non-zeros", convertToString( hostMatrix.getNumberOfNonzeroMatrixElements() ) }, { "rows", convertToString( hostMatrix.getRows() ) }, { "columns", convertToString( hostMatrix.getColumns() ) }, - { "matrix format", convertToString( getType( hostMatrix ) ) } + { "matrix format", MatrixInfo< HostMatrix >::getFormat() } //convertToString( getType( hostMatrix ) ) } } )); hostVector.setSize( hostMatrix.getColumns() ); @@ -294,7 +295,8 @@ benchmarkSpmvSynthetic( Benchmark& benchmark, benchmarkSpMV< Real, SlicedEllpackAlias >( benchmark, inputFileName, verboseMR ); benchmarkSpMV< Real, SparseMatrix_SlicedEllpack >( benchmark, inputFileName, verboseMR ); - //benchmarkSpMV< Real, Matrices::ChunkedEllpack >( benchmark, inputFileName, verboseMR ); + benchmarkSpMV< Real, Matrices::ChunkedEllpack >( benchmark, inputFileName, verboseMR ); + benchmarkSpMV< Real, Matrices::BiEllpack >( benchmark, inputFileName, verboseMR ); //// // Segments based sparse matrices diff --git a/src/TNL/Containers/Segments/CSR.h b/src/TNL/Containers/Segments/CSR.h index 3645e9f6a1..89cad0c6af 100644 --- a/src/TNL/Containers/Segments/CSR.h +++ b/src/TNL/Containers/Segments/CSR.h @@ -47,6 +47,8 @@ class CSR static String getSerializationType(); + static String getSegmentsType(); + /** * \brief Set sizes of particular segments. */ diff --git a/src/TNL/Containers/Segments/CSR.hpp b/src/TNL/Containers/Segments/CSR.hpp index 55dcba74c9..9a948b04e2 100644 --- a/src/TNL/Containers/Segments/CSR.hpp +++ b/src/TNL/Containers/Segments/CSR.hpp @@ -64,6 +64,16 @@ getSerializationType() return "CSR< [any_device], " + TNL::getSerializationType< IndexType >() + " >"; } +template< typename Device, + typename Index, + typename IndexAllocator > +String +CSR< Device, Index, IndexAllocator >:: +getSegmentsType() +{ + return ViewType::getSegmentsType(); +} + template< typename Device, typename Index, typename IndexAllocator > diff --git a/src/TNL/Containers/Segments/CSRView.h b/src/TNL/Containers/Segments/CSRView.h index 759fe8ff7f..f7cf815d04 100644 --- a/src/TNL/Containers/Segments/CSRView.h +++ b/src/TNL/Containers/Segments/CSRView.h @@ -52,6 +52,8 @@ class CSRView static String getSerializationType(); + static String getSegmentsType(); + __cuda_callable__ ViewType getView(); diff --git a/src/TNL/Containers/Segments/CSRView.hpp b/src/TNL/Containers/Segments/CSRView.hpp index 043e06e04e..fab5c6da72 100644 --- a/src/TNL/Containers/Segments/CSRView.hpp +++ b/src/TNL/Containers/Segments/CSRView.hpp @@ -64,6 +64,15 @@ getSerializationType() return "CSR< [any_device], " + TNL::getSerializationType< IndexType >() + " >"; } +template< typename Device, + typename Index > +String +CSRView< Device, Index >:: +getSegmentsType() +{ + return "CSR"; +} + template< typename Device, typename Index > __cuda_callable__ diff --git a/src/TNL/Containers/Segments/Ellpack.h b/src/TNL/Containers/Segments/Ellpack.h index 6edacb1cff..a1188a854e 100644 --- a/src/TNL/Containers/Segments/Ellpack.h +++ b/src/TNL/Containers/Segments/Ellpack.h @@ -39,7 +39,6 @@ class Ellpack //using ConstViewType = EllpackView< Device, std::add_const_t< Index >, RowMajorOrder, Alignment >; using SegmentViewType = SegmentView< IndexType, RowMajorOrder >; - Ellpack(); Ellpack( const SegmentsSizes& sizes ); @@ -52,6 +51,8 @@ class Ellpack static String getSerializationType(); + static String getSegmentsType(); + ViewType getView(); //ConstViewType getConstView() const; diff --git a/src/TNL/Containers/Segments/Ellpack.hpp b/src/TNL/Containers/Segments/Ellpack.hpp index 663a65bc80..9c59c5529e 100644 --- a/src/TNL/Containers/Segments/Ellpack.hpp +++ b/src/TNL/Containers/Segments/Ellpack.hpp @@ -88,6 +88,18 @@ getSerializationType() return "Ellpack< [any_device], " + TNL::getSerializationType< IndexType >() + " >"; } +template< typename Device, + typename Index, + typename IndexAllocator, + bool RowMajorOrder, + int Alignment > +String +Ellpack< Device, Index, IndexAllocator, RowMajorOrder, Alignment >:: +getSegmentsType() +{ + return ViewType::getSegmentsType(); +} + template< typename Device, typename Index, typename IndexAllocator, diff --git a/src/TNL/Containers/Segments/EllpackView.h b/src/TNL/Containers/Segments/EllpackView.h index dcbc56d1ba..10a89bd7ba 100644 --- a/src/TNL/Containers/Segments/EllpackView.h +++ b/src/TNL/Containers/Segments/EllpackView.h @@ -54,6 +54,8 @@ class EllpackView static String getSerializationType(); + static String getSegmentsType(); + __cuda_callable__ ViewType getView(); diff --git a/src/TNL/Containers/Segments/EllpackView.hpp b/src/TNL/Containers/Segments/EllpackView.hpp index ea2dc0d216..84086f380b 100644 --- a/src/TNL/Containers/Segments/EllpackView.hpp +++ b/src/TNL/Containers/Segments/EllpackView.hpp @@ -74,6 +74,17 @@ getSerializationType() return "Ellpack< [any_device], " + TNL::getSerializationType< IndexType >() + " >"; } +template< typename Device, + typename Index, + bool RowMajorOrder, + int Alignment > +String +EllpackView< Device, Index, RowMajorOrder, Alignment >:: +getSegmentsType() +{ + return "Ellpack"; +} + template< typename Device, typename Index, bool RowMajorOrder, diff --git a/src/TNL/Containers/Segments/SlicedEllpack.h b/src/TNL/Containers/Segments/SlicedEllpack.h index e1cdfa1d4d..2027f1d78a 100644 --- a/src/TNL/Containers/Segments/SlicedEllpack.h +++ b/src/TNL/Containers/Segments/SlicedEllpack.h @@ -49,6 +49,8 @@ class SlicedEllpack static String getSerializationType(); + static String getSegmentsType(); + ViewType getView(); ConstViewType getConstView() const; diff --git a/src/TNL/Containers/Segments/SlicedEllpack.hpp b/src/TNL/Containers/Segments/SlicedEllpack.hpp index 3d3a6d8c3d..9ba1276e3e 100644 --- a/src/TNL/Containers/Segments/SlicedEllpack.hpp +++ b/src/TNL/Containers/Segments/SlicedEllpack.hpp @@ -81,6 +81,18 @@ getSerializationType() return "SlicedEllpack< [any_device], " + TNL::getSerializationType< IndexType >() + " >"; } +template< typename Device, + typename Index, + typename IndexAllocator, + bool RowMajorOrder, + int SliceSize > +String +SlicedEllpack< Device, Index, IndexAllocator, RowMajorOrder, SliceSize >:: +getSegmentsType() +{ + return ViewType::getSegmentsType(); +} + template< typename Device, typename Index, typename IndexAllocator, diff --git a/src/TNL/Containers/Segments/SlicedEllpackView.h b/src/TNL/Containers/Segments/SlicedEllpackView.h index 23001553c6..6e2e55bbc3 100644 --- a/src/TNL/Containers/Segments/SlicedEllpackView.h +++ b/src/TNL/Containers/Segments/SlicedEllpackView.h @@ -56,6 +56,8 @@ class SlicedEllpackView static String getSerializationType(); + static String getSegmentsType(); + __cuda_callable__ ViewType getView(); diff --git a/src/TNL/Containers/Segments/SlicedEllpackView.hpp b/src/TNL/Containers/Segments/SlicedEllpackView.hpp index 3e3c8c09c2..f9e252fd93 100644 --- a/src/TNL/Containers/Segments/SlicedEllpackView.hpp +++ b/src/TNL/Containers/Segments/SlicedEllpackView.hpp @@ -85,6 +85,17 @@ getSerializationType() return "SlicedEllpack< [any_device], " + TNL::getSerializationType< IndexType >() + " >"; } +template< typename Device, + typename Index, + bool RowMajorOrder, + int SliceSize > +String +SlicedEllpackView< Device, Index, RowMajorOrder, SliceSize >:: +getSegmentsType() +{ + return "SlicedEllpack"; +} + template< typename Device, typename Index, bool RowMajorOrder, diff --git a/src/TNL/Matrices/MatrixInfo.h b/src/TNL/Matrices/MatrixInfo.h index 34f85dd82d..75cac40557 100644 --- a/src/TNL/Matrices/MatrixInfo.h +++ b/src/TNL/Matrices/MatrixInfo.h @@ -12,9 +12,17 @@ #include <TNL/String.h> #include <TNL/Matrices/Dense.h> -#include <TNL/Matrices/DenseView.h> +#include <TNL/Matrices/DenseMatrixView.h> #include <TNL/Matrices/SparseMatrix.h> #include <TNL/Matrices/SparseMatrixView.h> +#include <TNL/Containers/Segments/CSRView.h> +#include <TNL/Containers/Segments/EllpackView.h> +#include <TNL/Containers/Segments/SlicedEllpackView.h> +#include <TNL/Matrices/Legacy/CSR.h> +#include <TNL/Matrices/Legacy/Ellpack.h> +#include <TNL/Matrices/Legacy/SlicedEllpack.h> +#include <TNL/Matrices/Legacy/ChunkedEllpack.h> +#include <TNL/Matrices/Legacy/BiEllpack.h> namespace TNL { /** @@ -30,7 +38,7 @@ template< typename Real, typename Device, typename Index, bool RowMajorOrder > -struct MatrixInfo< DenseView< Real, Device, RowMajorOrder > > +struct MatrixInfo< DenseMatrixView< Real, Device, Index, RowMajorOrder > > { static String getDensity() { return String( "dense" ); }; }; @@ -40,12 +48,11 @@ template< typename Real, typename Index, bool RowMajorOrder, typename RealAllocator > -struct MatrixInfo< Dense< Real, Device, RowMajorOrder, RealAllocator > > -: public MatrixInfo< typename Dense< Real, Device, RowMajorOrder, RealAllocator >::ViewType > +struct MatrixInfo< Dense< Real, Device, Index, RowMajorOrder, RealAllocator > > +: public MatrixInfo< typename Dense< Real, Device, Index, RowMajorOrder, RealAllocator >::ViewType > { }; - template< typename Real, typename Device, typename Index, @@ -55,9 +62,7 @@ struct MatrixInfo< SparseMatrixView< Real, Device, Index, MatrixType, SegmentsVi { static String getDensity() { return String( "sparse" ); }; - static String getFormat() { - if( std::is_same< SegementsView ........ >) - }; + static String getFormat() { return SegmentsView< Device, Index >::getSegmentsType(); }; }; template< typename Real, @@ -68,9 +73,51 @@ template< typename Real, typename RealAllocator, typename IndexAllocator > struct MatrixInfo< SparseMatrix< Real, Device, Index, MatrixType, Segments, RealAllocator, IndexAllocator > > -:public MatrixInfo< typename SparseMatrix< Real, Device, Index, MatrixType, Segments, RealAllocator, IndexAllocator >::ViewType > +: public MatrixInfo< typename SparseMatrix< Real, Device, Index, MatrixType, Segments, RealAllocator, IndexAllocator >::ViewType > +{ +}; + +///// +// Legacy matrices +template< typename Real, typename Device, typename Index > +struct MatrixInfo< BiEllpack< Real, Device, Index > > +{ + static String getDensity() { return String( "sparse" ); }; + + static String getFormat() { return "BiEllpack Legacy"; }; +}; + +template< typename Real, typename Device, typename Index > +struct MatrixInfo< CSR< Real, Device, Index > > +{ + static String getDensity() { return String( "sparse" ); }; + + static String getFormat() { return "CSR Legacy"; }; +}; + +template< typename Real, typename Device, typename Index > +struct MatrixInfo< ChunkedEllpack< Real, Device, Index > > { -} + static String getDensity() { return String( "sparse" ); }; + + static String getFormat() { return "ChunkedEllpack Legacy"; }; +}; + +template< typename Real, typename Device, typename Index > +struct MatrixInfo< Ellpack< Real, Device, Index > > +{ + static String getDensity() { return String( "sparse" ); }; + + static String getFormat() { return "Ellpack Legacy"; }; +}; + +template< typename Real, typename Device, typename Index, int SliceSize > +struct MatrixInfo< SlicedEllpack< Real, Device, Index, SliceSize> > +{ + static String getDensity() { return String( "sparse" ); }; + + static String getFormat() { return "SlicedEllpack Legacy"; }; +}; } //namespace Matrices -} //namespace TNL \ No newline at end of file +} //namespace TNL -- GitLab