Ignore:
Timestamp:
May 13, 2017, 11:37:08 AM (2 years ago)
Author:
cameron
Message:

Hack for source/external buffers with mBufferBlocks=1; u8u16 test with segment-pipeline-parallel; simplified copying

File:
1 edited

Legend:

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

    r5446 r5448  
    138138
    139139void StreamSetBuffer::createBlockAlignedCopy(IDISA::IDISA_Builder * const iBuilder, Value * targetBlockPtr, Value * sourceBlockPtr, Value * itemsToCopy) const {
    140     Type * size_ty = iBuilder->getSizeTy();
    141140    Type * i8ptr = iBuilder->getInt8PtrTy();
     141    unsigned alignment = iBuilder->getBitBlockWidth() / 8;
    142142    Constant * blockSize = iBuilder->getSize(iBuilder->getBitBlockWidth());
    143     Function * f = iBuilder->GetInsertBlock()->getParent();
    144     BasicBlock * wholeBlockCopy = BasicBlock::Create(iBuilder->getContext(), "wholeBlockCopy", f, 0);
    145     BasicBlock * partialBlockCopy = BasicBlock::Create(iBuilder->getContext(), "partialBlockCopy", f, 0);
    146     BasicBlock * copyDone = BasicBlock::Create(iBuilder->getContext(), "copyDone", f, 0);
    147143    unsigned numStreams = getType()->getArrayNumElements();
    148144    auto elemTy = getType()->getArrayElementType();
    149145    unsigned fieldWidth = isa<ArrayType>(elemTy) ? elemTy->getArrayNumElements() : 1;
     146    if (numStreams == 1) {
     147        Value * copyBits = iBuilder->CreateMul(itemsToCopy, iBuilder->getSize(fieldWidth));
     148        Value * copyBytes = iBuilder->CreateLShr(iBuilder->CreateAdd(copyBits, iBuilder->getSize(7)), iBuilder->getSize(3));
     149        iBuilder->CreateMemMove(iBuilder->CreateBitCast(targetBlockPtr, i8ptr), iBuilder->CreateBitCast(sourceBlockPtr, i8ptr), copyBytes, alignment);
     150        return;
     151    }
    150152    Value * blocksToCopy = iBuilder->CreateUDiv(itemsToCopy, blockSize);
    151153    Value * partialItems = iBuilder->CreateURem(itemsToCopy, blockSize);
    152154    Value * partialBlockTargetPtr = iBuilder->CreateGEP(targetBlockPtr, blocksToCopy);
    153155    Value * partialBlockSourcePtr = iBuilder->CreateGEP(sourceBlockPtr, blocksToCopy);
    154     iBuilder->CreateCondBr(iBuilder->CreateICmpUGT(blocksToCopy, iBuilder->getSize(0)), wholeBlockCopy, partialBlockCopy);
    155     iBuilder->SetInsertPoint(wholeBlockCopy);
    156     unsigned alignment = iBuilder->getBitBlockWidth() / 8;
    157     Value * copyLength = iBuilder->CreateSub(iBuilder->CreatePtrToInt(partialBlockTargetPtr, size_ty), iBuilder->CreatePtrToInt(targetBlockPtr, size_ty));
    158     iBuilder->CreateMemMove(iBuilder->CreateBitCast(targetBlockPtr, i8ptr), iBuilder->CreateBitCast(sourceBlockPtr, i8ptr), copyLength, alignment);
    159     iBuilder->CreateCondBr(iBuilder->CreateICmpUGT(partialItems, iBuilder->getSize(0)), partialBlockCopy, copyDone);
    160     iBuilder->SetInsertPoint(partialBlockCopy);
    161     Value * copyBits = iBuilder->CreateMul(itemsToCopy, iBuilder->getSize(fieldWidth));
    162     Value * copyBytes = iBuilder->CreateLShr(iBuilder->CreateAdd(copyBits, iBuilder->getSize(7)), iBuilder->getSize(3));
     156    Value * blockCopyBytes = iBuilder->CreateMul(blocksToCopy, iBuilder->getSize(iBuilder->getBitBlockWidth() * numStreams * fieldWidth/8));
     157    iBuilder->CreateMemMove(iBuilder->CreateBitCast(targetBlockPtr, i8ptr), iBuilder->CreateBitCast(sourceBlockPtr, i8ptr), blockCopyBytes, alignment);
     158    Value * partialCopyBitsPreStream = iBuilder->CreateMul(partialItems, iBuilder->getSize(fieldWidth));
     159    Value * partialCopyBytesPreStream = iBuilder->CreateLShr(iBuilder->CreateAdd(partialCopyBitsPreStream, iBuilder->getSize(7)), iBuilder->getSize(3));
    163160    for (unsigned strm = 0; strm < numStreams; strm++) {
    164161        Value * strmTargetPtr = iBuilder->CreateGEP(partialBlockTargetPtr, {iBuilder->getInt32(0), iBuilder->getInt32(strm)});
    165162        Value * strmSourcePtr = iBuilder->CreateGEP(partialBlockSourcePtr, {iBuilder->getInt32(0), iBuilder->getInt32(strm)});
    166         iBuilder->CreateMemMove(iBuilder->CreateBitCast(strmTargetPtr, i8ptr), iBuilder->CreateBitCast(strmSourcePtr, i8ptr), copyBytes, alignment);
    167     }
    168     iBuilder->CreateBr(copyDone);
    169     iBuilder->SetInsertPoint(copyDone);
     163        iBuilder->CreateMemMove(iBuilder->CreateBitCast(strmTargetPtr, i8ptr), iBuilder->CreateBitCast(strmSourcePtr, i8ptr), partialCopyBytesPreStream, alignment);
     164    }
    170165}
    171166
Note: See TracChangeset for help on using the changeset viewer.