Template Numerical Library version\ main:4904c12
Loading...
Searching...
No Matches
TNL::Algorithms::Segments::ChunkedEllpackBase< Device, Index, Organization > Class Template Reference

ChunkedEllpackBase serves as a base class for TNL::Algorithms::Segments::ChunkedEllpack and TNL::Algorithms::Segments::ChunkedEllpackView. More...

#include <TNL/Algorithms/Segments/ChunkedEllpackBase.h>

Inheritance diagram for TNL::Algorithms::Segments::ChunkedEllpackBase< Device, Index, Organization >:
[legend]
Collaboration diagram for TNL::Algorithms::Segments::ChunkedEllpackBase< Device, Index, Organization >:
[legend]

Public Types

using ConstOffsetsView = typename OffsetsView::ConstViewType
 The type for representing the constant vector view with segment offsets.
using ConstSliceInfoContainerView = typename SliceInfoContainerView::ConstViewType
using DeviceType = Device
 The device where the segments are operating.
using IndexType = std::remove_const_t< Index >
 The type used for indexing of segments elements.
using OffsetsView = Containers::VectorView< Index, DeviceType, IndexType >
 The type for representing the vector view with segment offsets.
using SegmentViewType = ChunkedEllpackSegmentView< IndexType, Organization >
 Accessor type for one particular segment.
using SliceInfoContainerView
using SliceInfoType = detail::ChunkedEllpackSliceInfo< IndexType >
template<typename Device_, typename Index_>
using ViewTemplate = ChunkedEllpackBase< Device_, Index_, Organization >
 Templated view type.

Public Member Functions

__cuda_callable__ ChunkedEllpackBase ()=default
 Default constructor with no parameters to create empty segments view.
__cuda_callable__ ChunkedEllpackBase (ChunkedEllpackBase &&) noexcept=default
 Move constructor.
__cuda_callable__ ChunkedEllpackBase (const ChunkedEllpackBase &)=default
 Copy constructor.
__cuda_callable__ ChunkedEllpackBase (IndexType size, IndexType storageSize, IndexType numberOfSlices, IndexType chunksInSlice, IndexType desiredChunkSize, OffsetsView segmentToChunkMapping, OffsetsView segmentToSliceMapping, OffsetsView chunksToSegmentsMapping, OffsetsView segmentPointers, SliceInfoContainerView slices)
 Constructor with all necessary data and views.
template<typename Function>
void forAllElements (Function &&function) const
template<typename Condition, typename Function>
void forAllElementsIf (Condition condition, Function function) const
template<typename Function>
void forAllSegments (Function &&function) const
template<typename Array, typename Function>
void forElements (const Array &segmentIndexes, Function function) const
template<typename Array, typename Function>
void forElements (const Array &segmentIndexes, Index begin, Index end, Function function) const
template<typename Function>
void forElements (IndexType begin, IndexType end, Function &&function) const
template<typename Condition, typename Function>
void forElementsIf (IndexType begin, IndexType end, Condition condition, Function function) const
template<typename Function>
void forSegments (IndexType begin, IndexType end, Function &&function) const
__cuda_callable__ IndexType getChunksInSlice () const
 Returns the number of chunks in a slice.
__cuda_callable__ OffsetsView getChunksToSegmentsMappingView ()
 Returns a modifiable vector view with mapping of chunks to segments.
__cuda_callable__ ConstOffsetsView getChunksToSegmentsMappingView () const
 Returns a constant vector view with mapping of chunks to segments.
__cuda_callable__ IndexType getDesiredChunkSize () const
 Returns the desired chunk size.
__cuda_callable__ IndexType getElementCount () const
 Returns the number of elements managed by all segments.
__cuda_callable__ IndexType getGlobalIndex (IndexType segmentIdx, IndexType localIdx) const
 Computes the global index of an element managed by the segments.
__cuda_callable__ IndexType getNumberOfSlices () const
 Returns the number of slices.
__cuda_callable__ IndexType getSegmentCount () const
 Returns the number of segments.
__cuda_callable__ OffsetsView getSegmentPointersView ()
 Returns a modifiable vector view with segment pointers.
__cuda_callable__ ConstOffsetsView getSegmentPointersView () const
 Returns a constant vector view with segment pointers.
__cuda_callable__ IndexType getSegmentsCount () const
 Returns the number of segments. Deprecated, use getSegmentCount().
__cuda_callable__ IndexType getSegmentSize (IndexType segmentIdx) const
 Returns the size of a particular segment denoted by segmentIdx.
__cuda_callable__ OffsetsView getSegmentToChunkMappingView ()
 Returns a modifiable vector view with mapping of segments to chunks.
