@@ -24,36 +24,46 @@ namespace paddle {
24
24
namespace framework {
25
25
struct GpuPsGraphNode {
26
26
int64_t node_id;
27
- int neighbor_size, neighbor_offset;
27
+ unsigned int neighbor_size, neighbor_offset;
28
28
// this node's neighbor is stored on [neighbor_offset,neighbor_offset +
29
29
// neighbor_size) of int64_t *neighbor_list;
30
30
};
31
31
32
32
struct GpuPsCommGraph {
33
33
int64_t *neighbor_list;
34
34
GpuPsGraphNode *node_list;
35
- int neighbor_size, node_size;
35
+ unsigned int neighbor_size, node_size;
36
36
// the size of neighbor array and graph_node_list array
37
37
GpuPsCommGraph ()
38
38
: neighbor_list(NULL ), node_list(NULL ), neighbor_size(0 ), node_size(0 ) {}
39
39
GpuPsCommGraph (int64_t *neighbor_list_, GpuPsGraphNode *node_list_,
40
- int neighbor_size_, int node_size_)
40
+ unsigned int neighbor_size_, unsigned int node_size_)
41
41
: neighbor_list(neighbor_list_),
42
42
node_list (node_list_),
43
43
neighbor_size(neighbor_size_),
44
44
node_size(node_size_) {}
45
+ void init_on_cpu (unsigned int neighbor_size, unsigned int node_size) {
46
+ this ->neighbor_size = neighbor_size;
47
+ this ->node_size = node_size;
48
+ this ->neighbor_list = new int64_t [neighbor_size];
49
+ this ->node_list = new paddle::framework::GpuPsGraphNode[node_size];
50
+ }
51
+ void release_on_cpu () {
52
+ delete[] neighbor_list;
53
+ delete[] node_list;
54
+ }
45
55
void display_on_cpu () {
46
56
VLOG (0 ) << " neighbor_size = " << neighbor_size;
47
57
VLOG (0 ) << " node_size = " << node_size;
48
- for (int i = 0 ; i < neighbor_size; i++) {
58
+ for (size_t i = 0 ; i < neighbor_size; i++) {
49
59
VLOG (0 ) << " neighbor " << i << " " << neighbor_list[i];
50
60
}
51
- for (int i = 0 ; i < node_size; i++) {
61
+ for (size_t i = 0 ; i < node_size; i++) {
52
62
VLOG (0 ) << " node i " << node_list[i].node_id
53
63
<< " neighbor_size = " << node_list[i].neighbor_size ;
54
64
std::string str;
55
65
int offset = node_list[i].neighbor_offset ;
56
- for (int j = 0 ; j < node_list[i].neighbor_size ; j++) {
66
+ for (size_t j = 0 ; j < node_list[i].neighbor_size ; j++) {
57
67
if (j > 0 ) str += " ," ;
58
68
str += std::to_string (neighbor_list[j + offset]);
59
69
}
@@ -139,12 +149,18 @@ struct NeighborSampleQuery {
139
149
};
140
150
struct NeighborSampleResult {
141
151
int64_t *val;
152
+ int64_t *actual_val;
142
153
int *actual_sample_size, sample_size, key_size;
154
+ int total_sample_size;
143
155
std::shared_ptr<memory::Allocation> val_mem, actual_sample_size_mem;
156
+ std::shared_ptr<memory::Allocation> actual_val_mem;
144
157
int64_t *get_val () { return val; }
158
+ int64_t get_actual_val () { return (int64_t )actual_val; }
145
159
int *get_actual_sample_size () { return actual_sample_size; }
146
160
int get_sample_size () { return sample_size; }
147
161
int get_key_size () { return key_size; }
162
+ void set_total_sample_size (int s) { total_sample_size = s; }
163
+ int get_len () { return total_sample_size; }
148
164
void initialize (int _sample_size, int _key_size, int dev_id) {
149
165
sample_size = _sample_size;
150
166
key_size = _key_size;
@@ -165,18 +181,30 @@ struct NeighborSampleResult {
165
181
int *ac_size = new int [key_size];
166
182
cudaMemcpy (ac_size, actual_sample_size, key_size * sizeof (int ),
167
183
cudaMemcpyDeviceToHost); // 3, 1, 3
184
+ int total_sample_size = 0 ;
185
+ for (int i = 0 ; i < key_size; i++) {
186
+ total_sample_size += ac_size[i];
187
+ }
188
+ int64_t *res2 = new int64_t [total_sample_size]; // r
189
+ cudaMemcpy (res2, actual_val, total_sample_size * sizeof (int64_t ),
190
+ cudaMemcpyDeviceToHost); // r
168
191
192
+ int start = 0 ;
169
193
for (int i = 0 ; i < key_size; i++) {
170
194
VLOG (0 ) << " actual sample size for " << i << " th key is " << ac_size[i];
171
195
VLOG (0 ) << " sampled neighbors are " ;
172
- std::string neighbor;
196
+ std::string neighbor, neighbor2 ;
173
197
for (int j = 0 ; j < ac_size[i]; j++) {
174
- if (neighbor.size () > 0 ) neighbor += " ;" ;
175
- neighbor += std::to_string (res[i * sample_size + j]);
198
+ // if (neighbor.size() > 0) neighbor += ";";
199
+ if (neighbor2.size () > 0 ) neighbor2 += " ;" ; // r
200
+ // neighbor += std::to_string(res[i * sample_size + j]);
201
+ neighbor2 += std::to_string (res2[start + j]); // r
176
202
}
177
- VLOG (0 ) << neighbor;
203
+ VLOG (0 ) << neighbor << " " << neighbor2;
204
+ start += ac_size[i]; // r
178
205
}
179
206
delete[] res;
207
+ delete[] res2; // r
180
208
delete[] ac_size;
181
209
VLOG (0 ) << " ------------------" ;
182
210
}
0 commit comments