Ignore:
Timestamp:
Apr 8, 2018, 4:11:34 PM (13 months ago)
Author:
cameron
Message:

Use AlignedAllocator? when boost::align unavailable (Jenkins test server).

File:
1 edited

Legend:

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

    r5952 r5953  
    119119}
    120120
     121   
     122
     123   
    121124void grepBuffer(re::RE * pattern, const char * search_buffer, size_t bufferLength, MatchAccumulator * accum) {
    122125    const unsigned segmentSize = codegen::BufferSegments * codegen::SegmentSize * codegen::ThreadNum;
     
    796799}
    797800
    798 }
     801   
     802   
     803InternalSearchEngine::InternalSearchEngine() :
     804    mGrepRecordBreak(GrepRecordBreakKind::LF),
     805    mCaseInsensitive(false),
     806    mGrepDriver(nullptr),
     807    grepMatchFound(false) {}
     808   
     809InternalSearchEngine::~InternalSearchEngine() {
     810    delete mGrepDriver;
     811}
     812
     813void InternalSearchEngine::grepCodeGen(re::RE * matchingRE, re::RE * excludedRE, MatchAccumulator * accum) {
     814    mGrepDriver = new ParabixDriver("InternalEngine");
     815    auto & idb = mGrepDriver->getBuilder();
     816    Module * M = idb->getModule();
     817   
     818    const unsigned encodingBits = 8;
     819    const unsigned segmentSize = codegen::BufferSegments * codegen::SegmentSize * codegen::ThreadNum;
     820    auto segParallelModeSave = codegen::SegmentPipelineParallel;
     821    codegen::SegmentPipelineParallel = false;
     822   
     823    re::CC * breakCC = nullptr;
     824    if (mGrepRecordBreak == GrepRecordBreakKind::Null) {
     825        breakCC = re::makeByte(0);
     826    } else {// if (mGrepRecordBreak == GrepRecordBreakKind::LF)
     827        breakCC = re::makeByte(0x0A);
     828    }
     829   
     830    if (matchingRE) {
     831        matchingRE = resolveCaseInsensitiveMode(matchingRE, mCaseInsensitive);
     832        matchingRE = regular_expression_passes(matchingRE);
     833        matchingRE = re::exclude_CC(excludedRE, breakCC);
     834        matchingRE = resolveAnchors(excludedRE, breakCC);
     835    }
     836   
     837    if (excludedRE) {
     838        excludedRE = resolveCaseInsensitiveMode(matchingRE, mCaseInsensitive);
     839        excludedRE = regular_expression_passes(matchingRE);
     840        excludedRE = re::exclude_CC(excludedRE, breakCC);
     841        excludedRE = resolveAnchors(excludedRE, breakCC);
     842    }
     843   
     844    Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", idb->getVoidTy(), idb->getInt8PtrTy(), idb->getSizeTy(), nullptr));
     845    mainFunc->setCallingConv(CallingConv::C);
     846    auto args = mainFunc->arg_begin();
     847    Value * const buffer = &*(args++);
     848    buffer->setName("buffer");
     849    Value * length = &*(args++);
     850    length->setName("length");
     851   
     852    idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
     853    StreamSetBuffer * ByteStream = mGrepDriver->addBuffer<SourceBuffer>(idb, idb->getStreamSetTy(1, 8));
     854    kernel::Kernel * sourceK = mGrepDriver->addKernelInstance<kernel::MemorySourceKernel>(idb, idb->getInt8PtrTy());
     855    sourceK->setInitialArguments({buffer, length});
     856    mGrepDriver->makeKernelCall(sourceK, {}, {ByteStream});
     857   
     858    StreamSetBuffer * BasisBits = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(8, 1), segmentSize);
     859    kernel::Kernel * s2pk = mGrepDriver->addKernelInstance<kernel::S2PKernel>(idb);
     860    mGrepDriver->makeKernelCall(s2pk, {ByteStream}, {BasisBits});
     861   
     862    StreamSetBuffer * RecordBreakStream = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     863    std::string RBname = (mGrepRecordBreak == GrepRecordBreakKind::Null) ? "Null" : "LF";
     864    kernel::Kernel * breakK = mGrepDriver->addKernelInstance<kernel::ParabixCharacterClassKernelBuilder>(idb, RBname, std::vector<re::CC *>{breakCC}, 8);
     865    mGrepDriver->makeKernelCall(breakK, {BasisBits}, {RecordBreakStream});
     866   
     867    StreamSetBuffer * MatchingRecords = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     868   
     869    std::vector<std::string> externalStreamNames;
     870    if (matchingRE) {
     871        kernel::Kernel * includeK = mGrepDriver->addKernelInstance<kernel::ICGrepKernel>(idb, matchingRE, externalStreamNames);
     872        mGrepDriver->makeKernelCall(includeK, {BasisBits}, {MatchingRecords});
     873    }
     874   
     875    if (excludedRE) {
     876        StreamSetBuffer * ExcludedRecords = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     877        kernel::Kernel * excludeK = mGrepDriver->addKernelInstance<kernel::ICGrepKernel>(idb, excludedRE, externalStreamNames);
     878        mGrepDriver->makeKernelCall(excludeK, {BasisBits}, {ExcludedRecords});
     879       
     880        kernel::Kernel * invertK = mGrepDriver->addKernelInstance<kernel::InvertMatchesKernel>(idb);
     881        if (matchingRE) {
     882            StreamSetBuffer * nonExcluded = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     883            mGrepDriver->makeKernelCall(invertK, {ExcludedRecords, RecordBreakStream}, {nonExcluded});
     884            StreamSetBuffer * included = MatchingRecords;
     885            kernel::Kernel * streamsMergeK = mGrepDriver->addKernelInstance<kernel::StreamsMerge>(idb, 1, 2);
     886            mGrepDriver->makeKernelCall(streamsMergeK, {included, nonExcluded}, {MatchingRecords});
     887        }
     888        else {
     889            mGrepDriver->makeKernelCall(invertK, {ExcludedRecords, RecordBreakStream}, {MatchingRecords});
     890        }
     891    }
     892   
     893    kernel::Kernel * scanMatchK = mGrepDriver->addKernelInstance<kernel::ScanMatchKernel>(idb);
     894    scanMatchK->setInitialArguments({ConstantInt::get(idb->getIntAddrTy(), reinterpret_cast<intptr_t>(accum))});
     895    mGrepDriver->makeKernelCall(scanMatchK, {MatchingRecords, RecordBreakStream, ByteStream}, {});
     896    mGrepDriver->LinkFunction(*scanMatchK, "accumulate_match_wrapper", &accumulate_match_wrapper);
     897    mGrepDriver->LinkFunction(*scanMatchK, "finalize_match_wrapper", &finalize_match_wrapper);
     898   
     899    mGrepDriver->generatePipelineIR();
     900    mGrepDriver->deallocateBuffers();
     901    idb->CreateRetVoid();
     902    mGrepDriver->finalizeObject();
     903}
     904
     905void InternalSearchEngine::doGrep(const char * search_buffer, size_t bufferLength) {
     906    typedef void (*GrepFunctionType)(const char * buffer, const size_t length);
     907    auto f = reinterpret_cast<GrepFunctionType>(mGrepDriver->getMain());
     908    f(search_buffer, bufferLength);
     909}
     910
     911}
Note: See TracChangeset for help on using the changeset viewer.