Loading src/TNL/Containers/Segments/Ellpack.h +1 −1 Original line number Diff line number Diff line Loading @@ -124,7 +124,7 @@ class Ellpack }; } // namespace Segements } // namespace Conatiners } // namespace Containers } // namespace TNL #include <TNL/Containers/Segments/Ellpack.hpp> src/TNL/Matrices/Dense.h +18 −6 Original line number Diff line number Diff line Loading @@ -12,8 +12,8 @@ #include <TNL/Allocators/Default.h> #include <TNL/Devices/Host.h> #include <TNL/Matrices/DenseMatrixRowView.h> #include <TNL/Matrices/Matrix.h> #include <TNL/Matrices/DenseRow.h> #include <TNL/Containers/Segments/Ellpack.h> namespace TNL { Loading Loading @@ -42,11 +42,16 @@ public: using RealType = Real; using DeviceType = Device; using IndexType = Index; using CompressedRowLengthsVector = typename Matrix< Real, Device, Index >::CompressedRowLengthsVector; using ConstCompressedRowLengthsVectorView = typename Matrix< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView; using BaseType = Matrix< Real, Device, Index >; using MatrixRow = DenseRow< Real, Index >; using ValuesType = typename BaseType::ValuesVector; using ValuesViewType = typename ValuesType::ViewType; using SegmentsType = Containers::Segments::Ellpack< DeviceType, IndexType, typename Allocators::Default< Device >::template Allocator< IndexType >, RowMajorOrder >; using SegmentViewType = typename SegmentsType::SegmentViewType; using RowView = DenseMatrixRowView< SegmentViewType, ValuesViewType >; // TODO: remove this using CompressedRowLengthsVector = typename Matrix< Real, Device, Index >::CompressedRowLengthsVector; using ConstCompressedRowLengthsVectorView = typename Matrix< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView; template< typename _Real = Real, typename _Device = Device, Loading Loading @@ -81,6 +86,13 @@ public: void reset(); __cuda_callable__ const RowView getRow( const IndexType& rowIdx ) const; __cuda_callable__ RowView getRow( const IndexType& rowIdx ); void setValue( const RealType& v ); __cuda_callable__ Loading @@ -103,11 +115,11 @@ public: Real getElement( const IndexType row, const IndexType column ) const; __cuda_callable__ /*__cuda_callable__ MatrixRow getRow( const IndexType rowIndex ); __cuda_callable__ const MatrixRow getRow( const IndexType rowIndex ) const; const MatrixRow getRow( const IndexType rowIndex ) const;*/ template< typename Vector > __cuda_callable__ Loading src/TNL/Matrices/Dense.hpp +26 −47 Original line number Diff line number Diff line Loading @@ -158,6 +158,32 @@ void Dense< Real, Device, Index, RowMajorOrder, RealAllocator >::setValue( const this->values = value; } template< typename Real, typename Device, typename Index, bool RowMajorOrder, typename RealAllocator > __cuda_callable__ auto Dense< Real, Device, Index, RowMajorOrder, RealAllocator >:: getRow( const IndexType& rowIdx ) const -> const RowView { TNL_ASSERT_LT( rowIdx, this->getRows(), "Row index is larger than number of matrix rows." ); return RowView( this->segments.getSegmentView( rowIdx ), this->values.getView() ); } template< typename Real, typename Device, typename Index, bool RowMajorOrder, typename RealAllocator > __cuda_callable__ auto Dense< Real, Device, Index, RowMajorOrder, RealAllocator >:: getRow( const IndexType& rowIdx ) -> RowView { TNL_ASSERT_LT( rowIdx, this->getRows(), "Row index is larger than number of matrix rows." ); return RowView( this->segments.getSegmentView( rowIdx ), this->values.getView() ); } template< typename Real, typename Device, typename Index, Loading Loading @@ -236,46 +262,6 @@ Real Dense< Real, Device, Index, RowMajorOrder, RealAllocator >::getElement( con return this->values.getElement( this->getElementIndex( row, column ) ); } template< typename Real, typename Device, typename Index, bool RowMajorOrder, typename RealAllocator > __cuda_callable__ typename Dense< Real, Device, Index, RowMajorOrder, RealAllocator >::MatrixRow Dense< Real, Device, Index, RowMajorOrder, RealAllocator >:: getRow( const IndexType rowIndex ) { if( std::is_same< Device, Devices::Host >::value ) return MatrixRow( &this->values.getData()[ this->getElementIndex( rowIndex, 0 ) ], this->columns, 1 ); if( std::is_same< Device, Devices::Cuda >::value ) return MatrixRow( &this->values.getData()[ this->getElementIndex( rowIndex, 0 ) ], this->columns, this->rows ); } template< typename Real, typename Device, typename Index, bool RowMajorOrder, typename RealAllocator > __cuda_callable__ const typename Dense< Real, Device, Index, RowMajorOrder, RealAllocator >::MatrixRow Dense< Real, Device, Index, RowMajorOrder, RealAllocator >:: getRow( const IndexType rowIndex ) const { if( std::is_same< Device, Devices::Host >::value ) return MatrixRow( &this->values.getData()[ this->getElementIndex( rowIndex, 0 ) ], this->columns, 1 ); if( std::is_same< Device, Devices::Cuda >::value ) return MatrixRow( &this->values.getData()[ this->getElementIndex( rowIndex, 0 ) ], this->columns, this->rows ); } template< typename Real, typename Device, typename Index, Loading Loading @@ -898,13 +884,6 @@ Index Dense< Real, Device, Index, RowMajorOrder, RealAllocator >::getElementInde const IndexType column ) const { return this->segments.getGlobalIndex( row, column ); /*TNL_ASSERT( ( std::is_same< Device, Devices::Host >::value || std::is_same< Device, Devices::Cuda >::value ), ) if( std::is_same< Device, Devices::Host >::value ) return row * this->columns + column; if( std::is_same< Device, Devices::Cuda >::value ) return column * this->rows + row; return -1;*/ } template<> Loading src/TNL/Matrices/DenseMatrixRowView.h 0 → 100644 +52 −0 Original line number Diff line number Diff line /*************************************************************************** DenseMatrixRowView.h - description ------------------- begin : Jan 3, 2020 copyright : (C) 2020 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once namespace TNL { namespace Matrices { template< typename SegmentView, typename ValuesView > class DenseMatrixRowView { public: using RealType = typename ValuesView::RealType; using SegmentViewType = SegmentView; using IndexType = typename SegmentViewType::IndexType; using ValuesViewType = ValuesView; __cuda_callable__ DenseMatrixRowView( const SegmentViewType& segmentView, const ValuesViewType& values ); __cuda_callable__ IndexType getSize() const; __cuda_callable__ const RealType& getValue( const IndexType column ) const; __cuda_callable__ RealType& getValue( const IndexType column ); __cuda_callable__ void setElement( const IndexType column, const RealType& value ); protected: SegmentViewType segmentView; ValuesViewType values; }; } // namespace Matrices } // namespace TNL #include <TNL/Matrices/DenseMatrixRowView.hpp> src/TNL/Matrices/DenseMatrixRowView.hpp 0 → 100644 +71 −0 Original line number Diff line number Diff line /*************************************************************************** DenseMatrixRowView.hpp - description ------------------- begin : Jan 3, 2020 copyright : (C) 2020 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once #include <TNL/Matrices/DenseMatrixRowView.h> namespace TNL { namespace Matrices { template< typename SegmentView, typename ValuesView > __cuda_callable__ DenseMatrixRowView< SegmentView, ValuesView >:: DenseMatrixRowView( const SegmentViewType& segmentView, const ValuesViewType& values ) : segmentView( segmentView ), values( values ) { } template< typename SegmentView, typename ValuesView > __cuda_callable__ auto DenseMatrixRowView< SegmentView, ValuesView >:: getSize() const -> IndexType { return segmentView.getSize(); } template< typename SegmentView, typename ValuesView > __cuda_callable__ auto DenseMatrixRowView< SegmentView, ValuesView >:: getValue( const IndexType column ) const -> const RealType& { TNL_ASSERT_LT( column, this->getSize(), "Column index exceeds matrix row size." ); return values[ segmentView.getGlobalIndex( column ) ]; } template< typename SegmentView, typename ValuesView > __cuda_callable__ auto DenseMatrixRowView< SegmentView, ValuesView >:: getValue( const IndexType column ) -> RealType& { TNL_ASSERT_LT( column, this->getSize(), "Column index exceeds matrix row size." ); return values[ segmentView.getGlobalIndex( column ) ]; } template< typename SegmentView, typename ValuesView > __cuda_callable__ void DenseMatrixRowView< SegmentView, ValuesView >:: setElement( const IndexType column, const RealType& value ) { TNL_ASSERT_LT( column, this->getSize(), "Column index exceeds matrix row size." ); const IndexType globalIdx = segmentView.getGlobalIndex( column ); values[ globalIdx ] = value; } } // namespace Matrices } // namespace TNL Loading
src/TNL/Containers/Segments/Ellpack.h +1 −1 Original line number Diff line number Diff line Loading @@ -124,7 +124,7 @@ class Ellpack }; } // namespace Segements } // namespace Conatiners } // namespace Containers } // namespace TNL #include <TNL/Containers/Segments/Ellpack.hpp>
src/TNL/Matrices/Dense.h +18 −6 Original line number Diff line number Diff line Loading @@ -12,8 +12,8 @@ #include <TNL/Allocators/Default.h> #include <TNL/Devices/Host.h> #include <TNL/Matrices/DenseMatrixRowView.h> #include <TNL/Matrices/Matrix.h> #include <TNL/Matrices/DenseRow.h> #include <TNL/Containers/Segments/Ellpack.h> namespace TNL { Loading Loading @@ -42,11 +42,16 @@ public: using RealType = Real; using DeviceType = Device; using IndexType = Index; using CompressedRowLengthsVector = typename Matrix< Real, Device, Index >::CompressedRowLengthsVector; using ConstCompressedRowLengthsVectorView = typename Matrix< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView; using BaseType = Matrix< Real, Device, Index >; using MatrixRow = DenseRow< Real, Index >; using ValuesType = typename BaseType::ValuesVector; using ValuesViewType = typename ValuesType::ViewType; using SegmentsType = Containers::Segments::Ellpack< DeviceType, IndexType, typename Allocators::Default< Device >::template Allocator< IndexType >, RowMajorOrder >; using SegmentViewType = typename SegmentsType::SegmentViewType; using RowView = DenseMatrixRowView< SegmentViewType, ValuesViewType >; // TODO: remove this using CompressedRowLengthsVector = typename Matrix< Real, Device, Index >::CompressedRowLengthsVector; using ConstCompressedRowLengthsVectorView = typename Matrix< RealType, DeviceType, IndexType >::ConstCompressedRowLengthsVectorView; template< typename _Real = Real, typename _Device = Device, Loading Loading @@ -81,6 +86,13 @@ public: void reset(); __cuda_callable__ const RowView getRow( const IndexType& rowIdx ) const; __cuda_callable__ RowView getRow( const IndexType& rowIdx ); void setValue( const RealType& v ); __cuda_callable__ Loading @@ -103,11 +115,11 @@ public: Real getElement( const IndexType row, const IndexType column ) const; __cuda_callable__ /*__cuda_callable__ MatrixRow getRow( const IndexType rowIndex ); __cuda_callable__ const MatrixRow getRow( const IndexType rowIndex ) const; const MatrixRow getRow( const IndexType rowIndex ) const;*/ template< typename Vector > __cuda_callable__ Loading
src/TNL/Matrices/Dense.hpp +26 −47 Original line number Diff line number Diff line Loading @@ -158,6 +158,32 @@ void Dense< Real, Device, Index, RowMajorOrder, RealAllocator >::setValue( const this->values = value; } template< typename Real, typename Device, typename Index, bool RowMajorOrder, typename RealAllocator > __cuda_callable__ auto Dense< Real, Device, Index, RowMajorOrder, RealAllocator >:: getRow( const IndexType& rowIdx ) const -> const RowView { TNL_ASSERT_LT( rowIdx, this->getRows(), "Row index is larger than number of matrix rows." ); return RowView( this->segments.getSegmentView( rowIdx ), this->values.getView() ); } template< typename Real, typename Device, typename Index, bool RowMajorOrder, typename RealAllocator > __cuda_callable__ auto Dense< Real, Device, Index, RowMajorOrder, RealAllocator >:: getRow( const IndexType& rowIdx ) -> RowView { TNL_ASSERT_LT( rowIdx, this->getRows(), "Row index is larger than number of matrix rows." ); return RowView( this->segments.getSegmentView( rowIdx ), this->values.getView() ); } template< typename Real, typename Device, typename Index, Loading Loading @@ -236,46 +262,6 @@ Real Dense< Real, Device, Index, RowMajorOrder, RealAllocator >::getElement( con return this->values.getElement( this->getElementIndex( row, column ) ); } template< typename Real, typename Device, typename Index, bool RowMajorOrder, typename RealAllocator > __cuda_callable__ typename Dense< Real, Device, Index, RowMajorOrder, RealAllocator >::MatrixRow Dense< Real, Device, Index, RowMajorOrder, RealAllocator >:: getRow( const IndexType rowIndex ) { if( std::is_same< Device, Devices::Host >::value ) return MatrixRow( &this->values.getData()[ this->getElementIndex( rowIndex, 0 ) ], this->columns, 1 ); if( std::is_same< Device, Devices::Cuda >::value ) return MatrixRow( &this->values.getData()[ this->getElementIndex( rowIndex, 0 ) ], this->columns, this->rows ); } template< typename Real, typename Device, typename Index, bool RowMajorOrder, typename RealAllocator > __cuda_callable__ const typename Dense< Real, Device, Index, RowMajorOrder, RealAllocator >::MatrixRow Dense< Real, Device, Index, RowMajorOrder, RealAllocator >:: getRow( const IndexType rowIndex ) const { if( std::is_same< Device, Devices::Host >::value ) return MatrixRow( &this->values.getData()[ this->getElementIndex( rowIndex, 0 ) ], this->columns, 1 ); if( std::is_same< Device, Devices::Cuda >::value ) return MatrixRow( &this->values.getData()[ this->getElementIndex( rowIndex, 0 ) ], this->columns, this->rows ); } template< typename Real, typename Device, typename Index, Loading Loading @@ -898,13 +884,6 @@ Index Dense< Real, Device, Index, RowMajorOrder, RealAllocator >::getElementInde const IndexType column ) const { return this->segments.getGlobalIndex( row, column ); /*TNL_ASSERT( ( std::is_same< Device, Devices::Host >::value || std::is_same< Device, Devices::Cuda >::value ), ) if( std::is_same< Device, Devices::Host >::value ) return row * this->columns + column; if( std::is_same< Device, Devices::Cuda >::value ) return column * this->rows + row; return -1;*/ } template<> Loading
src/TNL/Matrices/DenseMatrixRowView.h 0 → 100644 +52 −0 Original line number Diff line number Diff line /*************************************************************************** DenseMatrixRowView.h - description ------------------- begin : Jan 3, 2020 copyright : (C) 2020 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once namespace TNL { namespace Matrices { template< typename SegmentView, typename ValuesView > class DenseMatrixRowView { public: using RealType = typename ValuesView::RealType; using SegmentViewType = SegmentView; using IndexType = typename SegmentViewType::IndexType; using ValuesViewType = ValuesView; __cuda_callable__ DenseMatrixRowView( const SegmentViewType& segmentView, const ValuesViewType& values ); __cuda_callable__ IndexType getSize() const; __cuda_callable__ const RealType& getValue( const IndexType column ) const; __cuda_callable__ RealType& getValue( const IndexType column ); __cuda_callable__ void setElement( const IndexType column, const RealType& value ); protected: SegmentViewType segmentView; ValuesViewType values; }; } // namespace Matrices } // namespace TNL #include <TNL/Matrices/DenseMatrixRowView.hpp>
src/TNL/Matrices/DenseMatrixRowView.hpp 0 → 100644 +71 −0 Original line number Diff line number Diff line /*************************************************************************** DenseMatrixRowView.hpp - description ------------------- begin : Jan 3, 2020 copyright : (C) 2020 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once #include <TNL/Matrices/DenseMatrixRowView.h> namespace TNL { namespace Matrices { template< typename SegmentView, typename ValuesView > __cuda_callable__ DenseMatrixRowView< SegmentView, ValuesView >:: DenseMatrixRowView( const SegmentViewType& segmentView, const ValuesViewType& values ) : segmentView( segmentView ), values( values ) { } template< typename SegmentView, typename ValuesView > __cuda_callable__ auto DenseMatrixRowView< SegmentView, ValuesView >:: getSize() const -> IndexType { return segmentView.getSize(); } template< typename SegmentView, typename ValuesView > __cuda_callable__ auto DenseMatrixRowView< SegmentView, ValuesView >:: getValue( const IndexType column ) const -> const RealType& { TNL_ASSERT_LT( column, this->getSize(), "Column index exceeds matrix row size." ); return values[ segmentView.getGlobalIndex( column ) ]; } template< typename SegmentView, typename ValuesView > __cuda_callable__ auto DenseMatrixRowView< SegmentView, ValuesView >:: getValue( const IndexType column ) -> RealType& { TNL_ASSERT_LT( column, this->getSize(), "Column index exceeds matrix row size." ); return values[ segmentView.getGlobalIndex( column ) ]; } template< typename SegmentView, typename ValuesView > __cuda_callable__ void DenseMatrixRowView< SegmentView, ValuesView >:: setElement( const IndexType column, const RealType& value ) { TNL_ASSERT_LT( column, this->getSize(), "Column index exceeds matrix row size." ); const IndexType globalIdx = segmentView.getGlobalIndex( column ); values[ globalIdx ] = value; } } // namespace Matrices } // namespace TNL