-
Notifications
You must be signed in to change notification settings - Fork 1
/
sparse_kernels.h
101 lines (90 loc) · 2.16 KB
/
sparse_kernels.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef SPARSE_KERNELS_H
#define SPARSE_KERNELS_H
#include <vector>
#include <utility>
#include "common.h"
#include "SpmatLocal.hpp"
#include <Eigen/Dense>
using namespace std;
typedef enum {k_sddmmA, k_spmmA, k_spmmB, k_sddmmB} KernelMode;
class KernelImplementation {
public:
// Performs an operation that looks like a local SDDMM
// and returns the number of nonzeros processed
virtual size_t sddmm_local(
SpmatLocal &S,
DenseMatrix &A,
DenseMatrix &B,
int block,
int offset
) = 0;
/*
* S is m x n
* A is m x r
* B is n x r
* When mode is 0, A = S B (output is A)
* When mode is 1, B = S^T A (output is B)
*
*/
virtual size_t spmm_local(
SpmatLocal &S,
DenseMatrix &A,
DenseMatrix &B,
MatMode mode,
int block) = 0;
size_t triple_function(
KernelMode mode,
SpmatLocal &S,
DenseMatrix &localA,
DenseMatrix &localB,
int block,
int offset
) {
size_t nnz_processed = 0;
if(mode == k_sddmmA || mode == k_sddmmB) {
nnz_processed += sddmm_local(
S,
localA,
localB,
block,
offset
);
}
else if(mode == k_spmmA) {
nnz_processed += spmm_local(
S,
localA,
localB,
Amat,
block);
}
else if(mode == k_spmmB) {
nnz_processed += spmm_local(
S,
localA,
localB,
Bmat,
block);
}
return nnz_processed;
}
};
/*
* Exactly the algebra on the box, no funny business.
*/
class StandardKernel : public KernelImplementation {
public:
virtual size_t sddmm_local(
SpmatLocal &S,
DenseMatrix &A,
DenseMatrix &B,
int block,
int offset);
size_t spmm_local(
SpmatLocal &S,
DenseMatrix &A,
DenseMatrix &B,
MatMode mode,
int block);
};
#endif