-
Notifications
You must be signed in to change notification settings - Fork 2
/
graph_gpu.hpp
249 lines (197 loc) · 6.24 KB
/
graph_gpu.hpp
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#ifndef GRAPH_GPU_HPP_
#define GRAPH_GPU_HPP_
#include <cstring>
#include <vector>
#include <thrust/device_ptr.h>
#include "types.hpp"
#include "graph.hpp"
#include "cuda_wrapper.hpp"
#ifdef MULTIPHASE
#include "clustering.hpp"
#endif
//all indices are stored in global index
class GraphGPU
{
private:
Graph* graph_;
GraphElem NV_, NE_;
int nbatches_;
int part_on_device_, part_on_batch_; //use edge-wise partition 1: yes 0: no
GraphElem nv_[NGPU], ne_[NGPU], ne_per_partition_[NGPU]; //maximum number of edges to fit on gpu
GraphElem vertex_per_device_host_[NGPU+1]; //subgraph vertex range on each device, allocated on host
GraphElem *vertex_per_device_[NGPU]; //subgraph vertex range on each device, allocated on devices
GraphElem *vertex_per_batch_[NGPU]; //divide full vertex range into batches (batched update)
std::vector< std::vector<GraphElem> > vertex_per_batch_partition_[NGPU]; //divide batched vertex ranges (batched update) into maximum-edge partition
GraphElem *edges_[NGPU];
GraphWeight *edgeWeights_[NGPU];
GraphElem2 *commIdKeys_[NGPU];
//GraphElem* indexOrders_[NGPU];
GraphElem* indices_[NGPU];
GraphWeight* vertexWeights_[NGPU];
GraphElem* commIds_[NGPU];
GraphElem** commIdsPtr_[NGPU];
GraphWeight* commWeights_[NGPU];
GraphWeight** commWeightsPtr_[NGPU];
GraphElem* newCommIds_[NGPU];
GraphElem* localCommNums_[NGPU];
GraphWeight* orderedWeights_[NGPU];
GraphWeight* reducedWeights_[NGPU];
GraphElem2* reducedCommIdKeys_[NGPU];
GraphElem maxOrder_;
GraphWeight mass_;
GraphElem* indicesHost_;
GraphElem* edgesHost_;
GraphWeight* edgeWeightsHost_;
std::vector<GraphElem> vertex_partition_[NGPU];
cudaStream_t cuStreams[NGPU][4];
//related to sorting
thrust::device_ptr<GraphWeight> ordered_weights_ptr[NGPU];
//thrust::device_ptr<GraphWeight> reduced_weights_ptr[NGPU]; //= thrust::device_pointer_cast(indexOrders_);
thrust::device_ptr<GraphElem2> keys_ptr[NGPU]; // = thrust::device_pointer_cast(commIdKeys_);
thrust::device_ptr<GraphElem> local_comm_nums_ptr[NGPU];
thrust::device_ptr<GraphWeight> reduced_weights_ptr[NGPU];
thrust::device_ptr<GraphElem2> reduced_keys_ptr[NGPU];
less_int2 comp;
equal_int2 is_equal_int2;
GraphElem e0_[NGPU], e1_[NGPU]; //memory position with respect to edgesHost_
GraphElem w0_[NGPU], w1_[NGPU]; //memory position with respect to edgeWeightsHost_
GraphElem v_base_[NGPU], v_end_[NGPU]; //first and last global indices of the vertices in a given gpu
GraphElem e_base_[NGPU], e_end_[NGPU]; //firt and last global indices of the edges in a give gpu
//GraphElem maxPartitions_;
//GraphElem ne_per_partition_cap_;
#ifdef MULTIPHASE
void* buffer_;
GraphElem* commIdsHost_;
GraphElem* vertexIdsHost_;
GraphElem* vertexIdsOffsetHost_;
GraphElem* numEdgesHost_;
GraphElem* sortedIndicesHost_;
GraphElem2* sortedVertexIdsHost_;
#endif
GraphElem determine_optimal_edges_per_partition
(
const GraphElem&,
const GraphElem&,
const unsigned& size
);
void determine_optimal_vertex_partition
(
GraphElem*,
const GraphElem&,
const GraphElem&,
const GraphElem&,
std::vector<GraphElem>& partition,
const GraphElem&
);
void determine_edge_device_partition();
void partition_graph_edge_batch();
GraphElem max_order();
void sum_vertex_weights(const int&);
void compute_mass();
#ifdef MULTIPHASE
GraphElem sort_vertex_by_community_ids();
void shuffle_edge_list();
void compress_all_edges();
void compress_edges();
Clustering* clusters_;
#endif
void sort_edges_by_community_ids
(
const GraphElem& v0, //starting global vertex index
const GraphElem& v1, //ending global vertex index
const GraphElem& e0, //starting global edge index
const GraphElem& e1, //ending global edge index
const int& host_id,
const int& exclude_self_loops
);
void louvain_update
(
const GraphElem& v0,
const GraphElem& v1,
const GraphElem& e0,
const GraphElem& e1,
const int& host_id
);
void update_community_weights
(
const GraphElem& v0,
const GraphElem& v1,
const GraphElem& e0,
const GraphElem& e1,
const int& host_id
);
void update_community_ids
(
const GraphElem& v0,
const GraphElem& v1,
const GraphElem& u0,
const GraphElem& u1,
const int& host_id
);
public:
GraphGPU (Graph* graph, const int& nbatches, const int& part_on_deivce, const int& part_on_batch);
~GraphGPU();
void set_community_ids(GraphElem* commIds);
void singleton_partition();
void compute_community_weights(const int&);
GraphWeight compute_modularity();
void sort_edges_by_community_ids
(
const int& batch,
const int& host_id
);
void louvain_update
(
const int& batch,
const int& host_id
);
void move_edges_to_device
(
const GraphElem& e0,
const GraphElem& e1,
const int& host_id,
cudaStream_t stream = 0
);
void move_edges_to_host
(
const GraphElem& e0,
const GraphElem& e1,
const int& host_id,
cudaStream_t stream = 0
);
void move_weights_to_device
(
const GraphElem& e0,
const GraphElem& e1,
const int& host_id,
cudaStream_t stream = 0
);
void move_weights_to_host
(
const GraphElem& e0,
const GraphElem& e1,
const int& host_id,
cudaStream_t stream = 0
);
void update_community_weights
(
const int& batch,
const int& host_id
);
void update_community_ids
(
const int& batch,
const int& host_id
);
void restore_community();
#ifdef MULTIPHASE
bool aggregation();
void dump_partition(const std::string&, GraphElem*);
#endif
#ifdef CHECK
void louvain_update_host(const int&);
void set_community_ids();
void compute_modularity_host();
#endif
};
#endif