Ignore:
Timestamp:
Dec 31, 2018, 5:25:19 PM (7 months ago)
Author:
nmedfort
Message:

Work on OptimizationBranch?; revisited pipeline termination

File:
1 edited

Legend:

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

    r6249 r6261  
    195195    BasicBlock * const expandAndCopyBack = b->CreateBasicBlock("ExpandAndCopyBack");
    196196    const auto blockSize = b->getBitBlockWidth() / 8;
    197     Constant * const blockSizeAlignmentMask = ConstantExpr::getNeg(b->getSize(blockSize));
    198     Value * const consumed = b->getConsumedItemCount("sourceBuffer");
    199     Value * const offset = b->CreateAnd(consumed, blockSizeAlignmentMask);
    200     Value * const unreadData = b->getRawOutputPointer("sourceBuffer", offset);
    201     Value * const remainingItems = b->CreateSub(produced, offset);
     197    Value * const consumedItems = b->getConsumedItemCount("sourceBuffer");
     198    ConstantInt * const BLOCK_WIDTH = b->getSize(b->getBitBlockWidth());
     199    Constant * const ALIGNMENT_MASK = ConstantExpr::getNeg(BLOCK_WIDTH);
     200    Value * const consumed = b->CreateAnd(consumedItems, ALIGNMENT_MASK);
     201    Value * const unreadData = b->getRawOutputPointer("sourceBuffer", consumed);
     202    Value * const remainingItems = b->CreateSub(produced, consumed);
    202203    Value * const potentialItems = b->CreateAdd(remainingItems, itemsToRead);
    203204    Value * const remainingBytes = b->CreateMul(remainingItems, codeUnitBytes);
    204     // Have we consumed enough data that we can safely copy back the unconsumed data and still leave enough space
    205     // for one segment without needing a temporary buffer?
     205    // Have we consumed enough data that we can safely copy back the unconsumed data and still
     206    // leave enough space for one segment without needing a temporary buffer?
    206207    Value * const canCopy = b->CreateICmpULT(b->CreateGEP(baseBuffer, potentialItems), unreadData);
    207208    b->CreateLikelyCondBr(canCopy, copyBack, expandAndCopyBack);
     
    220221    // Free the prior buffer if it exists
    221222    Value * const ancillaryBuffer = b->getScalarField("ancillaryBuffer");
     223    b->setScalarField("ancillaryBuffer", baseBuffer);
    222224    b->CreateFree(ancillaryBuffer);
    223     b->setScalarField("ancillaryBuffer", baseBuffer);
    224225    b->setScalarField("buffer", expandedBuffer);
    225226    b->setCapacity("sourceBuffer", expandedCapacity);
     
    230231    newBaseBuffer->addIncoming(baseBuffer, copyBack);
    231232    newBaseBuffer->addIncoming(expandedBuffer, expandAndCopyBack);
    232     Value * const newBaseAddress = b->CreateGEP(newBaseBuffer, b->CreateNeg(offset));
     233    Value * const newBaseAddress = b->CreateGEP(newBaseBuffer, b->CreateNeg(consumed));
    233234    b->setBaseAddress("sourceBuffer", newBaseAddress);
    234235    b->CreateBr(readData);
     
    272273    BasicBlock * finalizeMMap = b->CreateBasicBlock("finalizeMMap");
    273274    BasicBlock * finalizeDone = b->CreateBasicBlock("finalizeDone");
    274     b->CreateCondBr(b->CreateIsNotNull(b->getScalarField("useMMap")), finalizeMMap, finalizeRead);
     275    Value * const useMMap = b->CreateIsNotNull(b->getScalarField("useMMap"));
     276    b->CreateCondBr(useMMap, finalizeMMap, finalizeRead);
    275277    b->SetInsertPoint(finalizeMMap);
    276278    MMapSourceKernel::freeBuffer(b, mCodeUnitWidth);
     
    284286void FDSourceKernel::generateInitializeMethod(const std::unique_ptr<KernelBuilder> & b) {
    285287    BasicBlock * initializeRead = b->CreateBasicBlock("initializeRead");
    286     BasicBlock * tryMMap = b->CreateBasicBlock("tryMMap");
     288    BasicBlock * checkFileSize = b->CreateBasicBlock("checkFileSize");
    287289    BasicBlock * initializeMMap = b->CreateBasicBlock("initializeMMap");
    288290    BasicBlock * initializeDone = b->CreateBasicBlock("initializeDone");
     
    291293    // parameter, possibly overridden.
    292294
    293     Value * useMMap = b->getScalarField("useMMap");
     295    Value * const useMMap = b->getScalarField("useMMap");
    294296    Constant * const ZERO = ConstantInt::getNullValue(useMMap->getType());
    295     useMMap = b->CreateICmpNE(useMMap, ZERO);
    296297    // if the fileDescriptor is 0, the file is stdin, use readSource kernel logic.
    297     Value * fd = b->getScalarField("fileDescriptor");
    298     Value * notStdIn = b->CreateICmpNE(fd, b->getInt32(STDIN_FILENO));
    299     useMMap = b->CreateAnd(useMMap, notStdIn);
    300     b->CreateCondBr(useMMap, tryMMap, initializeRead);
    301 
    302     b->SetInsertPoint(tryMMap);
     298    Value * const fd = b->getScalarField("fileDescriptor");
     299    Value * const notStdIn = b->CreateICmpNE(fd, b->getInt32(STDIN_FILENO));
     300    Value * const tryMMap = b->CreateICmpNE(useMMap, ZERO);
     301    b->CreateCondBr(b->CreateAnd(tryMMap, notStdIn), checkFileSize, initializeRead);
     302
     303    b->SetInsertPoint(checkFileSize);
    303304    // If the fileSize is 0, we may have a virtual file such as /proc/cpuinfo
    304     Value * fileSize = b->CreateZExtOrTrunc(b->CreateCall(mFileSizeFunction, fd), b->getSizeTy());
    305     useMMap = b->CreateICmpNE(fileSize, b->getSize(0));
    306     b->CreateCondBr(useMMap, initializeMMap, initializeRead);
     305    Value * const fileSize = b->CreateCall(mFileSizeFunction, fd);
     306    Value * const emptyFile = b->CreateIsNotNull(fileSize);
     307    b->CreateUnlikelyCondBr(emptyFile, initializeRead, initializeMMap);
    307308
    308309    b->SetInsertPoint(initializeMMap);
     
    315316    ReadSourceKernel::generateInitializeMethod(mCodeUnitWidth, mStride,b);
    316317    b->CreateBr(initializeDone);
     318
    317319    b->SetInsertPoint(initializeDone);
    318320}
     
    322324    BasicBlock * DoSegmentMMap = b->CreateBasicBlock("DoSegmentMMap");
    323325    BasicBlock * DoSegmentDone = b->CreateBasicBlock("DoSegmentDone");
    324     b->CreateCondBr(b->CreateTrunc(b->getScalarField("useMMap"), b->getInt1Ty()), DoSegmentMMap, DoSegmentRead);
     326    Value * const useMMap = b->CreateIsNotNull(b->getScalarField("useMMap"));
     327    b->CreateCondBr(useMMap, DoSegmentMMap, DoSegmentRead);
    325328    b->SetInsertPoint(DoSegmentMMap);
    326329    MMapSourceKernel::generateDoSegmentMethod(mCodeUnitWidth, mStride, b);
     
    411414
    412415MMapSourceKernel::MMapSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & b, Scalar * const fd, StreamSet * const outputStream)
    413 : SegmentOrientedKernel("mmap_source" + std::to_string(codegen::SegmentSize) + "@" + std::to_string(outputStream->getFieldWidth())
     416: SegmentOrientedKernel(b, "mmap_source" + std::to_string(codegen::SegmentSize) + "@" + std::to_string(outputStream->getFieldWidth())
    414417// input streams
    415418,{}
     
    432435
    433436ReadSourceKernel::ReadSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & b, Scalar * const fd, StreamSet * const outputStream)
    434 : SegmentOrientedKernel("read_source" + std::to_string(codegen::SegmentSize) + "@" + std::to_string(outputStream->getFieldWidth())
     437: SegmentOrientedKernel(b, "read_source" + std::to_string(codegen::SegmentSize) + "@" + std::to_string(outputStream->getFieldWidth())
    435438// input streams
    436439,{}
     
    453456
    454457FDSourceKernel::FDSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & b, Scalar * const useMMap, Scalar * const fd, StreamSet * const outputStream)
    455 : SegmentOrientedKernel("FD_source" + std::to_string(codegen::SegmentSize) + "@" + std::to_string(outputStream->getFieldWidth())
     458: SegmentOrientedKernel(b, "FD_source" + std::to_string(codegen::SegmentSize) + "@" + std::to_string(outputStream->getFieldWidth())
    456459// input streams
    457460,{}
     
    474477}
    475478
    476 MemorySourceKernel::MemorySourceKernel(const std::unique_ptr<kernel::KernelBuilder> &, Scalar * fileSource, Scalar * fileItems, StreamSet * const outputStream)
    477 : SegmentOrientedKernel("memory_source" + std::to_string(codegen::SegmentSize) + "@" + std::to_string(outputStream->getFieldWidth()) + ":" + std::to_string(outputStream->getNumElements()),
     479MemorySourceKernel::MemorySourceKernel(const std::unique_ptr<kernel::KernelBuilder> & b, Scalar * fileSource, Scalar * fileItems, StreamSet * const outputStream)
     480: SegmentOrientedKernel(b, "memory_source" + std::to_string(codegen::SegmentSize) + "@" + std::to_string(outputStream->getFieldWidth()) + ":" + std::to_string(outputStream->getNumElements()),
    478481// input streams
    479482{},
Note: See TracChangeset for help on using the changeset viewer.