-
Notifications
You must be signed in to change notification settings - Fork 12
/
util.h
165 lines (144 loc) · 3.84 KB
/
util.h
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
/*
* Copyright 2016 The George Washington University
* Written by Hang Liu
* Directed by Prof. Howie Huang
*
* https://www.seas.gwu.edu/~howie/
* Contact: [email protected]
*
*
* Please cite the following paper:
*
* Hang Liu, H. Howie Huang and Yang Hu. 2016. iBFS: Concurrent Breadth-First Search on GPUs. Proceedings of the 2016 International Conference on Management of Data. ACM.
*
* This file is part of iBFS.
*
* iBFS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iBFS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with iBFS. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __UTIL_H__
#define __UTIL_H__
#include <stdint.h>
#include <sys/stat.h>
#include <stdio.h>
inline off_t fsize(const char *filename) {
struct stat st;
if (stat(filename, &st) == 0)
return st.st_size;
return -1;
}
static void HandleError( cudaError_t err,
const char *file,
int line ) {
if (err != cudaSuccess) {
printf( "%s in %s at line %d\n", \
cudaGetErrorString( err ),
file, line );
exit( EXIT_FAILURE );
}
}
#define H_ERR( err ) \
(HandleError( err, __FILE__, __LINE__ ))
//////////////////////////////////////////////////
//SCALE*THDS_NUMS*sizeof(int) should be
//limited by the size of the shared memory
/////////////////////////////////////////////////
//////////////////////////////////////////////////
#define THDS_NUM 256
#define BLKS_NUM 256
#define OMP_THDS 24
#define V_NON_INC -1
#define V_INI_HUB -2
#define VALIDATE_TIMES 1
#define NUM_SRC 128
#define INFTY 255
#define Q_CARD 3
enum ex_q_t
{
SML_Q,
MID_Q,
LRG_Q,
NONE
};
//--------------------------
typedef int index_t;
typedef int vertex_t;
typedef unsigned char depth_t;
typedef uint4 comp_t;
//--------------------------------
//operator overloading
inline __host__ __device__ uint4 operator-(uint4 a, uint4 b)
{
return make_uint4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
}
inline __host__ __device__ uint4 operator|=(uint4 a, uint4 b)
{
return make_uint4(a.x |= b.x, a.y |= b.y, a.z |= b.z, a.w |= b.w);
}
inline __host__ __device__ uint4 operator|(uint4 a, uint4 b)
{
return make_uint4(a.x | b.x, a.y | b.y, a.z | b.z, a.w | b.w);
}
inline __host__ __device__ uint4 operator^(uint4 a, uint4 b)
{
return make_uint4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w);
}
inline __host__ __device__ uint4 operator~(uint4 a)
{
return make_uint4(~a.x, ~a.y, ~a.z, ~a.w);
}
inline __host__ __device__ uint4 make_uint4(int a)
{
return make_uint4(a, 0, 0, 0);
}
inline __host__ __device__ uint4 operator<<(uint4 a, int b)
{
if(b<32) a.x=(a.x<<b);
else
{
if(b<64) a.y=a.x<<(b-32);
else if(b<96) a.z=a.x<<(b-64);
else a.w=a.x<<(b-96);
a.x=0;
}
return a;
}
inline __host__ __device__ uint4 operator&(uint4 a, uint4 b)
{
return make_uint4(a.x & b.x, a.y & b.y, a.z & b.z, a.w & b.w);
}
inline __host__ __device__ int operator!=(uint4 a, unsigned int b)
{
if( a.x != b ||
a.y != b ||
a.z != b ||
a.w != b ) return true;
else return false;
}
inline __host__ __device__ int operator!=(uint4 a, uint4 b)
{
if( a.x != b.x ||
a.y != b.y ||
a.z != b.z ||
a.w != b.w ) return true;
else return false;
}
inline __host__ __device__ int operator==(uint4 a, unsigned int b)
{
if(a.x == b &&
a.y == b &&
a.z == b &&
a.w == b) return true;
else return false;
}
#endif