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

Restore check-ins from the last several days

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

Legend:

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

    r5486 r5493  
    11301130               std::vector<Binding> && scalar_outputs,
    11311131               std::vector<Binding> && internal_scalars)
    1132 : KernelInterface(std::move(annotateKernelNameWithDebugFlags(std::move(kernelName)))
     1132: KernelInterface(annotateKernelNameWithDebugFlags(std::move(kernelName))
    11331133                  , std::move(stream_inputs), std::move(stream_outputs)
    11341134                  , std::move(scalar_parameters), std::move(scalar_outputs)
  • icGREP/icgrep-devel/icgrep/kernels/kernel_builder.cpp

    r5446 r5493  
    187187}
    188188
    189 void KernelBuilder::storeOutputStreamBlock(const std::string & name, Value * streamIndex, Value * toStore) {
     189StoreInst * KernelBuilder::storeOutputStreamBlock(const std::string & name, Value * streamIndex, Value * toStore) {
    190190    return CreateBlockAlignedStore(toStore, getOutputStreamBlockPtr(name, streamIndex));
    191191}
     
    197197}
    198198
    199 void KernelBuilder::storeOutputStreamPack(const std::string & name, Value * streamIndex, Value * packIndex, Value * toStore) {
     199StoreInst * KernelBuilder::storeOutputStreamPack(const std::string & name, Value * streamIndex, Value * packIndex, Value * toStore) {
    200200    return CreateBlockAlignedStore(toStore, getOutputStreamPackPtr(name, streamIndex, packIndex));
    201201}
  • icGREP/icgrep-devel/icgrep/kernels/kernel_builder.h

    r5489 r5493  
    6666    llvm::Value * getOutputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex);
    6767
    68     void storeOutputStreamBlock(const std::string & name, llvm::Value * streamIndex, llvm::Value * toStore);
     68    llvm::StoreInst * storeOutputStreamBlock(const std::string & name, llvm::Value * streamIndex, llvm::Value * toStore);
    6969
    7070    llvm::Value * getOutputStreamPackPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex);
    7171
    72     void storeOutputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex, llvm::Value * toStore);
     72    llvm::StoreInst * storeOutputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex, llvm::Value * toStore);
    7373
    7474    llvm::Value * getOutputStreamSetCount(const std::string & name);
  • icGREP/icgrep-devel/icgrep/kernels/lz4_index_decoder.cpp

    r5440 r5493  
    7171 */
    7272Value * LZ4IndexDecoderKernel::getWordOffset(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) {
    73     Value * wordWidthMask = iBuilder->getInt32(wordWidth - 1);
    74     return iBuilder->CreateAnd(
    75             iBuilder->CreateLoad(sOffset),
    76             wordWidthMask
    77             );
    78 }
    79 
     73    Value * offset = iBuilder->CreateLoad(sOffset);
     74    IntegerType * type = cast<IntegerType>(offset->getType());
     75    Constant * mask = ConstantInt::get(type, wordWidth - 1);
     76    return iBuilder->CreateAnd(offset, mask);
     77}
    8078
    8179/**
     
    8381 */
    8482Value * LZ4IndexDecoderKernel::getWordStartOffset(const std::unique_ptr<KernelBuilder> & iBuilder) {
    85     Value * wordWidthMask = iBuilder->getInt32(wordWidth - 1);
    86     return iBuilder->CreateAnd(
    87             iBuilder->CreateLoad(sOffset),
    88             iBuilder->CreateNot(wordWidthMask)
    89             );
    90 }
    91 
     83    Value * offset = iBuilder->CreateLoad(sOffset);
     84    IntegerType * type = cast<IntegerType>(offset->getType());
     85    Constant * mask = ConstantExpr::getNeg(ConstantInt::get(type, wordWidth));
     86    return iBuilder->CreateAnd(offset, mask);
     87}
    9288
    9389/**
     
    136132 */
    137133void LZ4IndexDecoderKernel::loadCurrentExtender(const std::unique_ptr<KernelBuilder> & iBuilder) {
    138     iBuilder->CreateStore(
    139             iBuilder->CreateExtractElement(extenders,
    140                 iBuilder->CreateLShr(
    141                     iBuilder->CreateLoad(sOffset),
    142                     iBuilder->getInt32(std::log2(wordWidth))
    143                     )
    144                 ),
    145             sExtender);
     134    Value * offset = iBuilder->CreateLoad(sOffset);
     135    IntegerType * type = cast<IntegerType>(offset->getType());
     136    ConstantInt * shift = ConstantInt::get(type, std::log2(wordWidth));
     137    Value * shiftedOffset = iBuilder->CreateLShr(offset, shift);
     138    Value * extender = iBuilder->CreateExtractElement(extenders, shiftedOffset);
     139    iBuilder->CreateStore(extender, sExtender);
    146140}
    147141
     
    195189    extenders = iBuilder->CreateBitCast(
    196190            iBuilder->loadInputStreamBlock("extenders", iBuilder->getInt32(0)),
    197             VectorType::get(iBuilder->getSizeTy(), iBuilder->getBitBlockWidth() / wordWidth),
     191            VectorType::get(iBuilder->getSizeTy(), iBuilder->getBitBlockWidth() / iBuilder->getSizeTy()->getBitWidth()),
    198192            "extenders");
    199193    // Create a series of stack variables which will be promoted by mem2reg.
  • 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 ...
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5486 r5493  
    150150    Type * i8ptr = iBuilder->getInt8PtrTy();
    151151    unsigned alignment = iBuilder->getBitBlockWidth() / 8;
    152     unsigned numStreams = getType()->getArrayNumElements();
    153     auto elemTy = getType()->getArrayElementType();
    154     unsigned fieldWidth = isa<ArrayType>(elemTy) ? elemTy->getArrayNumElements() : 1;
     152    uint64_t numStreams = 1;
     153    if (isa<ArrayType>(mBaseType)) {
     154        numStreams = mBaseType->getArrayNumElements();
     155    }
     156    const auto fieldWidth = mBaseType->getArrayElementType()->getScalarSizeInBits();
    155157    Value * blockCopyBytes = iBuilder->CreateMul(blocksToCopy, iBuilder->getSize(iBuilder->getBitBlockWidth() * numStreams * fieldWidth/8));
    156158    iBuilder->CreateMemMove(iBuilder->CreateBitCast(targetBlockPtr, i8ptr), iBuilder->CreateBitCast(sourceBlockPtr, i8ptr), blockCopyBytes, alignment);
     
    161163    const unsigned alignment = iBuilder->getBitBlockWidth() / 8;
    162164    Constant * const blockSize = iBuilder->getSize(iBuilder->getBitBlockWidth());
    163     const unsigned numStreams = getType()->getArrayNumElements();
    164     const auto elemTy = getType()->getArrayElementType();
    165     const auto fieldWidth = isa<ArrayType>(elemTy) ? elemTy->getArrayNumElements() : 1;
     165    uint64_t numStreams = 1;
     166    if (isa<ArrayType>(mBaseType)) {
     167        numStreams = mBaseType->getArrayNumElements();
     168    }
     169    const auto fieldWidth = mBaseType->getArrayElementType()->getScalarSizeInBits();
    166170    if (numStreams == 1) {
    167171        Value * copyBits = iBuilder->CreateMul(itemsToCopy, iBuilder->getSize(fieldWidth));
  • icGREP/icgrep-devel/icgrep/kernels/until_n.cpp

    r5451 r5493  
    7979    PHINode * blockGroupBase = kb->CreatePHI(kb->getSizeTy(), 2);
    8080    blockGroupBase->addIncoming(kb->getSize(0), entry);
    81     Value * groupPackPtr = kb->CreatePointerCast(kb->CreateGEP(sourceBitstream, {blockGroupBase}), iPackPtrTy);
     81    Value * groupPackPtr = kb->CreatePointerCast(kb->CreateGEP(sourceBitstream, blockGroupBase), iPackPtrTy);
    8282    Value * blockGroupLimit = kb->CreateAdd(blockGroupBase, blocksPerGroup);
    8383    blockGroupLimit = kb->CreateSelect(kb->CreateICmpULT(blockGroupLimit, blocksToDo), blockGroupLimit, blocksToDo);
     
    114114    seenSoFarPhi->addIncoming(seenSoFar, doScan);
    115115    Value * nonZeroPack = kb->CreateZExtOrTrunc(kb->CreateCountForwardZeroes(groupMaskPhi), kb->getSizeTy());
    116     Value * scanMask = kb->CreateLoad(kb->CreateGEP(groupPackPtr, {nonZeroPack}));
     116    Value * scanMask = kb->CreateLoad(kb->CreateGEP(groupPackPtr, nonZeroPack));
    117117    Value * packCount = kb->CreateZExtOrTrunc(kb->CreatePopcount(scanMask), kb->getSizeTy());
    118118    Value * newTotalSeen = kb->CreateAdd(packCount, seenSoFarPhi);
Note: See TracChangeset for help on using the changeset viewer.