-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbfs_kernels.cu
62 lines (49 loc) · 1.61 KB
/
bfs_kernels.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
#include "bfs_kernels.cuh"
__device__ unsigned terminate;
__managed__ unsigned numActiveThreads;
__global__
void BFSKernel1(
size_t graphSize, unsigned *activeMask, unsigned *V, unsigned *E,
unsigned *F, unsigned *X, unsigned *C, unsigned *Fu) {
unsigned activeMaskIdx = blockIdx.x * BLOCK_SIZE + threadIdx.x;
// If vertex is active at current iteration
if (activeMaskIdx < numActiveThreads) {
unsigned v = activeMask[activeMaskIdx];
// Remove v from current frontier
F[v] = FALSE;
// Iterate over v's neighbors
for (unsigned edge = V[v]; edge < V[v+1]; ++edge) {
unsigned neighbor = E[edge];
// If neighbor wasn't visited
if (not X[neighbor]) {
C[neighbor] = C[v] + 1;
Fu[neighbor] = TRUE;
}
}
}
}
__global__
void BFSKernel2(size_t graphSize, unsigned *F, unsigned *X, unsigned *Fu) {
int v = blockIdx.x * BLOCK_SIZE + threadIdx.x;
// If vertex v exists and has recently joined the frontier
if (v < graphSize and Fu[v]) {
// Copy the new frontier into F
F[v] = TRUE;
// Set v as visited
X[v] = TRUE;
// Clean up the new frontier
Fu[v] = FALSE;
terminate = FALSE;
}
}
// Very slow but correct "active mask" calculation; for debugging
__global__
void getActiveMaskTemp(size_t graphSize, unsigned *F, unsigned *activeMask) {
numActiveThreads = 0;
for (int i = 0; i < graphSize; ++i) {
if (F[i]) {
activeMask[numActiveThreads] = i;
++numActiveThreads;
}
}
}