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,
112 typedef Kokkos::Device<execution_space, typename execution_space::memory_space> device_type;
114 typedef Kokkos::LayoutRight Layout;
115 typedef Kokkos::View< VectorType*, Layout, execution_space > vector_type;
116 typedef KokkosSparse::CrsMatrix< VectorType, ordinal_type, device_type > matrix_type;
117 typedef typename matrix_type::StaticCrsGraphType matrix_graph_type;
118 typedef typename matrix_type::values_type matrix_values_type;
123 std::vector< std::vector<size_t> > fem_graph;
124 const size_t fem_length = nGrid * nGrid * nGrid;
131 vector_type(Kokkos::ViewAllocateWithoutInitializing(
"x"), fem_length, ensemble_length);
133 vector_type(Kokkos::ViewAllocateWithoutInitializing(
"y"), fem_length, ensemble_length);
137 matrix_graph_type matrix_graph =
138 Kokkos::create_staticcrsgraph<matrix_graph_type>(
139 std::string(
"test crs graph"), fem_graph);
140 matrix_values_type matrix_values =
141 matrix_values_type(Kokkos::ViewAllocateWithoutInitializing(
"matrix"), graph_length, ensemble_length);
142 matrix_type matrix(
"block_matrix", fem_length, matrix_values, matrix_graph);
143 matrix.dev_config = dev_config;
152 typename vector_type::array_type xx( x );
153 typename vector_type::array_type yy( y );
154 typename matrix_values_type::array_type mm( matrix_values );
167 Kokkos::Impl::Timer clock ;
168 for (
int iter = 0; iter < iterCount; ++iter) {
173 const double seconds_per_iter = clock.seconds() / ((
double) iterCount );
174 const double flops = 1.0e-9 * 2.0 * graph_length * ensemble_length;
176 std::vector<double> perf(5);
177 perf[0] = fem_length;
178 perf[1] = ensemble_length;
179 perf[2] = graph_length;
180 perf[3] = seconds_per_iter;
181 perf[4] = flops / seconds_per_iter;
185 template <
typename ScalarType,
typename OrdinalType,
typename Device>
190 KokkosSparse::DeviceConfig dev_config)
195 typedef Kokkos::Device<execution_space, typename execution_space::memory_space> device_type;
196 typedef Kokkos::View< value_type*, execution_space > vector_type;
197 typedef KokkosSparse::CrsMatrix< value_type, ordinal_type, device_type > matrix_type;
198 typedef typename matrix_type::StaticCrsGraphType matrix_graph_type;
199 typedef typename matrix_type::values_type matrix_values_type;
204 std::vector< std::vector<size_t> > fem_graph;
205 const size_t fem_length = nGrid * nGrid * nGrid;
211 std::vector<vector_type> x(ensemble_length);
212 std::vector<vector_type> y(ensemble_length);
213 for (
int e=0; e<ensemble_length; ++e) {
214 x[e] = vector_type(Kokkos::ViewAllocateWithoutInitializing(
"x"), fem_length);
215 y[e] = vector_type(Kokkos::ViewAllocateWithoutInitializing(
"y"), fem_length);
223 std::vector<matrix_type> matrix(ensemble_length);
224 for (
int e=0; e<ensemble_length; ++e) {
225 matrix_graph_type matrix_graph =
226 Kokkos::create_staticcrsgraph<matrix_graph_type>(
227 std::string(
"test crs graph"), fem_graph);
228 matrix_values_type matrix_values =
229 matrix_values_type(Kokkos::ViewAllocateWithoutInitializing(
"matrix"), graph_length);
230 matrix[e] = matrix_type(
"matrix", fem_length, matrix_values, matrix_graph);
238 for (
int iter = 0; iter < iterCount; ++iter) {
239 for (
int e=0; e<ensemble_length; ++e) {
245 Kokkos::Impl::Timer clock ;
246 for (
int iter = 0; iter < iterCount; ++iter) {
247 for (
int e=0; e<ensemble_length; ++e) {
253 const double seconds_per_iter = clock.seconds() / ((
double) iterCount );
254 const double flops = 1.0e-9 * 2.0 * graph_length * ensemble_length;
256 std::vector<double> perf(5);
257 perf[0] = fem_length;
258 perf[1] = ensemble_length;
259 perf[2] = graph_length;
260 perf[3] = seconds_per_iter;
261 perf[4] = flops / seconds_per_iter;
265 template <
class Storage>
274 KokkosSparse::DeviceConfig dev_config_) :
277 template <
typename ArgT>
279 const int ensemble = ArgT::value;
280 typedef typename Storage::template apply_N<ensemble> NewStorageApply;
283 const std::vector<double> perf_scalar =
284 test_scalar_spmv<Scalar,Ordinal,Device>(
287 const std::vector<double> perf_mpvector =
288 test_mpvector_spmv<storage_type>(
291 std::cout << nGrid <<
" , "
292 << perf_scalar[0] <<
" , "
293 << perf_scalar[2] <<
" , "
294 << perf_scalar[1] <<
" , "
295 << perf_scalar[3] <<
" , "
296 << perf_scalar[4] / perf_scalar[4] <<
" , "
297 << perf_scalar[4] <<
" , "
298 << perf_mpvector[4]/ perf_scalar[4] <<
" , "
299 << perf_mpvector[4] <<
" , "
304 template <
class Storage,
int entry_min,
int entry_max,
int entry_step>
307 KokkosSparse::DeviceConfig dev_config)
309 std::cout.precision(8);
310 std::cout << std::endl
311 <<
"\"Grid Size\" , "
313 <<
"\"FEM Graph Size\" , "
314 <<
"\"Ensemble Size\" , "
315 <<
"\"Scalar SpMv Time\" , "
316 <<
"\"Scalar SpMv Speedup\" , "
317 <<
"\"Scalar SpMv GFLOPS\" , "
318 <<
"\"MPVector SpMv Speedup\" , "
319 <<
"\"MPVector SpMv GFLOPS\" , "
323 typedef Sacado::mpl::range_c< int, entry_min, entry_max+1, entry_step > Range;
325 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)