__cuda_callable__ ConstOffsetsView getSegmentToChunkMappingView () const
 Returns a constant vector view with mapping of segments to chunks.
__cuda_callable__ OffsetsView getSegmentToSliceMappingView ()
 Returns a modifiable vector view with mapping of segments to slices.
__cuda_callable__ ConstOffsetsView getSegmentToSliceMappingView () const
 Returns a constant vector view with mapping of segments to slices.
__cuda_callable__ SegmentViewType getSegmentView (IndexType segmentIdx) const
 Returns a segment view (i.e., a segment accessor) for the specified segment index.
__cuda_callable__ IndexType getSize () const
 Returns the number of elements managed by all segments.
__cuda_callable__ SliceInfoContainerView getSlicesView ()
 Returns a modifiable view with slice information.
__cuda_callable__ ConstSliceInfoContainerView getSlicesView () const
 Returns a constant view with slice information.
__cuda_callable__ IndexType getStorageSize () const
 Returns number of elements that needs to be allocated by a container connected to this segments.
ChunkedEllpackBaseoperator= (ChunkedEllpackBase &&)=delete
 Move-assignment operator.
ChunkedEllpackBaseoperator= (const ChunkedEllpackBase &)=delete
 Copy-assignment operator.
void printStructure (std::ostream &str) const
 Prints the structure of the segments to the output stream.

Static Public Member Functions

static constexpr ElementsOrganization getOrganization ()
 Returns the data layout for the chunked ellpack format (it is always row-major order).
static std::string getSegmentsType ()
 Returns string with the segments type.
static std::string getSerializationType ()
 Returns string with the serialization type.
static constexpr bool havePadding ()
 This function denotes that the chunked ellpack format uses padding elements.

Protected Member Functions

__cuda_callable__ void bind (IndexType size, IndexType storageSize, IndexType numberOfSlices, IndexType chunksInSlice, IndexType desiredChunkSize, OffsetsView segmentToChunkMapping, OffsetsView segmentToSliceMapping, OffsetsView chunksToSegmentsMapping, OffsetsView segmentPointers, SliceInfoContainerView slices)
 Re-initializes the internal attributes of the base class.

Protected Attributes

IndexType chunksInSlice = 256
OffsetsView chunksToSegmentsMapping
IndexType desiredChunkSize = 16
IndexType numberOfSlices = 0
OffsetsView segmentPointers
 Keeps index of the first segment index.
OffsetsView segmentToChunkMapping
 For each segment, this keeps index of the first chunk within a slice.
OffsetsView segmentToSliceMapping
 For each segment, this keeps index of the slice which contains the segment.
IndexType size = 0
SliceInfoContainerView slices
IndexType storageSize = 0

Detailed Description

template<typename Device, typename Index, ElementsOrganization Organization>
class TNL::Algorithms::Segments::ChunkedEllpackBase< Device, Index, Organization >

ChunkedEllpackBase serves as a base class for TNL::Algorithms::Segments::ChunkedEllpack and TNL::Algorithms::Segments::ChunkedEllpackView.

Template Parameters
Deviceis type of device where the segments will be operating.
Indexis type for indexing of the elements managed by the segments.
Organizationis the organization of the elements in the segments—either row-major or column-major order.

Member Typedef Documentation

◆ SliceInfoContainerView

template<typename Device, typename Index, ElementsOrganization Organization>
using TNL::Algorithms::Segments::ChunkedEllpackBase< Device, Index, Organization >::SliceInfoContainerView
Initial value:
std::remove_const_t< Index > IndexType
The type used for indexing of segments elements.
Definition ChunkedEllpackBase.h:32
Device DeviceType
The device where the segments are operating.
Definition ChunkedEllpackBase.h:29
ArrayView is a simple data structure which provides a non-owning encapsulation of array data....
Definition ArrayView.h:55

◆ ViewTemplate

template<typename Device, typename Index, ElementsOrganization Organization>
template<typename Device_, typename Index_>
using TNL::Algorithms::Segments::ChunkedEllpackBase< Device, Index, Organization >::ViewTemplate = ChunkedEllpackBase< Device_, Index_, Organization >

Templated view type.

Template Parameters
Device_is alternative device type for the view.
Index_is alternative index type for the view.

Member Function Documentation

◆ bind()

template<typename Device, typename Index, ElementsOrganization Organization>
__cuda_callable__ void TNL::Algorithms::Segments::ChunkedEllpackBase< Device, Index, Organization >::bind ( IndexType size,
IndexType storageSize,
IndexType numberOfSlices,
IndexType chunksInSlice,
IndexType desiredChunkSize,
OffsetsView segmentToChunkMapping,
OffsetsView segmentToSliceMapping,
OffsetsView chunksToSegmentsMapping,
OffsetsView segmentPointers,
SliceInfoContainerView slices )
protected

