-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark_dist.cpp
167 lines (143 loc) · 4.05 KB
/
benchmark_dist.cpp
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
#include "benchmark_dist.hpp"
#include <iostream>
#include <fstream>
#include <string>
#include "distributed_sparse.h"
#include "15D_dense_shift.hpp"
#include "15D_sparse_shift.hpp"
#include "25D_cannon_dense.hpp"
#include "25D_cannon_sparse.hpp"
#include "SpmatLocal.hpp"
#include "FlexibleGrid.hpp"
#include "sparse_kernels.h"
#include "common.h"
#include "als_conjugate_gradients.h"
#include "gat.hpp"
#include <mpi.h>
#include "json.hpp"
using json = nlohmann::json;
using namespace std;
void benchmark_algorithm(SpmatLocal* spmat,
string algorithm_name,
string output_file,
bool fused,
int R,
int c,
string app
) {
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
ofstream fout;
fout.open(output_file, std::ios_base::app
);
StandardKernel local_ops;
Distributed_Sparse* d_ops;
if(algorithm_name=="15d_fusion1") {
d_ops = new Sparse15D_Dense_Shift(
spmat,
R,
c,
1,
&local_ops);
}
else if(algorithm_name=="15d_sparse") {
d_ops = new Sparse15D_Sparse_Shift(
spmat,
R,
c,
&local_ops);
}
else if(algorithm_name=="15d_fusion2") {
d_ops = new
Sparse15D_Dense_Shift(
spmat,
R,
c,
2,
&local_ops);
}
else if(algorithm_name=="25d_dense_replicate") {
d_ops = new Sparse25D_Cannon_Dense(
spmat,
R,
c,
&local_ops);
}
else if(algorithm_name=="25d_sparse_replicate") {
d_ops = new Sparse25D_Cannon_Sparse(
spmat,
R,
c,
&local_ops);
}
unique_ptr<GAT> gnn;
unique_ptr<Distributed_ALS> d_als;
vector<GATLayer> layers;
if(app=="gat") {
// Input features, features per head, output features
layers.emplace_back(256, 256, 4);
layers.emplace_back(1024, 256, 4);
layers.emplace_back(1024, 256, 6);
gnn.reset(new GAT(layers, d_ops));
}
else if(app=="als") {
d_als.reset(new Distributed_ALS(d_ops, true));
}
else {
assert(app=="vanilla");
}
DenseMatrix A = d_ops->like_A_matrix(0.001);
DenseMatrix B = d_ops->like_B_matrix(0.001);
VectorXd S = d_ops->like_S_values(1.0);
VectorXd sddmm_result = d_ops->like_S_values(0.0);
if(rank == 0) {
std::cout << "Starting benchmark " << app << endl;
}
d_ops->reset_performance_timers();
my_timer_t t = start_clock();
int num_trials = 0;
double application_communication_time = 0.0;
do {
num_trials++;
if(app == "vanilla") {
if(fused) {
d_ops->fusedSpMM(A,
B,
S,
sddmm_result,
Amat);
}
else {
d_ops->sddmmA(A, B, S, sddmm_result);
d_ops->spmmA(A, B, S);
}
}
else if(app=="gat") {
gnn->forwardPass();
}
else if(app=="als") {
d_als->application_communication_time = 0.0;
d_als->run_cg(1);
application_communication_time = d_als->application_communication_time;
}
} while(num_trials < 5);
MPI_Barrier(MPI_COMM_WORLD);
json j_obj;
double elapsed = stop_clock_get_elapsed(t);
double ops = 2 * spmat->dist_nnz * 2 * R * num_trials;
double throughput = ops / elapsed;
throughput /= 1e9;
j_obj["elapsed"] = elapsed;
j_obj["overall_throughput"] = throughput;
j_obj["fused"] = fused;
j_obj["num_trials"] = num_trials;
j_obj["alg_name"] = algorithm_name;
j_obj["alg_info"] = d_ops->json_algorithm_info();
j_obj["application_communication_time"] = application_communication_time;
j_obj["perf_stats"] = d_ops->json_perf_statistics();
if(rank == 0) {
fout << j_obj.dump(4) << "," << endl;
}
fout.close();
delete d_ops;
}