Loading Documentation/Examples/Matrices/DenseMatrix/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ set( COMMON_EXAMPLES DenseMatrixViewExample_forElements DenseMatrixViewExample_forRows DenseMatrixViewExample_forAllElements DenseMatrixViewExample_wrap ) if( BUILD_CUDA ) Loading Documentation/Examples/Matrices/DenseMatrix/DenseMatrixViewExample_wrap.cpp 0 → 100644 +34 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/Algorithms/ParallelFor.h> #include <TNL/Matrices/DenseMatrix.h> #include <TNL/Matrices/MatrixWrapping.h> #include <TNL/Devices/Host.h> #include <TNL/Devices/Cuda.h> template< typename Device > void wrapMatrixView() { const int rows( 3 ), columns( 4 ); TNL::Containers::Vector< double, Device > valuesVector { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; double* values = valuesVector.getData(); /*** * Wrap the array `values` to dense matrix view */ auto matrix = TNL::Matrices::wrapDenseMatrix< Device >( rows, columns, values ); std::cout << "Matrix reads as: " << std::endl << matrix << std::endl; } int main( int argc, char* argv[] ) { std::cout << "Wraping matrix view on host: " << std::endl; wrapMatrixView< TNL::Devices::Host >(); #ifdef HAVE_CUDA std::cout << "Wraping matrix view on CUDA device: " << std::endl; wrapMatrixView< TNL::Devices::Cuda >(); #endif } Documentation/Examples/Matrices/DenseMatrix/DenseMatrixViewExample_wrap.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line DenseMatrixViewExample_wrap.cpp No newline at end of file Documentation/Examples/Matrices/SparseMatrix/CMakeLists.txt +2 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ set( COMMON_EXAMPLES SparseMatrixViewExample_forElements SparseMatrixViewExample_forRows SparseMatrixViewExample_forAllElements SparseMatrixViewExample_wrapCSR SparseMatrixViewExample_wrapEllpack ) if( BUILD_CUDA ) Loading Documentation/Examples/Matrices/SparseMatrix/SparseMatrixViewExample_wrapCSR.cpp 0 → 100644 +45 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/Algorithms/ParallelFor.h> #include <TNL/Matrices/DenseMatrix.h> #include <TNL/Matrices/MatrixWrapping.h> #include <TNL/Devices/Host.h> #include <TNL/Devices/Cuda.h> template< typename Device > void wrapMatrixView() { /*** * Encode the following matrix to CSR format... * * / 1 2 0 0 \. * | 0 6 0 0 | * | 9 0 0 0 | * \ 0 0 15 16 / */ const int rows( 4 ), columns( 4 ); TNL::Containers::Vector< double, Device > valuesVector { 1, 2, 6, 9, 15, 16 }; TNL::Containers::Vector< int, Device > columnIndexesVector { 0, 1, 1, 0, 2, 3 }; TNL::Containers::Vector< int, Device > rowPointersVector { 0, 2, 3, 4, 6 }; double* values = valuesVector.getData(); int* columnIndexes = columnIndexesVector.getData(); int* rowPointers = rowPointersVector.getData(); /*** * Wrap the arrays `rowPointers, `values` and `columnIndexes` to sparse matrix view */ auto matrix = TNL::Matrices::wrapCSRMatrix< Device >( rows, columns, rowPointers, values, columnIndexes ); std::cout << "Matrix reads as: " << std::endl << matrix << std::endl; } int main( int argc, char* argv[] ) { std::cout << "Wraping matrix view on host: " << std::endl; wrapMatrixView< TNL::Devices::Host >(); #ifdef HAVE_CUDA std::cout << "Wraping matrix view on CUDA device: " << std::endl; wrapMatrixView< TNL::Devices::Cuda >(); #endif } Loading
Documentation/Examples/Matrices/DenseMatrix/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ set( COMMON_EXAMPLES DenseMatrixViewExample_forElements DenseMatrixViewExample_forRows DenseMatrixViewExample_forAllElements DenseMatrixViewExample_wrap ) if( BUILD_CUDA ) Loading
Documentation/Examples/Matrices/DenseMatrix/DenseMatrixViewExample_wrap.cpp 0 → 100644 +34 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/Algorithms/ParallelFor.h> #include <TNL/Matrices/DenseMatrix.h> #include <TNL/Matrices/MatrixWrapping.h> #include <TNL/Devices/Host.h> #include <TNL/Devices/Cuda.h> template< typename Device > void wrapMatrixView() { const int rows( 3 ), columns( 4 ); TNL::Containers::Vector< double, Device > valuesVector { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; double* values = valuesVector.getData(); /*** * Wrap the array `values` to dense matrix view */ auto matrix = TNL::Matrices::wrapDenseMatrix< Device >( rows, columns, values ); std::cout << "Matrix reads as: " << std::endl << matrix << std::endl; } int main( int argc, char* argv[] ) { std::cout << "Wraping matrix view on host: " << std::endl; wrapMatrixView< TNL::Devices::Host >(); #ifdef HAVE_CUDA std::cout << "Wraping matrix view on CUDA device: " << std::endl; wrapMatrixView< TNL::Devices::Cuda >(); #endif }
Documentation/Examples/Matrices/DenseMatrix/DenseMatrixViewExample_wrap.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line DenseMatrixViewExample_wrap.cpp No newline at end of file
Documentation/Examples/Matrices/SparseMatrix/CMakeLists.txt +2 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ set( COMMON_EXAMPLES SparseMatrixViewExample_forElements SparseMatrixViewExample_forRows SparseMatrixViewExample_forAllElements SparseMatrixViewExample_wrapCSR SparseMatrixViewExample_wrapEllpack ) if( BUILD_CUDA ) Loading
Documentation/Examples/Matrices/SparseMatrix/SparseMatrixViewExample_wrapCSR.cpp 0 → 100644 +45 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/Algorithms/ParallelFor.h> #include <TNL/Matrices/DenseMatrix.h> #include <TNL/Matrices/MatrixWrapping.h> #include <TNL/Devices/Host.h> #include <TNL/Devices/Cuda.h> template< typename Device > void wrapMatrixView() { /*** * Encode the following matrix to CSR format... * * / 1 2 0 0 \. * | 0 6 0 0 | * | 9 0 0 0 | * \ 0 0 15 16 / */ const int rows( 4 ), columns( 4 ); TNL::Containers::Vector< double, Device > valuesVector { 1, 2, 6, 9, 15, 16 }; TNL::Containers::Vector< int, Device > columnIndexesVector { 0, 1, 1, 0, 2, 3 }; TNL::Containers::Vector< int, Device > rowPointersVector { 0, 2, 3, 4, 6 }; double* values = valuesVector.getData(); int* columnIndexes = columnIndexesVector.getData(); int* rowPointers = rowPointersVector.getData(); /*** * Wrap the arrays `rowPointers, `values` and `columnIndexes` to sparse matrix view */ auto matrix = TNL::Matrices::wrapCSRMatrix< Device >( rows, columns, rowPointers, values, columnIndexes ); std::cout << "Matrix reads as: " << std::endl << matrix << std::endl; } int main( int argc, char* argv[] ) { std::cout << "Wraping matrix view on host: " << std::endl; wrapMatrixView< TNL::Devices::Host >(); #ifdef HAVE_CUDA std::cout << "Wraping matrix view on CUDA device: " << std::endl; wrapMatrixView< TNL::Devices::Cuda >(); #endif }