Ignore:
Timestamp:
May 7, 2017, 4:34:48 PM (2 years ago)
Author:
nmedfort
Message:

Continued refactoring work. PabloKernel? now abstract base type with a 'generatePabloMethod' hook to generate Pablo code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/array-test.cpp

    r5435 r5436  
    55 */
    66
    7 #include <IR_Gen/idisa_builder.h>                  // for IDISA_Builder
    87#include <IR_Gen/idisa_target.h>                   // for GetIDISA_Builder
    98#include <kernels/source_kernel.h>
    109#include <kernels/s2p_kernel.h>                    // for S2PKernel
    1110#include <kernels/alignedprint.h>
     11#include <kernels/kernel_builder.h>
    1212#include <kernels/streamset.h>                     // for SingleBlockBuffer
    1313#include <llvm/ExecutionEngine/ExecutionEngine.h>  // for ExecutionEngine
     
    4646static cl::list<std::string> inputFiles(cl::Positional, cl::desc("<input file ...>"), cl::OneOrMore);
    4747
    48 void generate(PabloKernel * kernel) {
    49 
    50     PabloBuilder pb(kernel->getEntryBlock());
    51 
    52     Var * input = kernel->getInputStreamVar("input");
     48class ParenthesisMatchingKernel final: public pablo::PabloKernel {
     49public:
     50    ParenthesisMatchingKernel(const std::unique_ptr<kernel::KernelBuilder> & b, const unsigned count);
     51    bool isCachable() const override { return true; }
     52    bool moduleIDisSignature() const override { return true; }
     53protected:
     54    void generatePabloMethod() override;
     55};
     56
     57ParenthesisMatchingKernel::ParenthesisMatchingKernel(const std::unique_ptr<kernel::KernelBuilder> & b, const unsigned count)
     58: PabloKernel(b, "MatchParens",
     59    {Binding{b->getStreamSetTy(8), "input"}},
     60    {Binding{b->getStreamSetTy(count), "matches"}, Binding{b->getStreamTy(), "errors"}}) {
     61
     62}
     63
     64void ParenthesisMatchingKernel::generatePabloMethod() {
     65
     66    PabloBuilder pb(getEntryBlock());
     67
     68    Var * input = getInputStreamVar("input");
    5369
    5470    PabloAST * basis[8];
     
    7692    Var * const index = pb.createVar("i", pb.getInteger(0));
    7793
    78     Var * matches = kernel->getOutputStreamVar("matches");
     94    Var * matches = getOutputStreamVar("matches");
    7995
    8096//    PabloBuilder outer = PabloBuilder::Create(pb);
     
    119135    // Mark any closing paren that was not actually used to close an opener as an error.
    120136    PabloAST * const unmatched_rparen = pb.createAnd(rparen, pb.createNot(all_closed), "unmatched_rparen");
    121     pb.createAssign(kernel->getOutputStreamVar("errors"), pb.createOr(accumulated_errors, unmatched_rparen));
     137    pb.createAssign(getOutputStreamVar("errors"), pb.createOr(accumulated_errors, unmatched_rparen));
    122138
    123139}
     
    128144    Module * const mod = iBuilder->getModule();
    129145
    130     Type * byteStreamTy = iBuilder->getStreamSetTy(1, 8);
    131 
    132     Function * const main = cast<Function>(mod->getOrInsertFunction("Main", iBuilder->getVoidTy(), byteStreamTy->getPointerTo(), iBuilder->getSizeTy(), nullptr));
     146    Type * const byteStreamTy = iBuilder->getStreamSetTy(1, 8);
     147
     148    Function * const main = cast<Function>(mod->getOrInsertFunction("Main", iBuilder->getVoidTy(), iBuilder->getSizeTy(), nullptr));
    133149    main->setCallingConv(CallingConv::C);
    134     Function::arg_iterator args = main->arg_begin();
     150    auto args = main->arg_begin();
    135151   
    136     Value * const inputStream = &*(args++);
    137     inputStream->setName("input");
    138     Value * const fileSize = &*(args++);
    139     fileSize->setName("fileSize");
     152    Value * const fileDecriptor = &*(args++);
     153    fileDecriptor->setName("input");
    140154
    141155    const unsigned segmentSize = codegen::SegmentSize;
    142156    const unsigned bufferSegments = codegen::BufferSegments;
    143157   
    144     SourceBuffer ByteStream(iBuilder, iBuilder->getStreamSetTy(1, 8));
    145 
    146     MMapSourceKernel mmapK(iBuilder, segmentSize);
    147     mmapK.setInitialArguments({fileSize});
    148 
    149     pxDriver.addKernelCall(mmapK, {}, {&ByteStream});
    150 
    151     CircularBuffer BasisBits(iBuilder, iBuilder->getStreamSetTy(8), segmentSize * bufferSegments);
    152 
    153     S2PKernel s2pk(iBuilder);
    154     pxDriver.addKernelCall(s2pk, {&ByteStream}, {&BasisBits});
    155 
    156     PabloKernel bm(iBuilder, "MatchParens",
    157         {Binding{iBuilder->getStreamSetTy(8), "input"}},
    158         {Binding{iBuilder->getStreamSetTy(count), "matches"}, Binding{iBuilder->getStreamTy(), "errors"}});
    159 
    160     generate(&bm);
    161 
    162     ExpandableBuffer matches(iBuilder, iBuilder->getStreamSetTy(count), segmentSize * bufferSegments);
    163     SingleBlockBuffer errors(iBuilder, iBuilder->getStreamTy());
    164 
    165     pxDriver.addKernelCall(bm, {&BasisBits}, {&matches, &errors});
    166 
    167     PrintStreamSet printer(iBuilder, {"matches", "errors"});
    168     pxDriver.addKernelCall(printer, {&matches, &errors}, {});
     158    auto ByteStream = pxDriver.addBuffer(make_unique<SourceBuffer>(iBuilder, byteStreamTy));
     159
     160    auto mmapK = pxDriver.addKernelInstance(make_unique<MMapSourceKernel>(iBuilder, segmentSize));
     161    mmapK->setInitialArguments({fileDecriptor});
     162
     163    pxDriver.makeKernelCall(mmapK, {}, {ByteStream});
     164
     165    auto BasisBits = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, byteStreamTy, segmentSize * bufferSegments));
     166
     167    auto s2pk = pxDriver.addKernelInstance(make_unique<S2PKernel>(iBuilder));
     168    pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
     169
     170    auto bm = pxDriver.addKernelInstance(make_unique<ParenthesisMatchingKernel>(iBuilder, count));
     171
     172    auto matches = pxDriver.addBuffer(make_unique<ExpandableBuffer>(iBuilder, iBuilder->getStreamSetTy(count), segmentSize * bufferSegments));
     173
     174    auto errors = pxDriver.addBuffer(make_unique<SingleBlockBuffer>(iBuilder, iBuilder->getStreamTy()));
     175
     176    pxDriver.makeKernelCall(bm, {BasisBits}, {matches, errors});
     177
     178    auto printer = pxDriver.addKernelInstance(make_unique<PrintStreamSet>(iBuilder, std::vector<std::string>{"matches", "errors"}));
     179    pxDriver.makeKernelCall(printer, {&matches, &errors}, {});
    169180
    170181    iBuilder->SetInsertPoint(BasicBlock::Create(mod->getContext(), "entry", main, 0));
    171 
    172     BasisBits.allocateBuffer(iBuilder);
    173     matches.allocateBuffer(iBuilder);
    174     errors.allocateBuffer(iBuilder);
    175 
    176182    pxDriver.generatePipelineIR();
    177183    iBuilder->CreateRetVoid();
Note: See TracChangeset for help on using the changeset viewer.