45 #include "KokkosSparse_CrsMatrix.hpp"
46 #include "KokkosSparse_spmv.hpp"
50 #include "Sacado_mpl_range_c.hpp"
51 #include "Sacado_mpl_for_each.hpp"
52 #include "Sacado_mpl_integral_c.hpp"
55 #include "impl/Kokkos_Timer.hpp"
57 template<
typename IntType >
64 return k + N * ( j + N * i );
69 std::vector< std::vector<size_t> > & graph )
71 graph.resize( N * N * N , std::vector<size_t>() );
75 for (
int i = 0 ; i < (
int) N ; ++i ) {
76 for (
int j = 0 ;
j < (
int) N ; ++
j ) {
77 for (
int k = 0 ; k < (
int) N ; ++k ) {
81 graph[row].reserve(27);
83 for (
int ii = -1 ; ii < 2 ; ++ii ) {
84 for (
int jj = -1 ; jj < 2 ; ++jj ) {
85 for (
int kk = -1 ; kk < 2 ; ++kk ) {
86 if ( 0 <= i + ii && i + ii < (
int) N &&
87 0 <=
j + jj &&
j + jj < (
int) N &&
88 0 <= k + kk && k + kk < (
int) N ) {
91 graph[row].push_back(col);
94 total += graph[row].size();
100 template <
typename StorageType,
typename MultiplyTag>
105 KokkosSparse::DeviceConfig dev_config,
113 typedef Kokkos::LayoutRight Layout;
114 typedef Kokkos::View< VectorType*, Layout, execution_space > vector_type;
115 typedef KokkosSparse::CrsMatrix< VectorType, ordinal_type, execution_space > matrix_type;
116 typedef typename matrix_type::StaticCrsGraphType matrix_graph_type;
117 typedef typename matrix_type::values_type matrix_values_type;
122 std::vector< std::vector<size_t> > fem_graph;
123 const size_t fem_length = nGrid * nGrid * nGrid;
130 vector_type(Kokkos::ViewAllocateWithoutInitializing(
"x"), fem_length, ensemble_length);
132 vector_type(Kokkos::ViewAllocateWithoutInitializing(
"y"), fem_length, ensemble_length);
136 matrix_graph_type matrix_graph =
137 Kokkos::create_staticcrsgraph<matrix_graph_type>(
138 std::string(
"test crs graph"), fem_graph);
139 matrix_values_type matrix_values =
140 matrix_values_type(Kokkos::ViewAllocateWithoutInitializing(
"matrix"), graph_length, ensemble_length);
141 matrix_type matrix(
"block_matrix", fem_length, matrix_values, matrix_graph);
142 matrix.dev_config = dev_config;
151 typename vector_type::array_type xx( x );
152 typename vector_type::array_type yy( y );
153 typename matrix_values_type::array_type mm( matrix_values );
165 execution_space::fence();
166 Kokkos::Impl::Timer clock ;
167 for (
int iter = 0; iter < iterCount; ++iter) {
170 execution_space::fence();
172 const double seconds_per_iter = clock.seconds() / ((
double) iterCount );
173 const double flops = 1.0e-9 * 2.0 * graph_length * ensemble_length;
175 std::vector<double> perf(5);
176 perf[0] = fem_length;
177 perf[1] = ensemble_length;
178 perf[2] = graph_length;
179 perf[3] = seconds_per_iter;
180 perf[4] = flops / seconds_per_iter;
184 template <
typename ScalarType,
typename OrdinalType,
typename Device>
189 KokkosSparse::DeviceConfig dev_config)
194 typedef Kokkos::View< value_type*, execution_space > vector_type;
195 typedef KokkosSparse::CrsMatrix< value_type, ordinal_type, execution_space > matrix_type;
196 typedef typename matrix_type::StaticCrsGraphType matrix_graph_type;
197 typedef typename matrix_type::values_type matrix_values_type;
202 std::vector< std::vector<size_t> > fem_graph;
203 const size_t fem_length = nGrid * nGrid * nGrid;
209 std::vector<vector_type> x(ensemble_length);
210 std::vector<vector_type> y(ensemble_length);
211 for (
int e=0; e<ensemble_length; ++e) {
212 x[e] = vector_type(Kokkos::ViewAllocateWithoutInitializing(
"x"), fem_length);
213 y[e] = vector_type(Kokkos::ViewAllocateWithoutInitializing(
"y"), fem_length);
221 std::vector<matrix_type> matrix(ensemble_length);
222 for (
int e=0; e<ensemble_length; ++e) {
223 matrix_graph_type matrix_graph =
224 Kokkos::create_staticcrsgraph<matrix_graph_type>(
225 std::string(
"test crs graph"), fem_graph);
226 matrix_values_type matrix_values =
227 matrix_values_type(Kokkos::ViewAllocateWithoutInitializing(
"matrix"), graph_length);
228 matrix[e] = matrix_type(
"matrix", fem_length, matrix_values, matrix_graph);
236 for (
int iter = 0; iter < iterCount; ++iter) {
237 for (
int e=0; e<ensemble_length; ++e) {
242 execution_space::fence();
243 Kokkos::Impl::Timer clock ;
244 for (
int iter = 0; iter < iterCount; ++iter) {
245 for (
int e=0; e<ensemble_length; ++e) {
249 execution_space::fence();
251 const double seconds_per_iter = clock.seconds() / ((
double) iterCount );
252 const double flops = 1.0e-9 * 2.0 * graph_length * ensemble_length;
254 std::vector<double> perf(5);
255 perf[0] = fem_length;
256 perf[1] = ensemble_length;
257 perf[2] = graph_length;
258 perf[3] = seconds_per_iter;
259 perf[4] = flops / seconds_per_iter;
263 template <
class Storage>
272 KokkosSparse::DeviceConfig dev_config_) :
275 template <
typename ArgT>
277 const int ensemble = ArgT::value;
278 typedef typename Storage::template apply_N<ensemble> NewStorageApply;
281 const std::vector<double> perf_scalar =
282 test_scalar_spmv<Scalar,Ordinal,Device>(
285 const std::vector<double> perf_mpvector =
286 test_mpvector_spmv<storage_type>(
289 std::cout << nGrid <<
" , "
290 << perf_scalar[0] <<
" , "
291 << perf_scalar[2] <<
" , "
292 << perf_scalar[1] <<
" , "
293 << perf_scalar[3] <<
" , "
294 << perf_scalar[4] / perf_scalar[4] <<
" , "
295 << perf_scalar[4] <<
" , "
296 << perf_mpvector[4]/ perf_scalar[4] <<
" , "
297 << perf_mpvector[4] <<
" , "
302 template <
class Storage,
int entry_min,
int entry_max,
int entry_step>
305 KokkosSparse::DeviceConfig dev_config)
307 std::cout.precision(8);
308 std::cout << std::endl
309 <<
"\"Grid Size\" , "
311 <<
"\"FEM Graph Size\" , "
312 <<
"\"Ensemble Size\" , "
313 <<
"\"Scalar SpMv Time\" , "
314 <<
"\"Scalar SpMv Speedup\" , "
315 <<
"\"Scalar SpMv GFLOPS\" , "
316 <<
"\"MPVector SpMv Speedup\" , "
317 <<
"\"MPVector SpMv GFLOPS\" , "
321 typedef Sacado::mpl::range_c< int, entry_min, entry_max+1, entry_step > Range;
323 Sacado::mpl::for_each_no_kokkos<Range>
f(op);
Stokhos::StandardStorage< int, double > storage_type
ordinal generate_fem_graph(ordinal N, std::vector< std::vector< ordinal > > &graph)
Stokhos_MV_Multiply_Op< Stokhos::DefaultMultiply > DefaultMultiply
Kokkos::DefaultExecutionSpace execution_space
std::vector< double > test_scalar_spmv(const int ensemble_length, const int nGrid, const int iterCount, KokkosSparse::DeviceConfig dev_config)
IntType map_fem_graph_coord(const IntType &N, const IntType &i, const IntType &j, const IntType &k)
void multiply(const CrsMatrix< MatrixValue, Device, Layout > &A, const InputMultiVectorType &x, OutputMultiVectorType &y, const std::vector< OrdinalType > &col_indices, SingleColumnMultivectorMultiply)
std::vector< double > test_mpvector_spmv(const int ensemble_length, const int nGrid, const int iterCount, KokkosSparse::DeviceConfig dev_config, MultiplyTag tag)
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
void performance_test_driver(const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const int use_print, const int use_trials, const int use_nodes[], const bool check, Kokkos::Example::FENL::DeviceConfig dev_config)
ScalarType f(const Teuchos::Array< ScalarType > &x, double a, double b)
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< InputType, InputP... > >::value &&Kokkos::is_view_uq_pce< Kokkos::View< OutputType, OutputP... > >::value >::type spmv(const char mode[], const AlphaType &a, const MatrixType &A, const Kokkos::View< InputType, InputP... > &x, const BetaType &b, const Kokkos::View< OutputType, OutputP... > &y, const RANK_ONE)