Loading Documentation/Doxyfile +2 −0 Original line number Diff line number Diff line Loading @@ -926,6 +926,8 @@ EXCLUDE_SYMBOLS += TNL::Assert::* # internal namespace EXAMPLE_PATH += Examples EXAMPLE_PATH += Tutorials EXAMPLE_PATH += output_snippets EXAMPLE_PATH += ../Release/Documentation/Tutorials EXAMPLE_PATH += ../Debug/Documentation/Tutorials # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and Loading Documentation/Tutorials/ReductionAndScan/SegmentedScanExample.cpp 0 → 100644 +52 −0 Original line number Diff line number Diff line #include <iostream> #include <cstdlib> #include <TNL/Containers/Vector.h> #include <TNL/Containers/Array.h> #include <TNL/Containers/Algorithms/Reduction.h> #include <TNL/Containers/StaticVector.h> using namespace TNL; using namespace TNL::Containers; using namespace TNL::Containers::Algorithms; template< typename Device > void scan( Vector< double, Device >& v ) { /*** * Reduction is sum of two numbers. */ auto reduce = [] __cuda_callable__ ( const double& a, const double& b ) { return a + b; }; /*** * As parameters, we pass vector on which the scan is to be performed, interval * where the scan is performed, lambda function which is used by the scan and * zero element (idempotent) of the 'sum' operation. */ Scan< Device >::perform( v, 0, v.getSize(), reduce, 0.0 ); } int main( int argc, char* argv[] ) { /*** * Firstly, test the prefix sum with vectors allocated on CPU. */ Vector< double, Devices::Host > host_v( 10 ); host_v = 1.0; std::cout << "host_v = " << host_v << std::endl; scan( host_v ); std::cout << "The prefix sum of the host vector is " << host_v << "." << std::endl; /*** * And then also on GPU. */ #ifdef HAVE_CUDA Vector< double, Devices::Cuda > cuda_v( 10 ); cuda_v = 1.0; std::cout << "cuda_v = " << cuda_v << std::endl; scan( cuda_v ); std::cout << "The prefix sum of the CUDA vector is " << cuda_v << "." << std::endl; #endif return EXIT_SUCCESS; } Documentation/Tutorials/ReductionAndScan/SegmentedScanExample.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line SegmentedScanExample.cpp No newline at end of file Loading
Documentation/Doxyfile +2 −0 Original line number Diff line number Diff line Loading @@ -926,6 +926,8 @@ EXCLUDE_SYMBOLS += TNL::Assert::* # internal namespace EXAMPLE_PATH += Examples EXAMPLE_PATH += Tutorials EXAMPLE_PATH += output_snippets EXAMPLE_PATH += ../Release/Documentation/Tutorials EXAMPLE_PATH += ../Debug/Documentation/Tutorials # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and Loading
Documentation/Tutorials/ReductionAndScan/SegmentedScanExample.cpp 0 → 100644 +52 −0 Original line number Diff line number Diff line #include <iostream> #include <cstdlib> #include <TNL/Containers/Vector.h> #include <TNL/Containers/Array.h> #include <TNL/Containers/Algorithms/Reduction.h> #include <TNL/Containers/StaticVector.h> using namespace TNL; using namespace TNL::Containers; using namespace TNL::Containers::Algorithms; template< typename Device > void scan( Vector< double, Device >& v ) { /*** * Reduction is sum of two numbers. */ auto reduce = [] __cuda_callable__ ( const double& a, const double& b ) { return a + b; }; /*** * As parameters, we pass vector on which the scan is to be performed, interval * where the scan is performed, lambda function which is used by the scan and * zero element (idempotent) of the 'sum' operation. */ Scan< Device >::perform( v, 0, v.getSize(), reduce, 0.0 ); } int main( int argc, char* argv[] ) { /*** * Firstly, test the prefix sum with vectors allocated on CPU. */ Vector< double, Devices::Host > host_v( 10 ); host_v = 1.0; std::cout << "host_v = " << host_v << std::endl; scan( host_v ); std::cout << "The prefix sum of the host vector is " << host_v << "." << std::endl; /*** * And then also on GPU. */ #ifdef HAVE_CUDA Vector< double, Devices::Cuda > cuda_v( 10 ); cuda_v = 1.0; std::cout << "cuda_v = " << cuda_v << std::endl; scan( cuda_v ); std::cout << "The prefix sum of the CUDA vector is " << cuda_v << "." << std::endl; #endif return EXIT_SUCCESS; }
Documentation/Tutorials/ReductionAndScan/SegmentedScanExample.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line SegmentedScanExample.cpp No newline at end of file