Ignore:
Timestamp:
Feb 5, 2017, 3:25:17 PM (3 years ago)
Author:
cameron
Message:

Refined copy-back buffers, use copyback in p2s_compressed; stdout/filesink mods for circular buffers

File:
1 edited

Legend:

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

    r5301 r5303  
    124124}
    125125
    126 void CircularCopybackBuffer::createCopyBack(Value * self, Value * overFlowItems) {
    127     // Must copy back one full block for each of the streams in the stream set.
     126void CircularCopybackBuffer::createCopyBack(Value * self, Value * overFlowItems) const {
     127    Function * f = iBuilder->GetInsertBlock()->getParent();
     128    BasicBlock * wholeBlockCopy = BasicBlock::Create(iBuilder->getContext(), "wholeBlockCopy", f, 0);
     129    BasicBlock * partialBlockCopy = BasicBlock::Create(iBuilder->getContext(), "partialBlockCopy", f, 0);
     130    BasicBlock * copyBackDone = BasicBlock::Create(iBuilder->getContext(), "copyBackDone", f, 0);
     131    Type * i8ptr = iBuilder->getInt8PtrTy();
     132    unsigned numStreams = getType()->getArrayNumElements();
     133    auto elemTy = getType()->getArrayElementType();
     134    unsigned fieldWidth = isa<ArrayType>(elemTy) ? elemTy->getArrayNumElements() : 1;
    128135    Constant * blockSize = iBuilder->getSize(iBuilder->getBitBlockWidth());
    129     Constant * blockSizeLess1 = iBuilder->getSize(iBuilder->getBitBlockWidth() - 1);
    130     Value * overFlowBlocks = iBuilder->CreateUDiv(iBuilder->CreateAdd(overFlowItems, blockSizeLess1), blockSize);
    131     Value * overFlowAreaPtr = iBuilder->CreateGEP(mStreamSetBufferPtr, iBuilder->getSize(mBufferBlocks));
    132     DataLayout dl(iBuilder->getModule());
    133     Constant * blockBytes = ConstantInt::get(iBuilder->getSizeTy(), dl.getTypeAllocSize(mStreamSetType) * iBuilder->getBitBlockWidth());
     136    Value * overFlowAreaPtr = iBuilder->CreateGEP(self, iBuilder->getSize(mBufferBlocks));
     137    Value * overFlowBlocks = iBuilder->CreateUDiv(overFlowItems, blockSize);
     138    Value * partialItems = iBuilder->CreateURem(overFlowItems, blockSize);
     139    iBuilder->CreateCondBr(iBuilder->CreateICmpUGT(overFlowBlocks, iBuilder->getSize(0)), wholeBlockCopy, partialBlockCopy);
     140    iBuilder->SetInsertPoint(wholeBlockCopy);
     141    unsigned alignment = iBuilder->getBitBlockWidth() / 8;
     142    Constant * blockBytes = iBuilder->getSize(fieldWidth * iBuilder->getBitBlockWidth()/8);
    134143    Value * copyLength = iBuilder->CreateMul(overFlowBlocks, blockBytes);
    135     Type * i8ptr = iBuilder->getInt8Ty()->getPointerTo();
    136     unsigned alignment = iBuilder->getBitBlockWidth() / 8;
    137     iBuilder->CreateMemMove(iBuilder->CreateBitCast(mStreamSetBufferPtr, i8ptr), iBuilder->CreateBitCast(overFlowAreaPtr, i8ptr), copyLength, alignment);
     144    iBuilder->CreateMemMove(iBuilder->CreateBitCast(self, i8ptr), iBuilder->CreateBitCast(overFlowAreaPtr, i8ptr), copyLength, alignment);
     145    iBuilder->CreateCondBr(iBuilder->CreateICmpUGT(partialItems, iBuilder->getSize(0)), partialBlockCopy, copyBackDone);
     146    iBuilder->SetInsertPoint(partialBlockCopy);
     147    Value * partialBlockTargetPtr = iBuilder->CreateGEP(self, overFlowBlocks);
     148    Value * partialBlockSourcePtr = iBuilder->CreateGEP(overFlowAreaPtr, overFlowBlocks);
     149    Value * copyBits = iBuilder->CreateMul(overFlowItems, iBuilder->getSize(fieldWidth));
     150    Value * copyBytes = iBuilder->CreateUDiv(iBuilder->CreateAdd(copyBits, iBuilder->getSize(7)), iBuilder->getSize(8));
     151    for (unsigned strm = 0; strm < numStreams; strm++) {
     152        Value * strmTargetPtr = iBuilder->CreateGEP(partialBlockTargetPtr, {iBuilder->getInt32(0), iBuilder->getInt32(strm)});
     153        Value * strmSourcePtr = iBuilder->CreateGEP(partialBlockSourcePtr, {iBuilder->getInt32(0), iBuilder->getInt32(strm)});
     154        iBuilder->CreateMemMove(iBuilder->CreateBitCast(strmTargetPtr, i8ptr), iBuilder->CreateBitCast(strmSourcePtr, i8ptr), copyBytes, alignment);
     155    }
     156    iBuilder->CreateBr(copyBackDone);
     157    iBuilder->SetInsertPoint(copyBackDone);
    138158}
    139159
Note: See TracChangeset for help on using the changeset viewer.