Re-initializes the internal attributes of the base class.

Note that this function is protected to ensure that the user cannot modify the base class of segments. For the same reason, in future code development we also need to make sure that all non-const functions in the base class return by value and not by reference.

◆ getGlobalIndex()

template<typename Device, typename Index, ElementsOrganization Organization>
__cuda_callable__ IndexType TNL::Algorithms::Segments::ChunkedEllpackBase< Device, Index, Organization >::getGlobalIndex ( IndexType segmentIdx,
IndexType localIdx ) const
nodiscard

Computes the global index of an element managed by the segments.

The global index serves as a reference to the element within its container.

Parameters
segmentIdxThe index of the segment containing the element.
localIdxThe local index of the element within the segment.
Returns
The global index of the element.

◆ getSegmentsType()

template<typename Device, typename Index, ElementsOrganization Organization>
std::string TNL::Algorithms::Segments::ChunkedEllpackBase< Device, Index, Organization >::getSegmentsType ( )
staticnodiscard

Returns string with the segments type.

Example
#include <iostream>
#include <functional>
#include <TNL/Algorithms/Segments/CSR.h>
#include <TNL/Algorithms/Segments/Ellpack.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Segments >
void
SegmentsExample()
{
/***
* Create segments and print the segments type.
*/
Segments segments;
std::cout << "The segments type is: " << segments.getSegmentsType() << '\n';
}
int
main( int argc, char* argv[] )
{
std::cout << "Example of CSR segments on host:\n";
SegmentsExample< TNL::Algorithms::Segments::CSR< TNL::Devices::Host, int > >();
std::cout << "Example of Ellpack segments on host:\n";
SegmentsExample< TNL::Algorithms::Segments::Ellpack< TNL::Devices::Host, int > >();
#ifdef __CUDACC__
std::cout << "Example of CSR segments on CUDA GPU:\n";
SegmentsExample< TNL::Algorithms::Segments::CSR< TNL::Devices::Cuda, int > >();
std::cout << "Example of Ellpack segments on CUDA GPU:\n";
SegmentsExample< TNL::Algorithms::Segments::Ellpack< TNL::Devices::Cuda, int > >();
#endif
return EXIT_SUCCESS;
}
Namespace for the segments data structures.
Definition _NamespaceDoxy.h:7
Output
Example of CSR segments on host:
The segments type is: CSR
Example of Ellpack segments on host:
The segments type is: Ellpack
Example of CSR segments on CUDA GPU:
The segments type is: CSR
Example of Ellpack segments on CUDA GPU:
The segments type is: Ellpack

◆ getSegmentView()

template<typename Device, typename Index, ElementsOrganization Organization>
__cuda_callable__ SegmentViewType TNL::Algorithms::Segments::ChunkedEllpackBase< Device, Index, Organization >::getSegmentView ( IndexType segmentIdx) const
nodiscard

Returns a segment view (i.e., a segment accessor) for the specified segment index.

