-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.cu
103 lines (91 loc) · 3.64 KB
/
info.cu
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
// Copyright (c) 2020, American University of Beirut
// See LICENSE.txt for copyright license
#include "info.h"
Info createInfo(Config config) {
Info info;
unsigned int numEdges = (isDirected(config.directedness))?(config.numEdges/2):(config.numEdges);
info.changed = (unsigned int*) malloc(sizeof(unsigned int));
info.numTriangles = (unsigned int*) malloc(numEdges*sizeof(unsigned int));
if(config.recount == AFFECTED) {
info.nodeAffected = (unsigned int*) malloc(config.numNodes*sizeof(unsigned int));
info.edgeAffected = (unsigned int*) malloc(numEdges*sizeof(unsigned int));
} else {
info.nodeAffected = NULL;
info.edgeAffected = NULL;
}
return info;
}
Info createInfoOnDevice(Config config) {
Info info;
unsigned int numEdges = (isDirected(config.directedness))?(config.numEdges/2):(config.numEdges);
cudaMalloc((void**) &info.changed, sizeof(unsigned int));
cudaMalloc((void**) &info.numTriangles, numEdges*sizeof(unsigned int));
if(config.recount == AFFECTED) {
cudaMalloc((void**) &info.nodeAffected, config.numNodes*sizeof(unsigned int));
cudaMalloc((void**) &info.edgeAffected, numEdges*sizeof(unsigned int));
} else {
info.nodeAffected = NULL;
info.edgeAffected = NULL;
}
return info;
}
void initInfo(Info info, Config config) {
unsigned int numEdges = (isDirected(config.directedness))?(config.numEdges/2):(config.numEdges);
if(config.recount == AFFECTED) {
for(unsigned int e = 0; e < numEdges; ++e) {
// NOTE: Initially assume all edges are affected
info.edgeAffected[e] = DIRECTLY_AFFECTED;
}
}
}
__global__ void init_edge_affected(unsigned int* edgeAffected, unsigned int numEdges) {
unsigned int e = blockIdx.x*blockDim.x + threadIdx.x;
if(e < numEdges) {
// NOTE: Initially assume all edges are affected
edgeAffected[e] = DIRECTLY_AFFECTED;
}
}
void initInfoOnDevice(Info info, Config config) {
unsigned int numEdges = (isDirected(config.directedness))?(config.numEdges/2):(config.numEdges);
if(config.recount == AFFECTED) {
init_edge_affected <<< (numEdges + 1024 - 1)/1024, 1024 >>>(info.edgeAffected, numEdges);
}
}
void clearIterInfo(Info info, Config config) {
unsigned int numEdges = (isDirected(config.directedness))?(config.numEdges/2):(config.numEdges);
*info.changed = 0;
memset(info.numTriangles, 0, numEdges*sizeof(unsigned int));
if(config.recount == AFFECTED) {
memset(info.nodeAffected, NOT_AFFECTED, config.numNodes*sizeof(unsigned int));
// NOTE: Affetced edges are not cleared because they are need it by next iteration
}
}
void clearIterInfoOnDevice(Info info, Config config) {
unsigned int numEdges = (isDirected(config.directedness))?(config.numEdges/2):(config.numEdges);
cudaMemset(info.changed, 0, sizeof(unsigned int));
cudaMemset(info.numTriangles, 0, numEdges*sizeof(unsigned int));
if(config.recount == AFFECTED) {
cudaMemset(info.nodeAffected, NOT_AFFECTED, config.numNodes*sizeof(unsigned int));
// NOTE: Affetced edges are not cleared because they are need it by next iteration
}
}
void freeInfo(Info info) {
free(info.changed);
free(info.numTriangles);
if(info.nodeAffected != NULL) {
free(info.nodeAffected);
}
if(info.edgeAffected != NULL) {
free(info.edgeAffected);
}
}
void freeInfoOnDevice(Info info) {
cudaFree(info.changed);
cudaFree(info.numTriangles);
if(info.nodeAffected != NULL) {
cudaFree(info.nodeAffected);
}
if(info.edgeAffected != NULL) {
cudaFree(info.edgeAffected);
}
}