-
Notifications
You must be signed in to change notification settings - Fork 1
/
bench_tensor.cc
141 lines (128 loc) · 4.44 KB
/
bench_tensor.cc
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
/* benchmarks for Leicht :: tensor.hpp
*/
#include "leicht.hpp"
#include <cblas-openblas.h>
using namespace std;
/*
* 10 * double gemm (512,512)
* 5400 ms, tensor
* 90 ms, openblas
* 60x
*
* 10 * float gemm (512,512)
* 1100 ms, tensor
* 50 ms, openblas
* 22x
*/
int
main(void)
{
cout << "Leicht::Tensor::GEMM<double>, 10 times" << endl;
{
Tensor<double> x (512, 512); x.rand_();
Tensor<double> y (512, 512); y.rand_();
Tensor<double> z (512, 512); z.zero_();
tic();
for (int i = 0; i < 100; i++) {
Tensor<double>::gemm(false, false, 1., &x, &y, 0., &z);
}
toc();
tic();
for (int i = 0; i < 100; i++) {
Tensor<double>::gemm(false, true, 1., &x, &y, 0., &z);
}
toc();
tic();
for (int i = 0; i < 100; i++) {
Tensor<double>::gemm( true, false, 1., &x, &y, 0., &z);
}
toc();
tic();
for (int i = 0; i < 100; i++) {
Tensor<double>::gemm( true, true, 1., &x, &y, 0., &z);
}
toc();
}
cout << "OpenBLAS::GEMM<double>, 10 times" << endl;
{
Tensor<double> x (512, 512); x.rand_();
Tensor<double> y (512, 512); y.rand_();
Tensor<double> z (512, 512); z.zero_();
tic();
for (int i = 0; i < 100; i++) {
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
512, 512, 512, 1., x.data, 512, y.data, 512, 0., z.data, 512);
}
toc();
tic();
for (int i = 0; i < 100; i++) {
cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
512, 512, 512, 1., x.data, 512, y.data, 512, 0., z.data, 512);
}
toc();
tic();
for (int i = 0; i < 100; i++) {
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasTrans,
512, 512, 512, 1., x.data, 512, y.data, 512, 0., z.data, 512);
}
toc();
tic();
for (int i = 0; i < 100; i++) {
cblas_dgemm(CblasRowMajor, CblasTrans, CblasTrans,
512, 512, 512, 1., x.data, 512, y.data, 512, 0., z.data, 512);
}
toc();
}
// cout << "Leicht::Tensor::GEMM<float>, 10 times" << endl;
// {
// Tensor<float> x (512, 512); x.rand_();
// Tensor<float> y (512, 512); y.rand_();
// Tensor<float> z (512, 512); z.zero_();
// tic();
// for (int i = 0; i < 100; i++) {
// Tensor<double>::gemm(false, false, 1., &x, &y, 0., &z);
// }
// toc();
// }
// cout << "OpenBLAS::GEMM<float>, 10 times" << endl;
// {
// Tensor<float> x (512, 512); x.rand_();
// Tensor<float> y (512, 512); y.rand_();
// Tensor<float> z (512, 512); z.zero_();
// tic();
// for (int i = 0; i < 100; i++) {
// cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
// 512, 512, 512, 1., x.data, 512, y.data, 512, 0., z.data, 512);
// }
// toc();
// }
return 0;
}
// [[[ Benchmarks ]]]
//ut GEMM Benchmark double 512x512, 2pass
//> Tensor<double> X (512,512); X.rand_();
//> Tensor<double> K (512,512); K.rand_();
//> Tensor<double> Y (512,512);
//> tic(); for (int i = 0; i < 2; i++) GEMM(1.,&X,&K,0.,&Y); toc();
//
//ut valid convolution benchmark
//> Tensor<double> X (224, 224); X.rand_();
//> Tensor<double> K (3,3); K.rand_();
//> Tensor<double> Y (222, 222);
//> tic();
//> for (int i = 0; i < 3*10; i++)
//> Conv2D("valid", X.data, 224, 224, K.data, 3, Y.data);
//> toc();
//ut transpose benchmark
//> Tensor<double> X (512,1024); X.rand_();
//> tic(); for (int i=0;i<10;i++) { auto y = X.transpose(); delete y; } toc();
//ut clone benchmark
//> Tensor<double> X(512,512); X.rand_();
//> tic(); for(int i=0;i<1000;i++) { auto y = X.clone(); delete y; } toc();
//
//ut openblas GEMM Benchmark double 512x512, 2pass
//> Tensor<double> X (512,512); X.rand_();
//> Tensor<double> K (512,512); K.rand_();
//> Tensor<double> Y (512,512);
//>tic(); for (int i = 0; i < 2; i++) GEMM(false, false, 1.,&X,&K,0.,&Y); toc();
//