-
Notifications
You must be signed in to change notification settings - Fork 3
/
poski-bench.h
162 lines (135 loc) · 6.39 KB
/
poski-bench.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "taco/tensor.h"
using namespace taco;
using namespace std;
#ifdef POSKI
extern "C" {
#include <poski/poski.h>
}
void tacoToPOSKI(const Tensor<double>& src, poski_mat_t& dst, bool transpose = false) {
int rows=src.getDimension(0);
int cols=src.getDimension(1);
// convert to CSR
Tensor<double> ACSR({rows,cols}, CSR);
for (auto& value : iterate<double>(src)) {
int i = transpose ? value.first.at(1) : value.first.at(0);
int j = transpose ? value.first.at(0) : value.first.at(1);
ACSR.insert({i,j},value.second);
}
ACSR.pack();
double *a_CSR;
int* ia_CSR;
int* ja_CSR;
getCSRArrays(ACSR,&ia_CSR,&ja_CSR,&a_CSR);
// default thread object
poski_threadarg_t *poski_thread = poski_InitThreads();
poski_ThreadHints(poski_thread, NULL, POSKI_OPENMP, 12);
poski_partitionarg_t *mat_partition = NULL;
// create CSR matrix
dst = poski_CreateMatCSR(ia_CSR, ja_CSR, a_CSR,
rows, cols, ACSR.getStorage().getValues().getSize(),
COPY_INPUTMAT, // greatest flexibility in tuning
poski_thread, mat_partition, 2, INDEX_ZERO_BASED, MAT_GENERAL);
}
void tacoToPOSKI(const Tensor<double>& src, poski_vec_t& dst) {
int cols=src.getDimension(0);
dst = poski_CreateVec((double*)(src.getStorage().getValues().getData()),
cols, STRIDE_UNIT, NULL);
}
void exprToPOSKI(BenchExpr Expr, map<string,Tensor<double>> exprOperands,int repeat, taco::util::TimeResults timevalue) {
switch(Expr) {
case SpMV: {
int rows=exprOperands.at("A").getDimension(0);
int cols=exprOperands.at("A").getDimension(1);
// Adding extras to let POSKI tune
int extra = 0;
if (rows%8)
extra = 8-rows%8;
Tensor<double> xposki({cols+extra}, Dense);
for (auto& value : iterate<double>(exprOperands.at("x"))) {
xposki.insert({value.first[0]}, value.second);
}
xposki.pack();
poski_Init();
poski_mat_t A_tunable;
tacoToPOSKI(exprOperands.at("A"),A_tunable);
Tensor<double> y_poski({rows}, Dense);
y_poski.pack();
poski_vec_t xposki_view, yposki_view;
tacoToPOSKI(y_poski,yposki_view);
xposki_view = poski_CreateVec((double*)(xposki.getStorage().getValues().getData()), cols, STRIDE_UNIT, NULL);
TACO_BENCH(poski_MatMult(A_tunable, OP_NORMAL, 1, xposki_view, 0, yposki_view);,"\nPOSKI",repeat,timevalue,true)
validate("POSKI", y_poski, exprOperands.at("yRef"));
// tune
poski_TuneHint_MatMult(A_tunable, OP_NORMAL, 1, xposki_view, 0, yposki_view, ALWAYS_TUNE_AGGRESSIVELY);
poski_TuneMat(A_tunable);
TACO_BENCH(poski_MatMult(A_tunable, OP_NORMAL, 1, xposki_view, 0, yposki_view);,"\nPOSKI Tuned",repeat,timevalue,true);
// commented for now as validate doesn't account for limited floating-point precision
// validate("POSKI Tuned", y_poski, exprOperands.at("yRef"));
// deallocate everything -- commented because of some crashes
// poski_DestroyMat(A_tunable);
// poski_DestroyVec(xoski_view);
// poski_DestroyVec(yoski_view);
// poski_DestroyThreads(poski_thread);
// poski_Close();
break;
}
case MATTRANSMUL:
case RESIDUAL: {
int rows=exprOperands.at("A").getDimension(0);
int cols=exprOperands.at("A").getDimension(1);
int extra = 0;
if (rows%8)
extra = 8-rows%8;
Tensor<double> xposki({cols+extra}, Dense);
for (auto& value : iterate<double>(exprOperands.at("x"))) {
xposki.insert({value.first[0]}, value.second);
}
xposki.pack();
poski_Init();
poski_mat_t A_tunable;
tacoToPOSKI(exprOperands.at("A"),A_tunable,Expr==MATTRANSMUL);
Tensor<double> y_poski({rows}, Dense);
y_poski.pack();
poski_vec_t xposki_view, yposki_view, zposki_view;
tacoToPOSKI(y_poski,yposki_view);
tacoToPOSKI(exprOperands.at("z"),zposki_view);
xposki_view = poski_CreateVec((double*)(xposki.getStorage().getValues().getData()), cols, STRIDE_UNIT, NULL);
double alpha = ((double*)(exprOperands.at("alpha").getStorage().getValues().getData()))[0];
double beta = ((double*)(exprOperands.at("beta").getStorage().getValues().getData()))[0];
double* yvals=((double*)(y_poski.getStorage().getValues().getData()));
double* zvals=((double*)(exprOperands.at("z").getStorage().getValues().getData()));
if (Expr==MATTRANSMUL) {
TACO_BENCH(for (auto k=0; k<rows; k++) {yvals[k]=zvals[k];} ;
poski_MatMult(A_tunable, OP_NORMAL, alpha, xposki_view, beta, yposki_view);,"\nPOSKI",repeat,timevalue,true) }
else {
TACO_BENCH(for (auto k=0; k<rows; k++) {yvals[k]=zvals[k];} ;
poski_MatMult(A_tunable, OP_NORMAL, -1.0, xposki_view, 1.0, yposki_view);,"\nPOSKI",repeat,timevalue,true) }
validate("POSKI", y_poski, exprOperands.at("yRef"));
// tune
if (Expr==MATTRANSMUL) {
poski_TuneHint_MatMult(A_tunable, OP_NORMAL, alpha, xposki_view, beta, yposki_view, ALWAYS_TUNE_AGGRESSIVELY); }
else {
poski_TuneHint_MatMult(A_tunable, OP_NORMAL, -1.0, xposki_view, 1.0, yposki_view, ALWAYS_TUNE_AGGRESSIVELY); }
poski_TuneMat(A_tunable);
if (Expr==MATTRANSMUL) {
TACO_BENCH(for (auto k=0; k<rows; k++) {yvals[k]=zvals[k];} ;
poski_MatMult(A_tunable, OP_NORMAL, alpha, xposki_view, beta, yposki_view);,"\nPOSKI Tuned",repeat,timevalue,true); }
else {
TACO_BENCH(for (auto k=0; k<rows; k++) {yvals[k]=zvals[k];} ;
poski_MatMult(A_tunable, OP_NORMAL, -1.0, xposki_view, 1.0, yposki_view);,"\nPOSKI Tuned",repeat,timevalue,true) }
// commented for now as validate doesn't account for limited floating-point precision
// validate("POSKI Tuned", y_poski, exprOperands.at("yRef"));
// deallocate everything -- commented because of some crashes
// poski_DestroyMat(A_tunable);
// poski_DestroyVec(xoski_view);
// poski_DestroyVec(yoski_view);
// poski_DestroyThreads(poski_thread);
// poski_Close();
break;
}
default:
cout << " !! Expression not implemented for POSKI" << endl;
break;
}
}
#endif