source: trunk/symbol_table/main_template.cpp @ 2140

Last change on this file since 2140 was 2140, checked in by ksherdy, 7 years ago

Fixed template.

File size: 7.9 KB
Line 
1/*
2 * Created on: 18-December-2011
3 * Author: Ken Herdy
4 *
5 * A simple test driver.
6 *
7 * Lookahead versus COPYBACK
8 *
9 * The current implementation applies bit stream length grouping based on 'end' markers.
10 * In a sense, 'end' markers are precomputed 'lookahead'.
11 * True 'lookahead' would compute the current block and number of 'lookahead' position and
12 * support 'shift back' and to mark the 'start' rather than the 'end' positions of lexical items.
13 *
14 * In any case, the current implementation 'expects' that the previous block will be located in a contiguous
15 * memory location that may be indexed as some negative offset of the base address of the current
16 * block.
17 *
18 * Further, to reduce complexity in processing, although structs of BitBlock types are not stored
19 * contiguously in memory, BitBlock struct members are copied into contiguous memory positions.
20 *
21 */
22
23#include "../lib/allocator.hpp"
24#include "../lib/bitblock.hpp"
25#include "../lib/bitblock_scan.hpp"
26#include "../lib/carryQ.hpp"
27#include "../lib/s2p.hpp"
28#include "../lib/perflib/perfsec.h"
29#include "transpose.hpp"
30#include "buffer.hpp"
31#include "marker_strms.hpp"     // GENERATED HEADER
32#include "hash_strms.hpp"       // GENERATED HEADER
33#include "group_strms.hpp"      // GENERATED HEADER
34#include <string>
35#include <iostream>
36#include <fstream>
37#include <sstream>
38using namespace std;
39
40#include "symbol_table.hpp"
41
42#ifdef BUFFER_PROFILING
43    BOM_Table * parser_timer;
44#elif CODE_CLOCKER
45    #define NUM_EVENTS 1
46    int Events[NUM_EVENTS] = {PAPI_TOT_CYC};
47    //int Events[NUM_EVENTS] = {PAPI_L2_DCM};
48    //int Events[NUM_EVENTS] = {PAPI_TOT_CYC, PAPI_BR_MSP};
49    int cal_size = 20;
50    CC * parser_timer = new CC(Events,NUM_EVENTS,cal_size);
51#else
52    void * parser_timer;
53#endif
54
55int main(int argc, char * argv[]) {
56
57    if (argc < 2) {
58            cout << "Usage: " << argv[0] << " <filename>" << endl;
59            exit(-1);
60    }
61
62    stringstream filename;
63    filename << argv[1];
64
65    ifstream is;
66    is.open (filename.str().c_str(), ios::binary);
67
68    if (!is) {
69        cerr << "Error: " << filename << endl;
70        abort();
71    }
72
73    // PERF_SEC_BIND(1);
74    PERF_SEC_INIT(parser_timer);
75
76    ///////////////////////////////////////////////////////////////////////////
77    // Parallel Data Streams with optional CopyBack
78    ///////////////////////////////////////////////////////////////////////////
79    uint8_t * COPYBACK;
80    uint8_t * src_buffer;
81    ALLOC_STATIC_ALIGNED_BYTE_BUFFER(COPYBACK, src_buffer);
82
83    // hash 0
84    BitBlock * COPYBACK_h0;
85    BitBlock * h0;
86    ALLOC_STATIC_ALIGNED_BITBLOCK_BUFFER(COPYBACK_h0, h0);
87
88    // hash 1
89    BitBlock * COPYBACK_h1;
90    BitBlock * h1;
91    ALLOC_STATIC_ALIGNED_BITBLOCK_BUFFER(COPYBACK_h1, h1);
92
93    // starts
94    BitBlock * COPYBACK_starts;
95    BitBlock * starts;
96    ALLOC_STATIC_ALIGNED_BITBLOCK_BUFFER(COPYBACK_starts, starts);
97
98    // follows_0 - Arbitrary length symbols
99    BitBlock * COPYBACK_follows_0;
100    BitBlock * follows_0;
101    ALLOC_STATIC_ALIGNED_BITBLOCK_BUFFER(COPYBACK_follows_0, follows_0);
102
103    ///////////////////////////////////////////////////////////////////////////
104    // Parallel Data Streams - No CopyBack
105    ///////////////////////////////////////////////////////////////////////////
106
107    Basis_bits basis_bits[SEGMENT_BLOCKS];
108    Markers markers[SEGMENT_BLOCKS];
109    Hash hash[SEGMENT_BLOCKS];
110    Groups groups[SEGMENT_BLOCKS];
111
112    // Symbol Table
113    gid<SEGMENT_SIZE> gids;
114    symbol_table<gid<SEGMENT_SIZE>, fast_pool_allocator<1024> > st;
115
116    is.read ((char *)src_buffer, SEGMENT_SIZE);
117    uint32_t chars_avail = is.gcount();
118
119    #if IDENTITY_TEST
120        cout << ","; // prepend delimeter
121    #endif
122
123    ///////////////////////////////////////////////////////////////////////////
124    // Full Segments
125    ///////////////////////////////////////////////////////////////////////////
126    while (chars_avail >= SEGMENT_SIZE) {
127        uint32_t blk;
128        for(blk=0;blk<SEGMENT_BLOCKS;blk++) {
129        s2p_do_block((BytePack *) &src_buffer[blk*BLOCK_SIZE], basis_bits[blk]);    // transpose
130        markers_do_block(basis_bits[blk], markers[blk]);                            // gen symbol spans, mark starts & follows
131        hash_strms_do_block(basis_bits[blk], hash[blk]);                            // gen hash bit streams
132        identity_group_do_block(markers[blk], groups[blk]);                         // sort marker bit stream (identity)
133    }
134
135    for(int blk=0;blk<SEGMENT_BLOCKS;blk++) {   // write contiguous bit streams
136        h0[blk] = hash[blk].h0;
137        h1[blk] = hash[blk].h1;
138        starts[blk] = groups[blk].starts;
139        follows_0[blk] = groups[blk].follows_0;
140    }
141
142    PERF_SEC_START(parser_timer);
143    st.resolve(src_buffer, groups, starts, follows_0, h0, h1, SEGMENT_BLOCKS, gids);
144    PERF_SEC_END(parser_timer, SEGMENT_SIZE);
145
146    COPY_BACK_BYTE_BUFFER(COPYBACK, src_buffer);
147    COPY_BACK_BITBLOCK_BUFFER(COPYBACK_h0,h0);
148    COPY_BACK_BITBLOCK_BUFFER(COPYBACK_h1,h1);
149    COPY_BACK_BITBLOCK_BUFFER(COPYBACK_starts,starts);
150    COPY_BACK_BITBLOCK_BUFFER(COPYBACK_follows_0,follows_0);
151
152    is.read ((char *)(src_buffer), SEGMENT_SIZE);
153    chars_avail = is.gcount();
154
155    #ifdef IDENTITY_TEST
156    uint32_t blk_offset;
157    for(int blk=0;blk<SEGMENT_BLOCKS;blk++) {
158        blk_offset = blk * BLOCK_SIZE;
159        gid_type gid;
160
161        #ifdef INDEX_AT_FOLLOWS
162            ForwardScanner<BitBlock, scanword_t> scanner(&(groups[blk].follows));
163        #else
164            ForwardScanner<BitBlock, scanword_t> scanner(&(groups[blk].starts));
165        #endif
166
167        scanner.scan_to_next();
168        while(!scanner.is_done()) {
169                gid = gids.at[scanner.get_pos() + blk_offset];
170                cout << string((char *)st.get_raw_data(gid), st.get_lgth(gid)) << ",";
171                scanner.scan_to_next();
172        }
173    }
174    #endif
175    }
176
177    /* Resolve Partial Segments */
178    uint32_t remaining = chars_avail;
179
180    ///////////////////////////////////////////////////////////////////////////
181    // Full blocks
182    ///////////////////////////////////////////////////////////////////////////
183    uint32_t blk = 0;
184    while (remaining >= BLOCK_SIZE) {
185        s2p_do_block((BytePack *) &src_buffer[blk*BLOCK_SIZE], basis_bits[blk]);
186        markers_do_block(basis_bits[blk], markers[blk]);
187        hash_strms_do_block(basis_bits[blk], hash[blk]);
188        identity_group_do_block(markers[blk], groups[blk]);
189        blk++;
190        remaining -= BLOCK_SIZE;
191    }
192
193    ///////////////////////////////////////////////////////////////////////////
194    // Final partial block or any carry
195    ///////////////////////////////////////////////////////////////////////////
196    if (remaining > 0 || @marker_strms_any_carry || @group_strms_any_carry /*|| hash_strms_any_carry*/) {
197        BitBlock EOF_mask = bitblock::srl(simd<1>::constant<1>(), convert(BLOCK_SIZE-remaining));
198        s2p_do_final_block((BytePack *) &src_buffer[blk*BLOCK_SIZE], basis_bits[blk], EOF_mask);
199        markers_do_final_block(basis_bits[blk], markers[blk], EOF_mask);
200        hash_strms_do_final_block(basis_bits[blk], hash[blk], EOF_mask);
201        identity_group_do_final_block(markers[blk], groups[blk], EOF_mask);
202        blk++;
203    }
204
205    uint32_t segment_blocks = blk;
206    for(int blk=0;blk<segment_blocks;blk++) { // write contiguous hash bit streams
207        h0[blk] = hash[blk].h0;
208        h1[blk] = hash[blk].h1;
209        starts[blk] = groups[blk].starts;
210        follows_0[blk] = groups[blk].follows_0;
211    }
212
213    // PERF_SEC_BIND(0);
214    PERF_SEC_START(parser_timer);
215    st.resolve(src_buffer, groups, starts, follows_0, h0, h1, segment_blocks, gids);
216    PERF_SEC_END(parser_timer, chars_avail);
217
218    #ifdef IDENTITY_TEST
219    uint32_t blk_offset;
220    for(int blk=0;blk<segment_blocks;blk++) {
221        blk_offset = blk * BLOCK_SIZE;
222        gid_type gid;
223
224        #ifdef INDEX_AT_FOLLOWS
225            ForwardScanner<BitBlock, scanword_t> scanner(&(groups[blk].follows));
226        #else
227            ForwardScanner<BitBlock, scanword_t> scanner(&(groups[blk].starts));
228        #endif
229
230        scanner.scan_to_next();
231        while(!scanner.is_done()) {
232                gid = gids.at[scanner.get_pos() + blk_offset];
233                cout << string((char *)st.get_raw_data(gid), st.get_lgth(gid)) << ",";
234                scanner.scan_to_next();
235        }
236    }
237    #endif
238
239    #ifdef GID_TEST
240        cout << st.get_max_gid() << endl;
241    #endif
242
243    PERF_SEC_DUMP(parser_timer);
244    PERF_SEC_DESTROY(parser_timer);
245
246    is.close();
247
248    return 1;
249}
250
251
Note: See TracBrowser for help on using the repository browser.