Ignore:
Timestamp:
Jun 25, 2016, 2:50:45 PM (3 years ago)
Author:
cameron
Message:

Support for segment-based processing

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

Legend:

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

    r5074 r5075  
    8585    iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", main,0));
    8686    BasicBlock * entryBlock = iBuilder->GetInsertBlock();
     87    BasicBlock * segmentCondBlock = nullptr;
     88    BasicBlock * segmentBodyBlock = nullptr;
     89    const unsigned segmentSize = codegen::SegmentSize;
     90   
     91    if (segmentSize > 1) {
     92        segmentCondBlock = BasicBlock::Create(mMod->getContext(), "segmentCond", main, 0);
     93        segmentBodyBlock = BasicBlock::Create(mMod->getContext(), "segmentBody", main, 0);
     94    }
    8795    BasicBlock * fullCondBlock = BasicBlock::Create(mMod->getContext(), "fullCond", main, 0);
    8896    BasicBlock * fullBodyBlock = BasicBlock::Create(mMod->getContext(), "fullBody", main, 0);
     
    9098
    9199   
    92     const unsigned segmentSize = 1;// or codegen::SegmentSize
    93    
    94100    StreamSetBuffer ByteStream(iBuilder, StreamSetType(1, (UTF_16 ? 16 : 8)), 0);
    95101    StreamSetBuffer BasisBits(iBuilder, StreamSetType((UTF_16 ? 16 : 8), 1), segmentSize);
     
    99105    BasisBits.allocateBuffer();
    100106    MatchResults.allocateBuffer();
    101 
    102     Value * initialBufferSize = bufferSize;
    103     Value * initialBlockNo = iBuilder->getInt64(0);
    104     BasicBlock * initialBlock = entryBlock;
    105107   
    106108    Value * s2pInstance = s2pk.createInstance({});
     
    110112        scanMatchInstance = scanMatchK.createInstance({iBuilder->CreateBitCast(inputStream, int8PtrTy), bufferSize, fileIdx});
    111113    }
    112     iBuilder->CreateBr(fullCondBlock);
    113    
     114
     115   
     116    Value * initialBufferSize = nullptr;
     117    Value * initialBlockNo = nullptr;
     118    BasicBlock * initialBlock = nullptr;
     119
     120    if (segmentSize > 1) {
     121        iBuilder->CreateBr(segmentCondBlock);
     122        iBuilder->SetInsertPoint(segmentCondBlock);
     123        PHINode * remainingBytes = iBuilder->CreatePHI(int64ty, 2, "remainingBytes");
     124        remainingBytes->addIncoming(bufferSize, entryBlock);
     125        PHINode * blockNo = iBuilder->CreatePHI(int64ty, 2, "blockNo");
     126        blockNo->addIncoming(iBuilder->getInt64(0), entryBlock);
     127
     128        Constant * const step = ConstantInt::get(int64ty, mBlockSize * segmentSize);
     129        Value * segmentCondTest = iBuilder->CreateICmpULT(remainingBytes, step);
     130        iBuilder->CreateCondBr(segmentCondTest, fullCondBlock, segmentBodyBlock);
     131        iBuilder->SetInsertPoint(segmentBodyBlock);
     132        for (unsigned i = 0; i < segmentSize; ++i) {
     133            Value * blkNo = iBuilder->CreateAdd(blockNo, iBuilder->getInt64(i));
     134            s2pk.createDoBlockCall(s2pInstance, {ByteStream.getBlockPointer(blkNo), BasisBits.getBlockPointer(blkNo)});
     135        }
     136        for (unsigned i = 0; i < segmentSize; ++i) {
     137            Value * blkNo = iBuilder->CreateAdd(blockNo, iBuilder->getInt64(i));
     138            icgrepK.createDoBlockCall(icgrepInstance, {BasisBits.getBlockPointer(blkNo), MatchResults.getBlockPointer(blkNo)});
     139        }
     140        if (!CountOnly) {
     141            for (unsigned i = 0; i < segmentSize; ++i) {
     142                Value * blkNo = iBuilder->CreateAdd(blockNo, iBuilder->getInt64(i));
     143                scanMatchK.createDoBlockCall(scanMatchInstance, {MatchResults.getBlockPointer(blkNo)});
     144            }
     145        }
     146        remainingBytes->addIncoming(iBuilder->CreateSub(remainingBytes, step), segmentBodyBlock);
     147        blockNo->addIncoming(iBuilder->CreateAdd(blockNo, iBuilder->getInt64(segmentSize)), segmentBodyBlock);
     148
     149        iBuilder->CreateBr(segmentCondBlock);
     150        initialBufferSize = remainingBytes;
     151        initialBlockNo = blockNo;
     152        initialBlock = segmentCondBlock;
     153    } else {
     154        initialBufferSize = bufferSize;
     155        initialBlockNo = iBuilder->getInt64(0);
     156        initialBlock = entryBlock;
     157        iBuilder->CreateBr(fullCondBlock);
     158    }
     159
    114160    iBuilder->SetInsertPoint(fullCondBlock);
    115161    PHINode * remainingBytes = iBuilder->CreatePHI(int64ty, 2, "remainingBytes");
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5047 r5075  
    3535        iBuilder->CreateGEP(getStreamSetBlockType(), mStreamSetBufferPtr, {blockNo});
    3636    Value * offset = iBuilder->CreateURem(blockNo, iBuilder->getInt64(mSegmentSize));
    37     return iBuilder->CreateGEP(getStreamSetBlockType(), mStreamSetBufferPtr, {offset});
     37    return iBuilder->CreateGEP(getStreamSetBlockType(), mStreamSetBufferPtr, {iBuilder->getInt64(0), offset});
    3838}
    3939
Note: See TracChangeset for help on using the changeset viewer.