Changeset 5889


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

BitByteGrepKernel? initial check-in

Location:
icGREP/icgrep-devel/icgrep
Files:
7 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());
  • icGREP/icgrep-devel/icgrep/kernels/grep_kernel.h

    r5881 r5889  
    5252};
    5353
     54struct ByteBitGrepSignature {
     55    ByteBitGrepSignature(re::RE * prefix, re::RE * suffix);
     56protected:
     57    re::RE * const  mPrefixRE;
     58    re::RE * const  mSuffixRE;
     59    std::string     mSignature;
     60};
     61
     62   
     63class ByteBitGrepKernel : public ByteBitGrepSignature, public pablo::PabloKernel {
     64public:
     65    ByteBitGrepKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, re::RE * const prefix, re::RE * const suffix, std::vector<std::string> externals = {});
     66    std::string makeSignature(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
     67    bool isCachable() const override { return true; }
     68protected:
     69    void generatePabloMethod() override;
     70    std::vector<std::string> mExternals;
     71};
     72
    5473class MatchedLinesKernel : public pablo::PabloKernel {
    5574public:
  • icGREP/icgrep-devel/icgrep/pablo/builder.cpp

    r5834 r5889  
    88#include <pablo/pe_scanthru.h>
    99#include <pablo/pe_repeat.h>
     10#include <pablo/pe_pack.h>
    1011#include <pablo/pe_infile.h>
    1112#include <pablo/pe_count.h>
     
    214215    return result;
    215216}
     217
     218   
     219PabloAST * PabloBuilder::createPackL(not_null<Integer *> fieldWidth, PabloAST * value) {
     220    MAKE_BINARY(createPackL, TypeId::PackL, fieldWidth.get(), value);
     221    return result;
     222}
     223
     224PabloAST * PabloBuilder::createPackH(not_null<Integer *> fieldWidth, PabloAST * value) {
     225    MAKE_BINARY(createPackH, TypeId::PackH, fieldWidth.get(), value);
     226    return result;
     227}
     228
    216229
    217230PabloAST * PabloBuilder::createAnd(PabloAST * expr1, PabloAST * expr2) {
  • icGREP/icgrep-devel/icgrep/pablo/builder.hpp

    r5836 r5889  
    3333
    3434    PabloBuilder createScope() noexcept {
    35         return PabloBuilder(&mPb->createScope(), this);
     35        return PabloBuilder(mPb->createScope(), this);
    3636    }
    3737
     
    157157
    158158    PabloAST * createRepeat(not_null<Integer *> fieldWidth, PabloAST * value, const llvm::StringRef & prefix);
     159   
     160    PabloAST * createPackL(const int64_t fieldWidth, PabloAST * value) {
     161        return createPackL(mPb->getInteger(fieldWidth), value);
     162    }
     163   
     164    PabloAST * createPackH(const int64_t fieldWidth, PabloAST * value) {
     165        return createPackH(mPb->getInteger(fieldWidth), value);
     166    }
     167   
     168    PabloAST * createPackL(not_null<Integer *> fieldWidth, PabloAST * value);
     169   
     170    PabloAST * createPackH(not_null<Integer *> fieldWidth, PabloAST * value);
     171
    159172
    160173    PabloAST * createOr(PabloAST * expr1, PabloAST * expr2);
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r5837 r5889  
    253253 * @brief createScope
    254254 ** ------------------------------------------------------------------------------------------------------------- */
    255 PabloBlock & PabloBlock::createScope() noexcept {
    256     return *new (mAllocator) PabloBlock(mParent, mAllocator);
     255PabloBlock * PabloBlock::createScope() noexcept {
     256    return new (mAllocator) PabloBlock(mParent, mAllocator);
    257257}
    258258
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r5836 r5889  
    6969    }
    7070
    71     PabloBlock & createScope() noexcept;
     71    PabloBlock * createScope() noexcept;
    7272
    7373    Advance * createAdvance(PabloAST * expr, Integer * shiftAmount) {
  • icGREP/icgrep-devel/icgrep/pablo/expression_map.hpp

    r5855 r5889  
    150150            case PabloAST::ClassTypeId::MatchStar:
    151151            case PabloAST::ClassTypeId::Assign:
     152            case PabloAST::ClassTypeId::PackL:
     153            case PabloAST::ClassTypeId::PackH:
    152154            case PabloAST::ClassTypeId::Extract:
    153155            case PabloAST::ClassTypeId::Repeat:
Note: See TracChangeset for help on using the changeset viewer.