// @HEADER // ***************************************************************************** // Stokhos Package // // Copyright 2009 NTESS and the Stokhos contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #include // Kokkos CrsMatrix #include "KokkosSparse_CrsMatrix.hpp" #include "KokkosSparse_spmv.hpp" // Utilities #include "Kokkos_Timer.hpp" 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 ); } inline size_t generate_fem_graph( size_t N , std::vector< std::vector > & graph ) { graph.resize( N * N * N , std::vector() ); size_t 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 size_t 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 ) { size_t 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 void test_spmm(const OrdinalType ensemble_length, const OrdinalType nGrid, const OrdinalType iterCount, std::vector& scalar_perf, std::vector& block_left_perf, std::vector& block_right_perf) { typedef ScalarType value_type; typedef OrdinalType ordinal_type; typedef Device execution_space; typedef Kokkos::View< value_type*, execution_space > vector_type; typedef Kokkos::View< value_type**, Kokkos::LayoutLeft, execution_space > left_multivec_type; //typedef Kokkos::View< value_type**, Kokkos::LayoutRight, execution_space > right_multivec_type; typedef KokkosSparse::CrsMatrix< value_type, ordinal_type, execution_space > matrix_type; typedef typename matrix_type::StaticCrsGraphType matrix_graph_type; typedef typename matrix_type::values_type matrix_values_type; //------------------------------ // Generate graph for "FEM" box structure: std::vector< std::vector > fem_graph; const size_t fem_length = nGrid * nGrid * nGrid; const size_t graph_length = generate_fem_graph( nGrid , fem_graph ); //------------------------------ // Generate input vectors: std::vector x(ensemble_length); std::vector y(ensemble_length); for (ordinal_type e=0; e( std::string("test crs graph"), fem_graph); matrix_values_type matrix_values = matrix_values_type(Kokkos::ViewAllocateWithoutInitializing("matrix"), graph_length); matrix_type matrix("matrix", fem_length, matrix_values, matrix_graph); Kokkos::deep_copy( matrix_values , value_type(1.0) ); //------------------------------ // Scalar multiply { // warm up for (ordinal_type iter = 0; iter < iterCount; ++iter) { for (ordinal_type e=0; e void performance_test_driver( const Ordinal nGrid, const Ordinal nIter, const Ordinal ensemble_min, const Ordinal ensemble_max, const Ordinal ensemble_step ) { std::cout.precision(8); std::cout << std::endl << "\"Grid Size\" , " << "\"FEM Size\" , " << "\"FEM Graph Size\" , " << "\"Ensemble Size\" , " << "\"Scalar SpMM Time\" , " << "\"Scalar SpMM Speedup\" , " << "\"Scalar SpMM GFLOPS\" , " << "\"Block-Left SpMM Speedup\" , " << "\"Block-Left SpMM GFLOPS\" , " //<< "\"Block_Right SpMM Speedup\" , " //<< "\"Block_Right SpMM GFLOPS\" , " << std::endl; std::vector perf_scalar, perf_block_left, perf_block_right; for (Ordinal e=ensemble_min; e<=ensemble_max; e+=ensemble_step) { test_spmm( e, nGrid, nIter, perf_scalar, perf_block_left, perf_block_right ); std::cout << nGrid << " , " << perf_scalar[0] << " , " << perf_scalar[2] << " , " << perf_scalar[1] << " , " << perf_scalar[3] << " , " << perf_scalar[4] / perf_scalar[4] << " , " << perf_scalar[4] << " , " << perf_block_left[4]/ perf_scalar[4] << " , " << perf_block_left[4] << " , " //<< perf_block_right[4]/ perf_scalar[4] << " , " //<< perf_block_right[4] << " , " << std::endl; } }