-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComTypes.h
More file actions
482 lines (405 loc) · 13.1 KB
/
Copy pathComTypes.h
File metadata and controls
482 lines (405 loc) · 13.1 KB
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
#ifndef COM_TYPES_H
#define COM_TYPES_H
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <iterator>
#include <algorithm>
#include <map>
#include <vector>
#include "uthash/uthash.h"
#include "uthash/utarray.h"
#include "Timer.h"
/* this constant defines the ratio of device memory that
will be used for the reference, the rest is for queries */
#define REF_DEV_BUF_RATIO (9.3/10.0)
/* the ratio of device memory reported by cuda runtime
that is available for allocation. I estimated this
ratio experimentally */
#define FREE_GLOBAL_MEM_RATIO 95.0/100.0
/* defines the maximum query and query-name lengths */
#define QRY_MAX_LENGTH (1024)
#define QRY_MAX_NAME_LENGTH (1024)
/* defines the state needed for each query: 1 for the null, and 2 ints
for the offset and the length */
#define QRY_STATE_SIZE (1 + 2 * sizeof(int))
// calculates the space needed to store the results in the GPU
#define RESULT_DATA_SIZE(qrystotlen, qryscount, minmatchlen) \
((qrystotlen - (qryscount * (minmatchlen - 1))) * sizeof(result_t))
#define MAX_rule_span 15//original 15
#define MAX_rule_span_pattern 15
#define MAX_rule_symbols 5
#define MAX_rule_span_double 28//Double the Max_rule_span for in kernel memory purpose
#define MIN_gap_size 1
#define MAX_nonterminals 2
#define MAXSCORE 99 //Feature Lexical: MaxEF
/***ALL OCCURNECES String Matching****/
#define ONEGAP_PREALLOCATION 60000000
#define PRECOMPUTECOUNT 100 //200
#define ONEGAP_PRECOMPUT_PREALLOCATION 60000000
#define TWOGAP_PREALLOCATION 70000000
#define LINEARBLOCK 700
#define ONEGAP_ENU_PREALLOCATION 20000000
#define TWOGAP_ENU_PREALLOCATION 35000000
#define isSample true
#define SAMPLER 300
#define SAMPLER_ONEGAP 65
#define SAMPLER_TWOGAP 70
typedef struct options_s {
char *reffile;
char *qryfile;
char *reftargetfile;
char *align;
char *timefile;
char *wordscdec;
int minmatchlen;
int fingerlen;
char* destinationDirectory;
} options_t;
typedef struct timing_s {
double suffixarray;
double qrysload;
double qrysin;
double refsin;
double resout;
double kernel;
double printout;
double kernel2;
double extractin;
double extractkernel;
} timing_t;
typedef struct result_s {
int up;
int down;
} result_t;
typedef struct result_s_two {
int up;
int down;
int firstfindhit;
int firstfindhitL;
int firstfindhitR;
int longestind;
int longestmatch;
} result_t_two;
typedef struct qrySID1{
unsigned int index;
uint8_t type;
//1. precomp -> based on one gap seed, get one gap rule: 1->1/2 precomp
//2. precomp -> based on two gaps seed, get twp gap rule: 2->2 precomp
//3. no precomp -> based on one gap seed, get one gap rule: 1->1/2 no precomp
//4. no precomp -> based on two gaps seed, get two gap rule: 2->2 no precomp
} qrySID;
typedef struct my_struct_lexicon {
const char *name; /* key */
int* alinged; //Only those aligned
//int all_suffix; ///All matches
UT_hash_handle hh; /* makes this structure hashable */
} hash_lexicon;
typedef struct my_struct {
const char *name; /* key */
int id;
UT_hash_handle hh; /* makes this structure hashable */
} hashtbl;
typedef struct my_struct2 {
const char *name;
int id; /* key */
UT_hash_handle hh; /* makes this structure hashable */
} hash_intchar;
typedef struct my_struct3 { /// Only Used in CreatedLexicon() in Extractpairs.cu, to get the target string faster
const char *name; /* key */
int* id;
UT_hash_handle hh; /* makes this structure hashable */
} hashtbl_aux;
typedef struct __attribute__((__packed__)) gappytyp {
//typedef struct gappytyp { //ROLL BACK
//If all four adds up, should minus 1 get the last position of aXb.
int qrystart;
uint8_t qrystart_len;
uint8_t qryend_len;
uint8_t gap;
} gappy;//gappy enum
typedef struct __attribute__((__packed__)) gappytyp2 {
//typedef struct gappytyp2 { //ROLL BACK
unsigned int blockid; //for the one gappy search index id
unsigned int gap2;
uint8_t qryend_len;
} twogappy;//gappy enum
typedef struct __attribute__((__packed__)) gappytyp_se2 {
//typedef struct gappytyp_se2 { //ROLL BACK
unsigned int blockid; //for the one gappy search index id
unsigned int gap2;///Change it to unsigned int, no longer uint8_t
uint8_t qryend_len;
unsigned int position; //positions on the twogap array
int start_on_salist;
int end_on_salist;
} two_gappy_search;//gappy to be searched
typedef struct __attribute__((__packed__)) gappytyp_se {
//typedef struct gappytyp_se { //ROLL BACK
int qrystart;
uint8_t qrystart_len;
uint8_t qryend_len;
uint8_t gap;
unsigned int position; //positions on the onegap array
int start_on_salist;
int end_on_salist;
} gappy_search;//gappy to be searched
typedef struct __attribute__((__packed__)) gappytyp_sa {
//typedef struct gappytyp_sa { //
unsigned int position;// this is the block ID on onegapsearch array! Not that position
unsigned int str_position;
uint8_t length; //on str array
} oneGapOnSA;//one gappy results on str
typedef struct __attribute__((__packed__)) gappytyp_sa2 {
//typedef struct gappytyp_sa2 { //
unsigned int position;// this is the block ID on twogapsearch array! Not that position
unsigned int str_position;
uint8_t length; //on str array - same as above - first end of the string aXb's b
uint8_t length2; //on str array - the extra second real end of the stirng aXbXc's c
} twoGapOnSA;//one gappy results on str
typedef struct __attribute__((__packed__)) gapPattern1 {
//typedef struct gapPattern1{ //ROLL BACK
int pattern[MAX_rule_symbols];
uint8_t number; // 1 - Max_rule_symbols
} gapPattern;
typedef struct __attribute__((__packed__)) gapPattern2 {
//typedef struct gapPattern2{ //ROLL BACK
int pattern[MAX_rule_symbols-4];
uint8_t number; // 1 - Max_rule_symbols
unsigned int blockid;//for sort purpose - one gap block id
} twoGapPattern;
typedef struct __attribute__((__packed__)) gappytyp2old {
//typedef struct gappytyp2old { //ROLL BACK
unsigned int gappy_index;
int qryend2;
uint8_t qryend_len;
uint8_t gap;
} two_gappy;
typedef struct __attribute__((__packed__)) gappytyp3 {
//typedef struct gappytyp3 { //ROLL BACK
unsigned int gappy_index;
unsigned int within_each_precomp;
int qryend2;
uint8_t qryend_len;
uint8_t gap;
} two_gappy_precomp;
typedef struct __attribute__((__packed__)) gappytyp4 {
//typedef struct gappytyp4 { //ROLL BACK
int gappy_index;
unsigned int ref_str_start; //start
uint8_t end;
uint8_t gap1;//use gap1 and gap2 to determine the gap length, one of them could be zero.
uint8_t gap1_1;
} rule_onegap;
typedef struct __attribute__((__packed__)) gappytyp5 {
//typedef struct gappytyp5 { //ROLL BACK
int twogappyindex; //detect whether it is bigger than two_gappy_precomp's count first
unsigned int ref_str_start;
uint8_t end;
uint8_t gap1; //first gap length
uint8_t gap1_1;
uint8_t gap2;
uint8_t gap2_1;
} rule_twogap;
typedef struct red_dup_s { // CUDA output
int blocknumber;
const char* lexical;
int f; // all aligned source
float all_suffix_fsample_score; //source with all suffix
int all_suffix_fsample; //source with all suffix
int* paircount; //fe pair count
float bb; //source with all suffix
float aa; //source with all suffix
float MaxLexFgivenE;
float MaxLexEgivenF;
} red_dup_t;
typedef struct qry_set_s {
int *qrysbuf;
int qrysbufsize;
int *qrys;
int *connectoffset;
int *qrysoffsettok; /* list of queries offsets
within the qrys buffer */
int qryscount; /* number of queries */
int resbufsize; /* size of the result buffer */
int totaltokens;
int totalconnect;
result_t* result;
result_t* result_connect;
result_t_two* result_two;
int* tokindex_qryindex;
//Continous Data
////////////////////////////////////
std::vector<std::vector<unsigned int> > continousQueryWithID;
unsigned int distinctContinousCount;
//Gappy Data Structures
////////////////////////////////////
unsigned int onegapcount_enu;//Done
gappy* onegap;//Done Sorted
gapPattern* onegapPattern;//Done sorted
unsigned int distinctOneGapCount;//Done
gappy_search* oneGapSearch;//Done
oneGapOnSA* oneGapSA;//Done sorted
unsigned int countOneGapSA;//Done
///////////////////////////////////////////
unsigned int twogapcount_enu;//Done
twogappy* twoGap;//Done
gapPattern2* twogapPattern;//Done
unsigned int distinctTwoGapCount;//Done
two_gappy_search* twoGapSearch;//Done
twoGapOnSA* twoGapSA;//Done
unsigned int countTwoGapSA;//Done
std::vector<std::vector<unsigned int> > twoGapQueryWithID;
std::vector<std::vector<unsigned int> > oneGapQueryWithID;
//two_gappy* twogaps;
//unsigned int twogapscount;
///////////////////////////////////////////Processed Up and Down with converted ids
result_t* globalOnPairsUpDownContinous;//bnum - ab
result_t* globalOnPairsUpDownGappy;//one gap - aXb, Xab, abX
result_t* globalOnPairsUpDownTwoGap;//two gap - aXbXc, XaXb, aXbX
////////////////////////////////Statistics all in here for contionous/one gap/two gap
red_dup_t* fast_speed;
red_dup_t* fast_speed_one_gap;
red_dup_t* fast_speed_two_gap;
} qry_set_t;
typedef struct precomp_st_end1{
unsigned int start;
unsigned int end;
} precomp_st_end;
typedef struct ref_s_tar {
int *buf;
long bufsize; /* size of the buffer */
int *str; /* reference string */
uint8_t *L_tar;
uint8_t *R_tar;
unsigned int toklen; /*the length of the sa, lcp, lcpcr, lcpcl and rank arrays */
int* sentenceind;
char** vocabulary;//from s->id to s->name on target lan side for faster speed
//Change global to local
hashtbl *users_target;
hash_intchar *intchar_target;
} ref_t_target;
typedef struct saind_s { // CUDA input
int start;
int end;
int matchlen;
int string_start;
} saind_t;
typedef struct __attribute__((__packed__)) res_phrase_s { // CUDA output
int tar_start;
int blocknumber;
uint8_t tar_end;
} res_phrase_t;
typedef struct workKeytyp {
int ch; //first key using int as ids
int eng; //second key
} wordKey;
typedef struct categ {
float val1;
float val2;
} category;
typedef struct taskRes_t { //search final results here
float MaxLexFgivenE;
float MaxLexEgivenF;
} lexTaskResults;
typedef struct lexicalFile { //search range and results here
categ* values;
workKeytyp* keys; //each contain two parts
unsigned int count;
} lexicalFileCuda;
typedef struct __attribute__((__packed__)) lexicalTaskt {
//typedef struct lexicalTaskt {
unsigned int fastSpeedId;
///Source side
int sourcePattern[MAX_rule_symbols];
uint8_t sourcePatternCounter;
///Target side
unsigned int targetStart;
uint8_t end;
uint8_t gap1; //first gap length
uint8_t gap1_1;
uint8_t gap2;
uint8_t gap2_1;
} lexicalTask;
typedef struct targetCate{
int target_start;
const char* str;
} tarCate;
typedef struct precompute1 {
int length;
int token;
long start;
long end;
} precomp_tok;
typedef struct __attribute__((__packed__)) precompute_enu{
//typedef struct precompute_enu {
int token_a;//aXb
int token_b;
unsigned int start;
unsigned int length;
bool reverse;
} precompute_enu;
typedef struct __attribute__((__packed__)) precompute_enu_21{
//typedef struct precompute_enu_2{ //roll back
unsigned int index;//aXb
unsigned int start;
uint8_t length;
} precompute_enu_2;
typedef struct __attribute__((__packed__)) precompute_enu_31{
//typedef struct precompute_enu_31{ ////ROLL BACK
unsigned int start;
uint8_t length;//The last position of aXb's b. inclusive
} precompute_enu_3;
typedef struct ref_s {
int *buf; /* This buffer contains all the state presented below
contiguously in the following order: lcp, lcpleft, lcpright, rank
This would make it easier when moving data to the GPU */
size_t bufsize; /* size of the buffer */
int *str; /* reference string, separate */
int *sa; /* reference suffix array separate */
int *lcp; /* longest common prefix array */
int *rank;
int *lcpleft; /*LCP Table Random Version */
int *lcpright;
unsigned int toklen; /*the length of the sa, lcp, lcpcr, lcpcl and rank arrays */
/* If this is a sub reference in a super reference then: */
int begin; /* is the beginning index of this
sub reference in the super reference */
int end; /* is the end index of this
sub reference in the super reference */
uint8_t *P;
unsigned int *RLP;
int *sentenceind;
int sentence_count;
int distinctTokenCount; //HashCount(user)+2
////Precomputation
int* frequentList;
precomp_st_end* precomp_index;//size: TOP*TOP
precompute_enu_3* precomp_onegap;
unsigned int precomp_count;
int* featureMissingCount; //size: TOP*TOP
char** vocabulary;//from s->id to s->name on source lan side for faster speed
///Change global to local
hashtbl *users;
hash_intchar *intchar;
} ref_t;
typedef struct ref_set_s {
ref_t * refs;
ref_t_target * refs_target;
int count;
} ref_set_t;
typedef struct context_s {
ref_t ref_d;
ref_t_target ref_target_d;
qry_set_t qryset_d;
result_t *resbuf_d;
saind_t* blocks_d;
result_t * globalOnPairsUpDown_d;
res_phrase_t* out_pair;
} context_t;
#endif /* COM_TYPES_H */