Ignore:
Timestamp:
Dec 20, 2017, 11:42:53 AM (19 months ago)
Author:
nmedfort
Message:

Bug fix for pipeline: it was terminating too early when there was insufficient output space to process all of the input for a kernel.

File:
1 edited

Legend:

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

    r5782 r5793  
    163163    }
    164164    consumed = b->CreateURem(consumed, bufferSize);
    165     Value * const limit = b->CreateSelect(b->CreateICmpULE(consumed, fromPosition), bufferSize, consumed);
     165    Constant * capacity = bufferSize;
     166    if (mOverflowBlocks) {
     167        capacity = ConstantInt::get(fromPosition->getType(), (mBufferBlocks + mOverflowBlocks) * b->getStride());
     168    }
     169    Value * const limit = b->CreateSelect(b->CreateICmpULE(consumed, fromPosition), capacity, consumed);
    166170    return b->CreateNUWSub(limit, fromPosition);
    167171}
     
    219223}
    220224
    221 void StreamSetBuffer::genCopyBackLogic(IDISA::IDISA_Builder * const b, Value * const handle, Value * priorProduced, Value * newProduced, const std::string Name) const {
    222     report_fatal_error("Copy back not supported for this buffer type:" + Name);
    223 }
    224 
    225225// Source File Buffer
    226226
     
    338338}
    339339
    340 Value * CircularBuffer::getLinearlyCopyableItems(IDISA::IDISA_Builder * const b, Value * const handle, Value * fromPosition, Value * availItems, bool reverse) const {
    341 //    Constant * bufSize = ConstantInt::get(priorProduced->getType(), mBufferBlocks * b->getBitBlockWidth());
    342 //    Value * from = b->CreateURem(fromPosition, bufSize);
    343 //    Value * avail = b->CreateURem(availItems, bufSize);
    344 //    Value * wraparound = b->CreateICmpUGT(from, avail);
    345 
    346 
    347     return nullptr;
    348 }
    349 
    350340Value * CircularBuffer::getRawItemPointer(IDISA::IDISA_Builder * const b, Value * const handle, Value * absolutePosition) const {
    351341    Value * ptr = getBaseAddress(b, handle);
     
    372362}
    373363
    374 Value * CircularCopybackBuffer::getLinearlyWritableItems(IDISA::IDISA_Builder * const b, Value * const handle, Value * fromPosition, Value * consumed, bool reverse) const {
    375     Value * writableProper = StreamSetBuffer::getLinearlyWritableItems(b, handle, fromPosition, consumed, reverse);
    376     if (reverse) return writableProper;
    377     return b->CreateAdd(writableProper, b->getSize(mOverflowBlocks * b->getBitBlockWidth()));
    378 }
    379 
    380 void CircularCopybackBuffer::genCopyBackLogic(IDISA::IDISA_Builder * const b, Value * const handle, Value * priorProduced, Value * newProduced, const std::string Name) const {
    381     assert (priorProduced->getType() == newProduced->getType());
    382     Constant * bufSize = ConstantInt::get(priorProduced->getType(), mBufferBlocks * b->getBitBlockWidth());
    383     Value * priorBufPos = b->CreateURem(priorProduced, bufSize);
    384     Value * newBufPos = b->CreateURem(newProduced, bufSize);
    385     BasicBlock * copyBack = b->CreateBasicBlock(Name + "_circularCopyBack");
    386     BasicBlock * done = b->CreateBasicBlock(Name + "_circularCopyBackDone");
    387     Value * wraparound = b->CreateICmpUGT(priorBufPos, newBufPos);
    388     b->CreateCondBr(wraparound, copyBack, done);
    389 
    390     b->SetInsertPoint(copyBack);
    391     Value * const baseAddress = getBaseAddress(b, handle);
    392     Value * overflowAddress = b->CreateGEP(baseAddress, b->getInt32(mBufferBlocks));
    393     // copyStream(b, baseAddress, b->getSize(0), overflowAddress, b->getSize(0), newBufPos);
    394     createBlockAlignedCopy(b, baseAddress, overflowAddress, newBufPos);
    395     b->CreateBr(done);
    396 
    397     b->SetInsertPoint(done);
    398 }
    399 
    400364
    401365// SwizzledCopybackBuffer Buffer
    402 
    403366void SwizzledCopybackBuffer::allocateBuffer(const std::unique_ptr<kernel::KernelBuilder> & b) {
    404367    Type * const ty = getType();
     
    450413}
    451414
    452 Value * SwizzledCopybackBuffer::getLinearlyWritableItems(IDISA::IDISA_Builder * const b, Value * const handle, Value * fromPosition, Value *consumed, bool reverse) const {
    453     Value * writableProper = StreamSetBuffer::getLinearlyWritableItems(b, handle, fromPosition, consumed, reverse);
    454     if (reverse) return writableProper;
    455     return b->CreateAdd(writableProper, b->getSize(mOverflowBlocks * b->getBitBlockWidth()));
    456 }
    457 
    458 void SwizzledCopybackBuffer::genCopyBackLogic(IDISA::IDISA_Builder * const b, Value * const handle, Value * priorProduced, Value * newProduced, const std::string Name) const {
    459     assert (priorProduced->getType() == newProduced->getType());
    460     Constant * bufSize = ConstantInt::get(priorProduced->getType(), mBufferBlocks * b->getBitBlockWidth());
    461     Value * priorBufPos = b->CreateURem(priorProduced, bufSize);
    462     Value * newBufPos = b->CreateURem(newProduced, bufSize);
    463     BasicBlock * copyBack = b->CreateBasicBlock(Name + "_swizzledCopyBack");
    464     BasicBlock * done = b->CreateBasicBlock(Name + "_swizzledCopyBackDone");
    465     Value * wraparound = b->CreateICmpUGT(priorBufPos, newBufPos);
    466     b->CreateCondBr(wraparound, copyBack, done);
    467     b->SetInsertPoint(copyBack);
    468     Value * overFlowAreaPtr = b->CreateGEP(handle, b->getSize(mBufferBlocks));
    469     createBlockAlignedCopy(b, handle, overFlowAreaPtr, newBufPos);
    470     b->CreateBr(done);
    471     b->SetInsertPoint(done);
    472 }
    473 
    474415// Expandable Buffer
    475416
     
    707648    Value * ptr = b->CreateGEP(handle, {b->getInt32(0), b->getInt32(int(Field::WorkingBlocks))});
    708649    return b->CreateMul(b->CreateLoad(ptr), b->getSize(b->getBitBlockWidth()));
    709 }
    710 
    711 void DynamicBuffer::genCopyBackLogic(IDISA::IDISA_Builder * const b, Value * const handle, Value * priorProducedCount, Value * newProducedCount, const std::string Name) const {
    712     assert (priorProducedCount->getType() == newProducedCount->getType());   
    713     Value * workingBlocks = b->CreateLoad(b->CreateGEP(handle, {b->getInt32(0), b->getInt32(int(DynamicBuffer::Field::WorkingBlocks))}));
    714     assert (workingBlocks->getType() == newProducedCount->getType());
    715     Value * bufSize = b->CreateMul(workingBlocks, ConstantInt::get(workingBlocks->getType(), b->getBitBlockWidth()));
    716     Value * priorBufPos = b->CreateURem(priorProducedCount, bufSize);
    717     Value * newBufPos = b->CreateURem(newProducedCount, bufSize);
    718     BasicBlock * copyBack = b->CreateBasicBlock(Name + "_dynamicCopyBack");
    719     BasicBlock * done = b->CreateBasicBlock(Name + "_dynamicCopyBackDone");
    720 
    721     Value * wraparound = b->CreateICmpUGT(priorBufPos, newBufPos);
    722     b->CreateCondBr(wraparound, copyBack, done);
    723 
    724     b->SetInsertPoint(copyBack);
    725     Value * bufBasePtr = getBaseAddress(b, handle);
    726     Value * overFlowAreaPtr = b->CreateGEP(bufBasePtr, workingBlocks);
    727     createBlockAlignedCopy(b, bufBasePtr, overFlowAreaPtr, newBufPos);
    728     b->CreateBr(done);
    729 
    730     b->SetInsertPoint(done);
    731650}
    732651
Note: See TracChangeset for help on using the changeset viewer.