Ignore:
Timestamp:
Dec 21, 2018, 1:06:11 PM (7 months ago)
Author:
nmedfort
Message:

Migrated processed/produced item counts out of kernels and into pipeline + corrected misbehaving kernels.

File:
1 edited

Legend:

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

    r6241 r6249  
    4141    IntegerType * const sizeTy = b->getSizeTy();
    4242    ConstantInt * const STRIDE_SIZE = b->getSize(stride);
    43     Constant * const PAGE_ITEMS = b->getSize(stride /(codeUnitWidth/8));
     43    Constant * const PAGE_ITEMS = b->getSize((8 * stride) / codeUnitWidth);
    4444    Value * const fd = b->getScalarField("fileDescriptor");
    45 
    4645    PointerType * const codeUnitPtrTy = b->getIntNTy(codeUnitWidth)->getPointerTo();
    4746    b->setScalarField("ancillaryBuffer", ConstantPointerNull::get(codeUnitPtrTy));
     
    8281    BasicBlock * const exit = b->CreateBasicBlock("mmapSourceExit");
    8382
    84     Constant * const MMAP_PAGE_SIZE = b->getSize(getPageSize());
    85 
    86     Constant * const STRIDE_SIZE = b->getSize(stride);
    87 
    88     Constant * const PAGE_ITEMS = b->getSize((8 * stride) / codeUnitWidth);
    89     Constant * const BLOCK_WIDTH = b->getSize(b->getBitBlockWidth());
    90     Constant * const CODE_UNIT_BYTES = b->getSize(codeUnitWidth / 8);
    91     Constant * const PADDING_SIZE = b->getSize(b->getBitBlockWidth() * codeUnitWidth / 8);
     83    ConstantInt * const MMAP_PAGE_SIZE = b->getSize(getPageSize());
     84    ConstantInt * const STRIDE_ITEMS = b->getSize(stride);
     85    ConstantInt * const BLOCK_WIDTH = b->getSize(b->getBitBlockWidth());
     86    ConstantInt * const CODE_UNIT_BYTES = b->getSize(codeUnitWidth / 8);
     87
     88    ConstantInt * const STRIDE_BYTES = b->getSize((codeUnitWidth * stride) / 8);
     89    ConstantInt * const PADDING_SIZE = b->getSize(b->getBitBlockWidth() * codeUnitWidth / 8);
    9290
    9391    Value * const consumedItems = b->getConsumedItemCount("sourceBuffer");
     
    104102    // instruct the OS that it can safely drop any fully consumed pages
    105103    b->CreateMAdvise(readableBuffer, unnecessaryBytes, CBuilder::ADVICE_DONTNEED);
    106     //b->setScalarField("buffer", b->CreateGEP(readableBuffer, unnecessaryBytes));
    107104    b->CreateBr(checkRemaining);
    108105
    109     // determine whether or not we've exhausted the file buffer
     106    // determine whether or not we've exhausted the "safe" region of the file buffer
    110107    b->SetInsertPoint(checkRemaining);
    111108    Value * const producedItems = b->getProducedItemCount("sourceBuffer");
    112     Value * const nextProducedItems = b->CreateAdd(producedItems, PAGE_ITEMS);
     109    Value * const nextProducedItems = b->CreateAdd(producedItems, STRIDE_ITEMS);
    113110    Value * const fileItems = b->getScalarField("fileItems");
    114111    Value * const lastPage = b->CreateICmpULE(fileItems, nextProducedItems);
     
    128125    Value * unconsumedBytes = b->CreateSub(readEndInt, readStartInt);
    129126    unconsumedBytes = b->CreateTrunc(unconsumedBytes, b->getSizeTy());
    130     Value * const bufferSize = b->CreateRoundUp(b->CreateAdd(unconsumedBytes, PADDING_SIZE), STRIDE_SIZE);
     127    Value * const bufferSize = b->CreateRoundUp(b->CreateAdd(unconsumedBytes, PADDING_SIZE), STRIDE_BYTES);
    131128    Value * const buffer = b->CreateAlignedMalloc(bufferSize, b->getCacheAlignment());
    132129    b->CreateMemCpy(buffer, readStart, unconsumedBytes, 1);
     
    141138    b->setBaseAddress("sourceBuffer", b->CreatePointerCast(offsettedBuffer, codeUnitPtrTy));
    142139    b->setTerminationSignal();
    143 
    144 
    145     BasicBlock * const terminationExit = b->GetInsertBlock();
     140    b->setProducedItemCount("sourceBuffer", fileItems);
    146141    b->CreateBr(exit);
    147142
    148     // finally, set the "produced" count to reflect current position in the file
    149143    b->SetInsertPoint(exit);
    150     PHINode * const newProducedItems = b->CreatePHI(b->getSizeTy(), 2);
    151     newProducedItems->addIncoming(nextProducedItems, checkRemaining);
    152     newProducedItems->addIncoming(fileItems, terminationExit);
    153     b->setProducedItemCount("sourceBuffer", newProducedItems);
    154144}
    155145void MMapSourceKernel::freeBuffer(const std::unique_ptr<KernelBuilder> & b, const unsigned codeUnitWidth) {
     
    261251    b->setScalarField("fileItems", itemsBuffered);
    262252    b->setTerminationSignal();
     253    b->setProducedItemCount("sourceBuffer", itemsBuffered);
    263254    b->CreateBr(readExit);
    264255
    265256    b->SetInsertPoint(readExit);
    266     PHINode * const itemsProduced = b->CreatePHI(itemsPending->getType(), 2);
    267     itemsProduced->addIncoming(itemsPending, readData);
    268     itemsProduced->addIncoming(itemsBuffered, setTermination);
    269     b->setProducedItemCount("sourceBuffer", itemsProduced);
    270257}
    271258
     
    285272    BasicBlock * finalizeMMap = b->CreateBasicBlock("finalizeMMap");
    286273    BasicBlock * finalizeDone = b->CreateBasicBlock("finalizeDone");
    287     b->CreateCondBr(b->CreateTrunc(b->getScalarField("useMMap"), b->getInt1Ty()), finalizeMMap, finalizeRead);
     274    b->CreateCondBr(b->CreateIsNotNull(b->getScalarField("useMMap")), finalizeMMap, finalizeRead);
    288275    b->SetInsertPoint(finalizeMMap);
    289276    MMapSourceKernel::freeBuffer(b, mCodeUnitWidth);
     
    303290    // The source will use MMapSource or readSoure kernel logic depending on the useMMap
    304291    // parameter, possibly overridden.
    305     Value * useMMap = b->CreateTrunc(b->getScalarField("useMMap"), b->getInt1Ty());
     292
     293    Value * useMMap = b->getScalarField("useMMap");
     294    Constant * const ZERO = ConstantInt::getNullValue(useMMap->getType());
     295    useMMap = b->CreateICmpNE(useMMap, ZERO);
    306296    // if the fileDescriptor is 0, the file is stdin, use readSource kernel logic.
    307297    Value * fd = b->getScalarField("fileDescriptor");
    308     useMMap = b->CreateAnd(useMMap, b->CreateICmpNE(fd, b->getInt32(STDIN_FILENO)));
     298    Value * notStdIn = b->CreateICmpNE(fd, b->getInt32(STDIN_FILENO));
     299    useMMap = b->CreateAnd(useMMap, notStdIn);
    309300    b->CreateCondBr(useMMap, tryMMap, initializeRead);
    310301
     
    321312    b->SetInsertPoint(initializeRead);
    322313    // Ensure that readSource logic is used throughout.
    323     b->setScalarField("useMMap", b->getInt8(0));
     314    b->setScalarField("useMMap", ZERO);
    324315    ReadSourceKernel::generateInitializeMethod(mCodeUnitWidth, mStride,b);
    325316    b->CreateBr(initializeDone);
     
    359350    Constant * const BLOCK_WIDTH = b->getSize(b->getBitBlockWidth());
    360351
    361     BasicBlock * const entry = b->GetInsertBlock();
    362352    BasicBlock * const createTemporary = b->CreateBasicBlock("createTemporary");
    363353    BasicBlock * const exit = b->CreateBasicBlock("exit");
     
    410400    b->setBaseAddress("sourceBuffer", b->CreatePointerCast(offsettedBuffer, codeUnitPtrTy));
    411401    b->setTerminationSignal();
    412     BasicBlock * const terminationExit = b->GetInsertBlock();
     402    b->setProducedItemCount("sourceBuffer", fileItems);
    413403    b->CreateBr(exit);
    414404
    415405    b->SetInsertPoint(exit);
    416     PHINode * const newProducedItems = b->CreatePHI(b->getSizeTy(), 2);
    417     newProducedItems->addIncoming(nextProducedItems, entry);
    418     newProducedItems->addIncoming(fileItems, terminationExit);
    419     b->setProducedItemCount("sourceBuffer", newProducedItems);
    420406}
    421407
Note: See TracChangeset for help on using the changeset viewer.