13 #include "KokkosSparse_CrsMatrix.hpp"
14 #include "KokkosSparse_spmv.hpp"
18 #include "Kokkos_Timer.hpp"
20 template<
typename IntType >
27 return k + N * ( j + N * i );
32 std::vector< std::vector<size_t> > & graph )
34 graph.resize( N * N * N , std::vector<size_t>() );
38 for (
int i = 0 ; i < (int) N ; ++i ) {
39 for (
int j = 0 ;
j < (int) N ; ++
j ) {
40 for (
int k = 0 ; k < (int) N ; ++k ) {
44 graph[row].reserve(27);
46 for (
int ii = -1 ; ii < 2 ; ++ii ) {
47 for (
int jj = -1 ; jj < 2 ; ++jj ) {
48 for (
int kk = -1 ; kk < 2 ; ++kk ) {
49 if ( 0 <= i + ii && i + ii < (
int) N &&
50 0 <=
j + jj &&
j + jj < (
int) N &&
51 0 <= k + kk && k + kk < (
int) N ) {
54 graph[row].push_back(col);
57 total += graph[row].size();
63 template <
typename ScalarType,
typename OrdinalType,
typename Device>
66 const OrdinalType nGrid,
67 const OrdinalType iterCount,
68 std::vector<double>& scalar_perf,
69 std::vector<double>& block_left_perf,
70 std::vector<double>& block_right_perf)
75 typedef Kokkos::View< value_type*, execution_space > vector_type;
76 typedef Kokkos::View< value_type**, Kokkos::LayoutLeft, execution_space > left_multivec_type;
78 typedef KokkosSparse::CrsMatrix< value_type, ordinal_type, execution_space > matrix_type;
79 typedef typename matrix_type::StaticCrsGraphType matrix_graph_type;
80 typedef typename matrix_type::values_type matrix_values_type;
85 std::vector< std::vector<size_t> > fem_graph;
86 const size_t fem_length = nGrid * nGrid * nGrid;
92 std::vector<vector_type> x(ensemble_length);
93 std::vector<vector_type> y(ensemble_length);
94 for (ordinal_type e=0; e<ensemble_length; ++e) {
95 x[e] = vector_type(Kokkos::ViewAllocateWithoutInitializing(
"x"), fem_length);
96 y[e] = vector_type(Kokkos::ViewAllocateWithoutInitializing(
"y"), fem_length);
101 left_multivec_type xl(Kokkos::ViewAllocateWithoutInitializing(
"xl"), fem_length, ensemble_length);
102 left_multivec_type yl(Kokkos::ViewAllocateWithoutInitializing(
"yl"), fem_length, ensemble_length);
113 matrix_graph_type matrix_graph =
114 Kokkos::create_staticcrsgraph<matrix_graph_type>(
115 std::string(
"test crs graph"), fem_graph);
116 matrix_values_type matrix_values =
117 matrix_values_type(Kokkos::ViewAllocateWithoutInitializing(
"matrix"), graph_length);
118 matrix_type matrix(
"matrix", fem_length, matrix_values, matrix_graph);
126 for (ordinal_type iter = 0; iter < iterCount; ++iter) {
127 for (ordinal_type e=0; e<ensemble_length; ++e) {
133 Kokkos::Timer clock ;
134 for (ordinal_type iter = 0; iter < iterCount; ++iter) {
135 for (ordinal_type e=0; e<ensemble_length; ++e) {
141 const double seconds_per_iter = clock.seconds() / ((
double) iterCount );
142 const double flops = 1.0e-9 * 2.0 * graph_length * ensemble_length;
144 scalar_perf.resize(5);
145 scalar_perf[0] = fem_length;
146 scalar_perf[1] = ensemble_length;
147 scalar_perf[2] = graph_length;
148 scalar_perf[3] = seconds_per_iter;
149 scalar_perf[4] = flops / seconds_per_iter;
157 for (ordinal_type iter = 0; iter < iterCount; ++iter) {
162 Kokkos::Timer clock ;
163 for (ordinal_type iter = 0; iter < iterCount; ++iter) {
168 const double seconds_per_iter = clock.seconds() / ((
double) iterCount );
169 const double flops = 1.0e-9 * 2.0 * graph_length * ensemble_length;
171 block_left_perf.resize(5);
172 block_left_perf[0] = fem_length;
173 block_left_perf[1] = ensemble_length;
174 block_left_perf[2] = graph_length;
175 block_left_perf[3] = seconds_per_iter;
176 block_left_perf[4] = flops / seconds_per_iter;
185 for (ordinal_type iter = 0; iter < iterCount; ++iter) {
190 Kokkos::Timer clock ;
191 for (ordinal_type iter = 0; iter < iterCount; ++iter) {
196 const double seconds_per_iter = clock.seconds() / ((
double) iterCount );
197 const double flops = 1.0e-9 * 2.0 * graph_length * ensemble_length;
199 block_right_perf.resize(5);
200 block_right_perf[0] = fem_length;
201 block_right_perf[1] = ensemble_length;
202 block_right_perf[2] = graph_length;
203 block_right_perf[3] = seconds_per_iter;
204 block_right_perf[4] = flops / seconds_per_iter;
210 template <
typename Scalar,
typename Ordinal,
typename Device>
217 std::cout.precision(8);
218 std::cout << std::endl
219 <<
"\"Grid Size\" , "
221 <<
"\"FEM Graph Size\" , "
222 <<
"\"Ensemble Size\" , "
223 <<
"\"Scalar SpMM Time\" , "
224 <<
"\"Scalar SpMM Speedup\" , "
225 <<
"\"Scalar SpMM GFLOPS\" , "
226 <<
"\"Block-Left SpMM Speedup\" , "
227 <<
"\"Block-Left SpMM GFLOPS\" , "
232 std::vector<double> perf_scalar, perf_block_left, perf_block_right;
233 for (
Ordinal e=ensemble_min; e<=ensemble_max; e+=ensemble_step) {
235 test_spmm<Scalar,Ordinal,Device>(
236 e, nGrid, nIter, perf_scalar, perf_block_left, perf_block_right );
238 std::cout << nGrid <<
" , "
239 << perf_scalar[0] <<
" , "
240 << perf_scalar[2] <<
" , "
241 << perf_scalar[1] <<
" , "
242 << perf_scalar[3] <<
" , "
243 << perf_scalar[4] / perf_scalar[4] <<
" , "
244 << perf_scalar[4] <<
" , "
245 << perf_block_left[4]/ perf_scalar[4] <<
" , "
246 << perf_block_left[4] <<
" , "
ordinal generate_fem_graph(ordinal N, std::vector< std::vector< ordinal > > &graph)
void test_spmm(const OrdinalType ensemble_length, const OrdinalType nGrid, const OrdinalType iterCount, std::vector< double > &scalar_perf, std::vector< double > &block_left_perf, std::vector< double > &block_right_perf)
Kokkos::DefaultExecutionSpace execution_space
IntType map_fem_graph_coord(const IntType &N, const IntType &i, const IntType &j, const IntType &k)
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)
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(KokkosKernels::Experimental::Controls, 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)