Ignore:
Timestamp:
Apr 18, 2017, 10:41:50 PM (2 years ago)
Author:
cameron
Message:

Factor out CountOnly? and InvertMatches? as separate kernels

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
2 edited

Legend:

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

    r5410 r5413  
    99#include <re/re_toolchain.h>
    1010#include <pablo/pablo_toolchain.h>
     11#include <IR_Gen/idisa_builder.h>  // for IDISA_Builder
     12#include <pablo/builder.hpp>  // for PabloBuilder
     13#include <pablo/pe_count.h>
    1114
    1215using namespace kernel;
     
    2629}
    2730
    28 inline std::string makeSignature(RE * const re_ast, const bool CountOnly) {
     31inline std::string makeSignature(RE * const re_ast) {
    2932    std::string signature = Printer_RE::PrintRE(re_ast);
    30     if (CountOnly) {
    31         signature += "-c";
    32     }
    33     if (AlgorithmOptionIsSet(InvertMatches)) {
    34         signature += "-v";
    35     }
    3633    return signature;
    3734}
    3835
    39 ICgrepKernelBuilder::ICgrepKernelBuilder (IDISA::IDISA_Builder * const iBuilder, RE * const re_ast, const bool CountOnly)
     36ICgrepKernelBuilder::ICgrepKernelBuilder (IDISA::IDISA_Builder * const iBuilder, RE * const re_ast)
    4037: PabloKernel(iBuilder, "",
    4138              {Binding{iBuilder->getStreamSetTy(8), "basis"}, Binding{iBuilder->getStreamSetTy(1, 1), "linebreak"}},
    42               CountOnly ? std::vector<Binding>{} : std::vector<Binding>{Binding{iBuilder->getStreamSetTy(1, 1), "matches"}},
     39              {Binding{iBuilder->getStreamSetTy(1, 1), "matches"}},
    4340              {},
    44               CountOnly ? std::vector<Binding>{Binding{iBuilder->getSizeTy(), "matchedLineCount"}} : std::vector<Binding>{})
    45 , mCountOnly(CountOnly)
     41              {})
    4642, mRE(re_ast)
    47 , mSignature(makeSignature(re_ast, CountOnly)) {
     43, mSignature(makeSignature(re_ast)) {
    4844    setName("Parabix:" + sha1sum(mSignature));
    4945}
     
    5450
    5551void ICgrepKernelBuilder::prepareKernel() {
    56     re2pablo_compiler(this, regular_expression_passes(mRE), mCountOnly);
     52    re2pablo_compiler(this, regular_expression_passes(mRE));
    5753    pablo_function_passes(this);
    5854    PabloKernel::prepareKernel();
    5955}
     56
     57void InvertMatchesKernel::generateDoBlockMethod() {
     58    Value * input = loadInputStreamBlock("matchedLines", iBuilder->getInt32(0));
     59    Value * lbs = loadInputStreamBlock("lineBreaks", iBuilder->getInt32(0));
     60    Value * inverted = iBuilder->CreateXor(input, lbs);
     61    storeOutputStreamBlock("nonMatches", iBuilder->getInt32(0), inverted);
     62}
     63
     64InvertMatchesKernel::InvertMatchesKernel(IDISA::IDISA_Builder * builder)
     65: BlockOrientedKernel(builder, "Invert", {Binding{builder->getStreamSetTy(1, 1), "matchedLines"}, Binding{builder->getStreamSetTy(1, 1), "lineBreaks"}}, {Binding{builder->getStreamSetTy(1, 1), "nonMatches"}}, {}, {}, {}) {
     66    setNoTerminateAttribute(true);
     67   
     68}
     69
     70
     71PopcountKernel::PopcountKernel (IDISA::IDISA_Builder * const iBuilder)
     72: PabloKernel(iBuilder, "Popcount",
     73              {Binding{iBuilder->getStreamSetTy(1), "toCount"}},
     74              {},
     75              {},
     76              {Binding{iBuilder->getSizeTy(), "countResult"}}) {
     77   
     78    auto pb = this->getEntryBlock();
     79    const auto toCount = pb->createExtract(getInputStreamVar("toCount"), pb->getInteger(0));
     80    pablo::Var * countResult = getOutputScalarVar("countResult");
     81    pb->createAssign(countResult, pb->createCount(toCount));
     82}
  • icGREP/icgrep-devel/icgrep/kernels/grep_kernel.h

    r5408 r5413  
    1414class ICgrepKernelBuilder: public pablo::PabloKernel {
    1515public:
    16     ICgrepKernelBuilder(IDISA::IDISA_Builder * const iBuilder, re::RE * const re_ast, const bool CountOnly = false);
     16    ICgrepKernelBuilder(IDISA::IDISA_Builder * const iBuilder, re::RE * const re_ast);
    1717   
    1818    std::string generateKernelSignature(std::string moduleId) override;
     
    2121
    2222private:
    23     const bool      mCountOnly;
    2423    re::RE * const  mRE;
    2524    std::string     mSignature;
    2625};
    2726
     27class InvertMatchesKernel : public BlockOrientedKernel {
     28public:
     29    InvertMatchesKernel(IDISA::IDISA_Builder * builder);
     30private:
     31    void generateDoBlockMethod() override;
     32};
     33
     34
     35class PopcountKernel : public pablo::PabloKernel {
     36public:
     37    PopcountKernel(IDISA::IDISA_Builder * builder);
     38};
     39
    2840}
    2941#endif
Note: See TracChangeset for help on using the changeset viewer.