Ignore:
Timestamp:
Oct 5, 2016, 11:11:51 AM (3 years ago)
Author:
cameron
Message:

Kernels compute and check produced item counts

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

Legend:

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

    r5175 r5183  
    166166    BasicBlock * blocksDone = BasicBlock::Create(iBuilder->getContext(), "blocksDone", doSegmentFunction, 0);
    167167    Type * const size_ty = iBuilder->getSizeTy();
    168     Value * stride = ConstantInt::get(size_ty, iBuilder->getStride());
     168    Constant * stride = ConstantInt::get(size_ty, iBuilder->getStride());
    169169    Value * strideBlocks = ConstantInt::get(size_ty, iBuilder->getStride() / iBuilder->getBitBlockWidth());
    170170   
     
    172172    Value * self = &*(args++);
    173173    Value * blocksToDo = &*(args);
    174 
    175174    Value * segmentNo = getLogicalSegmentNo(self);
     175    std::vector<Value *> inbufProducerPtrs;
     176   
     177    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
     178        Value * basePtr = getStreamSetBasePtr(self, mStreamSetInputs[i].ssName);
     179        inbufProducerPtrs.push_back(mStreamSetInputBuffers[i]->getProducerPosPtr(basePtr));
     180    }
     181   
     182    /* Determine the actually available data examining all input stream sets. */
     183    LoadInst * producerPos = iBuilder->CreateAlignedLoad(inbufProducerPtrs[0], sizeof(size_t));
     184    producerPos->setOrdering(AtomicOrdering::Acquire);
     185    Value * availablePos = producerPos;
     186    for (unsigned i = 1; i < inbufProducerPtrs.size(); i++) {
     187        LoadInst * producerPos = iBuilder->CreateAlignedLoad(inbufProducerPtrs[i], sizeof(size_t));
     188        producerPos->setOrdering(AtomicOrdering::Acquire);
     189        /* Set the available position to be the minimum of availablePos and producerPos. */
     190        availablePos = iBuilder->CreateSelect(iBuilder->CreateICmpULT(availablePos, producerPos), availablePos, producerPos);
     191    }
     192    Value * processed = getProcessedItemCount(self);
     193    Value * itemsAvail = iBuilder->CreateSub(availablePos, processed);
     194#ifndef NDEBUG
     195    iBuilder->CallPrintInt(mKernelName + "_itemsAvail", itemsAvail);
     196#endif
     197    Value * blocksAvail = iBuilder->CreateUDiv(itemsAvail, stride);
     198    /* Adjust the number of full blocks to do, based on the available data, if necessary. */
     199    blocksToDo = iBuilder->CreateSelect(iBuilder->CreateICmpULT(blocksToDo, blocksAvail), blocksToDo, blocksAvail);
    176200    iBuilder->CreateBr(blockLoopCond);
    177201
     
    190214   
    191215    iBuilder->SetInsertPoint(blocksDone);
    192     setProcessedItemCount(self, iBuilder->CreateAdd(getProcessedItemCount(self), iBuilder->CreateMul(blocksToDo, stride)));
     216    processed = iBuilder->CreateAdd(processed, iBuilder->CreateMul(blocksToDo, stride));
     217    setProcessedItemCount(self, processed);
     218    Value * produced = getProducedItemCount(self);
     219#ifndef NDEBUG
     220    iBuilder->CallPrintInt(mKernelName + "_produced", produced);
     221#endif
     222    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
     223        Value * basePtr = getStreamSetBasePtr(self, mStreamSetOutputs[i].ssName);
     224        Value * producerPosPtr = mStreamSetOutputBuffers[i]->getProducerPosPtr(basePtr);
     225        iBuilder->CreateAlignedStore(produced, producerPosPtr, sizeof(size_t))->setOrdering(AtomicOrdering::Release);
     226    }
     227
    193228    // Must be the last action, for synchronization.
    194229    setLogicalSegmentNo(self, iBuilder->CreateAdd(segmentNo, ConstantInt::get(size_ty, 1)));
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.cpp

    r5174 r5183  
    142142    iBuilder->SetInsertPoint(finalPartialBlock);
    143143    iBuilder->CreateCall(doBlockFunction, {self});
     144    /* Adjust the produced item count */
     145    Value * produced = getProducedItemCount(self);
     146    produced = iBuilder->CreateSub(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     147    setProducedItemCount(self, iBuilder->CreateAdd(produced, remainingBytes));
    144148   
    145149    iBuilder->CreateBr(exitBlock);
     
    170174        iBuilder->CreateBlockAlignedStore(p_bitblock[j], basisBitsBlock_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
    171175    }
     176    Value * produced = getProducedItemCount(self);
     177    produced = iBuilder->CreateAdd(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     178    setProducedItemCount(self, produced);   
    172179}
    173180   
Note: See TracChangeset for help on using the changeset viewer.