Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
CuspSpMM/TestSpMM.cpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Stokhos Package
5// Copyright (2009) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38//
39// ***********************************************************************
40// @HEADER
41
42#include <iostream>
43
44// CUSP
45#include <cusp/array2d.h>
46#include <cusp/csr_matrix.h>
47#include <cusp/MVmultiply.h>
48#include <cusp/gallery/poisson.h>
49#include <cusp/detail/timer.h>
50
51// Utilities
52#include "Teuchos_CommandLineProcessor.hpp"
53#include "Teuchos_StandardCatchMacros.hpp"
54
55int main(int argc, char *argv[])
56{
57 typedef int IndexType;
58 typedef double ValueType;
59 typedef cusp::device_memory MemorySpace;
60 //typedef cusp::row_major Orientation;
61
62 bool success = true;
63 bool verbose = false;
64 try {
65
66 // Setup command line options
67 Teuchos::CommandLineProcessor CLP;
68 CLP.setDocString("This test performance of block multiply routines.\n");
69 IndexType n = 32;
70 CLP.setOption("n", &n, "Number of mesh points in the each direction");
71 IndexType nrhs_begin = 32;
72 CLP.setOption("begin", &nrhs_begin,
73 "Staring number of right-hand-sides");
74 IndexType nrhs_end = 512;
75 CLP.setOption("end", &nrhs_end,
76 "Ending number of right-hand-sides");
77 IndexType nrhs_step = 32;
78 CLP.setOption("step", &nrhs_step,
79 "Increment in number of right-hand-sides");
80 IndexType nits = 10;
81 CLP.setOption("nits", &nits,
82 "Number of multiply iterations");
83 int device_id = 0;
84 CLP.setOption("device", &device_id, "CUDA device ID");
85 CLP.parse( argc, argv );
86
87 // Set CUDA device
88 cudaSetDevice(device_id);
89 cudaDeviceSetSharedMemConfig(cudaSharedMemBankSizeEightByte);
90
91 // create 3D Poisson problem
92 cusp::csr_matrix<IndexType, ValueType, MemorySpace> A;
93 cusp::gallery::poisson27pt(A, n, n, n);
94
95 std::cout << "nrhs , num_rows , num_entries , row_time , row_gflops , "
96 << "col_time , col_gflops" << std::endl;
97
98 for (IndexType nrhs = nrhs_begin; nrhs <= nrhs_end; nrhs += nrhs_step) {
99
100 double flops =
101 2.0 * static_cast<double>(A.num_entries) * static_cast<double>(nrhs);
102
103 // test row-major storage
104 cusp::array2d<ValueType, MemorySpace, cusp::row_major> x_row(
105 A.num_rows, nrhs, 1);
106 cusp::array2d<ValueType, MemorySpace, cusp::row_major> y_row(
107 A.num_rows, nrhs, 0);
108
109 cusp::detail::timer row_timer;
110 row_timer.start();
111 for (IndexType iter=0; iter<nits; ++iter) {
112 cusp::MVmultiply(A, x_row, y_row);
113 }
114 cudaDeviceSynchronize();
115 double row_time = row_timer.seconds_elapsed() / nits;
116 double row_gflops = 1.0e-9 * flops / row_time;
117
118 // test column-major storage
119 cusp::array2d<ValueType, MemorySpace, cusp::column_major> x_col(
120 A.num_rows, nrhs, 1);
121 cusp::array2d<ValueType, MemorySpace, cusp::column_major> y_col(
122 A.num_rows, nrhs, 0);
123
124 cusp::detail::timer col_timer;
125 col_timer.start();
126 for (IndexType iter=0; iter<nits; ++iter) {
127 cusp::MVmultiply(A, x_col, y_col);
128 }
129 cudaDeviceSynchronize();
130 double col_time = col_timer.seconds_elapsed() / nits;
131 double col_gflops = 1.0e-9 * flops / col_time;
132
133 std::cout << nrhs << " , "
134 << A.num_rows << " , " << A.num_entries << " , "
135 << row_time << " , " << row_gflops << " , "
136 << col_time << " , " << col_gflops
137 << std::endl;
138
139 }
140
141 }
142 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
143
144 if (success)
145 return 0;
146 return -1;
147}
int main(int argc, char *argv[])
void MVmultiply(LinearOperator &A, MatrixOrVector1 &B, MatrixOrVector2 &C)