Ignore:
Timestamp:
Jun 6, 2017, 6:20:55 PM (23 months ago)
Author:
cameron
Message:

Restore check-ins from the last several days

File:
1 edited

Legend:

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

    r5474 r5493  
    66#include <kernels/kernel_builder.h>
    77#include <kernels/streamset.h>
     8#include <llvm/IR/Module.h>
    89#include <sys/stat.h>
    910#include <fcntl.h>
     
    208209
    209210    Value * L = iBuilder->CreateGEP(originalPtr, pageSize);
    210 
    211 //    iBuilder->CallPrintInt("L", L);
    212 
    213211    Value * B = iBuilder->CreateGEP(buffer, capacity);
    214 
    215 //    iBuilder->CallPrintInt("B", B);
    216 
    217212    Value * const canAppend = iBuilder->CreateICmpULT(L, B);
    218213    iBuilder->CreateLikelyCondBr(canAppend, readData, waitOnConsumers);
     
    224219    // Then determine how much data has been consumed and how much needs to be copied back, noting
    225220    // that our "unproduced" data must be block aligned.
    226     const auto blockAlignment = iBuilder->getBitBlockWidth() / 8;
    227     Constant * const alignmentMask = ConstantExpr::getNot(iBuilder->getSize(blockAlignment - 1));
     221    const size_t blockAlignment = iBuilder->getBitBlockWidth() / 8;
     222    Constant * const alignmentMask = iBuilder->getSize(-blockAlignment);
    228223    Value * const consumed = iBuilder->CreateAnd(iBuilder->getConsumedItemCount("sourceBuffer"), alignmentMask);
    229224    Value * const remaining = iBuilder->CreateSub(bufferedSize, consumed);
     
    231226    Value * const consumedMajority = iBuilder->CreateICmpULT(iBuilder->CreateGEP(buffer, remaining), unconsumedPtr);
    232227
    233 //    iBuilder->CallPrintInt("consumedMajority", consumedMajority);
    234 
    235228    BasicBlock * const copyBack = iBuilder->CreateBasicBlock("CopyBack");
    236229    BasicBlock * const expandAndCopyBack = iBuilder->CreateBasicBlock("ExpandAndCopyBack");
    237230    BasicBlock * const calculateLogicalAddress = iBuilder->CreateBasicBlock("CalculateLogicalAddress");
     231
    238232    // Have we consumed enough data that we can safely copy back the unconsumed data without needing
    239233    // a temporary buffer? (i.e., B + remaining < L + consumed)
    240234    iBuilder->CreateLikelyCondBr(consumedMajority, copyBack, expandAndCopyBack);
    241235    iBuilder->SetInsertPoint(copyBack);
     236
    242237    // If so, just copy the data ...
    243     iBuilder->CreateMemCpy(buffer, unconsumedPtr, remaining, blockAlignment);
     238    iBuilder->CreateMemCpy(buffer, unconsumedPtr, remaining, 1);
    244239    iBuilder->CreateBr(calculateLogicalAddress);
     240
    245241    // Otherwise, allocate a buffer with twice the capacity and copy the unconsumed data back into it
    246242    iBuilder->SetInsertPoint(expandAndCopyBack);
    247243    Value * const expandedCapacity = iBuilder->CreateShl(capacity, 1);
    248     Value * const expandedBuffer = iBuilder->CreateCacheAlignedMalloc(expandedCapacity);
    249     Value * const expandedPtr = iBuilder->CreatePointerCast(expandedBuffer, codeUnitPtrTy);
    250     iBuilder->CreateMemCpy(expandedPtr, unconsumedPtr, remaining, blockAlignment);
     244    Value * const expandedBuffer = iBuilder->CreatePointerCast(iBuilder->CreateCacheAlignedMalloc(expandedCapacity), codeUnitPtrTy);
     245    iBuilder->CreateMemCpy(expandedBuffer, unconsumedPtr, remaining, 1);
    251246    iBuilder->CreateFree(buffer);
    252247    iBuilder->setScalarField("buffer", expandedBuffer);
    253248    iBuilder->setScalarField("capacity", expandedCapacity);
    254249    iBuilder->CreateBr(calculateLogicalAddress);
     250
    255251    // Update the logical address for this buffer....
    256252    iBuilder->SetInsertPoint(calculateLogicalAddress);
    257253    PHINode * const baseAddress = iBuilder->CreatePHI(codeUnitPtrTy, 2);
    258254    baseAddress->addIncoming(buffer, copyBack);
    259     baseAddress->addIncoming(expandedPtr, expandAndCopyBack);
     255    baseAddress->addIncoming(expandedBuffer, expandAndCopyBack);
    260256    Value * const modifiedPtr = iBuilder->CreateGEP(baseAddress, remaining);
    261     Value * const logicalAddress = iBuilder->CreateGEP(modifiedPtr, iBuilder->CreateNeg(produced));
     257    Value * const logicalAddress = iBuilder->CreateGEP(modifiedPtr, iBuilder->CreateNeg(iBuilder->CreateAnd(produced, alignmentMask)));
    262258    iBuilder->setBaseAddress("sourceBuffer", logicalAddress);
    263259    iBuilder->CreateBr(readData);
     260
    264261    // Regardless of whether we're simply appending data or had to allocate a new buffer, read a new page
    265262    // of data into the input source buffer. If we fail to read a full segment ...
Note: See TracChangeset for help on using the changeset viewer.