Ignore:
Timestamp:
Oct 18, 2017, 12:59:35 PM (21 months ago)
Author:
cameron
Message:

Complete the scanmatch kernel conversion to use MatchAccumulator? objects

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5694 r5695  
    2121namespace kernel {
    2222
    23 inline std::string getGrepTypeId(const GrepType grepType) {
    24     switch (grepType) {
    25         case GrepType::Normal:
    26             return "N";
    27         case GrepType::NameExpression:
    28             return "E";
    29         case GrepType::PropertyValue:
    30             return "P";
    31         case GrepType::CallBack:
    32             return "C";
    33         default:
    34             llvm_unreachable("unknown grep type!");
    35     }
    36 }
    37    
    3823void ScanMatchKernel::generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> &iBuilder) {
    3924
     
    7156    Value * match_result_ptr = iBuilder->CreateBitCast(match_result, scanwordVectorType->getPointerTo());
    7257    Value * line_break_ptr = iBuilder->CreateBitCast(line_break, scanwordVectorType->getPointerTo());
     58    Value * accumulator = iBuilder->getScalarField("accumulator_address");
    7359
    7460    iBuilder->CreateCondBr(iBuilder->CreateICmpUGT(blocksToDo, iBuilder->getSize(0)), initialBlock, blocksExit);
     
    154140            phiRecordStart->addIncoming(matchRecordStart, loop_final_block);
    155141            Value * matchRecordEnd = iBuilder->CreateAdd(phiScanwordPos, iBuilder->CreateCountForwardZeroes(phiMatchWord));
    156             if (mGrepType == GrepType::CallBack) {
    157                 Value * const inputStream = iBuilder->getRawInputPointer("InputStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
    158                 Function * dispatcher = m->getFunction("accumulate_match_wrapper"); assert (dispatcher);
    159                 //Function * dispatcher = iBuilder->LinkFunction<void (intptr_t, size_t, size_t, size_t)>("accumulate_match_wrapper", & grep::accumulate_match_wrapper);
    160                 Value * accumulator = iBuilder->getScalarField("accumulator_address");
    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});
    164             }
    165             else {
    166                 Function * matcher = m->getFunction("matcher"); assert (matcher);
    167                 auto args_matcher = matcher->arg_begin();
    168                 Value * const mrn = iBuilder->CreateZExtOrTrunc(matchRecordNum, args_matcher->getType());
    169                 Value * const mrs = iBuilder->CreateZExtOrTrunc(matchRecordStart, (++args_matcher)->getType());
    170                 Value * const mre = iBuilder->CreateZExtOrTrunc(matchRecordEnd, (++args_matcher)->getType());
    171                 Value * const inputStream = iBuilder->getRawInputPointer("InputStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
    172                 Value * const is = iBuilder->CreatePointerCast(inputStream, (++args_matcher)->getType());
    173                 if (mGrepType == GrepType::Normal) {
    174                     Value * const sz = iBuilder->CreateZExtOrTrunc(iBuilder->getBufferedSize("InputStream"), (++args_matcher)->getType());
    175                     Value * const fi = iBuilder->CreateZExtOrTrunc(iBuilder->getScalarField("FileIdx"), (++args_matcher)->getType());
    176                     iBuilder->CreateCall(matcher, {mrn, mrs, mre, is, sz, fi});
    177                 } else {
    178                     iBuilder->CreateCall(matcher, {mrn, mrs, mre, is});
    179                 }
    180             }
     142            Value * const inputStream = iBuilder->getRawInputPointer("InputStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
     143            Function * dispatcher = m->getFunction("accumulate_match_wrapper"); assert (dispatcher);
     144            Value * start_ptr = iBuilder->CreateGEP(inputStream, matchRecordStart);
     145            Value * end_ptr = iBuilder->CreateGEP(inputStream, matchRecordEnd);
     146            iBuilder->CreateCall(dispatcher, {accumulator, matchRecordNum, start_ptr, end_ptr});
    181147            Value * remaining_matches = iBuilder->CreateResetLowestBit(phiMatchWord);
    182148            phiMatchWord->addIncoming(remaining_matches, loop_final_block);
     
    231197    iBuilder->CreateCondBr(iBuilder->CreateICmpULT(itemsToDo, blockSize), callFinalizeScan, scanReturn);
    232198    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     }
     199    Value * bufSize = iBuilder->getBufferedSize("InputStream");
     200    Function * finalizer = m->getFunction("finalize_match_wrapper"); assert (finalizer);
     201    Value * const buffer_base = iBuilder->getRawInputPointer("InputStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
     202    Value * buffer_end_address = iBuilder->CreateGEP(buffer_base, bufSize);
     203    iBuilder->CreateCall(finalizer, {accumulator, buffer_end_address});
    241204    iBuilder->CreateBr(scanReturn);
    242205    iBuilder->SetInsertPoint(scanReturn);
     
    244207}
    245208
    246 ScanMatchKernel::ScanMatchKernel(const std::unique_ptr<kernel::KernelBuilder> & b, GrepType grepType, const unsigned codeUnitWidth)
    247 : MultiBlockKernel("scanMatch" + getGrepTypeId(grepType) + std::to_string(codeUnitWidth),
     209ScanMatchKernel::ScanMatchKernel(const std::unique_ptr<kernel::KernelBuilder> & b)
     210: MultiBlockKernel("scanMatch",
    248211    {Binding{b->getStreamSetTy(1, 1), "matchResult"}, Binding{b->getStreamSetTy(1, 1), "lineBreak"}, Binding{b->getStreamSetTy(1, 8), "InputStream", UnknownRate()}},
    249212    {},
     213    {Binding{b->getIntAddrTy(), "accumulator_address"}},
    250214    {},
    251     {},
    252     {Binding{b->getSizeTy(), "BlockNo"}, Binding{b->getSizeTy(), "LineNum"}})
    253 , mGrepType(grepType) {
    254     if (mGrepType == GrepType::CallBack) {
    255         mScalarInputs.push_back(Binding{b->getIntAddrTy(), "accumulator_address"});
    256     }
    257     else {
    258         mScalarInputs.push_back(Binding{b->getInt32Ty(), "FileIdx"});
    259     }
     215    {Binding{b->getSizeTy(), "BlockNo"}, Binding{b->getSizeTy(), "LineNum"}}) {}
    260216}
    261 
    262 }
Note: See TracChangeset for help on using the changeset viewer.