Commit ba6492b2 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Fixed ConstView for segments and deleted duplicit code in ChunkedEllpack.

parent e93c933e
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -28,13 +28,13 @@ class CSR
   public:

      using DeviceType = Device;
      using IndexType = Index;
      using OffsetsHolder = Containers::Vector< IndexType, DeviceType, typename std::remove_const< IndexType >::type, IndexAllocator >;
      using IndexType = std::remove_const_t< Index >;
      using OffsetsHolder = Containers::Vector< Index, DeviceType, IndexType, IndexAllocator >;
      using SegmentsSizes = OffsetsHolder;
      template< typename Device_, typename Index_ >
      using ViewTemplate = CSRView< Device_, Index_ >;
      using ViewType = CSRView< Device, Index >;
      using ConstViewType = CSRView< Device, std::add_const_t< Index > >;
      using ConstViewType = CSRView< Device, std::add_const_t< IndexType > >;
      using SegmentViewType = SegmentView< IndexType, true >;

      CSR();
@@ -57,7 +57,7 @@ class CSR

      ViewType getView();

      ConstViewType getConstView() const;
      const ConstViewType getConstView() const;

      /**
       * \brief Number segments.
+15 −46
Original line number Diff line number Diff line
@@ -98,9 +98,9 @@ getView()
template< typename Device,
          typename Index,
          typename IndexAllocator >
typename CSR< Device, Index, IndexAllocator >::ConstViewType
auto
CSR< Device, Index, IndexAllocator >::
getConstView() const
getConstView() const -> const ConstViewType
{
   return ConstViewType( this->offsets.getConstView() );
}
@@ -108,10 +108,8 @@ getConstView() const
template< typename Device,
          typename Index,
          typename IndexAllocator >
__cuda_callable__
Index
CSR< Device, Index, IndexAllocator >::
getSegmentsCount() const
__cuda_callable__ auto CSR< Device, Index, IndexAllocator >::
getSegmentsCount() const -> IndexType
{
   return this->offsets.getSize() - 1;
}
@@ -119,10 +117,8 @@ getSegmentsCount() const
template< typename Device,
          typename Index,
          typename IndexAllocator >
__cuda_callable__
Index
CSR< Device, Index, IndexAllocator >::
getSegmentSize( const IndexType segmentIdx ) const
__cuda_callable__ auto CSR< Device, Index, IndexAllocator >::
getSegmentSize( const IndexType segmentIdx ) const -> IndexType
{
   return details::CSR< Device, Index >::getSegmentSize( this->offsets, segmentIdx );
}
@@ -130,10 +126,8 @@ getSegmentSize( const IndexType segmentIdx ) const
template< typename Device,
          typename Index,
          typename IndexAllocator >
__cuda_callable__
Index
CSR< Device, Index, IndexAllocator >::
getSize() const
__cuda_callable__ auto CSR< Device, Index, IndexAllocator >::
getSize() const -> IndexType
{
   return this->getStorageSize();
}
@@ -141,10 +135,8 @@ getSize() const
template< typename Device,
          typename Index,
          typename IndexAllocator >
__cuda_callable__
Index
CSR< Device, Index, IndexAllocator >::
getStorageSize() const
__cuda_callable__ auto CSR< Device, Index, IndexAllocator >::
getStorageSize() const -> IndexType
{
   return details::CSR< Device, Index >::getStorageSize( this->offsets );
}
@@ -152,10 +144,8 @@ getStorageSize() const
template< typename Device,
          typename Index,
          typename IndexAllocator >
__cuda_callable__
Index
CSR< Device, Index, IndexAllocator >::
getGlobalIndex( const Index segmentIdx, const Index localIdx ) const
__cuda_callable__ auto CSR< Device, Index, IndexAllocator >::
getGlobalIndex( const Index segmentIdx, const Index localIdx ) const -> IndexType
{
   if( ! std::is_same< DeviceType, Devices::Host >::value )
   {
@@ -197,16 +187,7 @@ void
CSR< Device, Index, IndexAllocator >::
forSegments( IndexType first, IndexType last, Function& f, Args... args ) const
{
   const auto offsetsView = this->offsets.getConstView();
   auto l = [=] __cuda_callable__ ( const IndexType segmentIdx, Args... args ) mutable {
      const IndexType begin = offsetsView[ segmentIdx ];
      const IndexType end = offsetsView[ segmentIdx + 1 ];
      IndexType localIdx( 0 );
      for( IndexType globalIdx = begin; globalIdx < end; globalIdx++  )
         if( ! f( segmentIdx, localIdx++, globalIdx, args... ) )
            break;
   };
   Algorithms::ParallelFor< Device >::exec( first, last, l, args... );
   this->getConstView().forSegments( first, last, f, args... );
}

template< typename Device,
@@ -228,19 +209,7 @@ void
CSR< Device, Index, IndexAllocator >::
segmentsReduction( IndexType first, IndexType last, Fetch& fetch, Reduction& reduction, ResultKeeper& keeper, const Real& zero, Args... args ) const
{
   using RealType = decltype( fetch( IndexType(), IndexType(), IndexType(), std::declval< bool& >(), args... ) );
   const auto offsetsView = this->offsets.getConstView();
   auto l = [=] __cuda_callable__ ( const IndexType i, Args... args ) mutable {
      const IndexType begin = offsetsView[ i ];
      const IndexType end = offsetsView[ i + 1 ];
      RealType aux( zero );
      bool compute( true );
      IndexType localIdx( 0 );
      for( IndexType j = begin; j < end && compute; j++  )
         reduction( aux, fetch( i, localIdx++, j, compute, args... ) );
      keeper( i, aux );
   };
   Algorithms::ParallelFor< Device >::exec( first, last, l, args... );
   this->getConstView().segmentsReduction( first, last, fetch, reduction, keeper, zero, args... );
}

template< typename Device,
+4 −4
Original line number Diff line number Diff line
@@ -26,9 +26,9 @@ class CSRView
   public:

      using DeviceType = Device;
      using IndexType = Index;
      using OffsetsView = typename Containers::VectorView< IndexType, DeviceType, typename std::remove_const< IndexType >::type >;
      using ConstOffsetsView = typename Containers::Vector< IndexType, DeviceType, typename std::remove_const< IndexType >::type >::ConstViewType;
      using IndexType = std::remove_const_t< Index >;
      using OffsetsView = typename Containers::VectorView< Index, DeviceType, IndexType >;
      using ConstOffsetsView = typename Containers::Vector< Index, DeviceType,IndexType >::ConstViewType;
      using ViewType = CSRView;
      template< typename Device_, typename Index_ >
      using ViewTemplate = CSRView< Device_, Index_ >;
@@ -58,7 +58,7 @@ class CSRView
      ViewType getView();

      __cuda_callable__
      ConstViewType getConstView() const;
      const ConstViewType getConstView() const;

      /**
       * \brief Number segments.
+12 −22
Original line number Diff line number Diff line
@@ -96,59 +96,49 @@ getView()
template< typename Device,
          typename Index >
__cuda_callable__
typename CSRView< Device, Index >::ConstViewType
auto
CSRView< Device, Index >::
getConstView() const
getConstView() const -> const ConstViewType
{
   return ConstViewType( this->offsets.getConstView() );
}

template< typename Device,
          typename Index >
__cuda_callable__
Index
CSRView< Device, Index >::
getSegmentsCount() const
__cuda_callable__ auto CSRView< Device, Index >::
getSegmentsCount() const -> IndexType
{
   return this->offsets.getSize() - 1;
}

template< typename Device,
          typename Index >
__cuda_callable__
Index
CSRView< Device, Index >::
getSegmentSize( const IndexType segmentIdx ) const
__cuda_callable__ auto CSRView< Device, Index >::
getSegmentSize( const IndexType segmentIdx ) const -> IndexType
{
   return details::CSR< Device, Index >::getSegmentSize( this->offsets, segmentIdx );
}

template< typename Device,
          typename Index >
__cuda_callable__
Index
CSRView< Device, Index >::
getSize() const
__cuda_callable__ auto CSRView< Device, Index >::
getSize() const -> IndexType
{
   return this->getStorageSize();
}

template< typename Device,
          typename Index >
__cuda_callable__
Index
CSRView< Device, Index >::
getStorageSize() const
__cuda_callable__ auto CSRView< Device, Index >::
getStorageSize() const -> IndexType
{
   return details::CSR< Device, Index >::getStorageSize( this->offsets );
}

template< typename Device,
          typename Index >
__cuda_callable__
Index
CSRView< Device, Index >::
getGlobalIndex( const Index segmentIdx, const Index localIdx ) const
__cuda_callable__ auto CSRView< Device, Index >::
getGlobalIndex( const Index segmentIdx, const Index localIdx ) const -> IndexType
{
   if( ! std::is_same< DeviceType, Devices::Host >::value )
   {
+4 −4
Original line number Diff line number Diff line
@@ -28,13 +28,13 @@ class ChunkedEllpack
   public:

      using DeviceType = Device;
      using IndexType = Index;
      using OffsetsHolder = Containers::Vector< IndexType, DeviceType, typename std::remove_const< IndexType >::type, IndexAllocator >;
      using IndexType = std::remove_const_t< Index >;
      using OffsetsHolder = Containers::Vector< Index, DeviceType, IndexType, IndexAllocator >;
      static constexpr bool getRowMajorOrder() { return RowMajorOrder; }
      using ViewType = ChunkedEllpackView< Device, Index, RowMajorOrder >;
      template< typename Device_, typename Index_ >
      using ViewTemplate = ChunkedEllpackView< Device_, Index_, RowMajorOrder >;
      using ConstViewType = ChunkedEllpackView< Device, std::add_const_t< Index >, RowMajorOrder >;
      using ConstViewType = ChunkedEllpackView< Device, std::add_const_t< IndexType >, RowMajorOrder >;
      using SegmentViewType = ChunkedEllpackSegmentView< IndexType, RowMajorOrder >;
      using ChunkedEllpackSliceInfoType = details::ChunkedEllpackSliceInfo< IndexType >;
      //TODO: using ChunkedEllpackSliceInfoAllocator = typename IndexAllocatorType::retype< ChunkedEllpackSliceInfoType >;
@@ -55,7 +55,7 @@ class ChunkedEllpack

      ViewType getView();

      ConstViewType getConstView() const;
      const ConstViewType getConstView() const;

      /**
       * \brief Set sizes of particular segments.
Loading