Ignore:
Timestamp:
May 13, 2017, 12:27:30 PM (2 years ago)
Author:
cameron
Message:

FileSink? uses MultiBlockKernel?

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

Legend:

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

    r5448 r5449  
    854854        }
    855855    }
    856     kb->setProcessedItemCount(mStreamSetInputs[0].name, kb->CreateAdd(processed, linearlyAvailItems));
     856    kb->setProcessedItemCount(mStreamSetInputs[0].name, kb->CreateAdd(processedItemCount[0], linearlyAvailItems));
    857857    Value * reducedBlocksToDo = kb->CreateSub(blocksRemaining, linearlyWritableBlocks);
    858858    Value * fullBlocksRemain = kb->CreateICmpUGT(reducedBlocksToDo, kb->getSize(0));
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.cpp

    r5448 r5449  
    6767}
    6868
    69 void FileSink::generateDoSegmentMethod(const std::unique_ptr<KernelBuilder> &iBuilder) {
    70 
    71     PointerType * i8PtrTy = iBuilder->getInt8PtrTy();
    72 
     69void FileSink::generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & iBuilder) {
    7370    BasicBlock * closeFile = iBuilder->CreateBasicBlock("closeFile");
    7471    BasicBlock * fileOutExit = iBuilder->CreateBasicBlock("fileOutExit");
    75     Constant * blockItems = iBuilder->getSize(iBuilder->getBitBlockWidth());
    76     Constant * itemBytes = iBuilder->getSize(mCodeUnitWidth/8);
     72   
     73    PointerType * i8PtrTy = iBuilder->getInt8PtrTy();
     74    Constant * itemBytes = iBuilder->getSize(mCodeUnitWidth / 8);
     75    Value * fileDes = iBuilder->getScalarField("fileDes");
    7776
    78     Value * fileDes = iBuilder->getScalarField("fileDes");
    79     Value * available = iBuilder->getAvailableItemCount("codeUnitBuffer");
    80     Value * processed = iBuilder->getProcessedItemCount("codeUnitBuffer");
    81     Value * itemsToDo = iBuilder->CreateSub(available, processed);
    82     // There may be two memory areas if we are at the physical end of a circular buffer.
    83     const auto b  = getInputStreamSetBuffer("codeUnitBuffer");
    84     Value * wraparound = nullptr;
    85     if (isa<CircularBuffer>(b) || isa<CircularCopybackBuffer>(b)) {
    86         Value * accessible = iBuilder->getLinearlyAccessibleItems("codeUnitBuffer", processed);
    87         wraparound = iBuilder->CreateICmpULT(accessible, itemsToDo);
    88         itemsToDo = iBuilder->CreateSelect(wraparound, accessible, itemsToDo);
    89     }
     77    Function::arg_iterator args = mCurrentMethod->arg_begin();
     78    /* self = */ args++;
     79    Value * itemsToDo = &*(args++);
     80    Value * codeUnitBuffer = &*(args++);
    9081   
    91     Value * byteOffset = iBuilder->CreateMul(iBuilder->CreateURem(processed, blockItems), itemBytes);
    92     Value * bytePtr = iBuilder->CreatePointerCast(iBuilder->getInputStreamBlockPtr("codeUnitBuffer", iBuilder->getInt32(0)), i8PtrTy);
    93     bytePtr = iBuilder->CreateGEP(bytePtr, byteOffset);
    9482    Value * bytesToDo = mCodeUnitWidth == 8 ? itemsToDo : iBuilder->CreateMul(itemsToDo, itemBytes);
     83    Value * bytePtr = iBuilder->CreatePointerCast(codeUnitBuffer, i8PtrTy);
     84   
    9585    iBuilder->CreateWriteCall(fileDes, bytePtr, bytesToDo);
     86    iBuilder->CreateCondBr(iBuilder->CreateICmpULT(itemsToDo, iBuilder->getSize(iBuilder->getBitBlockWidth())), closeFile, fileOutExit);
    9687   
    97     processed = iBuilder->CreateAdd(processed, itemsToDo);
    98     iBuilder->setProcessedItemCount("codeUnitBuffer", processed);
    99    
    100     // Now we may process the second area (if required).
    101     if (isa<CircularBuffer>(b) || isa<CircularCopybackBuffer>(b)) {
    102         BasicBlock * wrapAroundWrite = iBuilder->CreateBasicBlock("wrapAroundWrite");
    103         BasicBlock * checkFinal = iBuilder->CreateBasicBlock("checkFinal");
    104         iBuilder->CreateCondBr(wraparound, wrapAroundWrite, checkFinal);
    105         iBuilder->SetInsertPoint(wrapAroundWrite);
    106        
    107         // Calculate from the updated value of processed;
    108         byteOffset = iBuilder->CreateMul(iBuilder->CreateURem(processed, blockItems), itemBytes);
    109         Value * bytePtr = iBuilder->CreatePointerCast(iBuilder->getInputStreamBlockPtr("codeUnitBuffer", iBuilder->getInt32(0)), i8PtrTy);
    110         bytePtr = iBuilder->CreateGEP(bytePtr, byteOffset);
    111         itemsToDo = iBuilder->CreateSub(available, processed);
    112         bytesToDo = mCodeUnitWidth == 8 ? itemsToDo : iBuilder->CreateMul(itemsToDo, itemBytes);
    113         iBuilder->CreateWriteCall(fileDes, bytePtr, bytesToDo);
    114         processed = iBuilder->CreateAdd(processed, itemsToDo);
    115         iBuilder->setProcessedItemCount("codeUnitBuffer", available);
    116         iBuilder->CreateBr(checkFinal);
    117         iBuilder->SetInsertPoint(checkFinal);
    118     }
    119     iBuilder->CreateCondBr(mIsFinal, closeFile, fileOutExit);
    120 
    12188    iBuilder->SetInsertPoint(closeFile);
    12289    iBuilder->CreateCloseCall(fileDes);
     
    12794   
    12895    iBuilder->CreateBr(fileOutExit);
    129 
     96   
    13097    iBuilder->SetInsertPoint(fileOutExit);
    13198}
    13299
    133100FileSink::FileSink(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned codeUnitWidth)
    134 : SegmentOrientedKernel("filesink", {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "codeUnitBuffer"}}, {},
     101: MultiBlockKernel("filesink", {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "codeUnitBuffer"}}, {},
    135102                {Binding{iBuilder->getInt8PtrTy(), "fileName"}}, {}, {Binding{iBuilder->getInt8PtrTy(), "tmpFileName"}, Binding{iBuilder->getInt32Ty(), "fileDes"}})
    136103, mCodeUnitWidth(codeUnitWidth) {
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.h

    r5441 r5449  
    2222};
    2323
    24 
    25 class FileSink final : public SegmentOrientedKernel {
     24class FileSink final : public MultiBlockKernel {
    2625public: 
    2726    FileSink(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned codeUnitWidth);
    2827protected:
    2928    void generateInitializeMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
    30     void generateDoSegmentMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
     29    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & iBuilder) override;
    3130private:
    3231    const unsigned mCodeUnitWidth;
Note: See TracChangeset for help on using the changeset viewer.