Loading src/TNL/Containers/Segments/ChunkedEllpack.h 0 → 100644 +151 −0 Original line number Diff line number Diff line /*************************************************************************** ChunkedEllpack.h - description ------------------- begin : Mar 21, 2020 copyright : (C) 2020 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once #include <TNL/Allocators/Default.h> #include <TNL/Containers/Vector.h> #include <TNL/Containers/Segments/ChunkedEllpackView.h> #include <TNL/Containers/Segments/SegmentView.h> namespace TNL { namespace Containers { namespace Segments { template< typename IndexType > struct ChunkedEllpackSliceInfo { IndexType size; IndexType chunkSize; IndexType firstRow; IndexType pointer; }; template< typename Device, typename Index, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >, bool RowMajorOrder = std::is_same< Device, Devices::Host >::value > class ChunkedEllpack { public: using DeviceType = Device; using IndexType = Index; //using OffsetsHolder = Containers::Vector< IndexType, DeviceType, typename std::remove_const< IndexType >::type, IndexAllocator >; static constexpr int getSliceSize() { return SliceSize; } static constexpr bool getRowMajorOrder() { return RowMajorOrder; } using ViewType = ChunkedEllpackView< Device, Index, RowMajorOrder, SliceSize >; template< typename Device_, typename Index_ > using ViewTemplate = ChunkedEllpackView< Device_, Index_, RowMajorOrder, SliceSize >; using ConstViewType = ChunkedEllpackView< Device, std::add_const_t< Index >, RowMajorOrder, SliceSize >; using SegmentViewType = SegmentView< IndexType, RowMajorOrder >; ChunkedEllpack(); ChunkedEllpack( const Vector< IndexType, DeviceType, IndexType >& sizes ); ChunkedEllpack( const ChunkedEllpack& segments ); ChunkedEllpack( const ChunkedEllpack&& segments ); static String getSerializationType(); static String getSegmentsType(); ViewType getView(); ConstViewType getConstView() const; /** * \brief Set sizes of particular segments. */ template< typename SizesHolder = OffsetsHolder > void setSegmentsSizes( const SizesHolder& sizes ); __cuda_callable__ IndexType getSegmentsCount() const; __cuda_callable__ IndexType getSegmentSize( const IndexType segmentIdx ) const; /** * \brief Number segments. */ __cuda_callable__ IndexType getSize() const; __cuda_callable__ IndexType getStorageSize() const; __cuda_callable__ IndexType getGlobalIndex( const Index segmentIdx, const Index localIdx ) const; __cuda_callable__ void getSegmentAndLocalIndex( const Index globalIdx, Index& segmentIdx, Index& localIdx ) const; __cuda_callable__ SegmentViewType getSegmentView( const IndexType segmentIdx ) const; /*** * \brief Go over all segments and for each segment element call * function 'f' with arguments 'args'. The return type of 'f' is bool. * When its true, the for-loop continues. Once 'f' returns false, the for-loop * is terminated. */ template< typename Function, typename... Args > void forSegments( IndexType first, IndexType last, Function& f, Args... args ) const; template< typename Function, typename... Args > void forAll( Function& f, Args... args ) const; /*** * \brief Go over all segments and perform a reduction in each of them. */ template< typename Fetch, typename Reduction, typename ResultKeeper, typename Real, typename... Args > void segmentsReduction( IndexType first, IndexType last, Fetch& fetch, Reduction& reduction, ResultKeeper& keeper, const Real& zero, Args... args ) const; template< typename Fetch, typename Reduction, typename ResultKeeper, typename Real, typename... Args > void allReduction( Fetch& fetch, Reduction& reduction, ResultKeeper& keeper, const Real& zero, Args... args ) const; ChunkedEllpack& operator=( const ChunkedEllpack& source ) = default; template< typename Device_, typename Index_, typename IndexAllocator_, bool RowMajorOrder_ > ChunkedEllpack& operator=( const ChunkedEllpack< Device_, Index_, IndexAllocator_, RowMajorOrder_, SliceSize >& source ); void save( File& file ) const; void load( File& file ); protected: template< typename SegmentsSizes > void resolveSliceSizes( SegmentsSizes& rowLengths ); template< typename SegmentsSizes > bool setSlice( SegmentsSizes& rowLengths, const IndexType sliceIdx, IndexType& elementsToAllocation ); IndexType chunksInSlice, desiredChunkSize; Containers::Vector< Index, Device, Index > rowToChunkMapping, rowToSliceMapping, rowPointers; Containers::Array< ChunkedEllpackSliceInfo, Device, Index > slices; IndexType numberOfSlices; }; } // namespace Segements } // namespace Conatiners } // namespace TNL #include <TNL/Containers/Segments/ChunkedEllpack.hpp> src/TNL/Containers/Segments/ChunkedEllpack.hpp 0 → 100644 +566 −0 File added.Preview size limit exceeded, changes collapsed. Show changes src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.cpp 0 → 100644 +11 −0 Original line number Diff line number Diff line /*************************************************************************** SparseMatrixTest_ChunkedEllpack.cpp - description ------------------- begin : Mar 21, 2020 copyright : (C) 2020 by Tomas Oberhuber et al. email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #include "SparseMatrixTest_ChunkedEllpack.h" src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.cu 0 → 100644 +11 −0 Original line number Diff line number Diff line /*************************************************************************** SparseMatrixTest_ChunkedEllpack.cu - description ------------------- begin : Mar 21, 2020 copyright : (C) 2020 by Tomas Oberhuber et al. email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #include "SparseMatrixTest_ChunkedEllpack.h" src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.h 0 → 100644 +46 −0 Original line number Diff line number Diff line /*************************************************************************** SparseMatrixTest_ChunkedEllpack.h - description ------------------- begin : Mar 21, 2020 copyright : (C) 2020 by Tomas Oberhuber et al. email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #include <iostream> #include <TNL/Containers/Segments/ChunkedEllpack.h> #include <TNL/Matrices/SparseMatrix.h> #ifdef HAVE_GTEST #include <gtest/gtest.h> const char* saveAndLoadFileName = "test_SparseMatrixTest_ChunkedEllpack_segments"; // types for which MatrixTest is instantiated using MatrixTypes = ::testing::Types < TNL::Matrices::SparseMatrix< int, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< long, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< float, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< double, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< int, TNL::Devices::Host, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< long, TNL::Devices::Host, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< float, TNL::Devices::Host, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< double, TNL::Devices::Host, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack > #ifdef HAVE_CUDA ,TNL::Matrices::SparseMatrix< int, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< long, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< float, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< double, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< int, TNL::Devices::Cuda, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< long, TNL::Devices::Cuda, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< float, TNL::Devices::Cuda, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< double, TNL::Devices::Cuda, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack > #endif >; #endif #include "SparseMatrixTest.h" #include "../main.h" Loading
src/TNL/Containers/Segments/ChunkedEllpack.h 0 → 100644 +151 −0 Original line number Diff line number Diff line /*************************************************************************** ChunkedEllpack.h - description ------------------- begin : Mar 21, 2020 copyright : (C) 2020 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once #include <TNL/Allocators/Default.h> #include <TNL/Containers/Vector.h> #include <TNL/Containers/Segments/ChunkedEllpackView.h> #include <TNL/Containers/Segments/SegmentView.h> namespace TNL { namespace Containers { namespace Segments { template< typename IndexType > struct ChunkedEllpackSliceInfo { IndexType size; IndexType chunkSize; IndexType firstRow; IndexType pointer; }; template< typename Device, typename Index, typename IndexAllocator = typename Allocators::Default< Device >::template Allocator< Index >, bool RowMajorOrder = std::is_same< Device, Devices::Host >::value > class ChunkedEllpack { public: using DeviceType = Device; using IndexType = Index; //using OffsetsHolder = Containers::Vector< IndexType, DeviceType, typename std::remove_const< IndexType >::type, IndexAllocator >; static constexpr int getSliceSize() { return SliceSize; } static constexpr bool getRowMajorOrder() { return RowMajorOrder; } using ViewType = ChunkedEllpackView< Device, Index, RowMajorOrder, SliceSize >; template< typename Device_, typename Index_ > using ViewTemplate = ChunkedEllpackView< Device_, Index_, RowMajorOrder, SliceSize >; using ConstViewType = ChunkedEllpackView< Device, std::add_const_t< Index >, RowMajorOrder, SliceSize >; using SegmentViewType = SegmentView< IndexType, RowMajorOrder >; ChunkedEllpack(); ChunkedEllpack( const Vector< IndexType, DeviceType, IndexType >& sizes ); ChunkedEllpack( const ChunkedEllpack& segments ); ChunkedEllpack( const ChunkedEllpack&& segments ); static String getSerializationType(); static String getSegmentsType(); ViewType getView(); ConstViewType getConstView() const; /** * \brief Set sizes of particular segments. */ template< typename SizesHolder = OffsetsHolder > void setSegmentsSizes( const SizesHolder& sizes ); __cuda_callable__ IndexType getSegmentsCount() const; __cuda_callable__ IndexType getSegmentSize( const IndexType segmentIdx ) const; /** * \brief Number segments. */ __cuda_callable__ IndexType getSize() const; __cuda_callable__ IndexType getStorageSize() const; __cuda_callable__ IndexType getGlobalIndex( const Index segmentIdx, const Index localIdx ) const; __cuda_callable__ void getSegmentAndLocalIndex( const Index globalIdx, Index& segmentIdx, Index& localIdx ) const; __cuda_callable__ SegmentViewType getSegmentView( const IndexType segmentIdx ) const; /*** * \brief Go over all segments and for each segment element call * function 'f' with arguments 'args'. The return type of 'f' is bool. * When its true, the for-loop continues. Once 'f' returns false, the for-loop * is terminated. */ template< typename Function, typename... Args > void forSegments( IndexType first, IndexType last, Function& f, Args... args ) const; template< typename Function, typename... Args > void forAll( Function& f, Args... args ) const; /*** * \brief Go over all segments and perform a reduction in each of them. */ template< typename Fetch, typename Reduction, typename ResultKeeper, typename Real, typename... Args > void segmentsReduction( IndexType first, IndexType last, Fetch& fetch, Reduction& reduction, ResultKeeper& keeper, const Real& zero, Args... args ) const; template< typename Fetch, typename Reduction, typename ResultKeeper, typename Real, typename... Args > void allReduction( Fetch& fetch, Reduction& reduction, ResultKeeper& keeper, const Real& zero, Args... args ) const; ChunkedEllpack& operator=( const ChunkedEllpack& source ) = default; template< typename Device_, typename Index_, typename IndexAllocator_, bool RowMajorOrder_ > ChunkedEllpack& operator=( const ChunkedEllpack< Device_, Index_, IndexAllocator_, RowMajorOrder_, SliceSize >& source ); void save( File& file ) const; void load( File& file ); protected: template< typename SegmentsSizes > void resolveSliceSizes( SegmentsSizes& rowLengths ); template< typename SegmentsSizes > bool setSlice( SegmentsSizes& rowLengths, const IndexType sliceIdx, IndexType& elementsToAllocation ); IndexType chunksInSlice, desiredChunkSize; Containers::Vector< Index, Device, Index > rowToChunkMapping, rowToSliceMapping, rowPointers; Containers::Array< ChunkedEllpackSliceInfo, Device, Index > slices; IndexType numberOfSlices; }; } // namespace Segements } // namespace Conatiners } // namespace TNL #include <TNL/Containers/Segments/ChunkedEllpack.hpp>
src/TNL/Containers/Segments/ChunkedEllpack.hpp 0 → 100644 +566 −0 File added.Preview size limit exceeded, changes collapsed. Show changes
src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.cpp 0 → 100644 +11 −0 Original line number Diff line number Diff line /*************************************************************************** SparseMatrixTest_ChunkedEllpack.cpp - description ------------------- begin : Mar 21, 2020 copyright : (C) 2020 by Tomas Oberhuber et al. email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #include "SparseMatrixTest_ChunkedEllpack.h"
src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.cu 0 → 100644 +11 −0 Original line number Diff line number Diff line /*************************************************************************** SparseMatrixTest_ChunkedEllpack.cu - description ------------------- begin : Mar 21, 2020 copyright : (C) 2020 by Tomas Oberhuber et al. email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #include "SparseMatrixTest_ChunkedEllpack.h"
src/UnitTests/Matrices/SparseMatrixTest_ChunkedEllpack.h 0 → 100644 +46 −0 Original line number Diff line number Diff line /*************************************************************************** SparseMatrixTest_ChunkedEllpack.h - description ------------------- begin : Mar 21, 2020 copyright : (C) 2020 by Tomas Oberhuber et al. email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #include <iostream> #include <TNL/Containers/Segments/ChunkedEllpack.h> #include <TNL/Matrices/SparseMatrix.h> #ifdef HAVE_GTEST #include <gtest/gtest.h> const char* saveAndLoadFileName = "test_SparseMatrixTest_ChunkedEllpack_segments"; // types for which MatrixTest is instantiated using MatrixTypes = ::testing::Types < TNL::Matrices::SparseMatrix< int, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< long, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< float, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< double, TNL::Devices::Host, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< int, TNL::Devices::Host, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< long, TNL::Devices::Host, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< float, TNL::Devices::Host, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< double, TNL::Devices::Host, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack > #ifdef HAVE_CUDA ,TNL::Matrices::SparseMatrix< int, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< long, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< float, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< double, TNL::Devices::Cuda, int, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< int, TNL::Devices::Cuda, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< long, TNL::Devices::Cuda, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< float, TNL::Devices::Cuda, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack >, TNL::Matrices::SparseMatrix< double, TNL::Devices::Cuda, long, TNL::Matrices::GeneralMatrix, TNL::Containers::Segments::ChunkedEllpack > #endif >; #endif #include "SparseMatrixTest.h" #include "../main.h"