// @HEADER // ***************************************************************************** // Stokhos Package // // Copyright 2009 NTESS and the Stokhos contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #include "Teuchos_UnitTestHelpers.hpp" #include "Stokhos_UnitTestHelpers.hpp" #include "Stokhos_Sacado_Kokkos_UQ_PCE.hpp" #include "KokkosSparse_CrsMatrix.hpp" #include "KokkosSparse_spmv.hpp" #include "Kokkos_CrsMatrix_UQ_PCE.hpp" #include "Kokkos_CrsMatrix_UQ_PCE_Cuda.hpp" #include "Stokhos_LegendreBasis.hpp" #include "Stokhos_CompletePolynomialBasis.hpp" #include "Stokhos_Sparse3Tensor.hpp" // For computing DeviceConfig #include "Kokkos_Core.hpp" // Helper functions template< typename IntType > inline IntType map_fem_graph_coord( const IntType& N, const IntType& i, const IntType& j, const IntType& k ) { return k + N * ( j + N * i ); } template < typename ordinal > inline ordinal generate_fem_graph( ordinal N, std::vector< std::vector >& graph ) { graph.resize( N * N * N, std::vector() ); ordinal total = 0; for ( int i = 0; i < (int) N; ++i ) { for ( int j = 0; j < (int) N; ++j ) { for ( int k = 0; k < (int) N; ++k ) { const ordinal row = map_fem_graph_coord((int)N,i,j,k); graph[row].reserve(27); for ( int ii = -1; ii < 2; ++ii ) { for ( int jj = -1; jj < 2; ++jj ) { for ( int kk = -1; kk < 2; ++kk ) { if ( 0 <= i + ii && i + ii < (int) N && 0 <= j + jj && j + jj < (int) N && 0 <= k + kk && k + kk < (int) N ) { ordinal col = map_fem_graph_coord((int)N,i+ii,j+jj,k+kk); graph[row].push_back(col); } }}} total += graph[row].size(); }}} return total; } template inline scalar generate_matrix_coefficient( const ordinal nFEM, const ordinal nStoch, const ordinal iRowFEM, const ordinal iColFEM, const ordinal iStoch ) { const scalar A_fem = ( 10.0 + scalar(iRowFEM) / scalar(nFEM) ) + ( 5.0 + scalar(iColFEM) / scalar(nFEM) ); const scalar A_stoch = ( 1.0 + scalar(iStoch) / scalar(nStoch) ); return A_fem + A_stoch; //return 1.0; } template inline scalar generate_vector_coefficient( const ordinal nFEM, const ordinal nStoch, const ordinal iColFEM, const ordinal iStoch ) { const scalar X_fem = 100.0 + scalar(iColFEM) / scalar(nFEM); const scalar X_stoch = 1.0 + scalar(iStoch) / scalar(nStoch); return X_fem + X_stoch; //return 1.0; } template kokkos_cijk_type build_cijk(ordinal_type stoch_dim, ordinal_type poly_ord) { using Teuchos::RCP; using Teuchos::rcp; using Teuchos::Array; typedef typename kokkos_cijk_type::value_type value_type; typedef typename kokkos_cijk_type::execution_space execution_space; typedef Stokhos::OneDOrthogPolyBasis one_d_basis; typedef Stokhos::LegendreBasis legendre_basis; typedef Stokhos::CompletePolynomialBasis product_basis; typedef Stokhos::Sparse3Tensor Cijk; // Create product basis Array< RCP > bases(stoch_dim); for (ordinal_type i=0; i basis = rcp(new product_basis(bases)); // Triple product tensor RCP cijk = basis->computeTripleProductTensor(); // Kokkos triple product tensor kokkos_cijk_type kokkos_cijk = Stokhos::create_product_tensor(*basis, *cijk); return kokkos_cijk; } // Reasonable tolerances for common precisions template struct ScalarTol {}; template <> struct ScalarTol { static float tol() { return 1e-4; } }; template <> struct ScalarTol { static double tol() { return 1e-10; } }; // Compare two rank-2 views for equality, to given precision template bool compare_rank_2_views(const array_type& y, const array_type& y_exp, const scalar_type rel_tol, const scalar_type abs_tol, Teuchos::FancyOStream& out) { typedef typename array_type::size_type size_type; typename array_type::HostMirror hy = Kokkos::create_mirror_view(y); typename array_type::HostMirror hy_exp = Kokkos::create_mirror_view(y_exp); Kokkos::deep_copy(hy, y); Kokkos::deep_copy(hy_exp, y_exp); size_type num_rows = y.extent(0); size_type num_cols = y.extent(1); bool success = true; for (size_type i=0; i bool compareRank1(const vector_type& y, const vector_type& y_exp, const scalar_type rel_tol, const scalar_type abs_tol, Teuchos::FancyOStream& out) { typedef typename vector_type::size_type size_type; typename vector_type::HostMirror hy = Kokkos::create_mirror_view(y); typename vector_type::HostMirror hy_exp = Kokkos::create_mirror_view(y_exp); Kokkos::deep_copy(hy, y); Kokkos::deep_copy(hy_exp, y_exp); size_type num_rows = y.extent(0); bool success = true; for (size_type i=0; i bool compareRank2(const vector_type& y, const vector_type& y_exp, const scalar_type rel_tol, const scalar_type abs_tol, Teuchos::FancyOStream& out) { typedef typename vector_type::size_type size_type; typename vector_type::HostMirror hy = Kokkos::create_mirror_view(y); typename vector_type::HostMirror hy_exp = Kokkos::create_mirror_view(y_exp); Kokkos::deep_copy(hy, y); Kokkos::deep_copy(hy_exp, y_exp); size_type num_rows = y.extent(0); size_type num_cols = y.extent(1); bool success = true; for (size_type col = 0; col < num_cols; ++col){ for (size_type i=0; i MatrixType buildDiagonalMatrix(typename MatrixType::ordinal_type nrow, typename MatrixType::ordinal_type pce_size, const CijkType& cijk) { typedef typename MatrixType::ordinal_type ordinal_type; typedef typename MatrixType::StaticCrsGraphType matrix_graph_type; typedef typename MatrixType::values_type matrix_values_type; std::vector< std::vector > graph(nrow); for (ordinal_type i=0; i(1, i); ordinal_type graph_length = nrow; matrix_graph_type matrix_graph = Kokkos::create_staticcrsgraph("graph", graph); matrix_values_type matrix_values = Kokkos::make_view("values", cijk, graph_length, pce_size); MatrixType matrix("matrix", nrow, matrix_values, matrix_graph); return matrix; } // // Tests // // Kernel to set diagonal of a matrix to prescribed values template struct ReplaceDiagonalValuesKernel { typedef typename MatrixType::execution_space execution_space; typedef typename MatrixType::size_type size_type; typedef typename MatrixType::value_type value_type; typedef typename MatrixType::ordinal_type ordinal_type; const MatrixType m_matrix; ReplaceDiagonalValuesKernel(const MatrixType matrix) : m_matrix(matrix) {}; // Replace diagonal entry for row 'i' with a value KOKKOS_INLINE_FUNCTION void operator() (const size_type i) const { const ordinal_type row = i; const ordinal_type col = i; value_type val = value_type(row); m_matrix.replaceValues(row, &col, 1, &val, false, true); } // Kernel launch static void apply(const MatrixType matrix) { const size_type nrow = matrix.numRows(); Kokkos::parallel_for( nrow, ReplaceDiagonalValuesKernel(matrix) ); } // Check the result is as expected static bool check(const MatrixType matrix, Teuchos::FancyOStream& out) { typedef typename MatrixType::values_type matrix_values_type; typename matrix_values_type::HostMirror host_matrix_values = Kokkos::create_mirror_view(matrix.values); Kokkos::deep_copy(host_matrix_values, matrix.values); const ordinal_type nrow = matrix.numRows(); bool success = true; value_type val_expected(Kokkos::cijk(matrix.values)); for (ordinal_type row=0; row struct AddDiagonalValuesKernel { typedef typename MatrixType::execution_space execution_space; typedef typename MatrixType::size_type size_type; typedef typename MatrixType::value_type value_type; typedef typename MatrixType::ordinal_type ordinal_type; const MatrixType m_matrix; AddDiagonalValuesKernel(const MatrixType matrix) : m_matrix(matrix) {}; // Replace diagonal entry for row 'i' with a value KOKKOS_INLINE_FUNCTION void operator() (const size_type i) const { const ordinal_type row = i; const ordinal_type col = i; value_type val = value_type(row); m_matrix.sumIntoValues(row, &col, 1, &val, false, true); } // Kernel launch static void apply(const MatrixType matrix) { const size_type nrow = matrix.numRows(); Kokkos::parallel_for( nrow, AddDiagonalValuesKernel(matrix) ); } // Check the result is as expected static bool check(const MatrixType matrix, Teuchos::FancyOStream& out) { typedef typename MatrixType::values_type matrix_values_type; typename matrix_values_type::HostMirror host_matrix_values = Kokkos::create_mirror_view(matrix.values); Kokkos::deep_copy(host_matrix_values, matrix.values); const ordinal_type nrow = matrix.numRows(); bool success = true; value_type val_expected(Kokkos::cijk(matrix.values)); for (ordinal_type row=0; row struct AddDiagonalValuesAtomicKernel { typedef typename MatrixType::execution_space execution_space; typedef typename MatrixType::size_type size_type; typedef typename MatrixType::value_type value_type; typedef typename MatrixType::ordinal_type ordinal_type; const MatrixType m_matrix; AddDiagonalValuesAtomicKernel(const MatrixType matrix) : m_matrix(matrix) {}; // Replace diagonal entry for row 'i' with a value KOKKOS_INLINE_FUNCTION void operator() (const size_type i) const { const ordinal_type row = 0; const ordinal_type col = 0; value_type val = value_type(i); m_matrix.sumIntoValues(row, &col, 1, &val, false, true); } // Kernel launch static void apply(const MatrixType matrix) { const size_type nrow = matrix.numRows(); Kokkos::parallel_for( nrow, AddDiagonalValuesAtomicKernel(matrix) ); } // Check the result is as expected static bool check(const MatrixType matrix, Teuchos::FancyOStream& out) { typedef typename MatrixType::values_type matrix_values_type; typename matrix_values_type::HostMirror host_matrix_values = Kokkos::create_mirror_view(matrix.values); Kokkos::deep_copy(host_matrix_values, matrix.values); const ordinal_type nrow = matrix.numRows(); bool success = true; value_type val_expected(Kokkos::cijk(matrix.values)); for (ordinal_type row=0; row Matrix; // Build Cijk tensor const Ordinal stoch_dim = 2; const Ordinal poly_ord = 3; Cijk cijk = build_cijk(stoch_dim, poly_ord); // Build diagonal matrix const Ordinal nrow = 10; const Ordinal pce_size = cijk.dimension(); Matrix matrix = buildDiagonalMatrix(nrow, pce_size, cijk); // Launch our kernel typedef ReplaceDiagonalValuesKernel kernel; kernel::apply(matrix); // Check the result success = kernel::check(matrix, out); } TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Kokkos_CrsMatrix_PCE, SumIntoValues, MatrixScalar ) { typedef typename MatrixScalar::ordinal_type Ordinal; typedef typename MatrixScalar::execution_space Device; typedef typename MatrixScalar::cijk_type Cijk; typedef KokkosSparse::CrsMatrix Matrix; // Build Cijk tensor const Ordinal stoch_dim = 2; const Ordinal poly_ord = 3; Cijk cijk = build_cijk(stoch_dim, poly_ord); // Build diagonal matrix const Ordinal nrow = 10; const Ordinal pce_size = cijk.dimension(); Matrix matrix = buildDiagonalMatrix(nrow, pce_size, cijk); // Launch our kernel typedef AddDiagonalValuesKernel kernel; kernel::apply(matrix); // Check the result success = kernel::check(matrix, out); } TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Kokkos_CrsMatrix_PCE, SumIntoValuesAtomic, MatrixScalar ) { typedef typename MatrixScalar::ordinal_type Ordinal; typedef typename MatrixScalar::execution_space Device; typedef typename MatrixScalar::cijk_type Cijk; typedef KokkosSparse::CrsMatrix Matrix; // Build Cijk tensor const Ordinal stoch_dim = 2; const Ordinal poly_ord = 3; Cijk cijk = build_cijk(stoch_dim, poly_ord); // Build diagonal matrix const Ordinal nrow = 10; const Ordinal pce_size = cijk.dimension(); Matrix matrix = buildDiagonalMatrix(nrow, pce_size, cijk); // Launch our kernel typedef AddDiagonalValuesAtomicKernel kernel; kernel::apply(matrix); // Check the result success = kernel::check(matrix, out); } template bool test_embedded_pce(const typename PCEType::ordinal_type nGrid, const typename PCEType::ordinal_type stoch_dim, const typename PCEType::ordinal_type poly_ord, KokkosSparse::DeviceConfig dev_config, Multiply multiply_op, Teuchos::FancyOStream& out) { typedef typename PCEType::ordinal_type ordinal_type; typedef typename PCEType::value_type scalar_type; typedef typename PCEType::storage_type storage_type; typedef typename PCEType::cijk_type cijk_type; typedef typename storage_type::execution_space execution_space; typedef Kokkos::LayoutLeft Layout; typedef Kokkos::View< PCEType*, Layout, execution_space > block_vector_type; typedef KokkosSparse::CrsMatrix< PCEType, ordinal_type, execution_space > block_matrix_type; typedef typename block_matrix_type::StaticCrsGraphType matrix_graph_type; typedef typename block_matrix_type::values_type matrix_values_type; // Build Cijk tensor cijk_type cijk = build_cijk(stoch_dim, poly_ord); const ordinal_type stoch_length = cijk.dimension(); // const ordinal_type align = 8; // const ordinal_type stoch_length_aligned = (stoch_length+align-1) & ~(align-1); const ordinal_type stoch_length_aligned = stoch_length; // Check pce_length == storage_type::static_size for static storage TEUCHOS_TEST_FOR_EXCEPTION( storage_type::is_static && storage_type::static_size != stoch_length, std::logic_error, "Static storage size must equal pce size"); // Generate FEM graph: const ordinal_type fem_length = nGrid * nGrid * nGrid; std::vector< std::vector > fem_graph; const ordinal_type fem_graph_length = generate_fem_graph( nGrid, fem_graph ); //------------------------------ // Generate input/output multivectors -- Sacado dimension is always last, // regardless of LayoutLeft/Right block_vector_type x = Kokkos::make_view("x", cijk, fem_length, stoch_length_aligned); block_vector_type y = Kokkos::make_view("y", cijk, fem_length, stoch_length_aligned); typename block_vector_type::HostMirror hx = Kokkos::create_mirror_view( x ); typename block_vector_type::HostMirror hy = Kokkos::create_mirror_view( y ); // View the block vector as an array of the embedded intrinsic type. typename block_vector_type::HostMirror::array_type hax = hx ; typename block_vector_type::HostMirror::array_type hay = hy ; for (ordinal_type iRowFEM=0; iRowFEM( fem_length, stoch_length, iRowFEM, iRowStoch ); hay(iRowStoch, iRowFEM) = 0.0; } } Kokkos::deep_copy( x, hx ); Kokkos::deep_copy( y, hy ); //------------------------------ // Generate block matrix -- it is always LayoutRight (currently) matrix_graph_type matrix_graph = Kokkos::create_staticcrsgraph( std::string("test crs graph"), fem_graph); matrix_values_type matrix_values = Kokkos::make_view( Kokkos::ViewAllocateWithoutInitializing("matrix"), cijk, fem_graph_length, stoch_length_aligned); block_matrix_type matrix( "block_matrix", fem_length, matrix_values, matrix_graph); matrix.dev_config = dev_config; typename matrix_values_type::HostMirror hM = Kokkos::create_mirror_view( matrix.values ); typename matrix_values_type::HostMirror::array_type haM = hM ; for (ordinal_type iRowFEM=0, iEntryFEM=0; iRowFEM( fem_length, stoch_length, iRowFEM, iColFEM, k); } } } Kokkos::deep_copy( matrix.values, hM ); //------------------------------ // multiply multiply_op( matrix, x, y ); //------------------------------ // generate correct answer typedef typename block_vector_type::array_type array_type; array_type ay_expected = array_type("ay_expected", stoch_length_aligned, fem_length); typename array_type::HostMirror hay_expected = Kokkos::create_mirror_view(ay_expected); typename cijk_type::HostMirror host_cijk = Kokkos::create_mirror_view(cijk); Kokkos::deep_copy(host_cijk, cijk); for (ordinal_type iRowFEM=0, iEntryFEM=0; iRowFEM( fem_length, stoch_length, iRowFEM, iColFEM, j); const scalar_type a_k = generate_matrix_coefficient( fem_length, stoch_length, iRowFEM, iColFEM, k); const scalar_type x_j = generate_vector_coefficient( fem_length, stoch_length, iColFEM, j); const scalar_type x_k = generate_vector_coefficient( fem_length, stoch_length, iColFEM, k); tmp += host_cijk.value(entry) * ( a_j * x_k + a_k * x_j ); } hay_expected(i, iRowFEM) += tmp; } } } Kokkos::deep_copy( ay_expected, hay_expected ); //------------------------------ // check typename block_vector_type::array_type ay = y; scalar_type rel_tol = ScalarTol::tol(); scalar_type abs_tol = ScalarTol::tol(); bool success = compare_rank_2_views(ay, ay_expected, rel_tol, abs_tol, out); return success; } TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_CrsMatrix_PCE, Multiply, Scalar, MultiplyOp ) { typedef typename Scalar::ordinal_type Ordinal; const Ordinal nGrid = 5; const Ordinal stoch_dim = 2; const Ordinal poly_ord = 3; KokkosSparse::DeviceConfig dev_config; success = test_embedded_pce( nGrid, stoch_dim, poly_ord, dev_config, MultiplyOp(), out); } struct Kokkos_MV_Multiply_Op { template void operator() (const Matrix& A, const InputVector& x, OutputVector& y) const { KokkosSparse::spmv("N", typename Matrix::value_type(1.0) , A, x, typename Matrix::value_type(0.0), y); } }; template struct Stokhos_MV_Multiply_Op { Tag tag; Stokhos_MV_Multiply_Op(const Tag& tg = Tag()) : tag(tg) {} template void operator() (const Matrix& A, const InputVector& x, OutputVector& y) const { Stokhos::multiply(A, x, y, tag); } }; TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Kokkos_CrsMatrix_PCE, MeanMultiplyRank1, Scalar ) { typedef typename Scalar::ordinal_type Ordinal; const Ordinal nGrid = 5; const Ordinal stoch_dim = 5; const Ordinal poly_ord = 3; KokkosSparse::DeviceConfig dev_config; typedef typename Scalar::ordinal_type ordinal_type; typedef typename Scalar::value_type scalar_type; typedef typename Scalar::storage_type storage_type; typedef typename Scalar::cijk_type cijk_type; typedef typename storage_type::execution_space execution_space; typedef Kokkos::LayoutLeft Layout; typedef Kokkos::View< Scalar*, Layout, execution_space > block_vector_type; typedef KokkosSparse::CrsMatrix< Scalar, ordinal_type, execution_space > block_matrix_type; typedef typename block_matrix_type::StaticCrsGraphType matrix_graph_type; typedef typename block_matrix_type::values_type matrix_values_type; // Build Cijk tensor cijk_type cijk = build_cijk(stoch_dim, poly_ord); cijk_type mean_cijk = Stokhos::create_mean_based_product_tensor(); const ordinal_type stoch_length = cijk.dimension(); const ordinal_type align = 8; const ordinal_type stoch_length_aligned = (stoch_length+align-1) & ~(align-1); // Generate FEM graph: const ordinal_type fem_length = nGrid * nGrid * nGrid; std::vector< std::vector > fem_graph; const ordinal_type fem_graph_length = generate_fem_graph( nGrid, fem_graph ); block_vector_type x = Kokkos::make_view("x", cijk, fem_length, stoch_length_aligned); block_vector_type y = Kokkos::make_view("y", cijk, fem_length, stoch_length_aligned); block_vector_type y_expected = Kokkos::make_view("y", cijk, fem_length, stoch_length_aligned); typename block_vector_type::HostMirror hx = Kokkos::create_mirror_view( x ); typename block_vector_type::HostMirror hy = Kokkos::create_mirror_view( y ); typename block_vector_type::HostMirror hy_expected = Kokkos::create_mirror_view( y_expected ); // View the block vector as an array of the embedded intrinsic type. typename block_vector_type::HostMirror::array_type hax = hx ; typename block_vector_type::HostMirror::array_type hay = hy ; typename block_vector_type::HostMirror::array_type hay_expected = hy_expected ; for (ordinal_type iRowFEM=0; iRowFEM( fem_length, stoch_length, iRowFEM, iRowStoch ); hay(iRowStoch,iRowFEM) = 0.0; hay_expected(iRowStoch,iRowFEM) = 0.0; } } Kokkos::deep_copy( x, hx ); Kokkos::deep_copy( y, hy ); Kokkos::deep_copy( y_expected, hy_expected ); //------------------------------ // Generate block matrix -- it is always LayoutRight (currently) matrix_graph_type matrix_graph = Kokkos::create_staticcrsgraph( std::string("test crs graph"), fem_graph); matrix_values_type matrix_values = Kokkos::make_view( Kokkos::ViewAllocateWithoutInitializing("matrix"), mean_cijk, fem_graph_length, ordinal_type(1)); //instead of stoch_length block_matrix_type matrix( "block_matrix", fem_length, matrix_values, matrix_graph); matrix.dev_config = dev_config; typename matrix_values_type::HostMirror hM = Kokkos::create_mirror_view( matrix.values ); typename matrix_values_type::HostMirror::array_type haM = hM ; for (ordinal_type iRowFEM=0, iEntryFEM=0; iRowFEM( fem_length, 1, iRowFEM, iColFEM, 0); for (ordinal_type iRowStoch=0; iRowStoch( Kokkos::ViewAllocateWithoutInitializing("matrix"), cijk, fem_graph_length, stoch_length_aligned); block_matrix_type full_matrix( "block_matrix", fem_length, full_matrix_values, matrix_graph); matrix.dev_config = dev_config; typename matrix_values_type::HostMirror full_hM = Kokkos::create_mirror_view( full_matrix.values ); typename matrix_values_type::HostMirror::array_type full_haM = full_hM ; for (ordinal_type iRowFEM=0, iEntryFEM=0; iRowFEM( fem_length, 1, iRowFEM, iColFEM, k); else full_haM(iEntryFEM, k) = 0.0; } } } Kokkos::deep_copy( full_matrix.values, full_hM ); */ //------------------------------ // multiply KokkosSparse::spmv("N", Scalar(1.0) , matrix, x, Scalar(0.0), y); //------------------------------ // multiply with same matrix but with sacado_size = x.sacado_size //Kokkos::MV_Multiply( y_expected, full_matrix, x ); //------------------------------ // check scalar_type rel_tol = ScalarTol::tol(); scalar_type abs_tol = ScalarTol::tol(); success = compareRank1(y, y_expected, rel_tol, abs_tol, out); } TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Kokkos_CrsMatrix_PCE, MeanMultiplyRank2, Scalar ) { typedef typename Scalar::ordinal_type ordinal_type; typedef typename Scalar::value_type scalar_type; typedef typename Scalar::storage_type storage_type; typedef typename Scalar::cijk_type cijk_type; typedef typename storage_type::execution_space execution_space; typedef Kokkos::LayoutLeft Layout; typedef Kokkos::View< Scalar**, Layout, execution_space > block_vector_type; typedef KokkosSparse::CrsMatrix< Scalar, ordinal_type, execution_space > block_matrix_type; typedef typename block_matrix_type::StaticCrsGraphType matrix_graph_type; typedef typename block_matrix_type::values_type matrix_values_type; const ordinal_type nGrid = 5; const ordinal_type stoch_dim = 2; const ordinal_type poly_ord = 3; KokkosSparse::DeviceConfig dev_config; // Build Cijk tensor cijk_type cijk = build_cijk(stoch_dim, poly_ord); cijk_type mean_cijk = Stokhos::create_mean_based_product_tensor(); const ordinal_type stoch_length = cijk.dimension(); const ordinal_type align = 8; const ordinal_type stoch_length_aligned = (stoch_length+align-1) & ~(align-1); const ordinal_type num_cols = 2; // Generate FEM graph: const ordinal_type fem_length = nGrid * nGrid * nGrid; std::vector< std::vector > fem_graph; const ordinal_type fem_graph_length = generate_fem_graph( nGrid, fem_graph ); block_vector_type x = Kokkos::make_view("x", cijk, fem_length, num_cols, stoch_length_aligned); block_vector_type y = Kokkos::make_view("y", cijk, fem_length, num_cols, stoch_length_aligned); block_vector_type y_expected = Kokkos::make_view("y_expected", cijk, fem_length, num_cols, stoch_length_aligned); typename block_vector_type::HostMirror hx = Kokkos::create_mirror_view( x ); typename block_vector_type::HostMirror hy = Kokkos::create_mirror_view( y ); typename block_vector_type::HostMirror hy_expected = Kokkos::create_mirror_view( y_expected ); for (ordinal_type i=0; i( fem_length, stoch_length, iRowFEM, iRowStoch ); hy(iRowFEM,i).fastAccessCoeff(iRowStoch) = 0.0; hy_expected(iRowFEM,i).fastAccessCoeff(iRowStoch) = 0.0; } } } Kokkos::deep_copy( x, hx ); Kokkos::deep_copy( y, hy ); Kokkos::deep_copy( y_expected, hy_expected ); //------------------------------ // Generate matrix with stochastic dimension 1 matrix_graph_type matrix_graph = Kokkos::create_staticcrsgraph( std::string("test crs graph"), fem_graph); matrix_values_type matrix_values = Kokkos::make_view( Kokkos::ViewAllocateWithoutInitializing("matrix"), mean_cijk, fem_graph_length, ordinal_type(1)); block_matrix_type matrix( "block_matrix", fem_length, matrix_values, matrix_graph); matrix.dev_config = dev_config; typename matrix_values_type::HostMirror hM = Kokkos::create_mirror_view( matrix.values ); typename matrix_values_type::HostMirror::array_type haM = hM ; for (ordinal_type iRowFEM=0, iEntryFEM=0; iRowFEM( fem_length, 1, iRowFEM, iColFEM, 0); for (ordinal_type i=0; i( Kokkos::ViewAllocateWithoutInitializing("matrix"), cijk, fem_graph_length, stoch_length_aligned); block_matrix_type full_matrix( "block_matrix", fem_length, full_matrix_values, matrix_graph); matrix.dev_config = dev_config; typename matrix_values_type::HostMirror full_hM = Kokkos::create_mirror_view( full_matrix.values ); typename matrix_values_type::HostMirror::array_type full_haM = full_hM ; for (ordinal_type iRowFEM=0, iEntryFEM=0; iRowFEM( fem_length, 1, iRowFEM, iColFEM, k); else full_haM(iEntryFEM, k) = 0.0; } } } Kokkos::deep_copy( full_matrix.values, full_hM ); */ //------------------------------ // multiply KokkosSparse::spmv("N", Scalar(1.0) , matrix, x, Scalar(0.0), y); //------------------------------ // multiply with full matrix //Kokkos::MV_Multiply( y_expected, full_matrix, x ); //------------------------------ // check scalar_type rel_tol = ScalarTol::tol(); scalar_type abs_tol = ScalarTol::tol(); success = compareRank2(y, y_expected, rel_tol, abs_tol, out); } typedef Kokkos_MV_Multiply_Op KokkosMultiply; #define CRSMATRIX_UQ_PCE_TESTS_MATRIXSCALAR( SCALAR ) \ TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \ Kokkos_CrsMatrix_PCE, ReplaceValues, SCALAR ) \ TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \ Kokkos_CrsMatrix_PCE, SumIntoValues, SCALAR ) \ TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \ Kokkos_CrsMatrix_PCE, SumIntoValuesAtomic, SCALAR ) #define CRSMATRIX_UQ_PCE_MEAN_MULTIPLY_TESTS( SCALAR ) \ TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \ Kokkos_CrsMatrix_PCE, MeanMultiplyRank1, SCALAR ) \ TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \ Kokkos_CrsMatrix_PCE, MeanMultiplyRank2, SCALAR ) #define CRS_MATRIX_UQ_PCE_MULTIPLY_TESTS_SCALAR_OP( SCALAR, OP ) \ TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \ Kokkos_CrsMatrix_PCE, Multiply, SCALAR, OP ) #define CRS_MATRIX_UQ_PCE_MULTIPLY_TESTS_SCALAR( SCALAR ) \ CRS_MATRIX_UQ_PCE_MULTIPLY_TESTS_SCALAR_OP( SCALAR, KokkosMultiply ) #define CRSMATRIX_UQ_PCE_TESTS_STORAGE( STORAGE ) \ typedef Sacado::UQ::PCE UQ_PCE_ ## STORAGE; \ CRSMATRIX_UQ_PCE_TESTS_MATRIXSCALAR( UQ_PCE_ ## STORAGE ) \ CRS_MATRIX_UQ_PCE_MULTIPLY_TESTS_SCALAR( UQ_PCE_ ## STORAGE ) \ CRSMATRIX_UQ_PCE_MEAN_MULTIPLY_TESTS( UQ_PCE_ ## STORAGE ) #define CRSMATRIX_UQ_PCE_TESTS_ORDINAL_SCALAR_DEVICE( ORDINAL, SCALAR, DEVICE ) \ typedef Stokhos::DynamicStorage DS; \ CRSMATRIX_UQ_PCE_TESTS_STORAGE( DS ) #define CRSMATRIX_UQ_PCE_TESTS_DEVICE( DEVICE ) \ CRSMATRIX_UQ_PCE_TESTS_ORDINAL_SCALAR_DEVICE( int, double, DEVICE )