-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConstDefine.h
200 lines (142 loc) · 3.74 KB
/
ConstDefine.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
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
#pragma once
// 头文件 宏定义 变量/类定义声明
// global header file system util
#include <cstdio>
#include <iostream>
#include <fstream>
#include <utility>
#include <thread>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <tuple>
#include <string>
#include <cstdlib>
#include <assert.h>
#ifdef WIN32
#include "WinTimer.h"
#else
#include <sys/time.h>
#include <unistd.h>
#endif
#ifdef WIN32
#define sleep(x) Sleep(x*1000)
#else
#endif
#ifdef WIN32
#define DIS_RESULT
#endif
// not recommended!!
// self-definition util
// 易造成循环引用 不重要
// way1: 改用 extern 方式
// way2: #include "util.h" / main中引用
// 编译不通过 : makefile没更新
//using namespace std;
//#define DIS_SIM_RESULT
#define MAX_CPU_THREAD 16384
#define MAX_TRAJ 100
// 这几个宏定义相关
#define MAX_DIST 300000 // okay
#define ALPHA 0.5
#define EPSILON 0.85
#define GPUOnceCnt 128
#define DUALGPU false
#define SIZE_DATA 16
#define MAXTRAJSIZE 49000
// 这几个宏定义相关:THREADNUM = THREADROW * THREADCOLUMN
// 处理 P Q num不平衡 not smart 16*16 is okay, only bound exsists imbalance!!
// seems no impartant!
#define THREADROW 16
#define THREADCOLUMN 16
// 转置需要方阵
#define THREADROW2 16
#define THREADCOLUMN2 16 // maybe better!!
#define THREADNUM 256 // = (THREADROW*THREADCOLUMN)
//#define IFSORTING 1
// NY: 200
// LA:
// TWITTER:
// predefined !!!
// 数据集相关 must < THREADNUM, kernel is correct
#define MAXTRAJLEN 256
#define GPUSMALLMEM 200
#define GPUDATAMEM 500
#define GPUBIGMEM 10
#define DEBUGMODE 1
// not recommended??
#ifdef WIN32
#else
class MyTimer
{
public:
MyTimer() {
};
double iStart;
double iEnd;
// 注意 double 类型 不然float会出错!!
// linux 秒
double cpuSecond() {
struct timeval tp;
gettimeofday(&tp, NULL);
return ((double)tp.tv_sec + (double)tp.tv_usec*1.0e-6);
}
inline void start()
{
iStart = cpuSecond();
}
inline void stop()
{
iEnd = cpuSecond();
}
inline double elapse()
{
return iEnd - iStart;
}
};
#endif
typedef struct Keywordtuple {
int keywordid;
float keywordvalue;
}Keywordtuple;
// only for invert-list
typedef struct Pointtuple {
int pointid;
float keywordvalue;
}Pointtuple;
typedef std::pair<size_t, size_t> trajPair; // very smart 定义数据结构
// 8 bytes [* 4 = 32 bytes(L2 Cache)]
typedef struct Latlon {
float lat;
float lon;
}Latlon;
// every task of GPU has a StatInfoTable
// 16 bytes now
typedef struct StatInfoTable {
int latlonIdxP, latlonIdxQ; // starting id of latlon data for each traj (each task / block) in GPU, accumulated ,including padding
int pointNumP, pointNumQ; // # of points in each traj, excluding padding! -->> the significance of padding may not that big!
int keycntP, keycntQ; // # of total keywords in each traj, including padding, not-accumulated
// # of word in each traj, similar to int pointNumP, pointNumQ; // # of points in each traj
// only used in kernel-V2
int textIdxP, textIdxQ; // starting position of text data for each traj (each task / block), accumulated, including padding
// used in kernel-V2 + kernel-V3
size_t keywordpmqnMatrixId, keywordpmqMatrixId, keywordpqMatrixId; // starting ID in GPU for each block, accumulated
// point-level: no padding; keyword-level: padding
// for v4
size_t DensepqIdx; // Id ~= Idx for step-4 to locate the dense-matrix offset
//int padding;?
//int keycntPnoPadding, keycntQnoPadding;
}StatInfoTable;
// this exsist oonly on CPU, as for Ccusparse<t>csrgemm -> qkq ppk
typedef struct TrajStatTable {
// only to Traj, common attributes
int latlonIdx;
int pointNum;
int keycnt;
int textIdx;
// for the input para. of Ccusparse<t>csrgemm for qkq ppk
size_t csrRowPtrIdx, csrColIndIdx, csrValIdx; // only for v4
size_t nnz;
int row, col;
}TrajStatTable;