-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoski-bench.h
169 lines (143 loc) · 6.46 KB
/
oski-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
163
164
165
166
167
168
169
#include "taco/tensor.h"
using namespace taco;
using namespace std;
#ifdef OSKI
extern "C" {
#include <oski/oski.h>
}
void tacoToOSKI(const Tensor<double>& src, oski_matrix_t& dst) {
int rows=src.getDimension(0);
int cols=src.getDimension(1);
if (src.getFormat() == CSC) {
double *a_CSC;
int* ia_CSC;
int* ja_CSC;
getCSCArrays(src,&ia_CSC,&ja_CSC,&a_CSC);
dst = oski_CreateMatCSC(ia_CSC,ja_CSC,a_CSC,
rows, cols, SHARE_INPUTMAT, 1, INDEX_ZERO_BASED);
} else {
double *a_CSR;
int* ia_CSR;
int* ja_CSR;
getCSRArrays(src,&ia_CSR,&ja_CSR,&a_CSR);
dst = oski_CreateMatCSR(ia_CSR,ja_CSR,a_CSR,
rows, cols, SHARE_INPUTMAT, 1, INDEX_ZERO_BASED);
}
}
void tacoToOSKI(const Tensor<double>& src, oski_vecview_t& dst) {
int cols=src.getDimension(0);
dst = oski_CreateVecView((double*)(src.getStorage().getValues().getData()),
cols, STRIDE_UNIT);
}
void exprToOSKI(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);
oski_matrix_t Aoski;
oski_vecview_t xoski, yoski;
oski_Init();
tacoToOSKI(exprOperands.at("A"),Aoski);
tacoToOSKI(exprOperands.at("x"),xoski);
Tensor<double> y_oski({rows}, Dense);
y_oski.pack();
tacoToOSKI(y_oski,yoski);
TACO_BENCH( oski_MatMult(Aoski, OP_NORMAL, 1, xoski, 0, yoski);,"\nOSKI",repeat,timevalue,true );
validate("OSKI", y_oski, exprOperands.at("yRef"));
// Tuned version
oski_SetHintMatMult(Aoski, OP_NORMAL, 1.0, SYMBOLIC_VEC, 0.0, SYMBOLIC_VEC, ALWAYS_TUNE_AGGRESSIVELY);
oski_TuneMat(Aoski);
char* xform = oski_GetMatTransforms (Aoski);
int blockSize=0;
if (xform) {
fprintf (stdout, "\tDid tune: '%s'\n", xform);
std::string oskiTune(xform);
std::string oskiBegin=oskiTune.substr(oskiTune.find(",")+2);
std::string oskiXSize=oskiBegin.substr(0,oskiBegin.find(","));
int XOski=atoi(oskiXSize.c_str());
if (XOski!=0)
blockSize = XOski;
oski_Free (xform);
}
TACO_BENCH(oski_MatMult(Aoski, OP_NORMAL, 1, xoski, 0, yoski);,"\nOSKI Tuned",repeat,timevalue,true);
// commented for now as validate doesn't account for limited floating-point precision
// validate("OSKI Tuned", y_oski, exprOperands.at("yRef"));
// commented to avoid some crashes with poski
// oski_DestroyMat(Aoski);
// oski_DestroyVecView(xoski);
// oski_DestroyVecView(yoski);
// oski_Close();
// Taco block version with oski tuned number
if (blockSize>0) {
cout << "y(i,ib) = A(i,j,ib,jb)*x(j,jb) -- DSDD " <<endl;
IndexVar i, j, ib,jb;
Tensor<double> yb({rows/blockSize,blockSize}, Format({Dense,Dense}));
Tensor<double> xb({cols/blockSize,blockSize}, Format({Dense,Dense}));
Tensor<double> Ab({rows/blockSize,cols/blockSize,blockSize,blockSize},
Format({Dense,Sparse,Dense,Dense}));
int i_b=0;
for (auto& value : iterate<double>(exprOperands.at("x"))) {
xb.insert({value.first.at(0)/blockSize,value.first.at(0)%blockSize},
value.second);
i_b++;
}
xb.pack();
for (auto& value : iterate<double>(exprOperands.at("A"))) {
Ab.insert({value.first.at(0)/blockSize,value.first.at(1)/blockSize,
value.first.at(0)%blockSize,value.first.at(1)%blockSize},
value.second);
}
Ab.pack();
yb(i,ib) = Ab(i,j,ib,jb) * xb(j,jb);
TACO_BENCH(yb.compile();, "Compile",1,timevalue,false)
TACO_BENCH(yb.assemble();,"Assemble",1,timevalue,false)
TACO_BENCH(yb.compute();, "Compute",repeat, timevalue, true)
}
break;
}
case MATTRANSMUL:
case RESIDUAL: {
int rows=exprOperands.at("A").getDimension(0);
int cols=exprOperands.at("A").getDimension(1);
oski_matrix_t Aoski;
oski_vecview_t xoski, yoski, zoski;
oski_Init();
tacoToOSKI(exprOperands.at("A"),Aoski);
tacoToOSKI(exprOperands.at("x"),xoski);
tacoToOSKI(exprOperands.at("z"),zoski);
Tensor<double> y_oski({rows}, Dense);
y_oski.pack();
tacoToOSKI(y_oski,yoski);
double alpha = ((double*)(exprOperands.at("alpha").getStorage().getValues().getData()))[0];
double beta = ((double*)(exprOperands.at("beta").getStorage().getValues().getData()))[0];
double* yvals=((double*)(y_oski.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];} ;
oski_MatMult(Aoski, OP_TRANS, alpha, xoski, beta, yoski);,"\nOSKI",repeat,timevalue,true); }
else {
TACO_BENCH(for (auto k=0; k<rows; k++) {yvals[k]=zvals[k];} ;
oski_MatMult(Aoski, OP_NORMAL, -1.0, xoski, 1.0, yoski);,"\nOSKI",repeat,timevalue,true); }
validate("OSKI", y_oski, exprOperands.at("yRef"));
// Tuned version
if (Expr==MATTRANSMUL) {
oski_SetHintMatMult(Aoski, OP_TRANS, alpha, SYMBOLIC_VEC, beta, SYMBOLIC_VEC, ALWAYS_TUNE_AGGRESSIVELY); }
else {
oski_SetHintMatMult(Aoski, OP_NORMAL, -1.0, SYMBOLIC_VEC, 1.0, SYMBOLIC_VEC, ALWAYS_TUNE_AGGRESSIVELY); }
oski_TuneMat(Aoski);
if (Expr==MATTRANSMUL) {
TACO_BENCH(for (auto k=0; k<rows; k++) {yvals[k]=zvals[k];} ;
oski_MatMult(Aoski, OP_TRANS, alpha, xoski, beta, yoski);,"\nOSKI Tuned",repeat,timevalue,true); }
else {
TACO_BENCH(for (auto k=0; k<rows; k++) {yvals[k]=zvals[k];} ;
oski_MatMult(Aoski, OP_NORMAL, -1.0, xoski, 1.0, yoski);,"\nOSKI Tuned",repeat,timevalue,true); }
// commented for now as validate doesn't account for limited floating-point precision
// validate("OSKI Tuned", y_oski, exprOperands.at("yRef"));
break;
}
default:
cout << " !! Expression not implemented for OSKI" << endl;
break;
}
}
#endif