Loading Documentation/Examples/Algorithms/Segments/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ set( COMMON_EXAMPLES SegmentsExample_CSR_getSerializationType SegmentsExample_CSR_getSegmentsType SegmentsExample_CSR_setSegmentsSizes SegmentsExample_CSR_getSegmentView ) if( BUILD_CUDA ) Loading Documentation/Examples/Algorithms/Segments/SegmentsExample_CSR_getSegmentView.cpp 0 → 100644 +47 −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/Algorithms/SequentialFor.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 SegmentView = typename SegmentsType::SegmentViewType; /*** * Create segments with given segments sizes. */ const int size( 5 ); SegmentsType segments{ 1, 2, 3, 4, 5 }; auto view = segments.getView(); /*** * Print the elemets mapping using segment view. */ std::cout << "Mapping of local indexes to global indexes:" << std::endl; 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" ); }; TNL::Algorithms::SequentialFor< Device >::exec( 0, size, f ); } 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_getSegmentView.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line SegmentsExample_CSR_getSegmentView.cpp No newline at end of file Documentation/Examples/Algorithms/Segments/SegmentsExample_CSR_getSegmentsType.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line SegmentsExample_CSR_getSegmentsType.cpp No newline at end of file Documentation/Examples/Algorithms/Segments/SegmentsExample_CSR_sequentialForAllSegments.cpp 0 → 100644 +42 −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::SegmentView; /*** * Create segments with given segments sizes. */ SegmentsType segments{ 1, 2, 3, 4, 5 }; std::cout << "Segments sizes are: " << segments << std::endl; /*** * Print the elemets mapping using segment view. */ std::cout << "Elements mapping:" << std::endl; segments.sequentialForAllSegments( [] __cuda_callable__ ( const SegmentView segment ) { printf( "Segment idx. %d: \n", segments.getSegmentIndex() ); // printf works even in GPU kernels for( auto element : segment ) printf( "%d -> %d ", element.localIndex(), element.globalIndex() ); } ); } 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; } Loading
Documentation/Examples/Algorithms/Segments/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ set( COMMON_EXAMPLES SegmentsExample_CSR_getSerializationType SegmentsExample_CSR_getSegmentsType SegmentsExample_CSR_setSegmentsSizes SegmentsExample_CSR_getSegmentView ) if( BUILD_CUDA ) Loading
Documentation/Examples/Algorithms/Segments/SegmentsExample_CSR_getSegmentView.cpp 0 → 100644 +47 −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/Algorithms/SequentialFor.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 SegmentView = typename SegmentsType::SegmentViewType; /*** * Create segments with given segments sizes. */ const int size( 5 ); SegmentsType segments{ 1, 2, 3, 4, 5 }; auto view = segments.getView(); /*** * Print the elemets mapping using segment view. */ std::cout << "Mapping of local indexes to global indexes:" << std::endl; 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" ); }; TNL::Algorithms::SequentialFor< Device >::exec( 0, size, f ); } 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_getSegmentView.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line SegmentsExample_CSR_getSegmentView.cpp No newline at end of file
Documentation/Examples/Algorithms/Segments/SegmentsExample_CSR_getSegmentsType.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line SegmentsExample_CSR_getSegmentsType.cpp No newline at end of file
Documentation/Examples/Algorithms/Segments/SegmentsExample_CSR_sequentialForAllSegments.cpp 0 → 100644 +42 −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::SegmentView; /*** * Create segments with given segments sizes. */ SegmentsType segments{ 1, 2, 3, 4, 5 }; std::cout << "Segments sizes are: " << segments << std::endl; /*** * Print the elemets mapping using segment view. */ std::cout << "Elements mapping:" << std::endl; segments.sequentialForAllSegments( [] __cuda_callable__ ( const SegmentView segment ) { printf( "Segment idx. %d: \n", segments.getSegmentIndex() ); // printf works even in GPU kernels for( auto element : segment ) printf( "%d -> %d ", element.localIndex(), element.globalIndex() ); } ); } 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; }