Ignore:
Timestamp:
Mar 2, 2017, 12:18:43 PM (3 years ago)
Author:
cameron
Message:

Swizzled bitstream deletion and -enable-AVX-deletion in u8u16

File:
1 edited

Legend:

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

    r5353 r5355  
    111111}
    112112
     113Value * StreamSetBuffer::getLinearlyAccessibleBlocks(llvm::Value * fromBlock) const {
     114    Constant * bufBlocks = iBuilder->getSize(mBufferBlocks);
     115    return iBuilder->CreateSub(bufBlocks, iBuilder->CreateURem(fromBlock, bufBlocks));
     116}
     117
    113118
    114119// Single Block Buffer
     
    153158
    154159void CircularCopybackBuffer::createCopyBack(Value * self, Value * overFlowItems) const {
     160    Type * size_ty = iBuilder->getSizeTy();
     161    Type * i8ptr = iBuilder->getInt8PtrTy();
     162    Constant * blockSize = iBuilder->getSize(iBuilder->getBitBlockWidth());
    155163    Function * f = iBuilder->GetInsertBlock()->getParent();
    156164    BasicBlock * wholeBlockCopy = BasicBlock::Create(iBuilder->getContext(), "wholeBlockCopy", f, 0);
    157165    BasicBlock * partialBlockCopy = BasicBlock::Create(iBuilder->getContext(), "partialBlockCopy", f, 0);
    158166    BasicBlock * copyBackDone = BasicBlock::Create(iBuilder->getContext(), "copyBackDone", f, 0);
    159     Type * i8ptr = iBuilder->getInt8PtrTy();
    160167    unsigned numStreams = getType()->getArrayNumElements();
    161168    auto elemTy = getType()->getArrayElementType();
    162169    unsigned fieldWidth = isa<ArrayType>(elemTy) ? elemTy->getArrayNumElements() : 1;
    163     Constant * blockSize = iBuilder->getSize(iBuilder->getBitBlockWidth());
    164170    Value * overFlowAreaPtr = iBuilder->CreateGEP(self, iBuilder->getSize(mBufferBlocks));
    165171    Value * overFlowBlocks = iBuilder->CreateUDiv(overFlowItems, blockSize);
    166172    Value * partialItems = iBuilder->CreateURem(overFlowItems, blockSize);
     173    Value * partialBlockTargetPtr = iBuilder->CreateGEP(self, overFlowBlocks);
     174    Value * partialBlockSourcePtr = iBuilder->CreateGEP(overFlowAreaPtr, overFlowBlocks);
    167175    iBuilder->CreateCondBr(iBuilder->CreateICmpUGT(overFlowBlocks, iBuilder->getSize(0)), wholeBlockCopy, partialBlockCopy);
    168176    iBuilder->SetInsertPoint(wholeBlockCopy);
    169177    unsigned alignment = iBuilder->getBitBlockWidth() / 8;
    170     Constant * blockBytes = iBuilder->getSize(fieldWidth * iBuilder->getBitBlockWidth()/8);
    171     Value * copyLength = iBuilder->CreateMul(overFlowBlocks, blockBytes);
     178    Value * copyLength = iBuilder->CreateSub(iBuilder->CreatePtrToInt(partialBlockTargetPtr, size_ty), iBuilder->CreatePtrToInt(self, size_ty));
    172179    iBuilder->CreateMemMove(iBuilder->CreateBitCast(self, i8ptr), iBuilder->CreateBitCast(overFlowAreaPtr, i8ptr), copyLength, alignment);
    173180    iBuilder->CreateCondBr(iBuilder->CreateICmpUGT(partialItems, iBuilder->getSize(0)), partialBlockCopy, copyBackDone);
    174181    iBuilder->SetInsertPoint(partialBlockCopy);
    175     Value * partialBlockTargetPtr = iBuilder->CreateGEP(self, overFlowBlocks);
    176     Value * partialBlockSourcePtr = iBuilder->CreateGEP(overFlowAreaPtr, overFlowBlocks);
    177182    Value * copyBits = iBuilder->CreateMul(overFlowItems, iBuilder->getSize(fieldWidth));
    178183    Value * copyBytes = iBuilder->CreateLShr(iBuilder->CreateAdd(copyBits, iBuilder->getSize(7)), iBuilder->getSize(3));
     
    189194    return iBuilder->CreateGEP(self, modByBufferBlocks(blockIndex));
    190195}
     196
     197// SwizzledCopybackBuffer Buffer
     198
     199void SwizzledCopybackBuffer::allocateBuffer() {
     200    mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(getType(), iBuilder->getSize(mBufferBlocks + mOverflowBlocks));
     201}
     202
     203void SwizzledCopybackBuffer::createCopyBack(Value * self, Value * overFlowItems) const {
     204    Type * size_ty = iBuilder->getSizeTy();
     205    Type * i8ptr = iBuilder->getInt8PtrTy();
     206    Constant * blockSize = iBuilder->getSize(iBuilder->getBitBlockWidth());
     207    Function * f = iBuilder->GetInsertBlock()->getParent();
     208    BasicBlock * wholeBlockCopy = BasicBlock::Create(iBuilder->getContext(), "wholeBlockCopy", f, 0);
     209    BasicBlock * partialBlockCopy = BasicBlock::Create(iBuilder->getContext(), "partialBlockCopy", f, 0);
     210    BasicBlock * copyBackDone = BasicBlock::Create(iBuilder->getContext(), "copyBackDone", f, 0);
     211    unsigned numStreams = getType()->getArrayNumElements();
     212    unsigned swizzleFactor = iBuilder->getBitBlockWidth()/mFieldWidth;
     213    auto elemTy = getType()->getArrayElementType();
     214    unsigned fieldWidth = isa<ArrayType>(elemTy) ? elemTy->getArrayNumElements() : 1;
     215    Value * overFlowAreaPtr = iBuilder->CreateGEP(self, iBuilder->getSize(mBufferBlocks));
     216    Value * overFlowBlocks = iBuilder->CreateUDiv(overFlowItems, blockSize);
     217    Value * partialItems = iBuilder->CreateURem(overFlowItems, blockSize);
     218    Value * partialBlockTargetPtr = iBuilder->CreateGEP(self, overFlowBlocks);
     219    Value * partialBlockSourcePtr = iBuilder->CreateGEP(overFlowAreaPtr, overFlowBlocks);
     220    iBuilder->CreateCondBr(iBuilder->CreateICmpUGT(overFlowBlocks, iBuilder->getSize(0)), wholeBlockCopy, partialBlockCopy);
     221    iBuilder->SetInsertPoint(wholeBlockCopy);
     222    unsigned alignment = iBuilder->getBitBlockWidth() / 8;
     223    Value * copyLength = iBuilder->CreateSub(iBuilder->CreatePtrToInt(partialBlockTargetPtr, size_ty), iBuilder->CreatePtrToInt(self, size_ty));
     224    iBuilder->CreateMemMove(iBuilder->CreateBitCast(self, i8ptr), iBuilder->CreateBitCast(overFlowAreaPtr, i8ptr), copyLength, alignment);
     225    iBuilder->CreateCondBr(iBuilder->CreateICmpUGT(partialItems, iBuilder->getSize(0)), partialBlockCopy, copyBackDone);
     226    iBuilder->SetInsertPoint(partialBlockCopy);
     227    Value * copyBits = iBuilder->CreateMul(overFlowItems, iBuilder->getSize(fieldWidth * swizzleFactor));
     228    Value * copyBytes = iBuilder->CreateLShr(iBuilder->CreateAdd(copyBits, iBuilder->getSize(7)), iBuilder->getSize(3));
     229    for (unsigned strm = 0; strm < numStreams; strm += swizzleFactor) {
     230        Value * strmTargetPtr = iBuilder->CreateGEP(partialBlockTargetPtr, {iBuilder->getInt32(0), iBuilder->getInt32(strm)});
     231        Value * strmSourcePtr = iBuilder->CreateGEP(partialBlockSourcePtr, {iBuilder->getInt32(0), iBuilder->getInt32(strm)});
     232        iBuilder->CreateMemMove(iBuilder->CreateBitCast(strmTargetPtr, i8ptr), iBuilder->CreateBitCast(strmSourcePtr, i8ptr), copyBytes, alignment);
     233    }
     234    iBuilder->CreateBr(copyBackDone);
     235    iBuilder->SetInsertPoint(copyBackDone);
     236}
     237
     238Value * SwizzledCopybackBuffer::getStreamSetBlockPtr(Value * self, Value * blockIndex) const {
     239    assert (blockIndex->getType()->isIntegerTy());
     240   
     241    Value * offset = nullptr;
     242    if (mBufferBlocks == 1) {
     243        offset = ConstantInt::getNullValue(iBuilder->getSizeTy());
     244    } else if ((mBufferBlocks & (mBufferBlocks - 1)) == 0) { // is power of 2
     245        offset = iBuilder->CreateAnd(blockIndex, ConstantInt::get(blockIndex->getType(), mBufferBlocks - 1));
     246    } else {
     247        offset = iBuilder->CreateURem(blockIndex, ConstantInt::get(blockIndex->getType(), mBufferBlocks));
     248    }
     249    return iBuilder->CreateGEP(self, offset);
     250}
     251
     252SwizzledCopybackBuffer::SwizzledCopybackBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned fieldwidth, unsigned AddressSpace)
     253: StreamSetBuffer(BufferKind::SwizzledCopybackBuffer, b, type, resolveStreamSetType(b, type), bufferBlocks, AddressSpace), mOverflowBlocks(overflowBlocks), mFieldWidth(fieldwidth) {
     254   
     255}
     256
     257
    191258
    192259// Expandable Buffer
Note: See TracChangeset for help on using the changeset viewer.