45 #include "Kokkos_Sparse_CrsMatrix.hpp" 49 #include "Sacado_mpl_range_c.hpp" 50 #include "Sacado_mpl_for_each.hpp" 51 #include "Sacado_mpl_integral_c.hpp" 54 #include "impl/Kokkos_Timer.hpp" 56 template<
typename IntType >
63 return k + N * (
j + N * i );
68 std::vector< std::vector<size_t> > & graph )
70 graph.resize( N * N * N , std::vector<size_t>() );
74 for (
int i = 0 ; i < (
int) N ; ++i ) {
75 for (
int j = 0 ;
j < (
int) N ; ++
j ) {
76 for (
int k = 0 ; k < (
int) N ; ++k ) {
80 graph[row].reserve(27);
82 for (
int ii = -1 ; ii < 2 ; ++ii ) {
83 for (
int jj = -1 ; jj < 2 ; ++jj ) {
84 for (
int kk = -1 ; kk < 2 ; ++kk ) {
85 if ( 0 <= i + ii && i + ii < (
int) N &&
86 0 <=
j + jj &&
j + jj < (
int) N &&
87 0 <= k + kk && k + kk < (
int) N ) {
90 graph[row].push_back(col);
93 total += graph[row].size();
99 template <
typename StorageType,
typename MultiplyTag>
104 Kokkos::DeviceConfig dev_config,
112 typedef Kokkos::LayoutRight Layout;
113 typedef Kokkos::View< VectorType*, Layout, execution_space > vector_type;
114 typedef Kokkos::CrsMatrix< VectorType, ordinal_type, execution_space > matrix_type;
115 typedef typename matrix_type::StaticCrsGraphType matrix_graph_type;
116 typedef typename matrix_type::values_type matrix_values_type;
121 std::vector< std::vector<size_t> > fem_graph;
122 const size_t fem_length = nGrid * nGrid * nGrid;
129 vector_type(Kokkos::ViewAllocateWithoutInitializing(
"x"), fem_length, ensemble_length);
131 vector_type(Kokkos::ViewAllocateWithoutInitializing(
"y"), fem_length, ensemble_length);
135 matrix_graph_type matrix_graph =
136 Kokkos::create_staticcrsgraph<matrix_graph_type>(
137 std::string(
"test crs graph"), fem_graph);
138 matrix_values_type matrix_values =
139 matrix_values_type(Kokkos::ViewAllocateWithoutInitializing(
"matrix"), graph_length, ensemble_length);
140 matrix_type matrix(
"block_matrix", fem_length, matrix_values, matrix_graph);
141 matrix.dev_config = dev_config;
150 typename vector_type::array_type xx(
x );
151 typename vector_type::array_type yy(
y );
152 typename matrix_values_type::array_type mm( matrix_values );
164 execution_space::fence();
165 Kokkos::Impl::Timer clock ;
166 for (
int iter = 0; iter < iterCount; ++iter) {
169 execution_space::fence();
171 const double seconds_per_iter = clock.seconds() / ((
double) iterCount );
172 const double flops = 1.0e-9 * 2.0 * graph_length * ensemble_length;
174 std::vector<double> perf(5);
175 perf[0] = fem_length;
176 perf[1] = ensemble_length;
177 perf[2] = graph_length;
178 perf[3] = seconds_per_iter;
179 perf[4] = flops / seconds_per_iter;
183 template <
typename ScalarType,
typename OrdinalType,
typename Device>
188 Kokkos::DeviceConfig dev_config)
193 typedef Kokkos::View< value_type*, execution_space > vector_type;
194 typedef Kokkos::CrsMatrix< value_type, ordinal_type, execution_space > matrix_type;
195 typedef typename matrix_type::StaticCrsGraphType matrix_graph_type;
196 typedef typename matrix_type::values_type matrix_values_type;
201 std::vector< std::vector<size_t> > fem_graph;
202 const size_t fem_length = nGrid * nGrid * nGrid;
208 std::vector<vector_type>
x(ensemble_length);
209 std::vector<vector_type>
y(ensemble_length);
210 for (
int e=0; e<ensemble_length; ++e) {
211 x[e] = vector_type(Kokkos::ViewAllocateWithoutInitializing(
"x"), fem_length);
212 y[e] = vector_type(Kokkos::ViewAllocateWithoutInitializing(
"y"), fem_length);
220 std::vector<matrix_type> matrix(ensemble_length);
221 for (
int e=0; e<ensemble_length; ++e) {
222 matrix_graph_type matrix_graph =
223 Kokkos::create_staticcrsgraph<matrix_graph_type>(
224 std::string(
"test crs graph"), fem_graph);
225 matrix_values_type matrix_values =
226 matrix_values_type(Kokkos::ViewAllocateWithoutInitializing(
"matrix"), graph_length);
227 matrix[e] = matrix_type(
"matrix", fem_length, matrix_values, matrix_graph);
235 for (
int iter = 0; iter < iterCount; ++iter) {
236 for (
int e=0; e<ensemble_length; ++e) {
241 execution_space::fence();
242 Kokkos::Impl::Timer clock ;
243 for (
int iter = 0; iter < iterCount; ++iter) {
244 for (
int e=0; e<ensemble_length; ++e) {
248 execution_space::fence();
250 const double seconds_per_iter = clock.seconds() / ((
double) iterCount );
251 const double flops = 1.0e-9 * 2.0 * graph_length * ensemble_length;
253 std::vector<double> perf(5);
254 perf[0] = fem_length;
255 perf[1] = ensemble_length;
256 perf[2] = graph_length;
257 perf[3] = seconds_per_iter;
258 perf[4] = flops / seconds_per_iter;
262 template <
class Storage>
271 Kokkos::DeviceConfig dev_config_) :
274 template <
typename ArgT>
276 const int ensemble = ArgT::value;
277 typedef typename Storage::template apply_N<ensemble> NewStorageApply;
280 const std::vector<double> perf_scalar =
281 test_scalar_spmv<Scalar,Ordinal,Device>(
284 const std::vector<double> perf_mpvector =
285 test_mpvector_spmv<storage_type>(
288 std::cout <<
nGrid <<
" , " 289 << perf_scalar[0] <<
" , " 290 << perf_scalar[2] <<
" , " 291 << perf_scalar[1] <<
" , " 292 << perf_scalar[3] <<
" , " 293 << perf_scalar[4] / perf_scalar[4] <<
" , " 294 << perf_scalar[4] <<
" , " 295 << perf_mpvector[4]/ perf_scalar[4] <<
" , " 296 << perf_mpvector[4] <<
" , " 301 template <
class Storage,
int entry_min,
int entry_max,
int entry_step>
304 Kokkos::DeviceConfig dev_config)
306 std::cout.precision(8);
307 std::cout << std::endl
308 <<
"\"Grid Size\" , " 310 <<
"\"FEM Graph Size\" , " 311 <<
"\"Ensemble Size\" , " 312 <<
"\"Scalar SpMv Time\" , " 313 <<
"\"Scalar SpMv Speedup\" , " 314 <<
"\"Scalar SpMv GFLOPS\" , " 315 <<
"\"MPVector SpMv Speedup\" , " 316 <<
"\"MPVector SpMv GFLOPS\" , " 320 typedef Sacado::mpl::range_c< int, entry_min, entry_max+1, entry_step > Range;
322 Sacado::mpl::for_each_no_kokkos<Range>
f(op);
Stokhos::StandardStorage< int, double > storage_type
Stokhos_MV_Multiply_Op< Stokhos::DefaultMultiply > DefaultMultiply
Kokkos::DefaultExecutionSpace execution_space
void multiply(const CrsMatrix< MatrixValue, Device, Layout > &A, const InputMultiVectorType &x, OutputMultiVectorType &y, const std::vector< OrdinalType > &col_indices, SingleColumnMultivectorMultiply)
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
IntType map_fem_graph_coord(const IntType &N, const IntType &i, const IntType &j, const IntType &k)
void performance_test_driver(const int nGrid, const int nIter, Kokkos::DeviceConfig dev_config)
size_t generate_fem_graph(size_t N, std::vector< std::vector< size_t > > &graph)
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
std::vector< double > test_scalar_spmv(const int ensemble_length, const int nGrid, const int iterCount, Kokkos::DeviceConfig dev_config)
ScalarType f(const Teuchos::Array< ScalarType > &x, double a, double b)
std::vector< double > test_mpvector_spmv(const int ensemble_length, const int nGrid, const int iterCount, Kokkos::DeviceConfig dev_config, MultiplyTag tag)
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType ValueType * y
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)