Changeset 6067


Ignore:
Timestamp:
Jun 7, 2018, 5:06:26 PM (4 months ago)
Author:
cameron
Message:

Source kernels bug fix: size/items calculations when codeUnitSize != 8

File:
1 edited

Legend:

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

    r6049 r6067  
    3636    IntegerType * const sizeTy = b->getSizeTy();
    3737    ConstantInt * const PAGE_SIZE = b->getSize(getpagesize());
     38    Constant * const PAGE_ITEMS = b->getSize(getpagesize()/(codeUnitWidth/8));
    3839    Value * const fd = b->getScalarField("fileDescriptor");
    3940    assert (fileSizeMethod);
     
    4748    b->setBaseAddress("sourceBuffer", fileBuffer);
    4849    b->CreateMAdvise(fileBuffer, fileSize, CBuilder::ADVICE_WILLNEED);
     50    Value * fileItems = fileSize;
    4951    if (LLVM_UNLIKELY(codeUnitWidth > 8)) {
    50         fileSize = b->CreateUDiv(fileSize, b->getSize(codeUnitWidth / 8));
    51     }
    52     b->setScalarField("fileSize", fileSize);
     52        fileItems = b->CreateUDiv(fileSize, b->getSize(codeUnitWidth / 8));
     53    }
     54    b->setScalarField("fileItems", fileItems);
    5355    b->CreateBr(exit);
    5456
     
    5759    b->setScalarField("buffer", emptyFilePtr);
    5860    b->setBaseAddress("sourceBuffer", emptyFilePtr);
    59     b->setScalarField("fileSize", PAGE_SIZE);
     61    b->setScalarField("fileItems", PAGE_ITEMS);
    6062    b->setTerminationSignal();
    6163    b->CreateBr(exit);
     
    7375
    7476    Constant * const PAGE_SIZE = b->getSize(getpagesize());
     77    Constant * const PAGE_ITEMS = b->getSize(getpagesize()/(codeUnitWidth/8));
    7578    Constant * const BLOCK_WIDTH = b->getSize(b->getBitBlockWidth());
    7679    Constant * const CODE_UNIT_BYTES = b->getSize(codeUnitWidth / 8);
    7780
    78     Value * const fileItems = b->getScalarField("fileSize");
     81    Value * const fileItems = b->getScalarField("fileItems");
    7982    Value * const consumedItems = b->getConsumedItemCount("sourceBuffer");
    8083    Value * const consumedBytes = b->CreateMul(consumedItems, CODE_UNIT_BYTES);
     
    9699    b->SetInsertPoint(checkRemaining);
    97100    Value * const producedItems = b->getProducedItemCount("sourceBuffer");
    98     Value * const nextProducedItems = b->CreateAdd(producedItems, PAGE_SIZE);
     101    Value * const nextProducedItems = b->CreateAdd(producedItems, PAGE_ITEMS);
    99102    Value * const lastPage = b->CreateICmpULE(fileItems, nextProducedItems);
    100103    b->CreateUnlikelyCondBr(lastPage, setTermination, exit);
     
    106109    Value * const readStart = b->getRawOutputPointer("sourceBuffer", consumedOffset);
    107110    Value * const readEnd = b->getRawOutputPointer("sourceBuffer", fileItems);
    108     Value * const unconsumedBytes = b->CreateTrunc(b->CreatePtrDiff(readEnd, readStart), b->getSizeTy());
     111    Value * unconsumedBytes = b->CreateTrunc(b->CreatePtrDiff(readEnd, readStart), b->getSizeTy());
     112    if (LLVM_UNLIKELY(codeUnitWidth > 8)) {
     113        unconsumedBytes = b->CreateMul(unconsumedBytes, CODE_UNIT_BYTES);
     114    }
    109115    Value * const bufferSize = b->CreateRoundUp(b->CreateAdd(unconsumedBytes, BLOCK_WIDTH), PAGE_SIZE);
    110116    Value * const buffer = b->CreateAlignedMalloc(bufferSize, b->getCacheAlignment());
     
    318324    Value * const fileSource = b->getScalarField("fileSource");
    319325    b->setBaseAddress("sourceBuffer", fileSource);
    320     Value * const fileSize = b->getScalarField("fileSize");
    321     b->setCapacity("sourceBuffer", fileSize);
     326    Value * const fileItems = b->getScalarField("fileItems");
     327    b->setCapacity("sourceBuffer", fileItems);
    322328    if (mStreamSetCount > 1) {
    323         b->setProducedItemCount("sourceBuffer", fileSize);
     329        b->setProducedItemCount("sourceBuffer", fileItems);
    324330        b->setTerminationSignal();
    325331    }
     
    329335    if (mStreamSetCount == 1) {
    330336        Constant * const PAGE_SIZE = b->getSize(getStride());
     337        Constant * const PAGE_ITEMS = b->getSize(getStride()/(mCodeUnitWidth/8));
    331338        Constant * const BLOCK_WIDTH = b->getSize(b->getBitBlockWidth());
     339        Constant * const CODE_UNIT_BYTES = b->getSize(mCodeUnitWidth / 8);
    332340
    333341        BasicBlock * const entry = b->GetInsertBlock();
     
    335343        BasicBlock * const exit = b->CreateBasicBlock("exit");
    336344
    337         Value * const fileItems = b->getScalarField("fileSize");
     345        Value * const fileItems = b->getScalarField("fileItems");
    338346        Value * const producedItems = b->getProducedItemCount("sourceBuffer");
    339         Value * const nextProducedItems = b->CreateAdd(producedItems, PAGE_SIZE);
     347        Value * const nextProducedItems = b->CreateAdd(producedItems, PAGE_ITEMS);
    340348        Value * const lastPage = b->CreateICmpULE(fileItems, nextProducedItems);
    341349        b->CreateUnlikelyCondBr(lastPage, createTemporary, exit);
     
    346354        Value * const readStart = b->getRawOutputPointer("sourceBuffer", consumedOffset);
    347355        Value * const readEnd = b->getRawOutputPointer("sourceBuffer", fileItems);
    348         Value * const unconsumedBytes = b->CreateTrunc(b->CreatePtrDiff(readEnd, readStart), b->getSizeTy());
     356        Value * unconsumedBytes = b->CreateTrunc(b->CreatePtrDiff(readEnd, readStart), b->getSizeTy());
     357        if (LLVM_UNLIKELY(mCodeUnitWidth > 8)) {
     358            unconsumedBytes = b->CreateMul(unconsumedBytes, CODE_UNIT_BYTES);
     359        }
    349360        Value * const bufferSize = b->CreateRoundUp(b->CreateAdd(unconsumedBytes, BLOCK_WIDTH), PAGE_SIZE);
    350361        Value * const buffer = b->CreateAlignedMalloc(bufferSize, b->getCacheAlignment());
     
    392403// internal scalars
    393404, {Binding{b->getIntNTy(codeUnitWidth)->getPointerTo(), "buffer"}
    394 ,  Binding{b->getSizeTy(), "fileSize"}})
     405,  Binding{b->getSizeTy(), "fileItems"}})
    395406, mCodeUnitWidth(codeUnitWidth)
    396407, mFileSizeFunction(nullptr) {
     
    428439// internal scalars
    429440, {Binding{b->getIntNTy(codeUnitWidth)->getPointerTo(), "buffer"},
    430    Binding{b->getSizeTy(), "fileSize"}})
     441   Binding{b->getSizeTy(), "fileItems"}})
    431442, mCodeUnitWidth(codeUnitWidth)
    432443, mFileSizeFunction(nullptr) {
     
    442453{Binding{b->getStreamSetTy(streamSetCount, codeUnitWidth), "sourceBuffer"}},
    443454// input scalar
    444 {Binding{b->getIntNTy(codeUnitWidth)->getPointerTo(), "fileSource"}, Binding{b->getSizeTy(), "fileSize"}},
     455{Binding{b->getIntNTy(codeUnitWidth)->getPointerTo(), "fileSource"}, Binding{b->getSizeTy(), "fileItems"}},
    445456{},
    446457// internal scalar
Note: See TracChangeset for help on using the changeset viewer.