/[escript]/trunk/cusplibrary/performance/spmv/bytes_per_spmv.h
ViewVC logotype

Contents of /trunk/cusplibrary/performance/spmv/bytes_per_spmv.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5148 - (show annotations)
Mon Sep 15 01:25:23 2014 UTC (6 years, 4 months ago) by caltinay
File MIME type: text/plain
File size: 2361 byte(s)
Merging ripley diagonal storage + CUDA support into trunk.
Options file version has been incremented due to new options
'cuda' and 'nvccflags'.

1 #pragma once
2
3 #include <cusp/coo_matrix.h>
4 #include <cusp/csr_matrix.h>
5 #include <cusp/dia_matrix.h>
6 #include <cusp/ell_matrix.h>
7 #include <cusp/hyb_matrix.h>
8
9 template <typename IndexType, typename ValueType>
10 size_t bytes_per_spmv(const cusp::dia_matrix<IndexType,ValueType,cusp::host_memory>& mtx)
11 {
12 // note: this neglects diag_offsets, which is < 1% of other parts
13 size_t bytes = 0;
14 bytes += 2*sizeof(ValueType) * mtx.num_entries; // A[i,j] and x[j]
15 bytes += 2*sizeof(ValueType) * mtx.num_rows; // y[i] = y[i] + ...
16 return bytes;
17 }
18
19 template <typename IndexType, typename ValueType>
20 size_t bytes_per_spmv(const cusp::ell_matrix<IndexType,ValueType,cusp::host_memory>& mtx)
21 {
22 size_t bytes = 0;
23 bytes += 1*sizeof(ValueType) * mtx.num_rows * mtx.values.num_cols; // A[i,j] and padding
24 bytes += 1*sizeof(IndexType) * mtx.num_entries; // column index
25 bytes += 1*sizeof(ValueType) * mtx.num_entries; // x[j]
26 bytes += 2*sizeof(ValueType) * mtx.num_rows; // y[i] = y[i] + ...
27 return bytes;
28 }
29
30 template <typename IndexType, typename ValueType>
31 size_t bytes_per_spmv(const cusp::csr_matrix<IndexType,ValueType,cusp::host_memory>& mtx)
32 {
33 size_t bytes = 0;
34 bytes += 2*sizeof(IndexType) * mtx.num_rows; // row pointer
35 bytes += 1*sizeof(IndexType) * mtx.num_entries; // column index
36 bytes += 2*sizeof(ValueType) * mtx.num_entries; // A[i,j] and x[j]
37 bytes += 2*sizeof(ValueType) * mtx.num_rows; // y[i] = y[i] + ...
38 return bytes;
39 }
40
41 template <typename IndexType, typename ValueType>
42 size_t bytes_per_spmv(const cusp::coo_matrix<IndexType,ValueType,cusp::host_memory>& mtx)
43 {
44 size_t bytes = 0;
45 bytes += 2*sizeof(IndexType) * mtx.num_entries; // row and column indices
46 bytes += 2*sizeof(ValueType) * mtx.num_entries; // A[i,j] and x[j]
47
48 std::vector<size_t> occupied_rows(mtx.num_rows, 0);
49 for(size_t n = 0; n < mtx.num_entries; n++)
50 occupied_rows[mtx.row_indices[n]] = 1;
51 for(size_t n = 0; n < mtx.num_rows; n++)
52 if(occupied_rows[n] == 1)
53 bytes += 2*sizeof(ValueType); // y[i] = y[i] + ...
54 return bytes;
55 }
56
57 template <typename IndexType, typename ValueType>
58 size_t bytes_per_spmv(const cusp::hyb_matrix<IndexType,ValueType,cusp::host_memory>& mtx)
59 {
60 return bytes_per_spmv(mtx.ell) + bytes_per_spmv(mtx.coo);
61 }
62

  ViewVC Help
Powered by ViewVC 1.1.26