|
using | ConstOffsetsView = typename OffsetsView::ConstViewType |
| The type for representing the constant vector view with row offsets used in the CSR format.
|
|
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 row offsets used in the CSR format.
|
|
using | SegmentViewType = SegmentView< IndexType, RowMajorOrder > |
| Accessor type fro one particular segment.
|
|
template<typename Device, typename Index>
class TNL::Algorithms::Segments::CSRBase< Device, Index >
CSRBase serves as a base class for CSR and CSRView.
- Template Parameters
-
Device | is type of device where the segments will be operating. |
Index | is type for indexing of the elements managed by the segments. |
template<typename Device , typename Index >
template<typename Function >
Iterate over all elements of given segments in parallel and call given lambda function.
- Template Parameters
-
Function | is a type of the lambda function to be performed on each element. |
- Parameters
-
begin | defines begining of an interval [ begin, end ) of segments on elements of which we want to apply the lambda function. |
end | defines end of an interval [ begin, end ) of segments on elements of which we want to apply the lambda function. |
function | is the lambda function to be applied on the elements of the segments. |
Declaration of the lambda function function is supposed to be
#define __cuda_callable__
Definition Macros.h:49
std::remove_const_t< Index > IndexType
The type used for indexing of segments elements.
Definition CSRBase.h:29
where segmentIdx is index of segment where given element belong to, localIdx is rank of the element within the segment and globalIdx is index of the element within the related container.
- Example
#include <iostream>
#include <TNL/Containers/Vector.h>
#include <TNL/Algorithms/Segments/CSR.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device >
void
SegmentsExample()
{
const int size( 5 );
SegmentsType segments{ 1, 2, 3, 4, 5 };
auto data_view = data.getView();
segments.forElements( 0,
size,
{
if( localIdx <= segmentIdx )
data_view[ globalIdx ] = segmentIdx;
} );
{
return data_view[ globalIdx ];
};
}
int
main( int argc, char* argv[] )
{
SegmentsExample< TNL::Devices::Host >();
#ifdef __CUDACC__
SegmentsExample< TNL::Devices::Cuda >();
#endif
return EXIT_SUCCESS;
}
Data structure for CSR segments format.
Definition CSR.h:27
Array is responsible for memory management, access to array elements, and general array operations.
Definition Array.h:64
- Output
Example of CSR segments on host:
Seg. 0: [ 0 ]
Seg. 1: [ 1, 1 ]
Seg. 2: [ 2, 2, 2 ]
Seg. 3: [ 3, 3, 3, 3 ]
Seg. 4: [ 4, 4, 4, 4, 4 ]
Example of CSR segments on CUDA GPU:
Seg. 0: [ 0 ]
Seg. 1: [ 1, 1 ]
Seg. 2: [ 2, 2, 2 ]
Seg. 3: [ 3, 3, 3, 3 ]
Seg. 4: [ 4, 4, 4, 4, 4 ]
template<typename Device , typename Index >
template<typename Function >
Iterate over all segments in parallel and call given lambda function.
- Template Parameters
-
Function | is a type of the lambda function to be performed on each segment. |
- Parameters
-
begin | defines begining of an interval [ begin, end ) of segments on elements of which we want to apply the lambda function. |
end | defines end of an interval [ begin, end ) of segments on elements of which we want to apply the lambda function. |
function | is the lambda function to be applied on the elements of the segments. |
Declaration of the lambda function function is supposed to be
Data structure for accessing particular segment.
Definition SegmentView.h:21
where segment represents given segment (see TNL::Algorithms::Segments::SegmentView). Its type is given by SegmentViewType.
- Example
#include <iostream>
#include <functional>
#include <TNL/Containers/Vector.h>
#include <TNL/Algorithms/Segments/CSR.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device >
void
SegmentsExample()
{
const int size( 5 );
SegmentsType segments{ 1, 2, 3, 4, 5 };
auto data_view = data.getView();
segments.forSegments( 0,
size,
{
for( auto element : segment )
if( element.localIndex() <= element.segmentIndex() )
data_view[ element.globalIndex() ] = element.segmentIndex() + element.localIndex();
} );
{
return data_view[ globalIdx ];
};
}
int
main( int argc, char* argv[] )
{
SegmentsExample< TNL::Devices::Host >();
#ifdef __CUDACC__
SegmentsExample< TNL::Devices::Cuda >();
#endif
return EXIT_SUCCESS;
}
- Output
Example of CSR segments on host:
Seg. 0: [ 0 ]
Seg. 1: [ 1, 2 ]
Seg. 2: [ 2, 3, 4 ]
Seg. 3: [ 3, 4, 5, 6 ]
Seg. 4: [ 4, 5, 6, 7, 8 ]
Example of CSR segments on CUDA GPU:
Seg. 0: [ 0 ]
Seg. 1: [ 1, 2 ]
Seg. 2: [ 2, 3, 4 ]
Seg. 3: [ 3, 4, 5, 6 ]
Seg. 4: [ 4, 5, 6, 7, 8 ]
template<typename Device , typename Index >
template<typename Function >
Call TNL::Algorithms::Segments::CSR::forSegments sequentially for particular segments.
With this method, the given segments are processed sequentially one-by-one. This is usefull for example for printing of segments based data structures or for debugging reasons.
- Parameters
-
begin | defines begining of an interval [ begin, end ) of segments on elements of which we want to apply the lambda function. |
end | defines end of an interval [ begin, end ) of segments on elements of which we want to apply the lambda function. |
function | is the lambda function to be applied on the elements of the segments. |
See TNL::Algorithms::Segments::CSR::forSegments for more details.
- Example
#include <iostream>
#include <functional>
#include <TNL/Containers/Vector.h>
#include <TNL/Algorithms/Segments/CSR.h>
#include <TNL/Algorithms/SequentialFor.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Device >
void
SegmentsExample()
{
using SegmentView =
typename SegmentsType::SegmentViewType;
const int size( 5 );
SegmentsType segments{ 1, 2, 3, 4, 5 };
{
printf( "Segment idx. %d: ", segment.getSegmentIndex() );
for( auto element : segment )
printf( "%d -> %d \t", element.localIndex(), element.globalIndex() );
printf( "\n" );
};
segments.sequentialForSegments( 0, size, f );
}
int
main( int argc, char* argv[] )
{
SegmentsExample< TNL::Devices::Host >();
#ifdef __CUDACC__
SegmentsExample< TNL::Devices::Cuda >();
#endif
return EXIT_SUCCESS;
}
- 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 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