-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtaco-bench.h
64 lines (53 loc) · 1.93 KB
/
taco-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
#include "taco.h"
using namespace taco;
using namespace std;
// MACRO to benchmark some CODE with REPEAT times and COLD/WARM cache
#define TACO_BENCH(CODE, NAME, REPEAT, TIMER, COLD) { \
TACO_TIME_REPEAT(CODE, REPEAT, TIMER, COLD); \
cout << NAME << " time (ms)" << endl << TIMER << endl; \
}
#define CHECK_PRODUCT(NAME) { \
if (products.at(NAME)) { \
cout << "taco-bench was not compiled with "<< NAME << " and will not use it" << endl; \
products.at(NAME)=false; \
} \
}
// Enum of possible expressions to Benchmark
enum BenchExpr {SpMV, PLUS3, MATTRANSMUL, RESIDUAL, SDDMM, SparsitySpMV, SparsityTTV, SparsitySpMDM};
// Compare two tensors of different formats
bool compare(const Tensor<double>&Dst, const Tensor<double>&Ref) {
if (Dst.getDimensions() != Ref.getDimensions()) {
return false;
}
std::set<std::vector<int>> coords;
for (const auto& val : Dst) {
if (!coords.insert(val.first).second) {
return false;
}
}
vector<std::pair<std::vector<int>,double>> valsDst;
for (const auto& val : Dst) {
if (val.second != 0) {
valsDst.push_back(val);
}
}
vector<std::pair<std::vector<int>,double>> valsRef;
for (const auto& val : Ref) {
if (val.second != 0) {
valsRef.push_back(val);
}
}
std::sort(valsRef.begin(), valsRef.end());
std::sort(valsDst.begin(), valsDst.end());
return valsDst == valsRef;
}
void validate (string name, const Tensor<double>& Dst, const Tensor<double>& Ref) {
if (Dst.getFormat()==Ref.getFormat()) {
if (!equals (Dst, Ref))
cout << "\033[1;31m Validation Error with " << name << " \033[0m" << endl;
}
else {
if (!compare(Dst,Ref))
cout << "\033[1;31m Validation Error with " << name << " \033[0m" << endl;
}
}