Ignore:
Timestamp:
Mar 4, 2018, 4:46:25 PM (17 months ago)
Author:
cameron
Message:

BitByteGrepKernel? initial check-in

File:
1 edited

Legend:

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

    r5888 r5889  
    99#include <re/re_toolchain.h>
    1010#include <re/re_reverse.h>
     11#include <pablo/codegenstate.h>
    1112#include <pablo/pablo_toolchain.h>
    1213#include <kernels/kernel_builder.h>
     
    1819#include <pablo/pe_count.h>
    1920#include <pablo/pe_matchstar.h>
     21#include <pablo/pe_pack.h>
    2022#include <cc/cc_compiler.h>         // for CC_Compiler
    2123#include <cc/alphabet.h>
     
    240242}
    241243
     244// Helper to compute stream set inputs to pass into PabloKernel constructor.
     245inline std::vector<Binding> byteBitGrepInputs(const std::unique_ptr<kernel::KernelBuilder> & b,
     246                                         const std::vector<std::string> & externals) {
     247    std::vector<Binding> streamSetInputs = {
     248        Binding{b->getStreamSetTy(1, 8), "bytedata"},
     249    };
     250    for (auto & e : externals) {
     251        streamSetInputs.push_back(Binding{b->getStreamSetTy(1, 1), e});
     252    }
     253    return streamSetInputs;
     254}
     255
     256
     257ByteBitGrepSignature::ByteBitGrepSignature(RE * prefix, RE * suffix)
     258: mPrefixRE(prefix)
     259, mSuffixRE(suffix)
     260, mSignature(Printer_RE::PrintRE(mPrefixRE) + Printer_RE::PrintRE(mSuffixRE) ) {
     261   
     262}
     263
     264ByteBitGrepKernel::ByteBitGrepKernel(const std::unique_ptr<kernel::KernelBuilder> & b, RE * const prefixRE, RE * const suffixRE, std::vector<std::string> externals)
     265: ByteBitGrepSignature(prefixRE, suffixRE)
     266, PabloKernel(b, "bBc" + sha1sum(mSignature),
     267              // inputs
     268              byteBitGrepInputs(b, externals),
     269              // output
     270{Binding{b->getStreamSetTy(1, 1), "matches", FixedRate(), Add1()}})
     271, mExternals(externals) {
     272}
     273
     274std::string ByteBitGrepKernel::makeSignature(const std::unique_ptr<kernel::KernelBuilder> &) {
     275    return mSignature;
     276}
     277
     278
     279void ByteBitGrepKernel::generatePabloMethod() {
     280    PabloBuilder pb(getEntryScope());
     281    PabloAST * u8bytes = pb.createExtract(getInput(0), pb.getInteger(0));
     282    cc::Direct_CC_Compiler dcc(getEntryScope(), u8bytes);
     283    RE_Compiler re_byte_compiler(getEntryScope(), dcc);
     284    for (auto & e : mExternals) {
     285        re_byte_compiler.addPrecompiled(e, pb.createExtract(getInputStreamVar(e), pb.getInteger(0)));
     286    }
     287    PabloAST * const prefixMatches = re_byte_compiler.compile(mPrefixRE);
     288   
     289    PabloBlock * scope1 = getEntryScope()->createScope();
     290    pb.createIf(prefixMatches, scope1);
     291   
     292    PabloAST * nybbles[2];
     293    nybbles[0] = scope1->createPackL(scope1->getInteger(8), u8bytes);
     294    nybbles[1] = scope1->createPackH(scope1->getInteger(8), u8bytes);
     295   
     296    PabloAST * bitpairs[4];
     297    for (unsigned i = 0; i < 2; i++) {
     298        bitpairs[2*i] = scope1->createPackL(scope1->getInteger(4), nybbles[i]);
     299        bitpairs[2*i + 1] = scope1->createPackH(scope1->getInteger(4), nybbles[i]);
     300    }
     301   
     302    std::vector<PabloAST *> basis(8);
     303    for (unsigned i = 0; i < 4; i++) {
     304        basis[7-2*i] = scope1->createPackL(scope1->getInteger(2), bitpairs[i]);
     305        basis[7-(2*i + 1)] = scope1->createPackH(scope1->getInteger(2), bitpairs[i]);
     306    }
     307   
     308    cc::Parabix_CC_Compiler ccc(scope1, basis);
     309    RE_Compiler re_compiler(scope1, ccc);
     310    PabloAST * const matches = re_compiler.compile(mSuffixRE);
     311    Var * const output = getOutputStreamVar("matches");
     312    pb.createAssign(pb.createExtract(output, pb.getInteger(0)), matches);
     313}
     314
     315
     316
     317
    242318void MatchedLinesKernel::generatePabloMethod() {
    243319    PabloBuilder pb(getEntryScope());
Note: See TracChangeset for help on using the changeset viewer.