Ignore:
Timestamp:
Mar 30, 2017, 1:22:39 PM (2 years ago)
Author:
nmedfort
Message:

Bug fixes for last check in

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

Legend:

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

    r5377 r5379  
    318318}
    319319
    320 llvm::Value * KernelBuilder::reserveItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const {
     320void KernelBuilder::reserveBytes(llvm::Value * instance, const std::string & name, llvm::Value * value) const {
    321321    assert ("instance cannot be null!" && instance);
    322322    Value * itemCount = getProducedItemCount(instance, name);
    323323    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    324     return buf->reserveItemCount(getStreamSetBufferPtr(name), itemCount, value);
     324    buf->reserveBytes(getStreamSetBufferPtr(name), itemCount, value);
    325325}
    326326
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5377 r5379  
    4848    virtual void setProducedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const;
    4949
    50     virtual llvm::Value * reserveItemCount(llvm::Value * instance, const std::string & name, llvm::Value * requested) const;
     50    virtual void reserveBytes(llvm::Value * instance, const std::string & name, llvm::Value * requested) const;
    5151
    5252    bool hasNoTerminateAttribute() { return mNoTerminateAttribute;}
     
    196196    llvm::Value * getRawOutputPointer(const std::string & name, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
    197197
    198     llvm::Value * reserveItemCount(const std::string & name, llvm::Value * requested) const {
    199         return reserveItemCount(getSelf(), name, requested);
     198    void reserveBytes(const std::string & name, llvm::Value * requested) const {
     199        reserveBytes(getSelf(), name, requested);
    200200    }
    201201
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5377 r5379  
    6363    Value * const inputStream = iBuilder->CreatePointerCast(getRawInputPointer("InputStream", iBuilder->getInt32(0), iBuilder->getInt32(0)), codeUnitTy);
    6464
    65     Value * fileSize = iBuilder->CreateAdd(getProcessedItemCount("InputStream"), getScalarField("PendingBytes"));
     65    Value * const fileSize = iBuilder->CreateAdd(getProcessedItemCount("InputStream"), getScalarField("PendingBytes"));
    6666
    6767    Constant * matchProcessor = nullptr;
     
    8080        default: llvm_unreachable("unknown grep type");
    8181    }
    82     Value * const matchesPtr = getInputStreamBlockPtr("matchResult", iBuilder->getInt32(0));
    83     Value * const matches = iBuilder->CreateBitCast(iBuilder->CreateBlockAlignedLoad(matchesPtr), scanwordVectorType);
    84 
    85     Value * const linebreaksPtr = getInputStreamBlockPtr("lineBreak", iBuilder->getInt32(0));
    86     Value * const linebreaks = iBuilder->CreateBitCast(iBuilder->CreateBlockAlignedLoad(linebreaksPtr), scanwordVectorType);
     82
     83    Value * const matches = iBuilder->CreateBitCast(loadInputStreamBlock("matchResult", iBuilder->getInt32(0)), scanwordVectorType);
     84    Value * const linebreaks = iBuilder->CreateBitCast(loadInputStreamBlock("lineBreak", iBuilder->getInt32(0)), scanwordVectorType);
    8785
    8886    iBuilder->CreateBr(scanWordIteration);
     
    206204        Value * nextScanwordPos = iBuilder->CreateAdd(phiScanwordPos, ConstantInt::get(sizeTy, sizeTy->getBitWidth()));
    207205        phiScanwordPos->addIncoming(nextScanwordPos, return_block);
    208 
    209206        Value * nextIndex = iBuilder->CreateAdd(phiIndex, iBuilder->getInt32(1));
    210207        phiIndex->addIncoming(nextIndex, return_block);
  • icGREP/icgrep-devel/icgrep/kernels/stdin_kernel.cpp

    r5377 r5379  
    1010using namespace llvm;
    1111
    12 inline static unsigned ceil_log2(const unsigned v) {
    13     assert ("log2(0) is undefined!" && v != 0);
    14     return 32 - __builtin_clz(v - 1);
    15 }
    16 
    1712namespace kernel {
    1813
     
    2116    BasicBlock * setTermination = CreateBasicBlock("setTermination");
    2217    BasicBlock * stdInExit = CreateBasicBlock("stdInExit");
    23     ConstantInt * segmentItems = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth() / mCodeUnitWidth);
    24     ConstantInt * segmentItems2 = iBuilder->getSize(2 * mSegmentBlocks * iBuilder->getBitBlockWidth() / mCodeUnitWidth);
    25     // on the first segment, we buffer twice the data necessary to ensure that we can safely check for a non-LF line break
    26     Value * itemsRead = getProducedItemCount("codeUnitBuffer");
    27     Value * isFirst = iBuilder->CreateICmpEQ(itemsRead, iBuilder->getSize(0));
    28     Value * itemsToRead = iBuilder->CreateSelect(isFirst, segmentItems2, segmentItems);
    29 
    30     Value * segmentBytes = reserveItemCount("codeUnitBuffer", itemsToRead);
    31     Value * bytePtr =  getOutputStreamBlockPtr("codeUnitBuffer", iBuilder->getInt32(0));
    32     bytePtr = iBuilder->CreatePointerCast(bytePtr, iBuilder->getInt8PtrTy());
    33     Value * bytesRead = iBuilder->CreateReadCall(iBuilder->getInt32(STDIN_FILENO), bytePtr, segmentBytes);
    34     itemsRead = iBuilder->CreateAdd(itemsRead, iBuilder->CreateUDiv(bytesRead, iBuilder->getSize(mCodeUnitWidth / 8)));
    35 
    36     iBuilder->CreateCondBr(iBuilder->CreateICmpEQ(bytesRead, iBuilder->getSize(0)), setTermination, stdInExit);
     18    ConstantInt * segmentBytes = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
     19    ConstantInt * segmentBytes2 = iBuilder->getSize(2 * mSegmentBlocks * iBuilder->getBitBlockWidth());
     20    // on the first segment, we buffer twice the data to ensure the ScanMatch kernel can safely check for a non-LF line break
     21    Value * const itemsAlreadyRead = getProducedItemCount("codeUnitBuffer");
     22    Value * const bytesToRead = iBuilder->CreateSelect(iBuilder->CreateICmpEQ(itemsAlreadyRead, iBuilder->getSize(0)), segmentBytes2, segmentBytes);
     23    reserveBytes("codeUnitBuffer", bytesToRead);
     24    Value * const bytePtr = iBuilder->CreatePointerCast(getOutputStreamBlockPtr("codeUnitBuffer", iBuilder->getInt32(0)), iBuilder->getInt8PtrTy());
     25    Value * const bytesRead = iBuilder->CreateReadCall(iBuilder->getInt32(STDIN_FILENO), bytePtr, bytesToRead);
     26    Value * const itemsRead = iBuilder->CreateAdd(itemsAlreadyRead, iBuilder->CreateUDiv(bytesRead, iBuilder->getSize(mCodeUnitWidth / 8)));
     27    setProducedItemCount("codeUnitBuffer", itemsRead);
     28    iBuilder->CreateCondBr(iBuilder->CreateICmpEQ(bytesRead, ConstantInt::getNullValue(bytesRead->getType())), setTermination, stdInExit);
    3729    iBuilder->SetInsertPoint(setTermination);
    3830    setTerminationSignal();
    3931    iBuilder->CreateBr(stdInExit);
     32    stdInExit->moveAfter(iBuilder->GetInsertBlock());
    4033    iBuilder->SetInsertPoint(stdInExit);
    41 
    42     setProducedItemCount("codeUnitBuffer", itemsRead);
    4334}
    4435
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5377 r5379  
    115115}
    116116
    117 Value * StreamSetBuffer::reserveItemCount(Value * self, llvm::Value * position, llvm::Value *requested) const {
     117void StreamSetBuffer::reserveBytes(Value * self, llvm::Value * position, llvm::Value *requested) const {
    118118    report_fatal_error("reserve() can only be used with ExtensibleBuffers");
    119119}
     
    157157    Type * ty = getType();
    158158    Value * instance = iBuilder->CreateCacheAlignedAlloca(ty);
    159     ConstantInt * const capacity = iBuilder->getSize(mBufferBlocks);
    160159    Value * const capacityPtr = iBuilder->CreateGEP(instance, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    161     iBuilder->CreateStore(capacity, capacityPtr);
    162     Constant * const size = ConstantExpr::getMul(ConstantExpr::getSizeOf(ty), capacity);
    163     Value * addr = iBuilder->CreateAlignedMalloc(iBuilder->CreateMul(iBuilder->CreateShl(size, 1), size), iBuilder->getCacheAlignment());
    164     iBuilder->CreateMemZero(addr, size, iBuilder->getCacheAlignment());
     160    Constant * const initialSize = ConstantExpr::getMul(ConstantExpr::getSizeOf(ty->getStructElementType(1)->getPointerElementType()), iBuilder->getSize(mBufferBlocks));
     161    iBuilder->CreateStore(initialSize, capacityPtr);
     162    Value * addr = iBuilder->CreateAlignedMalloc(initialSize, iBuilder->getCacheAlignment());
     163    iBuilder->CreateMemZero(addr, initialSize, iBuilder->getCacheAlignment());
    165164    Value * const addrPtr = iBuilder->CreateGEP(instance, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    166165    addr = iBuilder->CreatePointerCast(addr, addrPtr->getType()->getPointerElementType());
     
    173172}
    174173
    175 Value * ExtensibleBuffer::reserveItemCount(Value * self, llvm::Value * position, llvm::Value * requested) const {
    176 
     174void ExtensibleBuffer::reserveBytes(Value * const self, llvm::Value * const position, llvm::Value * const requested) const {
    177175    Value * const capacityPtr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    178     Value * const capacity = iBuilder->CreateLoad(capacityPtr);
    179     Type * const intTy = capacity->getType();
    180     Constant * const blockSize = ConstantExpr::getIntegerCast(ConstantExpr::getSizeOf(getType()->getStructElementType(1)), intTy, false);
    181     Constant * const blockSize2 = ConstantExpr::getMul(blockSize, ConstantInt::get(intTy, 2));
    182 
     176    Value * const currentSize = iBuilder->CreateLoad(capacityPtr);
     177    Type * const intTy = currentSize->getType();
     178    assert (position->getType() == requested->getType());
     179    Constant * const blockSize = ConstantExpr::getIntegerCast(ConstantExpr::getIntegerCast(ConstantExpr::getSizeOf(getType()->getStructElementType(1)), intTy, false), requested->getType(), false);
    183180    BasicBlock * const entry = iBuilder->GetInsertBlock();
    184181    BasicBlock * const expand = BasicBlock::Create(iBuilder->getContext(), "expand", entry->getParent());
    185182    BasicBlock * const resume = BasicBlock::Create(iBuilder->getContext(), "resume", entry->getParent());
    186 
    187     Value * const reserved = iBuilder->CreateAdd(position, requested);
    188 
    189     iBuilder->CreateLikelyCondBr(iBuilder->CreateICmpULT(reserved, capacity), resume, expand);
     183    Value * const reserved = iBuilder->CreateAdd(iBuilder->CreateMul(position, blockSize), requested);
     184    iBuilder->CreateLikelyCondBr(iBuilder->CreateICmpULT(reserved, currentSize), resume, expand);
    190185
    191186    iBuilder->SetInsertPoint(expand);
    192 
    193     Value * const currentSize = iBuilder->CreateMul(capacity, blockSize);
    194     Value * const reservedSize = iBuilder->CreateMul(reserved, blockSize2);
    195 
     187    Value * const reservedSize = iBuilder->CreateShl(reserved, 1);
    196188    Value * newAddr = iBuilder->CreateAlignedMalloc(reservedSize, iBuilder->getCacheAlignment());
    197189    Value * const baseAddrPtr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    198190    Value * const baseAddr = iBuilder->CreateLoad(baseAddrPtr);
    199 
    200191    iBuilder->CreateMemCpy(newAddr, baseAddr, currentSize, iBuilder->getCacheAlignment());
    201192    iBuilder->CreateAlignedFree(baseAddr);
    202     iBuilder->CreateMemZero(iBuilder->CreateGEP(newAddr, currentSize), iBuilder->CreateSub(reservedSize, currentSize), iBuilder->getCacheAlignment());
    203 
     193    Value * const remainingSize = iBuilder->CreateSub(reservedSize, currentSize);
     194    iBuilder->CreateMemZero(iBuilder->CreateGEP(newAddr, currentSize), remainingSize, iBuilder->getBitBlockWidth() / 8);
    204195    newAddr = iBuilder->CreatePointerCast(newAddr, baseAddr->getType());
    205 
     196    iBuilder->CreateStore(reservedSize, capacityPtr);
    206197    iBuilder->CreateStore(newAddr, baseAddrPtr);
    207     iBuilder->CreateStore(iBuilder->CreateShl(capacity, 1), capacityPtr);
    208 
    209198    iBuilder->CreateBr(resume);
    210199
    211200    iBuilder->SetInsertPoint(resume);
    212 
    213     return iBuilder->CreateMul(requested, blockSize);
    214 }
    215 
    216 Value * ExtensibleBuffer::getBaseAddress(Value * self) const {
     201}
     202
     203Value * ExtensibleBuffer::getBaseAddress(Value * const self) const {
    217204    return iBuilder->CreateLoad(iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)}));
    218205}
     
    220207// Circular Buffer
    221208
    222 Value * CircularBuffer::getStreamSetBlockPtr(Value * self, Value * blockIndex) const {
     209Value * CircularBuffer::getStreamSetBlockPtr(Value * const self, Value * const blockIndex) const {
    223210    return iBuilder->CreateGEP(self, modByBufferBlocks(blockIndex));
    224211}
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5377 r5379  
    5959    virtual llvm::Value * getLinearlyAccessibleBlocks(llvm::Value * self, llvm::Value * fromBlock) const;
    6060
    61     virtual llvm::Value * reserveItemCount(llvm::Value * self, llvm::Value * position, llvm::Value * requested) const;
     61    virtual void reserveBytes(llvm::Value * self, llvm::Value * position, llvm::Value * requested) const;
    6262
    6363    virtual ~StreamSetBuffer() = 0;
     
    129129    void allocateBuffer() override;
    130130
    131     llvm::Value * reserveItemCount(llvm::Value * self, llvm::Value * position, llvm::Value * requested) const override;
     131    void reserveBytes(llvm::Value * self, llvm::Value * position, llvm::Value * requested) const override;
    132132
    133133protected:
Note: See TracChangeset for help on using the changeset viewer.