Changeset 5416 for icGREP/icgrep-devel


Ignore:
Timestamp:
Apr 19, 2017, 5:58:50 PM (2 years ago)
Author:
cameron
Message:

icgrep: transfer ownership of kernel builders to Parabix Driver

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5413 r5416  
    509509        // TODO: use fstat(STDIN_FILENO) to see if we can mmap the stdin safely and avoid the calls to read
    510510        ByteStream = pxDriver.addBuffer(make_unique<ExtensibleBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8), segmentSize));
    511         sourceK = new kernel::StdInKernel(iBuilder, segmentSize);
     511        sourceK = pxDriver.addKernelInstance(make_unique<kernel::StdInKernel>(iBuilder, segmentSize));
    512512    } else {
    513513        ByteStream = pxDriver.addBuffer(make_unique<SourceFileBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8)));
    514         sourceK = new kernel::FileSourceKernel(iBuilder, inputStream->getType(), segmentSize);
     514        sourceK = pxDriver.addKernelInstance(make_unique<kernel::FileSourceKernel>(iBuilder, inputStream->getType(), segmentSize));
    515515        sourceK->setInitialArguments({inputStream, fileSize});
    516516    }
    517     pxDriver.addKernelCall(*sourceK, {}, {ByteStream});
     517    pxDriver.makeKernelCall(sourceK, {}, {ByteStream});
    518518   
    519519    StreamSetBuffer * BasisBits = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(8, 1), segmentSize * bufferSegments));
    520520
    521     kernel::S2PKernel s2pk(iBuilder);
    522     pxDriver.addKernelCall(s2pk, {ByteStream}, {BasisBits});
    523 
    524     kernel::LineBreakKernelBuilder linebreakK(iBuilder, encodingBits);
     521    kernel::KernelBuilder * s2pk = pxDriver.addKernelInstance(make_unique<kernel::S2PKernel>(iBuilder));
     522    pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
     523
     524    kernel::KernelBuilder * linebreakK = pxDriver.addKernelInstance(make_unique<kernel::LineBreakKernelBuilder>(iBuilder, encodingBits));
    525525    StreamSetBuffer * LineBreakStream = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    526     pxDriver.addKernelCall(linebreakK, {BasisBits}, {LineBreakStream});
     526    pxDriver.makeKernelCall(linebreakK, {BasisBits}, {LineBreakStream});
    527527   
    528528    StreamSetBuffer * MatchResults = nullptr;
     
    538538    }
    539539#endif
    540     kernel::ICgrepKernelBuilder icgrepK(iBuilder, re_ast);
    541     pxDriver.addKernelCall(icgrepK, {BasisBits, LineBreakStream}, {MatchResults});
    542    
    543     kernel::InvertMatchesKernel invertK(iBuilder);
     540    kernel::KernelBuilder * icgrepK = pxDriver.addKernelInstance(make_unique<kernel::ICgrepKernelBuilder>(iBuilder, re_ast));
     541    pxDriver.makeKernelCall(icgrepK, {BasisBits, LineBreakStream}, {MatchResults});
     542   
     543    kernel::KernelBuilder * invertK = pxDriver.addKernelInstance(make_unique<kernel::InvertMatchesKernel>(iBuilder));
    544544    if (AlgorithmOptionIsSet(re::InvertMatches)) {
    545545        StreamSetBuffer * OriginalMatches = MatchResults;
    546546        MatchResults = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    547         pxDriver.addKernelCall(invertK, {OriginalMatches, LineBreakStream}, {MatchResults});
     547        pxDriver.makeKernelCall(invertK, {OriginalMatches, LineBreakStream}, {MatchResults});
    548548    }
    549549
    550550    if (CountOnly) {
    551         kernel::PopcountKernel popcountK(iBuilder);
    552         pxDriver.addKernelCall(popcountK, {MatchResults}, {});
     551        kernel::KernelBuilder * popcountK = pxDriver.addKernelInstance(make_unique<kernel::PopcountKernel>(iBuilder));
     552        pxDriver.makeKernelCall(popcountK, {MatchResults}, {});
    553553        pxDriver.generatePipelineIR();
    554         iBuilder->CreateRet(popcountK.createGetAccumulatorCall("countResult"));
     554        iBuilder->CreateRet(popcountK->createGetAccumulatorCall("countResult"));
    555555
    556556        pxDriver.linkAndFinalize();
     
    570570
    571571        if (CPU_Only) {
    572 
    573             kernel::ScanMatchKernel scanMatchK(iBuilder, grepType, encodingBits);
    574             scanMatchK.setInitialArguments({fileIdx});
    575 
    576             pxDriver.addKernelCall(scanMatchK, {MatchResults, LineBreakStream, ByteStream}, {});
    577 
    578             linkGrepFunction(pxDriver, grepType, UTF_16, scanMatchK);
     572            kernel::KernelBuilder * scanMatchK = pxDriver.addKernelInstance(make_unique<kernel::ScanMatchKernel>(iBuilder, grepType, encodingBits));
     573            scanMatchK->setInitialArguments({fileIdx});
     574
     575            pxDriver.makeKernelCall(scanMatchK, {MatchResults, LineBreakStream, ByteStream}, {});
     576
     577            linkGrepFunction(pxDriver, grepType, UTF_16, *scanMatchK);
    579578
    580579            pxDriver.generatePipelineIR();
     
    609608
    610609    delete iBuilder;
    611     delete sourceK;
    612610
    613611    if (CountOnly) {
     
    653651        // TODO: use fstat(STDIN_FILENO) to see if we can mmap the stdin safely and avoid the calls to read
    654652        ByteStream = pxDriver.addBuffer(make_unique<ExtensibleBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8), segmentSize));
    655         sourceK = new kernel::StdInKernel(iBuilder, segmentSize);
    656     } else {
    657         ByteStream = pxDriver.addExternalBuffer(make_unique<ExternalFileBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8)), inputStream);
    658         sourceK = new kernel::MMapSourceKernel(iBuilder, segmentSize);
    659         sourceK->setInitialArguments({fileSize});
    660     }
    661     pxDriver.addKernelCall(*sourceK, {}, {ByteStream});
    662 
     653        sourceK = pxDriver.addKernelInstance(make_unique<kernel::StdInKernel>(iBuilder, segmentSize));
     654    } else {
     655        ByteStream = pxDriver.addBuffer(make_unique<SourceFileBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8)));
     656        sourceK = pxDriver.addKernelInstance(make_unique<kernel::FileSourceKernel>(iBuilder, inputStream->getType(), segmentSize));
     657        sourceK->setInitialArguments({inputStream, fileSize});
     658    }
     659    pxDriver.makeKernelCall(sourceK, {}, {ByteStream});
    663660    StreamSetBuffer * BasisBits = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(8, 1), segmentSize * bufferSegments));
    664 
    665     kernel::S2PKernel s2pk(iBuilder);
    666     pxDriver.addKernelCall(s2pk, {ByteStream}, {BasisBits});
    667 
    668     kernel::LineBreakKernelBuilder linebreakK(iBuilder, encodingBits);
     661   
     662    kernel::KernelBuilder * s2pk = pxDriver.addKernelInstance(make_unique<kernel::S2PKernel>(iBuilder));
     663    pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
     664   
     665    kernel::KernelBuilder * linebreakK = pxDriver.addKernelInstance(make_unique<kernel::LineBreakKernelBuilder>(iBuilder, encodingBits));
    669666    StreamSetBuffer * LineBreakStream = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    670     pxDriver.addKernelCall(linebreakK, {BasisBits}, {LineBreakStream});
    671    
    672     std::vector<pablo::PabloKernel *> icgrepKs;
     667    pxDriver.makeKernelCall(linebreakK, {BasisBits}, {LineBreakStream});
     668   
    673669    std::vector<StreamSetBuffer *> MatchResultsBufs;
    674670
    675671    for(unsigned i = 0; i < REs.size(); ++i){
    676         pablo::PabloKernel * const icgrepK = new kernel::ICgrepKernelBuilder(iBuilder, REs[i]);
    677672        StreamSetBuffer * MatchResults = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    678         pxDriver.addKernelCall(*icgrepK, {BasisBits, LineBreakStream}, {MatchResults});
    679         icgrepKs.push_back(icgrepK);
     673        kernel::KernelBuilder * icgrepK = pxDriver.addKernelInstance(make_unique<kernel::ICgrepKernelBuilder>(iBuilder, REs[i]));
     674        pxDriver.makeKernelCall(icgrepK, {BasisBits, LineBreakStream}, {MatchResults});
    680675        MatchResultsBufs.push_back(MatchResults);
    681676    }
    682 
    683     StreamSetBuffer * MergedResults = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    684 
    685     kernel::StreamsMerge streamsMergeK(iBuilder, 1, REs.size());
    686     pxDriver.addKernelCall(streamsMergeK, MatchResultsBufs, {MergedResults});
    687    
    688     kernel::InvertMatchesKernel invertK(iBuilder);
     677    StreamSetBuffer * MergedResults = MatchResultsBufs[0];
     678    if (REs.size() > 1) {
     679        MergedResults = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     680        kernel::KernelBuilder * streamsMergeK = pxDriver.addKernelInstance(make_unique<kernel::StreamsMerge>(iBuilder, 1, REs.size()));
     681        pxDriver.makeKernelCall(streamsMergeK, MatchResultsBufs, {MergedResults});
     682    }
     683   
    689684    if (AlgorithmOptionIsSet(re::InvertMatches)) {
     685        kernel::KernelBuilder * invertK = pxDriver.addKernelInstance(make_unique<kernel::InvertMatchesKernel>(iBuilder));
    690686        StreamSetBuffer * OriginalMatches = MergedResults;
    691687        MergedResults = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    692         pxDriver.addKernelCall(invertK, {OriginalMatches, LineBreakStream}, {MergedResults});
     688        pxDriver.makeKernelCall(invertK, {OriginalMatches, LineBreakStream}, {MergedResults});
    693689    }
    694690    if (CountOnly) {
     
    708704    }
    709705
    710     delete iBuilder;
    711     delete sourceK;
     706    //delete iBuilder;
    712707
    713708    if (CountOnly) {
Note: See TracChangeset for help on using the changeset viewer.