Ignore:
Timestamp:
Jul 5, 2017, 10:34:41 AM (2 years ago)
Author:
cameron
Message:

Decouple finalizeMatchResults, creating separate MatchedLinesKernel?

File:
1 edited

Legend:

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

    r5493 r5548  
    8383}
    8484
     85bool GrepEngine::matchesNeedToBeMovedToEOL() const {
     86    if ((Mode == QuietMode) | (Mode == FilesWithMatch) | (Mode == FilesWithoutMatch)) {
     87        return false;
     88    }
     89    else if (LineRegexpFlag) {
     90        return false;
     91    }
     92    // TODO: return false for other cases based on regexp analysis, e.g., regexp ends with $.
     93    return true;
     94}
     95   
    8596void GrepEngine::doGrep(const std::string & fileName) const{
    8697#ifdef CUDA_ENABLED
     
    306317    Type * const int64tyPtr = PointerType::get(int64Ty, 1);
    307318    Type * const voidTy = idb->getVoidTy();
     319   
     320    size_t MatchLimit = ((grepMode == QuietMode) | (grepMode == FilesWithMatch) | (grepMode == FilesWithoutMatch)) ? 1 : MaxCountFlag;
    308321
    309322    Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", voidTy, int64tyPtr, sizeTyPtr, sizeTyPtr, int64tyPtr, nullptr));
     
    362375        mGrepDriver->makeKernelCall(streamsMergeK, MatchResultsBufs, {MergedResults});
    363376    }
    364 
     377    StreamSetBuffer * Matches = MergedResults;
     378
     379    if (matchesNeedToBeMovedToEOL()) {
     380        StreamSetBuffer * OriginalMatches = Matches;
     381        kernel::Kernel * matchedLinesK = mGrepDriver->addKernelInstance(make_unique<kernel::MatchedLinesKernel>(idb));
     382        Matches = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     383        mGrepDriver->makeKernelCall(matchedLinesK, {OriginalMatches, LineBreakStream}, {Matches});
     384    }
     385   
     386    if (InvertMatchFlag) {
     387        kernel::Kernel * invertK = mGrepDriver->addKernelInstance(make_unique<kernel::InvertMatchesKernel>(idb));
     388        StreamSetBuffer * OriginalMatches = Matches;
     389        Matches = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     390        mGrepDriver->makeKernelCall(invertK, {OriginalMatches, LineBreakStream}, {Matches});
     391    }
     392    if (MatchLimit > 0) {
     393        kernel::Kernel * untilK = mGrepDriver->addKernelInstance(make_unique<kernel::UntilNkernel>(idb));
     394        untilK->setInitialArguments({idb->getSize(MatchLimit)});
     395        StreamSetBuffer * AllMatches = Matches;
     396        Matches = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     397        mGrepDriver->makeKernelCall(untilK, {AllMatches}, {Matches});
     398    }
     399   
    365400    kernel::Kernel * matchCountK = mGrepDriver->addKernelInstance(make_unique<kernel::PopcountKernel>(idb));
    366     mGrepDriver->makeKernelCall(matchCountK, {MergedResults}, {});
     401    mGrepDriver->makeKernelCall(matchCountK, {Matches}, {});
    367402    mGrepDriver->generatePipelineIR();
    368403    idb->setKernel(matchCountK);
     
    441476        mGrepDriver->makeKernelCall(streamsMergeK, MatchResultsBufs, {MergedResults});
    442477    }
     478    StreamSetBuffer * Matches = MergedResults;
     479   
     480    if (matchesNeedToBeMovedToEOL()) {
     481        StreamSetBuffer * OriginalMatches = Matches;
     482        kernel::Kernel * matchedLinesK = mGrepDriver->addKernelInstance(make_unique<kernel::MatchedLinesKernel>(idb));
     483        Matches = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     484        mGrepDriver->makeKernelCall(matchedLinesK, {OriginalMatches, LineBreakStream}, {Matches});
     485    }
    443486   
    444487    if (InvertMatchFlag) {
    445488        kernel::Kernel * invertK = mGrepDriver->addKernelInstance(make_unique<kernel::InvertMatchesKernel>(idb));
    446         StreamSetBuffer * OriginalMatches = MergedResults;
    447         MergedResults = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    448         mGrepDriver->makeKernelCall(invertK, {OriginalMatches, LineBreakStream}, {MergedResults});
     489        StreamSetBuffer * OriginalMatches = Matches;
     490        Matches = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     491        mGrepDriver->makeKernelCall(invertK, {OriginalMatches, LineBreakStream}, {Matches});
    449492    }
    450493    if (MatchLimit > 0) {
    451494        kernel::Kernel * untilK = mGrepDriver->addKernelInstance(make_unique<kernel::UntilNkernel>(idb));
    452495        untilK->setInitialArguments({idb->getSize(MatchLimit)});
    453         StreamSetBuffer * AllMatches = MergedResults;
    454         MergedResults = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    455         mGrepDriver->makeKernelCall(untilK, {AllMatches}, {MergedResults});
     496        StreamSetBuffer * AllMatches = Matches;
     497        Matches = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     498        mGrepDriver->makeKernelCall(untilK, {AllMatches}, {Matches});
    456499    }
    457500    if (grepMode == NormalMode) {
    458501        kernel::Kernel * scanMatchK = mGrepDriver->addKernelInstance(make_unique<kernel::ScanMatchKernel>(idb, GrepType::Normal, encodingBits));
    459502        scanMatchK->setInitialArguments({fileIdx});
    460         mGrepDriver->makeKernelCall(scanMatchK, {MergedResults, LineBreakStream, ByteStream}, {});
     503        mGrepDriver->makeKernelCall(scanMatchK, {Matches, LineBreakStream, ByteStream}, {});
    461504        if (UTF_16) {
    462505            mGrepDriver->LinkFunction(*scanMatchK, "matcher", &wrapped_report_match<uint16_t>);
     
    465508        }
    466509        mGrepDriver->generatePipelineIR();
     510        mGrepDriver->deallocateBuffers();
     511
    467512        idb->CreateRet(idb->getInt64(0));
    468513    } else {
    469514        kernel::Kernel * matchCountK = mGrepDriver->addKernelInstance(make_unique<kernel::PopcountKernel>(idb));
    470         mGrepDriver->makeKernelCall(matchCountK, {MergedResults}, {});
     515        mGrepDriver->makeKernelCall(matchCountK, {Matches}, {});
    471516        mGrepDriver->generatePipelineIR();
    472517        idb->setKernel(matchCountK);
    473518        Value * matchedLineCount = idb->getAccumulator("countResult");
    474519        matchedLineCount = idb->CreateZExt(matchedLineCount, int64Ty);
     520        mGrepDriver->deallocateBuffers();
    475521        idb->CreateRet(matchedLineCount);
    476522    }
     
    546592    pxDriver.makeKernelCall(icgrepK, {BasisBits, LineBreakStream}, {MatchResults});
    547593   
     594    StreamSetBuffer * MatchedLines = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize));
     595    kernel::Kernel * matchedLinesK = pxDriver.addKernelInstance(make_unique<kernel::MatchedLinesKernel>(idb));
     596    pxDriver.makeKernelCall(matchedLinesK, {MatchResults, LineBreakStream}, {MatchedLines});
     597   
    548598    kernel::Kernel * scanMatchK = pxDriver.addKernelInstance(make_unique<kernel::ScanMatchKernel>(idb, GrepType::NameExpression, 8));
    549599    scanMatchK->setInitialArguments({idb->getInt32(0)});
    550     pxDriver.makeKernelCall(scanMatchK, {MatchResults, LineBreakStream, ByteStream}, {});
     600    pxDriver.makeKernelCall(scanMatchK, {MatchedLines, LineBreakStream, ByteStream}, {});
    551601    pxDriver.LinkFunction(*scanMatchK, "matcher", &insert_codepoints);
    552602    pxDriver.generatePipelineIR();
     
    618668    kernel::Kernel * icgrepK = pxDriver.addKernelInstance(make_unique<kernel::ICGrepKernel>(idb, propertyValuePattern));
    619669    pxDriver.makeKernelCall(icgrepK, {BasisBits, LineBreakStream}, {MatchResults});
    620    
     670
     671    StreamSetBuffer * MatchedLines = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize));
     672    kernel::Kernel * matchedLinesK = pxDriver.addKernelInstance(make_unique<kernel::MatchedLinesKernel>(idb));
     673    pxDriver.makeKernelCall(matchedLinesK, {MatchResults, LineBreakStream}, {MatchedLines});
     674
    621675    kernel::Kernel * scanMatchK = pxDriver.addKernelInstance(make_unique<kernel::ScanMatchKernel>(idb, GrepType::PropertyValue, 8));
    622676    scanMatchK->setInitialArguments({idb->getInt32(0)});
    623     pxDriver.makeKernelCall(scanMatchK, {MatchResults, LineBreakStream, ByteStream}, {});
     677    pxDriver.makeKernelCall(scanMatchK, {MatchedLines, LineBreakStream, ByteStream}, {});
    624678    pxDriver.LinkFunction(*scanMatchK, "matcher", &insert_property_values);
    625679    pxDriver.generatePipelineIR();
Note: See TracChangeset for help on using the changeset viewer.