Ignore:
Timestamp:
Oct 11, 2016, 10:40:35 AM (3 years ago)
Author:
cameron
Message:

Do segment method now handles partial/final segment

File:
1 edited

Legend:

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

    r5185 r5188  
    4444    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doSegmentFunction, 0));
    4545    Constant * stride = ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride());
    46     Constant * strideBytes = ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride() * mCodeUnitWidth/8);
     46    Constant * itemBytes = ConstantInt::get(iBuilder->getSizeTy(), mCodeUnitWidth/8);
    4747   
    4848    Function::arg_iterator args = doSegmentFunction->arg_begin();
     
    5757    producerPos->setOrdering(AtomicOrdering::Acquire);
    5858    //iBuilder->CallPrintInt("producerPos", producerPos);
     59    Value * endSignal = iBuilder->CreateLoad(mStreamSetInputBuffers[0]->hasEndOfInputPtr(streamStructPtr));
    5960
     61    Value * blockNo = getScalarField(self, blockNoScalar);
     62    //iBuilder->CallPrintInt("blockNo", blockNo);
     63    Value * basePtr = getStreamSetBlockPtr(self, "codeUnitBuffer", blockNo);
     64    //iBuilder->CallPrintInt("basePtr", iBuilder->CreatePtrToInt(basePtr, iBuilder->getInt64Ty()));
     65   
    6066    Value * processed = getProcessedItemCount(self);
    6167    Value * itemsAvail = iBuilder->CreateSub(producerPos, processed);
     
    6369    Value * blocksAvail = iBuilder->CreateUDiv(itemsAvail, stride);
    6470    //iBuilder->CallPrintInt("blocksAvail", blocksAvail);
     71   
     72    Value * lessThanFullSegment = iBuilder->CreateICmpULT(blocksAvail, blocksToDo);
     73    Value * inFinalSegment = iBuilder->CreateAnd(endSignal, lessThanFullSegment);
    6574    /* Adjust the number of full blocks to do, based on the available data, if necessary. */
    66     blocksToDo = iBuilder->CreateSelect(iBuilder->CreateICmpULT(blocksToDo, blocksAvail), blocksToDo, blocksAvail);
    67     Value * blockNo = getScalarField(self, blockNoScalar);
    68     //iBuilder->CallPrintInt("blockNo", blockNo);
    69     Value * basePtr = getStreamSetBlockPtr(self, "codeUnitBuffer", blockNo);
    70     //iBuilder->CallPrintInt("basePtr", iBuilder->CreatePtrToInt(basePtr, iBuilder->getInt64Ty()));
    71     Value * bytesToDo = iBuilder->CreateMul(blocksToDo, strideBytes);
     75    blocksToDo = iBuilder->CreateSelect(lessThanFullSegment, blocksAvail, blocksToDo);
     76   
     77    Value * itemsToDo = iBuilder->CreateMul(blocksToDo, stride);
     78    itemsToDo = iBuilder->CreateSelect(inFinalSegment, itemsAvail, itemsToDo);
    7279    //iBuilder->CallPrintInt("bytesToDo", bytesToDo);
    73     iBuilder->CreateCall(writefn, std::vector<Value *>({iBuilder->getInt32(1), iBuilder->CreateBitCast(basePtr, i8PtrTy), bytesToDo}));
     80    iBuilder->CreateCall(writefn, std::vector<Value *>({iBuilder->getInt32(1), iBuilder->CreateBitCast(basePtr, i8PtrTy), iBuilder->CreateMul(itemsToDo, itemBytes)}));
    7481   
    7582    setScalarField(self, blockNoScalar, iBuilder->CreateAdd(blockNo, blocksToDo));
    76     processed = iBuilder->CreateAdd(processed, iBuilder->CreateMul(blocksToDo, stride));
     83    processed = iBuilder->CreateAdd(processed, itemsToDo);
    7784    setProcessedItemCount(self, processed);
    7885    mStreamSetInputBuffers[0]->setConsumerPos(streamStructPtr, processed);
Note: See TracChangeset for help on using the changeset viewer.