Changeset 5183 for icGREP


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
Files:
4 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   
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5170 r5183  
    9292        iBuilder->CreateBlockAlignedStore(f->second, outputSet_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
    9393    }
    94     iBuilder->CreateRetVoid();
    9594   
    9695    #ifdef PRINT_TIMING_INFORMATION
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp

    r5141 r5183  
    5151    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    5252    Module * m = iBuilder->getModule();
    53     pablo_compiler->compile(m->getFunction(mKernelName + doBlock_suffix));
     53    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
     54    pablo_compiler->compile(doBlockFunction);
     55    Function::arg_iterator args = doBlockFunction->arg_begin();
     56    Value * self = &*(args);
     57    Value * produced = getProducedItemCount(self);
     58    produced = iBuilder->CreateAdd(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     59    setProducedItemCount(self, produced);
     60    iBuilder->CreateRetVoid();
    5461    iBuilder->restoreIP(savePoint);
    5562}
     
    7481    setScalarField(self, "EOFmask", iBuilder->bitblock_mask_from(remaining));
    7582    iBuilder->CreateCall(doBlockFunction, doBlockArgs);
     83    /* Adjust the produced item count */
     84    Value * produced = getProducedItemCount(self);
     85    produced = iBuilder->CreateSub(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     86    setProducedItemCount(self, iBuilder->CreateAdd(produced, remaining));
    7687    iBuilder->CreateRetVoid();
    7788    iBuilder->restoreIP(savePoint);
Note: See TracChangeset for help on using the changeset viewer.