Ignore:
Timestamp:
Dec 31, 2017, 7:22:14 PM (13 months ago)
Author:
cameron
Message:

Supporting multiple alphabets in RE compilation - initial check-in

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/grep_kernel.cpp

    r5797 r5816  
    1919#include <cc/cc_compiler.h>         // for CC_Compiler
    2020#include <cc/alphabet.h>
     21#include <re/re_compiler.h>
    2122#include <llvm/Support/raw_ostream.h>
    2223
     
    175176}
    176177
    177 ICGrepKernel::ICGrepKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, RE * const re, unsigned numOfCharacterClasses)
     178inline static unsigned ceil_log2(const unsigned v) {
     179    assert ("log2(0) is undefined!" && v != 0);
     180    return (sizeof(unsigned) * CHAR_BIT) - __builtin_clz(v - 1U);
     181}
     182
     183// Helper to compute stream set inputs to pass into PabloKernel constructor.
     184std::vector<Binding> icGrepInputs(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, std::vector<cc::Alphabet *> alphabets) {
     185    std::vector<Binding> streamSetInputs = {Binding{iBuilder->getStreamSetTy(8), "basis"},
     186        Binding{iBuilder->getStreamSetTy(1, 1), "linebreak"},
     187        Binding{iBuilder->getStreamSetTy(1, 1), "cr+lf"},
     188        Binding{iBuilder->getStreamSetTy(3, 1), "required"}};
     189    for (unsigned i = 0; i < alphabets.size(); i++) {
     190        unsigned basis_size = ceil_log2(alphabets[i]->getSize());
     191        streamSetInputs.push_back(Binding{iBuilder->getStreamSetTy(basis_size, 1), "basisSet" + std::to_string(i)});
     192    }
     193    return streamSetInputs;
     194}
     195
     196ICGrepKernel::ICGrepKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, RE * const re, std::vector<cc::Alphabet *> alphabets)
    178197: ICGrepSignature(re)
    179198, PabloKernel(iBuilder, "ic" + sha1sum(mSignature),
    180199// inputs
    181 {Binding{iBuilder->getStreamSetTy(numOfCharacterClasses), "basis"},
    182 Binding{iBuilder->getStreamSetTy(1, 1), "linebreak"},
    183 Binding{iBuilder->getStreamSetTy(1, 1), "cr+lf"},
    184 Binding{iBuilder->getStreamSetTy(3, 1), "required"}},
     200icGrepInputs(iBuilder, alphabets),
    185201// output
    186202{Binding{iBuilder->getStreamSetTy(1, 1), "matches", FixedRate(), Add1()}}) {
    187 
     203    mAlphabets = alphabets;
    188204}
    189205
     
    193209
    194210void ICGrepKernel::generatePabloMethod() {
    195     PabloAST * const match_post = re2pablo_compiler(this, mRE);
     211    Var * const basis = getInputStreamVar("basis");
     212    cc::CC_Compiler cc_compiler(this, basis);
     213    RE_Compiler re_compiler(this, cc_compiler);
     214    for (unsigned i = 0; i < mAlphabets.size(); i++) {
     215        auto basis = getInputStreamVar("basisSet" + std::to_string(i));
     216        re_compiler.addAlphabet(mAlphabets[i], basis);
     217    }
     218    PabloAST * const match_post = re_compiler.compile(mRE);
    196219    PabloBlock * const pb = getEntryBlock();
    197220    Var * const output = getOutputStreamVar("matches");
Note: See TracChangeset for help on using the changeset viewer.