File: bytes_per_spmv.h

package info (click to toggle)
python-escript 5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 87,772 kB
  • ctags: 49,550
  • sloc: python: 585,488; cpp: 133,173; ansic: 18,675; xml: 3,283; sh: 690; makefile: 215
file content (62 lines) | stat: -rw-r--r-- 2,361 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#include <cusp/coo_matrix.h>
#include <cusp/csr_matrix.h>
#include <cusp/dia_matrix.h>
#include <cusp/ell_matrix.h>
#include <cusp/hyb_matrix.h>
    
template <typename IndexType, typename ValueType>
size_t bytes_per_spmv(const cusp::dia_matrix<IndexType,ValueType,cusp::host_memory>& mtx)
{
    // note: this neglects diag_offsets, which is < 1% of other parts
    size_t bytes = 0;
    bytes += 2*sizeof(ValueType) * mtx.num_entries;  // A[i,j] and x[j]
    bytes += 2*sizeof(ValueType) * mtx.num_rows;     // y[i] = y[i] + ...
    return bytes;
}

template <typename IndexType, typename ValueType>
size_t bytes_per_spmv(const cusp::ell_matrix<IndexType,ValueType,cusp::host_memory>& mtx)
{
    size_t bytes = 0;
    bytes += 1*sizeof(ValueType) * mtx.num_rows * mtx.values.num_cols; // A[i,j] and padding
    bytes += 1*sizeof(IndexType) * mtx.num_entries;  // column index
    bytes += 1*sizeof(ValueType) * mtx.num_entries;  // x[j]
    bytes += 2*sizeof(ValueType) * mtx.num_rows;     // y[i] = y[i] + ...
    return bytes;
}

template <typename IndexType, typename ValueType>
size_t bytes_per_spmv(const cusp::csr_matrix<IndexType,ValueType,cusp::host_memory>& mtx)
{
    size_t bytes = 0;
    bytes += 2*sizeof(IndexType) * mtx.num_rows;     // row pointer
    bytes += 1*sizeof(IndexType) * mtx.num_entries;  // column index
    bytes += 2*sizeof(ValueType) * mtx.num_entries;  // A[i,j] and x[j]
    bytes += 2*sizeof(ValueType) * mtx.num_rows;     // y[i] = y[i] + ...
    return bytes;
}

template <typename IndexType, typename ValueType>
size_t bytes_per_spmv(const cusp::coo_matrix<IndexType,ValueType,cusp::host_memory>& mtx)
{
    size_t bytes = 0;
    bytes += 2*sizeof(IndexType) * mtx.num_entries; // row and column indices
    bytes += 2*sizeof(ValueType) * mtx.num_entries; // A[i,j] and x[j]

    std::vector<size_t> occupied_rows(mtx.num_rows, 0);
    for(size_t n = 0; n < mtx.num_entries; n++)
        occupied_rows[mtx.row_indices[n]] = 1;
    for(size_t n = 0; n < mtx.num_rows; n++)
        if(occupied_rows[n] == 1)
            bytes += 2*sizeof(ValueType);            // y[i] = y[i] + ...
    return bytes;
}

template <typename IndexType, typename ValueType>
size_t bytes_per_spmv(const cusp::hyb_matrix<IndexType,ValueType,cusp::host_memory>& mtx)
{
    return bytes_per_spmv(mtx.ell) + bytes_per_spmv(mtx.coo);
}