Parameters
segmentIdxThe index of the requested segment.
Returns
The segment view of the specified segment.
Example
#include <iostream>
#include <TNL/Containers/Vector.h>
#include <TNL/Algorithms/Segments/CSR.h>
#include <TNL/Algorithms/Segments/Ellpack.h>
#include <TNL/Algorithms/SequentialFor.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Segments >
void
SegmentsExample()
{
using Device = typename Segments::DeviceType;
/***
* Create segments with given segments sizes.
*/
const int size( 5 );
Segments segments{ 1, 2, 3, 4, 5 };
auto view = segments.getView();
/***
* Print the elements mapping using segment view.
*/
std::cout << "Mapping of local indexes to global indexes:\n";
auto f = [ = ] __cuda_callable__( int segmentIdx )
{
printf( "Segment idx. %d: ", segmentIdx ); // printf works even in GPU kernels
auto segment = view.getSegmentView( segmentIdx );
for( auto element : segment )
printf( "%d -> %d \t", element.localIndex(), element.globalIndex() );
printf( "\n" );
};
}
int
main( int argc, char* argv[] )
{
std::cout << "Example of CSR segments on host:\n";
SegmentsExample< TNL::Algorithms::Segments::CSR< TNL::Devices::Host, int > >();
std::cout << "Example of Ellpack segments on host:\n";
SegmentsExample< TNL::Algorithms::Segments::Ellpack< TNL::Devices::Host, int > >();
#ifdef __CUDACC__
std::cout << "Example of CSR segments on CUDA GPU:\n";
SegmentsExample< TNL::Algorithms::Segments::CSR< TNL::Devices::Cuda, int > >();
std::cout << "Example of Ellpack segments on CUDA GPU:\n";
SegmentsExample< TNL::Algorithms::Segments::Ellpack< TNL::Devices::Cuda, int > >();
#endif
return EXIT_SUCCESS;
}
#define __cuda_callable__
Definition Macros.h:49
static void exec(Index start, Index end, Function f)
Static method for execution of the loop.
Definition SequentialFor.h:36
Output
Example of CSR segments on host:
Mapping of local indexes to global indexes:
Segment idx. 0: 0 -> 0
Segment idx. 1: 0 -> 1 1 -> 2
Segment idx. 2: 0 -> 3 1 -> 4 2 -> 5
Segment idx. 3: 0 -> 6 1 -> 7 2 -> 8 3 -> 9
Segment idx. 4: 0 -> 10 1 -> 11 2 -> 12 3 -> 13 4 -> 14
Example of Ellpack segments on host:
Mapping of local indexes to global indexes:
Segment idx. 0: 0 -> 0 1 -> 1 2 -> 2 3 -> 3 4 -> 4
Segment idx. 1: 0 -> 5 1 -> 6 2 -> 7 3 -> 8 4 -> 9
Segment idx. 2: 0 -> 10 1 -> 11 2 -> 12 3 -> 13 4 -> 14
Segment idx. 3: 0 -> 15 1 -> 16 2 -> 17 3 -> 18 4 -> 19
Segment idx. 4: 0 -> 20 1 -> 21 2 -> 22 3 -> 23 4 -> 24
Example of CSR segments on CUDA GPU:
Mapping of local indexes to global indexes:
Segment idx. 0: 0 -> 0
Segment idx. 1: 0 -> 1 1 -> 2
Segment idx. 2: 0 -> 3 1 -> 4 2 -> 5
Segment idx. 3: 0 -> 6 1 -> 7 2 -> 8 3 -> 9
Segment idx. 4: 0 -> 10 1 -> 11 2 -> 12 3 -> 13 4 -> 14
Example of Ellpack segments on CUDA GPU:
Mapping of local indexes to global indexes:
Segment idx. 0: 0 -> 0 1 -> 32 2 -> 64 3 -> 96 4 -> 128
Segment idx. 1: 0 -> 1 1 -> 33 2 -> 65 3 -> 97 4 -> 129
Segment idx. 2: 0 -> 2 1 -> 34 2 -> 66 3 -> 98 4 -> 130
Segment idx. 3: 0 -> 3 1 -> 35 2 -> 67 3 -> 99 4 -> 131
Segment idx. 4: 0 -> 4 1 -> 36 2 -> 68 3 -> 100 4 -> 132

◆ getSerializationType()

template<typename Device, typename Index, ElementsOrganization Organization>
std::string TNL::Algorithms::Segments::ChunkedEllpackBase< Device, Index, Organization >::getSerializationType ( )
staticnodiscard

Returns string with the serialization type.

Example
#include <iostream>
#include <functional>
#include <TNL/Algorithms/Segments/CSR.h>
#include <TNL/Algorithms/Segments/Ellpack.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Segments >
void
SegmentsExample()
{
/***
* Create segments and print the serialization type.
*/
Segments segments;
std::cout << "The serialization type is: " << segments.getSerializationType() << '\n';
}
int
main( int argc, char* argv[] )
{
std::cout << "Example of CSR segments on host:\n";
SegmentsExample< TNL::Algorithms::Segments::CSR< TNL::Devices::Host, int > >();
std::cout << "Example of Ellpack segments on host:\n";
SegmentsExample< TNL::Algorithms::Segments::Ellpack< TNL::Devices::Host, int > >();
#ifdef __CUDACC__
std::cout << "Example of CSR segments on CUDA GPU:\n";
SegmentsExample< TNL::Algorithms::Segments::CSR< TNL::Devices::Cuda, int > >();
std::cout << "Example of Ellpack segments on CUDA GPU:\n";
SegmentsExample< TNL::Algorithms::Segments::Ellpack< TNL::Devices::Cuda, int > >();
#endif
return EXIT_SUCCESS;
}
Output
Example of CSR segments on host:
The serialization type is: CSR< int >
Example of Ellpack segments on host:
The serialization type is: Ellpack< int, RowMajorOrder, 32 >
Example of CSR segments on CUDA GPU:
The serialization type is: CSR< int >
Example of Ellpack segments on CUDA GPU:
The serialization type is: Ellpack< int, ColumnMajorOrder, 32 >

The documentation for this class was generated from the following file: