Loading Documentation/Examples/Algorithms/Segments/CMakeLists.txt +4 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,10 @@ set( COMMON_EXAMPLES SegmentsExample_CSR_getSegmentsType SegmentsExample_CSR_setSegmentsSizes SegmentsExample_CSR_getSegmentView SegmentsExample_CSR_forElements SegmentsExample_CSR_forSegments SegmentsExample_CSR_sequentialForSegments SegmentsExample_CSR_reduceSegments ) if( BUILD_CUDA ) Loading Documentation/Examples/Algorithms/Segments/SegmentsExample_CSR_forElements.cpp 0 → 100644 +49 −0 Original line number Diff line number Diff line #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() { using SegmentsType = typename TNL::Algorithms::Segments::CSR< Device, int >; /*** * Create segments with given segments sizes. */ const int size( 5 ); SegmentsType segments{ 1, 2, 3, 4, 5 }; /*** * Allocate array for the segments; */ TNL::Containers::Array< double, Device > data( segments.getStorageSize(), 0.0 ); /*** * Insert data into particular segments. */ auto data_view = data.getView(); segments.forElements( 0, size, [=] __cuda_callable__ ( int segmentIdx, int localIdx, int globalIdx ) mutable { if( localIdx <= segmentIdx ) data_view[ globalIdx ] = segmentIdx; } ); /*** * Print the data managed by the segments. */ auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; }; printSegments( segments, fetch, std::cout ); } int main( int argc, char* argv[] ) { std::cout << "Example of CSR segments on host: " << std::endl; SegmentsExample< TNL::Devices::Host >(); #ifdef HAVE_CUDA std::cout << "Example of CSR segments on CUDA GPU: " << std::endl; SegmentsExample< TNL::Devices::Cuda >(); #endif return EXIT_SUCCESS; } Documentation/Examples/Algorithms/Segments/SegmentsExample_CSR_forElements.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line SegmentsExample_CSR_forElements.cpp No newline at end of file Documentation/Examples/Algorithms/Segments/SegmentsExample_CSR_forSegments.cpp 0 → 100644 +52 −0 Original line number Diff line number Diff line #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() { using SegmentsType = typename TNL::Algorithms::Segments::CSR< Device, int >; using SegmentViewType = typename SegmentsType::SegmentViewType; /*** * Create segments with given segments sizes. */ const int size( 5 ); SegmentsType segments{ 1, 2, 3, 4, 5 }; /*** * Allocate array for the segments; */ TNL::Containers::Array< double, Device > data( segments.getStorageSize(), 0.0 ); /*** * Insert data into particular segments. */ auto data_view = data.getView(); segments.forSegments( 0, size, [=] __cuda_callable__ ( const SegmentViewType& segment ) mutable { for( auto element : segment ) if( element.localIndex() <= element.segmentIndex() ) data_view[ element.globalIndex() ] = element.segmentIndex() + element.localIndex(); } ); /*** * Print the data managed by the segments. */ auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; }; printSegments( segments, fetch, std::cout ); } int main( int argc, char* argv[] ) { std::cout << "Example of CSR segments on host: " << std::endl; SegmentsExample< TNL::Devices::Host >(); #ifdef HAVE_CUDA std::cout << "Example of CSR segments on CUDA GPU: " << std::endl; SegmentsExample< TNL::Devices::Cuda >(); #endif return EXIT_SUCCESS; } Documentation/Examples/Algorithms/Segments/SegmentsExample_CSR_forSegments.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line SegmentsExample_CSR_forSegments.cpp No newline at end of file Loading
Documentation/Examples/Algorithms/Segments/CMakeLists.txt +4 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,10 @@ set( COMMON_EXAMPLES SegmentsExample_CSR_getSegmentsType SegmentsExample_CSR_setSegmentsSizes SegmentsExample_CSR_getSegmentView SegmentsExample_CSR_forElements SegmentsExample_CSR_forSegments SegmentsExample_CSR_sequentialForSegments SegmentsExample_CSR_reduceSegments ) if( BUILD_CUDA ) Loading
Documentation/Examples/Algorithms/Segments/SegmentsExample_CSR_forElements.cpp 0 → 100644 +49 −0 Original line number Diff line number Diff line #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() { using SegmentsType = typename TNL::Algorithms::Segments::CSR< Device, int >; /*** * Create segments with given segments sizes. */ const int size( 5 ); SegmentsType segments{ 1, 2, 3, 4, 5 }; /*** * Allocate array for the segments; */ TNL::Containers::Array< double, Device > data( segments.getStorageSize(), 0.0 ); /*** * Insert data into particular segments. */ auto data_view = data.getView(); segments.forElements( 0, size, [=] __cuda_callable__ ( int segmentIdx, int localIdx, int globalIdx ) mutable { if( localIdx <= segmentIdx ) data_view[ globalIdx ] = segmentIdx; } ); /*** * Print the data managed by the segments. */ auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; }; printSegments( segments, fetch, std::cout ); } int main( int argc, char* argv[] ) { std::cout << "Example of CSR segments on host: " << std::endl; SegmentsExample< TNL::Devices::Host >(); #ifdef HAVE_CUDA std::cout << "Example of CSR segments on CUDA GPU: " << std::endl; SegmentsExample< TNL::Devices::Cuda >(); #endif return EXIT_SUCCESS; }
Documentation/Examples/Algorithms/Segments/SegmentsExample_CSR_forElements.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line SegmentsExample_CSR_forElements.cpp No newline at end of file
Documentation/Examples/Algorithms/Segments/SegmentsExample_CSR_forSegments.cpp 0 → 100644 +52 −0 Original line number Diff line number Diff line #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() { using SegmentsType = typename TNL::Algorithms::Segments::CSR< Device, int >; using SegmentViewType = typename SegmentsType::SegmentViewType; /*** * Create segments with given segments sizes. */ const int size( 5 ); SegmentsType segments{ 1, 2, 3, 4, 5 }; /*** * Allocate array for the segments; */ TNL::Containers::Array< double, Device > data( segments.getStorageSize(), 0.0 ); /*** * Insert data into particular segments. */ auto data_view = data.getView(); segments.forSegments( 0, size, [=] __cuda_callable__ ( const SegmentViewType& segment ) mutable { for( auto element : segment ) if( element.localIndex() <= element.segmentIndex() ) data_view[ element.globalIndex() ] = element.segmentIndex() + element.localIndex(); } ); /*** * Print the data managed by the segments. */ auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; }; printSegments( segments, fetch, std::cout ); } int main( int argc, char* argv[] ) { std::cout << "Example of CSR segments on host: " << std::endl; SegmentsExample< TNL::Devices::Host >(); #ifdef HAVE_CUDA std::cout << "Example of CSR segments on CUDA GPU: " << std::endl; SegmentsExample< TNL::Devices::Cuda >(); #endif return EXIT_SUCCESS; }
Documentation/Examples/Algorithms/Segments/SegmentsExample_CSR_forSegments.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line SegmentsExample_CSR_forSegments.cpp No newline at end of file