Changeset 5003


Ignore:
Timestamp:
Apr 7, 2016, 1:45:24 PM (20 months ago)
Author:
nmedfort
Message:

Symbol table bug fix and support for >1 block lookahead.

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

Legend:

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

    r5001 r5003  
    223223    Type * const int32PtrTy = PointerType::get(iBuilder->getInt32Ty(), 0);
    224224    FunctionType * const gatherFunctionType = FunctionType::get(iBuilder->getVoidTy(), {iBuilder->getInt8PtrTy(), int32PtrTy, int32PtrTy, iBuilder->getInt32Ty(), iBuilder->getInt8PtrTy()}, false);
    225     Value * const gatherFunctionPtrArray = iBuilder->CreateAlloca(PointerType::get(gatherFunctionType, 0), iBuilder->getInt32(endpoints.size()));
     225    Value * const gatherFunctionPtrArray = iBuilder->CreateAlloca(PointerType::get(gatherFunctionType, 0), iBuilder->getInt32(endpoints.size()), "gatherFunctionPtrArray");
    226226
    227227    unsigned i = 0;
     
    494494        for (unsigned blockCount = 0; blockCount < minCount; ++blockCount) {
    495495            Value * tokenData = generateMaskedGather(base, startPos, activeLanes);
    496             Value * ptr = iBuilder->CreateOr(buffer, iBuilder->CreateOr(gatherIV, iBuilder->getInt32(blockCount * 4)));
     496            Value * ptr = iBuilder->CreateGEP(buffer, iBuilder->CreateOr(gatherIV, iBuilder->getInt32(blockCount * 4)));
    497497            iBuilder->CreateAlignedStore(tokenData, ptr, transposedByteWidth);
    498498            startPos = iBuilder->CreateAdd(startPos, four);
     
    595595        iBuilder->CreateRetVoid();
    596596
    597         function->dump();
    598 
    599597        iBuilder->restoreIP(ip);
    600598    }
     
    613611    endpoints.push_back(17);
    614612    endpoints.push_back(27);
     613    endpoints.push_back(39);
     614    endpoints.push_back(77);
     615    endpoints.push_back(124);
     616    endpoints.push_back(178);
     617    endpoints.push_back(278);
    615618
    616619    PabloCompiler pablo_compiler(mMod, iBuilder);
     
    659662    BasicBlock * entryBlock = iBuilder->GetInsertBlock();
    660663
    661     BasicBlock * leadingTestBlock = BasicBlock::Create(mMod->getContext(), "leadingCond", main, 0);
    662     BasicBlock * safetyCheckBlock = BasicBlock::Create(mMod->getContext(), "safetyCheck", main, 0);
    663     BasicBlock * leadingBodyBlock = BasicBlock::Create(mMod->getContext(), "leadingBody", main, 0);
    664 
    665     BasicBlock * regularTestBlock = BasicBlock::Create(mMod->getContext(), "fullCond", main, 0);
    666     BasicBlock * regularBodyBlock = BasicBlock::Create(mMod->getContext(), "fullBody", main, 0);
    667     BasicBlock * regularExitBlock = BasicBlock::Create(mMod->getContext(), "fullExit", main, 0);
    668 
    669     BasicBlock * partialBlock = BasicBlock::Create(mMod->getContext(),  "partialBlock", main, 0);
    670 
    671     BasicBlock * finalTestBlock = BasicBlock::Create(mMod->getContext(),  "finalCond", main, 0);
    672     BasicBlock * finalBodyBlock = BasicBlock::Create(mMod->getContext(),  "finalBody", main, 0);
    673 
    674     BasicBlock * remainingBlock = BasicBlock::Create(mMod->getContext(), "remaining", main, 0);
     664    BasicBlock * leadingBlock = BasicBlock::Create(mMod->getContext(), "leadingBody", main, 0);
     665
     666    BasicBlock * partialLeadingCond = BasicBlock::Create(mMod->getContext(), "partialLeadingCond", main, 0);
     667    BasicBlock * partialLeadingBody = BasicBlock::Create(mMod->getContext(), "partialLeadingBody", main, 0);
     668
     669    BasicBlock * regularCondBlock = BasicBlock::Create(mMod->getContext(), "regularCond", main, 0);
     670    BasicBlock * regularBodyBlock = BasicBlock::Create(mMod->getContext(), "regularBody", main, 0);
     671
     672    BasicBlock * partialCondBlock = BasicBlock::Create(mMod->getContext(), "partialCond", main, 0);
     673    BasicBlock * partialBodyBlock = BasicBlock::Create(mMod->getContext(),  "partialBody", main, 0);
     674
     675    BasicBlock * flushLengthGroupsBlock = BasicBlock::Create(mMod->getContext(), "flushLengthGroups", main, 0);
    675676
    676677    Instance * s2pInstance = mS2PKernel->instantiate(inputStream);
     
    686687    Value * const blockSize = iBuilder->getInt64(mBlockSize);
    687688
    688     // If the buffer size is smaller than our largest length group, only check up to the buffer size.
    689     Value * safetyCheck = iBuilder->CreateICmpUGE(bufferSize, blockSize);
    690     if (blockSize == requiredBytes) {
    691         iBuilder->CreateCondBr(safetyCheck, leadingTestBlock, remainingBlock); // fix this to be a special case
    692     } else {
    693         throw std::runtime_error("Not supported yet!");
    694     }
    695 
    696689    // First compute any necessary leading blocks to allow the sorting kernel access to the "future" data produced by
    697690    // the leading kernel ...
    698     iBuilder->SetInsertPoint(leadingTestBlock);
    699     PHINode * blockNo = iBuilder->CreatePHI(intType, 2);
    700     blockNo->addIncoming(iBuilder->getInt64(0), entryBlock);
    701     PHINode * remainingBytes = iBuilder->CreatePHI(intType, 2);
    702     remainingBytes->addIncoming(bufferSize, entryBlock);
    703     Value * leadingBlocksCond = iBuilder->CreateICmpULT(blockNo, iBuilder->getInt64(leadingBlocks));
    704     iBuilder->CreateCondBr(leadingBlocksCond, safetyCheckBlock, regularTestBlock);
    705 
    706     iBuilder->SetInsertPoint(safetyCheckBlock);
    707     Value * safetyCheckCond = iBuilder->CreateICmpULT(remainingBytes, blockSize);
    708     iBuilder->CreateCondBr(safetyCheckCond, regularExitBlock, leadingBodyBlock);
    709 
    710     iBuilder->SetInsertPoint(leadingBodyBlock);
    711 
     691
     692    Value * enoughDataForLookaheadCond = iBuilder->CreateICmpUGE(bufferSize, requiredBytes);
     693    iBuilder->CreateCondBr(enoughDataForLookaheadCond, leadingBlock, partialLeadingCond);
     694
     695    iBuilder->SetInsertPoint(leadingBlock);
     696    for (unsigned i = 0; i < leadingBlocks; ++i) {
     697        s2pInstance->CreateDoBlockCall();
     698        leadingInstance->CreateDoBlockCall();
     699    }
     700    iBuilder->CreateBr(regularCondBlock);
     701
     702    iBuilder->SetInsertPoint(partialLeadingCond);
     703    PHINode * remainingBytes1 = iBuilder->CreatePHI(intType, 2);
     704    remainingBytes1->addIncoming(bufferSize, entryBlock);
     705    Value * remainingCond = iBuilder->CreateICmpUGT(remainingBytes1, blockSize);
     706    iBuilder->CreateCondBr(remainingCond, partialLeadingBody, partialCondBlock);
     707
     708    iBuilder->SetInsertPoint(partialLeadingBody);
    712709    s2pInstance->CreateDoBlockCall();
    713710    leadingInstance->CreateDoBlockCall();
    714     blockNo->addIncoming(iBuilder->CreateAdd(blockNo, iBuilder->getInt64(1)), leadingBodyBlock);
    715     remainingBytes->addIncoming(iBuilder->CreateSub(remainingBytes, blockSize), leadingBodyBlock);
    716     iBuilder->CreateBr(leadingTestBlock);
     711    remainingBytes1->addIncoming(iBuilder->CreateSub(remainingBytes1, blockSize), partialLeadingBody);
     712    iBuilder->CreateBr(partialLeadingCond);
    717713
    718714    // Now all the data for which we can produce and consume a full leading block...
    719     iBuilder->SetInsertPoint(regularTestBlock);
     715    iBuilder->SetInsertPoint(regularCondBlock);
    720716    PHINode * remainingBytes2 = iBuilder->CreatePHI(intType, 2);
    721     remainingBytes2->addIncoming(remainingBytes, leadingTestBlock);
    722     Value * remainingBytesCond = iBuilder->CreateICmpULT(remainingBytes2, requiredBytes);
    723     iBuilder->CreateCondBr(remainingBytesCond, regularExitBlock, regularBodyBlock);
     717    remainingBytes2->addIncoming(bufferSize, leadingBlock);
     718    Value * remainingBytesCond = iBuilder->CreateICmpUGT(remainingBytes2, requiredBytes);
     719    iBuilder->CreateCondBr(remainingBytesCond, regularBodyBlock, partialCondBlock);
    724720
    725721    iBuilder->SetInsertPoint(regularBodyBlock);
    726 
    727722    s2pInstance->CreateDoBlockCall();
    728723    leadingInstance->CreateDoBlockCall();
    729724    sortingInstance->CreateDoBlockCall();
    730725    gatheringInstance->CreateDoBlockCall();
    731 
    732726    remainingBytes2->addIncoming(iBuilder->CreateSub(remainingBytes2, blockSize), regularBodyBlock);
    733     iBuilder->CreateBr(regularTestBlock);
     727    iBuilder->CreateBr(regularCondBlock);
    734728
    735729    // Check if we have a partial blocks worth of leading data remaining
    736     iBuilder->SetInsertPoint(regularExitBlock);
    737     PHINode * remainingBytes3 = iBuilder->CreatePHI(intType, 2);
    738     remainingBytes3->addIncoming(remainingBytes, safetyCheckBlock);
    739     remainingBytes3->addIncoming(remainingBytes2, regularTestBlock);
    740     Value * partialBlockCond = iBuilder->CreateICmpNE(remainingBytes3, ConstantInt::getNullValue(intType));
    741     iBuilder->CreateCondBr(partialBlockCond, finalTestBlock, partialBlock);
     730    iBuilder->SetInsertPoint(partialCondBlock);
     731    PHINode * remainingBytes3 = iBuilder->CreatePHI(intType, 3);
     732    remainingBytes3->addIncoming(bufferSize, partialLeadingCond);
     733    remainingBytes3->addIncoming(remainingBytes2, regularCondBlock);
     734    Value * partialBlockCond = iBuilder->CreateICmpSGT(remainingBytes3, iBuilder->getInt64(0));
     735    iBuilder->CreateCondBr(partialBlockCond, partialBodyBlock, flushLengthGroupsBlock);
    742736
    743737    // If we do, process it and mask out the data
    744     iBuilder->SetInsertPoint(partialBlock);
    745     s2pInstance->CreateDoBlockCall();
    746     leadingInstance->CreateDoBlockCall();
    747     leadingInstance->clearOutputStreamSet();
     738    iBuilder->SetInsertPoint(partialBodyBlock);
     739    s2pInstance->clearOutputStreamSet();
     740    leadingInstance->CreateDoBlockCall();   
    748741    sortingInstance->CreateDoBlockCall();
    749742    gatheringInstance->CreateDoBlockCall();
    750 
    751     iBuilder->CreateBr(finalTestBlock);
    752 
    753     // Now clear the leading data and test the final blocks
    754     iBuilder->SetInsertPoint(finalTestBlock);
    755     PHINode * remainingFullBlocks = iBuilder->CreatePHI(iBuilder->getInt64Ty(), 3);
    756     remainingFullBlocks->addIncoming(iBuilder->getInt64(leadingBlocks), regularExitBlock);
    757     remainingFullBlocks->addIncoming(iBuilder->getInt64(leadingBlocks), partialBlock);
    758     Value * remainingFullBlocksCond = iBuilder->CreateICmpUGT(remainingFullBlocks, ConstantInt::getNullValue(intType));
    759     iBuilder->CreateCondBr(remainingFullBlocksCond, finalBodyBlock, remainingBlock);
    760 
    761     iBuilder->SetInsertPoint(finalBodyBlock);
    762 
    763     leadingInstance->clearOutputStreamSet();
    764     sortingInstance->CreateDoBlockCall();
    765     gatheringInstance->CreateDoBlockCall();
    766 
    767     remainingFullBlocks->addIncoming(iBuilder->CreateSub(remainingFullBlocks, iBuilder->getInt64(1)), finalBodyBlock);
    768 
    769 
    770     iBuilder->CreateBr(finalTestBlock);
    771 
     743    remainingBytes3->addIncoming(iBuilder->CreateSub(remainingBytes3, blockSize), partialBodyBlock);
     744    iBuilder->CreateBr(partialCondBlock);
    772745
    773746    // perform a final partial gather on all length groups ...
    774     iBuilder->SetInsertPoint(remainingBlock);
     747    iBuilder->SetInsertPoint(flushLengthGroupsBlock);
    775748
    776749    Value * const base = iBuilder->CreateLoad(gatheringInstance->getInternalState("Base"));
     
    778751
    779752    for (unsigned i = 0; i < mGatherFunction.size(); ++i) {
    780         BasicBlock * nonEmptyGroup = BasicBlock::Create(mMod->getContext(), "", main, 0);
     753        BasicBlock * nonEmptyGroup = BasicBlock::Create(mMod->getContext(), "flushLengthGroup" + std::to_string(i), main, 0);
    781754
    782755        BasicBlock * nextNonEmptyGroup = BasicBlock::Create(mMod->getContext(), "", main, 0);
  • icGREP/icgrep-devel/icgrep/symboltable.cpp

    r4991 r5003  
    3535typedef void (*SymTableFunctionType)(char * byte_data, size_t filesize);
    3636
    37 static cl::list<std::string> files(cl::Positional, cl::desc("<input file ...>"), cl::OneOrMore);
     37static cl::list<std::string> files(cl::Positional, cl::desc("<input file ...>"), cl::ZeroOrMore);
    3838
    3939void process(const std::string & fileName, SymTableFunctionType function) {
Note: See TracChangeset for help on using the changeset viewer.