Changeset 6049


Ignore:
Timestamp:
May 17, 2018, 4:41:59 PM (3 months ago)
Author:
nmedfort
Message:

Bug fix for ReadSourceKernel?

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

Legend:

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

    r6047 r6049  
    140140/// READ SOURCE KERNEL
    141141
    142 void ReadSourceKernel::generateInitializeMethod(const unsigned codeUnitWidth, const unsigned stride, const std::unique_ptr<KernelBuilder> & b) {
     142void ReadSourceKernel::generateInitializeMethod(const unsigned codeUnitWidth, const std::unique_ptr<KernelBuilder> & b) {
    143143    const unsigned pageSize = getpagesize();
    144     const auto bufferSize = std::max(pageSize * 8, codegen::SegmentSize * stride  * 4);
    145     ConstantInt * const bufferItems = b->getSize(bufferSize);
     144    ConstantInt * const bufferItems = b->getSize(pageSize * 4);
    146145    const auto codeUnitSize = codeUnitWidth / 8;
    147     ConstantInt * const bufferBytes = b->getSize(bufferSize * codeUnitSize);
     146    ConstantInt * const bufferBytes = b->getSize(pageSize * 4 * codeUnitSize);
    148147    PointerType * const codeUnitPtrTy = b->getIntNTy(codeUnitWidth)->getPointerTo();
    149148    Value * const buffer = b->CreatePointerCast(b->CreateCacheAlignedMalloc(bufferBytes), codeUnitPtrTy);
     
    151150    b->setScalarField("buffer", buffer);
    152151    b->setCapacity("sourceBuffer", bufferItems);
    153     b->setScalarField("fileSize", b->getSize(0));
    154 }
    155 
    156 void ReadSourceKernel::generateDoSegmentMethod(const unsigned codeUnitWidth, const unsigned stride, const std::unique_ptr<KernelBuilder> & b) {
     152}
     153
     154void ReadSourceKernel::generateDoSegmentMethod(const unsigned codeUnitWidth, const std::unique_ptr<KernelBuilder> & b) {
    157155
    158156    const unsigned pageSize = getpagesize();
    159     ConstantInt * const itemsToRead = b->getSize(std::max(pageSize, codegen::SegmentSize * stride * 2));
     157    ConstantInt * const itemsToRead = b->getSize(pageSize);
    160158    ConstantInt * const codeUnitBytes = b->getSize(codeUnitWidth / 8);
    161     ConstantInt * const itemsPerSegment = b->getSize(codegen::SegmentSize * stride);
    162 
    163     BasicBlock * const entry = b->GetInsertBlock();
    164     BasicBlock * const checkData = b->CreateBasicBlock("CheckData");
     159
    165160    BasicBlock * const moveData = b->CreateBasicBlock("MoveData");
    166161    BasicBlock * const prepareBuffer = b->CreateBasicBlock("PrepareBuffer");
     
    171166    // Do we have enough unread data to support one segment?
    172167    Value * const produced = b->getProducedItemCount("sourceBuffer");
    173     Value * const buffered = b->getScalarField("fileSize");
    174     Value * const itemsPending = b->CreateAdd(produced, itemsPerSegment);
    175 
    176     b->CreateLikelyCondBr(b->CreateICmpULT(itemsPending, buffered), readExit, checkData);
     168    Value * const itemsPending = b->CreateAdd(produced, itemsToRead);
    177169
    178170    // Can we append to our existing buffer without impacting any subsequent kernel?
    179     b->SetInsertPoint(checkData);
    180171    Value * const capacity = b->getCapacity("sourceBuffer");
    181     Value * const readEnd = b->getRawOutputPointer("sourceBuffer", b->CreateAdd(buffered, itemsToRead));
     172    Value * const readEnd = b->getRawOutputPointer("sourceBuffer", itemsPending);
    182173    Value * const baseBuffer = b->getScalarField("buffer");
    183174    Value * const bufferLimit = b->CreateGEP(baseBuffer, capacity);
     
    198189    Value * const offset = b->CreateAnd(consumed, blockSizeAlignmentMask);
    199190    Value * const unreadData = b->getRawOutputPointer("sourceBuffer", offset);
    200     Value * const remainingItems = b->CreateSub(buffered, offset);
     191    Value * const remainingItems = b->CreateSub(produced, offset);
    201192    Value * const remainingBytes = b->CreateMul(remainingItems, codeUnitBytes);
    202193
     
    222213
    223214    b->SetInsertPoint(prepareBuffer);
    224     PHINode * newBaseBuffer = b->CreatePHI(baseBuffer->getType(), 2);
     215    PHINode * const newBaseBuffer = b->CreatePHI(baseBuffer->getType(), 2);
    225216    newBaseBuffer->addIncoming(baseBuffer, copyBack);
    226217    newBaseBuffer->addIncoming(expandedBuffer, expandAndCopyBack);
     
    231222    // of data into the input source buffer. If we fail to read a full page ...
    232223    b->SetInsertPoint(readData);
    233     Value * const sourceBuffer = b->getRawOutputPointer("sourceBuffer", buffered);
     224    Value * const sourceBuffer = b->getRawOutputPointer("sourceBuffer", produced);
    234225    Value * const fd = b->getScalarField("fileDescriptor");
    235226    Constant * const bytesToRead = ConstantExpr::getMul(itemsToRead, codeUnitBytes);
    236227    Value * const bytesRead = b->CreateReadCall(fd, sourceBuffer, bytesToRead);
    237228    Value * const itemsRead = b->CreateUDiv(bytesRead, codeUnitBytes);
    238     Value * const itemsBuffered = b->CreateAdd(buffered, itemsRead);
    239     b->setScalarField("fileSize", itemsBuffered);
     229    Value * const itemsBuffered = b->CreateAdd(produced, itemsRead);
    240230    b->CreateUnlikelyCondBr(b->CreateICmpULT(itemsBuffered, itemsPending), setTermination, readExit);
    241231
     
    248238
    249239    b->SetInsertPoint(readExit);
    250     PHINode * const itemsProduced = b->CreatePHI(itemsPending->getType(), 3);
    251     itemsProduced->addIncoming(itemsPending, entry);
     240    PHINode * const itemsProduced = b->CreatePHI(itemsPending->getType(), 2);
    252241    itemsProduced->addIncoming(itemsPending, readData);
    253242    itemsProduced->addIncoming(itemsBuffered, setTermination);
     
    305294    // Ensure that readSource logic is used throughout.
    306295    b->setScalarField("useMMap", b->getInt8(0));
    307     ReadSourceKernel::generateInitializeMethod(mCodeUnitWidth, getStride(), b);
     296    ReadSourceKernel::generateInitializeMethod(mCodeUnitWidth,b);
    308297    b->CreateBr(initializeDone);
    309298    b->SetInsertPoint(initializeDone);
     
    319308    b->CreateBr(DoSegmentDone);
    320309    b->SetInsertPoint(DoSegmentRead);
    321     ReadSourceKernel::generateDoSegmentMethod(mCodeUnitWidth, getStride(), b);
     310    ReadSourceKernel::generateDoSegmentMethod(mCodeUnitWidth, b);
    322311    b->CreateBr(DoSegmentDone);
    323312    b->SetInsertPoint(DoSegmentDone);
     
    421410, {}
    422411// internal scalars
    423 , {Binding{b->getIntNTy(codeUnitWidth)->getPointerTo(), "buffer"}
    424 ,  Binding{b->getSizeTy(), "fileSize"}})
     412, {Binding{b->getIntNTy(codeUnitWidth)->getPointerTo(), "buffer"}})
    425413, mCodeUnitWidth(codeUnitWidth) {
    426414    addAttribute(MustExplicitlyTerminate());
  • icGREP/icgrep-devel/icgrep/kernels/source_kernel.h

    r6008 r6049  
    4646    bool hasSignature() const override { return false; }
    4747    void generateInitializeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
    48         generateInitializeMethod(mCodeUnitWidth, getStride(), iBuilder);
     48        generateInitializeMethod(mCodeUnitWidth, iBuilder);
    4949    }
    5050    void generateDoSegmentMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
    51         generateDoSegmentMethod(mCodeUnitWidth, getStride(), iBuilder);
     51        generateDoSegmentMethod(mCodeUnitWidth, iBuilder);
    5252    }
    5353    void generateFinalizeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override {
     
    5555    }
    5656protected:
    57     static void generateInitializeMethod(const unsigned codeUnitWidth, const unsigned stride, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
    58     static void generateDoSegmentMethod(const unsigned codeUnitWidth, const unsigned stride, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
     57    static void generateInitializeMethod(const unsigned codeUnitWidth, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
     58    static void generateDoSegmentMethod(const unsigned codeUnitWidth, const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
    5959    static void freeBuffer(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
    6060private:
Note: See TracChangeset for help on using the changeset viewer.