Feb 6, 2015, 9:37:37 AM (5 years ago)

Evaluation of optimization; diagram tweaks

1 edited


  • docs/Working/icGrep/architecture.tex

    r4446 r4466  
    3 \include{fig-compiler}
    52\subsection{Regular Expression Preprocessing}
     6As show in Figure \ref{fig:compiler},
     7icGrep is composed of three logical layers: \RegularExpression{}, \Pablo{} and the LLVM layer, each with their own intermediate representation
     8(IR), transformation and compilation modules.
     10As we traverse the layers, the IR becomes significantly more complex as it begins to mirror the final machine code.
     12The \REParser{} validates and transforms the input \RegularExpression{} into an abstract syntax tree (AST).
     14The AST is a minimalistic representation that, unlike traditional \RegularExpression{}, is not converted into a NFA or DFA for further processing.
     16Instead, icGrep passes the AST into the transformation module, which includes a set of \RegularExpression{} specific optimization passes.
     18The initial \emph{Nullable} pass, determines whether the \RegularExpression{} contains any prefixes or suffixes that may be removed or
     19modified whilst still providing the same number of matches as the original expression.
     21For example, ``\verb|a*bc+|'' is equivalent to ``\verb|bc|'' because the Kleene Star (Plus) operator matches zero (one) or more instances of a
     22specific character.
     24The \emph{toUTF8} pass converts the characters in the input \RegularExpression{} into the equivalent expression(s) that represent the sequences
     25of 8-bit code units necessary to identify the presence of a particular character.
     27Since some characters have multiple logically equivalent representations, such as \textcolor{red}{\textbf{????}}, this may produce nested sequences or alternations.
     29This is described in more detail in \S\ref{sec:Unicode:toUTF8}.
     31To alleviate this, the final \emph{Simplification} pass flattens nested sequences and alternations into their simplest legal form.
     33For example, ``\verb`a(b((c|d)|e))`'' would become ``\verb`ab(c|d|e)`'' and ``\verb`([0-9]{3,5}){3,5}`'', ``\verb`[0-9]{9,25}`''.
     39The \RegularExpression{} layer has two compilers: the \CodeUnit{} and \RegularExpressionCompiler{}, both of which produce \Pablo{} IR.
     41Recall that the \Pablo{} layer assumes a transposed view of the input data.
     43The \emph{\CodeUnitCompiler{}} transforms the input code unit classes, either extracted from the \RegularExpression{} or produced by the
     44\emph{toUTF8} transformation, into a series of bit stream equations.
     46The \emph{\RegularExpressionCompiler{}} assumes that these have been calculated and transforms the \RegularExpression{} AST into
     47a sequence of instructions.
     49For instance, it would convert any alternations into a sequence of calculations that are merged with \verb|OR|s.
     51The results of these passes are combined and transformed through a series of typical optimization passes, including dead code elimination
     52(DCE), common subexpression elimination (CSE), and constant folding.
     54These are necessary at this stage because the \RegularExpression{} AST may include common subsequences that are costly to recognize in
     55that form.
     57Similarly, to keep the \CodeUnitCompiler{} a linear time function, it may introduce redundant IR instructions as it applies traditional Boolean
     58algebra transformations, such as de Morgan's law, to the computed streams.
     60An intended side-effect of these passes is that they eliminate the need to analyze the data-dependencies inherent in the carry-bit logic,
     61which is necessary for some \Pablo{} instructions but problematic for optimizers to reason about non-conservatively.
     63The \PabloCompiler{} then converts the \Pablo{} IR into LLVM IR.
     65This is a relatively straightforward conversion:
     67the only complexities it introduces is the generation of Phi nodes, linking of statically-compiled functions, and assignment of carry variables.
     69It produces the dynamically-generated match function used by the icGrep.
    771\subsection{Dynamic Grep Engine}
     75As shown in Figure \ref{fig:execution}, icGrep takes the input data and transposed it into 8 parallel bit streams through S2P module.
     76The required streams, e.g. line break stream, can then be generated using the 8 basis bits streams.
     77The JIT function retrieves the 8 basis bits and the required streams from their memory addresses and starts the matching process.
     78Named Property Library that includes all the predefined Unicode categories is installed into JIT function and can be called during the matching process.
     79JIT function returns one bitstream that marks all the matching positions.
     80A match scanner will scan through this bitstream and calculate the total counts or write the context of each match position.
     82We can also apply a pipeline parallelism strategy to further speed up the process of icGrep.
     83S2P and Required Streams Generator can be process in a separate thread and start even before the dynamic compilation starts.
     84The output of S2P and Required Streams Generator, that is the 8 basis bits streams and the required streams,
     85needs to be stored in a shared memory space so that the JIT function can read from it.
     86To be more efficient of memory space usage, we only allocate limit amount of space for the shared data.
     87When each chunk of the shared space is filled up with the bitstream data,
     88the thread will start writing to the first chunk if it is released by JIT function.
     89Otherwise, it will wait for JIT function until it finishes processing that chunk.
     90Therefore, the performance is depended on the slowest thread.
     91In the case that the cost of transposition and required stream generation is more than the matching process,
     92we can further divide up the work and assign two threads for S2P and Required Streams Generator.
Note: See TracChangeset for help on using the changeset viewer.