Ignore:
Timestamp:
Oct 18, 2017, 9:35:52 AM (21 months ago)
Author:
cameron
Message:

Update scanmatch callback protocol to use line start/end pointers; add finalize callback for buffer end

Location:
icGREP/icgrep-devel/icgrep
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/UCD/PropertyObjects.cpp

    r5685 r5694  
    6161public:
    6262   
    63     PropertyValueAccumulator(const char * searchBuffer, std::vector<std::string> & accumulatedPropertyValues)
    64     : mSearchBuffer(searchBuffer), mParsedPropertyValueSet(accumulatedPropertyValues) {}
    65    
    66     void accumulate_match(const size_t lineNum, size_t line_start, size_t line_end) override;
     63    PropertyValueAccumulator(std::vector<std::string> & accumulatedPropertyValues)
     64    : mParsedPropertyValueSet(accumulatedPropertyValues) {}
     65   
     66    void accumulate_match(const size_t lineNum, char * line_start, char * line_end) override;
    6767private:
    68     const char * mSearchBuffer;
    6968    std::vector<std::string> & mParsedPropertyValueSet;
    7069};
    71 void PropertyValueAccumulator::accumulate_match(const size_t lineNum, size_t line_start, size_t line_end) {
     70void PropertyValueAccumulator::accumulate_match(const size_t lineNum, char * line_start, char * line_end) {
    7271    assert (line_start <= line_end);
    73     mParsedPropertyValueSet.emplace_back(mSearchBuffer + line_start, mSearchBuffer + line_end);
     72    mParsedPropertyValueSet.emplace_back(line_start, line_end);
    7473}
    7574
     
    9190    std::memset(aligned + n, 0, m);
    9291   
    93     PropertyValueAccumulator accum(aligned, accumulatedValues);
     92    PropertyValueAccumulator accum(accumulatedValues);
    9493    grepBuffer(pattern, aligned, n, & accum);
    9594    alloc.deallocate(aligned, 0);
    9695   
    97     UnicodeSet a;
     96    UnicodeSet a = UnicodeSet();
    9897    for (auto v : accumulatedValues) {
    9998        int e = GetPropertyValueEnumCode(v);
     
    214213    std::memset(aligned + n, 0, m);
    215214   
    216     PropertyValueAccumulator accum(aligned, accumulatedValues);
     215    PropertyValueAccumulator accum(accumulatedValues);
    217216    grepBuffer(pattern, aligned, n, & accum);
    218217    alloc.deallocate(aligned, 0);
    219218   
    220     UnicodeSet a;
     219    UnicodeSet a = UnicodeSet();
    221220    for (auto v : accumulatedValues) {
    222221        int e = baseObj->GetPropertyValueEnumCode(v);
     
    271270const unsigned firstCodepointLengthAndVal(const std::string & s, codepoint_t & cp) {
    272271    size_t lgth = s.length();
     272    cp = 0;
    273273    if (lgth == 0) return 0;
    274274    unsigned char s0 = s[0];
     
    293293    : mCodepointTableByLineNum(cps), mDefaultValueSet(defaultValueSet) {}
    294294   
    295     void accumulate_match(const size_t lineNum, size_t line_start, size_t line_end) override;
     295    void accumulate_match(const size_t lineNum, char * line_start, char * line_end) override;
    296296    UnicodeSet getAccumulatedSet() { return mAccumSet; }
    297297private:
     
    300300    UnicodeSet mAccumSet;
    301301};
    302 void SetByLineNumberAccumulator::accumulate_match(const size_t lineNum, size_t line_start, size_t line_end) {
     302void SetByLineNumberAccumulator::accumulate_match(const size_t lineNum, char * line_start, char * line_end) {
    303303    if (lineNum >= mCodepointTableByLineNum.size()) mAccumSet = mAccumSet + mDefaultValueSet;
    304304    else mAccumSet.insert(mCodepointTableByLineNum[lineNum]);
     
    309309    if (value_spec == "NaN") return mNaNCodepointSet;
    310310    else {
    311         UnicodeSet result_set;
     311        UnicodeSet result_set = UnicodeSet();
    312312        unsigned val_bytes = value_spec.length();
    313313        const char * value_str = value_spec.c_str();
     
    338338    if (value_spec == "") return mNullCodepointSet;
    339339    else {
    340         UnicodeSet result_set;
     340        UnicodeSet result_set = UnicodeSet();
    341341        unsigned val_bytes = value_spec.length();
    342342        codepoint_t cp;
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5678 r5694  
    5252    BasicBlock * const scanWordExit = iBuilder->CreateBasicBlock("ScanWordExit");
    5353    BasicBlock * const blocksExit = iBuilder->CreateBasicBlock("blocksExit");
     54    BasicBlock * const callFinalizeScan = iBuilder->CreateBasicBlock("callFinalizeScan");
     55    BasicBlock * const scanReturn = iBuilder->CreateBasicBlock("scanReturn");
    5456    IntegerType * const sizeTy = iBuilder->getSizeTy();
    5557    const unsigned fieldCount = iBuilder->getBitBlockWidth() / sizeTy->getBitWidth();
    5658    VectorType * const scanwordVectorType =  VectorType::get(sizeTy, fieldCount);
    5759    Constant * blockSize = iBuilder->getSize(iBuilder->getBitBlockWidth());
    58     Constant * blockSizeLess1 = iBuilder->getSize(iBuilder->getBitBlockWidth() - 1);
    5960
    6061    Function::arg_iterator args = mCurrentMethod->arg_begin();
     
    6667    /* input_stream = */ args++;
    6768
    68     Value * blocksToDo = iBuilder->CreateUDiv(iBuilder->CreateAdd(itemsToDo, blockSizeLess1), blockSize);
     69    Value * blocksToDo = iBuilder->CreateUDivCeil(itemsToDo, blockSize);
    6970   
    7071    Value * match_result_ptr = iBuilder->CreateBitCast(match_result, scanwordVectorType->getPointerTo());
     
    154155            Value * matchRecordEnd = iBuilder->CreateAdd(phiScanwordPos, iBuilder->CreateCountForwardZeroes(phiMatchWord));
    155156            if (mGrepType == GrepType::CallBack) {
     157                Value * const inputStream = iBuilder->getRawInputPointer("InputStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
    156158                Function * dispatcher = m->getFunction("accumulate_match_wrapper"); assert (dispatcher);
    157159                //Function * dispatcher = iBuilder->LinkFunction<void (intptr_t, size_t, size_t, size_t)>("accumulate_match_wrapper", & grep::accumulate_match_wrapper);
    158160                Value * accumulator = iBuilder->getScalarField("accumulator_address");
    159                 iBuilder->CreateCall(dispatcher, {accumulator, matchRecordNum, matchRecordStart, matchRecordEnd});
     161                Value * start_ptr = iBuilder->CreateGEP(inputStream, matchRecordStart);
     162                Value * end_ptr = iBuilder->CreateGEP(inputStream, matchRecordEnd);
     163                iBuilder->CreateCall(dispatcher, {accumulator, matchRecordNum, start_ptr, end_ptr});
    160164            }
    161165            else {
     
    225229
    226230    iBuilder->SetInsertPoint(blocksExit);
     231    iBuilder->CreateCondBr(iBuilder->CreateICmpULT(itemsToDo, blockSize), callFinalizeScan, scanReturn);
     232    iBuilder->SetInsertPoint(callFinalizeScan);
     233    if (mGrepType == GrepType::CallBack) {
     234        Value * bufSize = iBuilder->getBufferedSize("InputStream");
     235        Function * finalizer = m->getFunction("finalize_match_wrapper"); assert (finalizer);
     236        Value * accumulator = iBuilder->getScalarField("accumulator_address");
     237        Value * const buffer_base = iBuilder->getRawInputPointer("InputStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
     238        Value * buffer_end_address = iBuilder->CreateGEP(buffer_base, bufSize);
     239        iBuilder->CreateCall(finalizer, {accumulator, buffer_end_address});
     240    }
     241    iBuilder->CreateBr(scanReturn);
     242    iBuilder->SetInsertPoint(scanReturn);
     243   
    227244}
    228245
  • icGREP/icgrep-devel/icgrep/kernels/source_kernel.cpp

    r5693 r5694  
    363363    BasicBlock * finalizeDone = kb->CreateBasicBlock("finalizeDone");
    364364    // if the fileDescriptor is 0, the file is stdin, use readSource kernel logic, otherwise use mmap logic.
    365     kb->CreateCondBr(kb->CreateICmpEQ(kb->getScalarField("fileDescriptor"), kb->getInt32(0)), finalizeRead, finalizeMMap);
     365    kb->CreateCondBr(kb->CreateICmpEQ(kb->getScalarField("fileDescriptor"), kb->getInt32(STDIN_FILENO)), finalizeRead, finalizeMMap);
    366366    kb->SetInsertPoint(finalizeRead);
    367367    reinterpret_cast<ReadSourceKernel *>(this)->ReadSourceKernel::generateFinalizeMethod(kb);
     
    378378    BasicBlock * initializeDone = kb->CreateBasicBlock("initializeDone");
    379379    // if the fileDescriptor is 0, the file is stdin, use readSource kernel logic, otherwise use MMap logic.
    380     kb->CreateCondBr(kb->CreateICmpEQ(kb->getScalarField("fileDescriptor"), kb->getInt32(0)), initializeRead, initializeMMap);
     380    kb->CreateCondBr(kb->CreateICmpEQ(kb->getScalarField("fileDescriptor"), kb->getInt32(STDIN_FILENO)), initializeRead, initializeMMap);
    381381    kb->SetInsertPoint(initializeRead);
    382382    reinterpret_cast<ReadSourceKernel *>(this)->ReadSourceKernel::generateInitializeMethod(kb);
     
    393393    BasicBlock * DoSegmentDone = kb->CreateBasicBlock("DoSegmentDone");
    394394    // if the fileDescriptor is 0, the file is stdin, use readSource kernel logic, otherwise use MMap logic.
    395     kb->CreateCondBr(kb->CreateICmpEQ(kb->getScalarField("fileDescriptor"), kb->getInt32(0)), DoSegmentRead, DoSegmentMMap);
     395    kb->CreateCondBr(kb->CreateICmpEQ(kb->getScalarField("fileDescriptor"), kb->getInt32(STDIN_FILENO)), DoSegmentRead, DoSegmentMMap);
    396396    kb->SetInsertPoint(DoSegmentRead);
    397397    reinterpret_cast<ReadSourceKernel *>(this)->ReadSourceKernel::generateDoSegmentMethod(kb);
  • icGREP/icgrep-devel/icgrep/toolchain/grep_pipeline.cpp

    r5679 r5694  
    2727
    2828namespace grep {
     29void accumulate_match_wrapper(intptr_t accum_addr, const size_t lineNum, char * line_start, char * line_end) {
     30    reinterpret_cast<MatchAccumulator *>(accum_addr)->accumulate_match(lineNum, line_start, line_end);
     31}
    2932
    30    
    31 void accumulate_match_wrapper(intptr_t accum_addr, const size_t lineNum, size_t line_start, size_t line_end) {
    32     reinterpret_cast<MatchAccumulator *>(accum_addr)->accumulate_match(lineNum, line_start, line_end);
     33void finalize_match_wrapper(intptr_t accum_addr, char * buffer_end) {
     34    reinterpret_cast<MatchAccumulator *>(accum_addr)->finalize_match(buffer_end);
    3335}
    3436
     
    8082    pxDriver.makeKernelCall(scanMatchK, {MatchedLines, LineBreakStream, ByteStream}, {});
    8183    pxDriver.LinkFunction(*scanMatchK, "accumulate_match_wrapper", &accumulate_match_wrapper);
     84    pxDriver.LinkFunction(*scanMatchK, "finalize_match_wrapper", &finalize_match_wrapper);
    8285    pxDriver.generatePipelineIR();
    8386    pxDriver.deallocateBuffers();
  • icGREP/icgrep-devel/icgrep/toolchain/grep_pipeline.h

    r5679 r5694  
    1717public:
    1818    MatchAccumulator() {};
    19     virtual void accumulate_match(const size_t lineNum, size_t line_start, size_t line_end) = 0;
     19    virtual void accumulate_match(const size_t lineNum, char * line_start, char * line_end) = 0;
     20    virtual void finalize_match(char * buffer_end) {}  // default: no op
    2021};
    2122
    22 void accumulate_match_wrapper(intptr_t accum_addr, const size_t lineNum, size_t line_start, size_t line_end);
     23void accumulate_match_wrapper(intptr_t accum_addr, const size_t lineNum, char * line_start, char * line_end);
    2324   
    2425void grepBuffer(re::RE * pattern, const char * buffer, size_t bufferLength, MatchAccumulator * accum);
Note: See TracChangeset for help on using the changeset viewer.