Changeset 5311 for icGREP


Ignore:
Timestamp:
Feb 10, 2017, 3:55:14 PM (2 years ago)
Author:
nmedfort
Message:

Removed BlockNo? + updated LookAhead? to use getInputStream.

Location:
icGREP/icgrep-devel/icgrep
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.cpp

    r5297 r5311  
    2626    Type * T = iBuilder->getIntNTy(mScanwordBitWidth);
    2727    VectorType * scanwordVectorType =  VectorType::get(T, fieldCount);
    28     Value * blockNo = getBlockNo();
     28    Value * blockNo = getScalarField("BlockNo");
    2929    Value * scanwordPos = iBuilder->CreateMul(blockNo, ConstantInt::get(blockNo->getType(), iBuilder->getBitBlockWidth()));
    3030   
     
    4343        scanwordPos = iBuilder->CreateAdd(scanwordPos, ConstantInt::get(T, mScanwordBitWidth));
    4444    }
     45
     46    setScalarField("BlockNo", iBuilder->CreateAdd(blockNo, iBuilder->getSize(1)));
    4547}
    4648
     
    9496BlockOrientedKernel(iBuilder, "scanMatch",
    9597              {Binding{iBuilder->getStreamSetTy(dist + 1), "matchResults"}},
    96               {}, {}, {}, {}),
     98              {}, {}, {}, {Binding{iBuilder->getSizeTy(), "BlockNo"}}),
    9799mEditDistance(dist),
    98100mScanwordBitWidth(iBuilder->getSizeTy()->getBitWidth()) {
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5310 r5311  
    1313#include <llvm/Support/raw_ostream.h>
    1414
    15 static const auto BLOCK_NO_SCALAR = "blockNo";
    16 
    1715static const auto DO_BLOCK_SUFFIX = "_DoBlock";
    1816
     
    108106        addScalar(binding.type, binding.name);
    109107    }
    110     addScalar(iBuilder->getSizeTy(), BLOCK_NO_SCALAR);
    111108    addScalar(iBuilder->getSizeTy(), LOGICAL_SEGMENT_NO_SCALAR);
    112109    addScalar(iBuilder->getInt1Ty(), TERMINATION_SIGNAL);
     
    245242}
    246243
    247 Value * KernelBuilder::getBlockNo() const {
    248     return getScalarField(mSelf, BLOCK_NO_SCALAR);
    249 }
    250 
    251 void KernelBuilder::setBlockNo(Value * value) const {
    252     setScalarField(mSelf, BLOCK_NO_SCALAR, value);
    253 }
    254 
    255244inline Value * KernelBuilder::computeBlockIndex(const std::vector<Binding> & bindings, const std::string & name, Value * itemCount) const {
    256245    for (const Binding & b : bindings) {
     
    279268}
    280269
     270llvm::Value * KernelBuilder::getInputStream(Value * blockAdjustment, const std::string & name, llvm::Value * streamIndex) const {
     271    Value * blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
     272    blockIndex = iBuilder->CreateAdd(blockIndex, blockAdjustment);
     273    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
     274    return buf->getStream(getStreamSetBufferPtr(name), streamIndex, blockIndex);
     275}
     276
    281277Value * KernelBuilder::getOutputStream(const std::string & name, Value * streamIndex) const {
    282278    Value * const blockIndex = computeBlockIndex(mStreamSetOutputs, name, getProducedItemCount(name));
     
    326322Value * KernelBuilder::createGetAccumulatorCall(Value * self, const std::string & accumName) const {
    327323    return iBuilder->CreateCall(getAccumulatorFunction(accumName), {self});
    328 }
    329 
    330 Value * KernelBuilder::getInputStreamSetPtr(const std::string & name, Value * blockNo) const {
    331     return getInputStreamSetBuffer(name)->getStreamSetPtr(getStreamSetBufferPtr(name), blockNo);
    332324}
    333325
     
    385377
    386378    ConstantInt * stride = iBuilder->getSize(iBuilder->getStride());
    387     ConstantInt * strideBlocks = iBuilder->getSize(iBuilder->getStride() / iBuilder->getBitBlockWidth());
    388379
    389380    Value * availablePos = producerPos[0];
     
    405396
    406397    iBuilder->SetInsertPoint(strideLoopBody);
    407     Value * blockNo = getBlockNo();
    408398
    409399    CreateDoBlockMethodCall();
    410400
    411     setBlockNo(iBuilder->CreateAdd(blockNo, strideBlocks));
    412 
    413401    // Update counts
    414 
    415402    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
    416403        Value * processed = getProcessedItemCount(mStreamSetInputs[i].name);
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5310 r5311  
    153153    llvm::ConstantInt * getScalarIndex(const std::string & name) const;
    154154
    155     llvm::Value * getBlockNo() const;
    156 
    157     void setBlockNo(llvm::Value * value) const;
    158    
    159155    // Get the value of a scalar field for a given instance.
    160156    llvm::Value * getScalarField(const std::string & fieldName) const {
     
    183179    llvm::Value * getOutputStream(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex) const;
    184180
     181    llvm::Value * getInputStream(llvm::Value * blockAdjustment, const std::string & name, llvm::Value * streamIndex) const;
     182
    185183    llvm::Value * getRawInputPointer(const std::string & name, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
    186184
     
    195193    }
    196194
    197     llvm::Value * getInputStreamSetPtr(const std::string & name, llvm::Value * blockNo) const;
    198 
    199195    inline llvm::Value * getProcessedItemCount(const std::string & name) const {
    200196        return getProcessedItemCount(getSelf(), name);
     
    229225
    230226    // Stream set helpers.
    231 //    llvm::Value * getStream(const std::string & name, llvm::Value * blockNo, llvm::Value * index) const;
    232 
    233 //    llvm::Value * getStream(const std::string & name, llvm::Value * blockNo, llvm::Value * index1, llvm::Value * index2) const;
    234227
    235228    llvm::Value * getStreamSetBufferPtr(const std::string & name) const;
    236 
    237 //    llvm::Value * getStreamSetBufferPtr(llvm::Value * index) const;
    238229
    239230    llvm::Value * getScalarFieldPtr(llvm::Value * instance, const std::string & name) const;
  • icGREP/icgrep-devel/icgrep/kernels/radix64.cpp

    r5307 r5311  
    8181    Constant * Const4 = iBuilder->getSize(4);
    8282    Constant * tripleBlockSize = iBuilder->getSize(3 * iBuilder->getStride());
    83     Constant * stride = iBuilder->getSize(iBuilder->getStride());
    8483    Constant * packSize = iBuilder->getSize(PACK_SIZE);
    8584    Constant * triplePackSize = iBuilder->getSize(3 * PACK_SIZE); // 3 packs per loop.
     
    161160    setProcessedItemCount("sourceStream", processed);
    162161   
    163     setBlockNo(iBuilder->CreateUDiv(processed, stride));
    164162    // We have produced 4 output bytes for every 3 input bytes.
    165163    Value * totalProduced = iBuilder->CreateMul(iBuilder->CreateUDiv(processed, Const3), Const4);
     
    235233    setProcessedItemCount("sourceStream", processed);
    236234
    237     setBlockNo(iBuilder->CreateUDiv(processed, stride));
    238235    // We have produced 4 output bytes for every 3 input bytes.  If the number of input
    239236    // bytes is not a multiple of 3, then we have one more output byte for each excess
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5297 r5311  
    4747    const unsigned fieldCount = iBuilder->getBitBlockWidth() / T->getBitWidth();
    4848    Type * scanwordVectorType =  VectorType::get(T, fieldCount);
    49     Value * blockNo = getBlockNo();
     49    Value * blockNo = getScalarField("BlockNo");
    5050    Value * scanwordPos = iBuilder->CreateMul(blockNo, ConstantInt::get(blockNo->getType(), iBuilder->getBitBlockWidth()));   
    5151    Value * recordStart = getScalarField("LineStart");
     
    6565    setScalarField("LineStart", recordStart);
    6666    setScalarField("LineNum", recordNum);
     67    setScalarField("BlockNo", iBuilder->CreateAdd(blockNo, iBuilder->getSize(1)));
    6768}
    6869
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5307 r5311  
    9595}
    9696
    97 Value * ExternalFileBuffer::getLinearlyAccessibleItems(llvm::Value * fromPosition) const {
    98     throw std::runtime_error("External buffers: getLinearlyAccessibleItems not supported.");
     97Value * ExternalFileBuffer::getLinearlyAccessibleItems(llvm::Value *) const {
     98    report_fatal_error("External buffers: getLinearlyAccessibleItems not supported.");
    9999}
    100100
    101101// Circular Buffer
    102102
    103 Value * CircularBuffer::getStreamSetPtr(Value * self, Value * blockNo) const {
    104     assert (blockNo->getType()->isIntegerTy());
     103Value * CircularBuffer::getStreamSetPtr(Value * self, Value * blockIndex) const {
     104    assert (blockIndex->getType()->isIntegerTy());
    105105    Value * offset = nullptr;
    106106    if (mBufferBlocks == 1) {
    107107        offset = ConstantInt::getNullValue(iBuilder->getSizeTy());
    108108    } else if ((mBufferBlocks & (mBufferBlocks - 1)) == 0) { // is power of 2
    109         offset = iBuilder->CreateAnd(blockNo, ConstantInt::get(blockNo->getType(), mBufferBlocks - 1));
     109        offset = iBuilder->CreateAnd(blockIndex, ConstantInt::get(blockIndex->getType(), mBufferBlocks - 1));
    110110    } else {
    111         offset = iBuilder->CreateURem(blockNo, ConstantInt::get(blockNo->getType(), mBufferBlocks));
     111        offset = iBuilder->CreateURem(blockIndex, ConstantInt::get(blockIndex->getType(), mBufferBlocks));
    112112    }
    113113    return iBuilder->CreateGEP(self, offset);
     
    155155}
    156156
    157 Value * CircularCopybackBuffer::getStreamSetPtr(Value * self, Value * blockNo) const {
    158     assert (blockNo->getType()->isIntegerTy());
     157Value * CircularCopybackBuffer::getStreamSetPtr(Value * self, Value * blockIndex) const {
     158    assert (blockIndex->getType()->isIntegerTy());
    159159   
    160160    Value * offset = nullptr;
     
    162162        offset = ConstantInt::getNullValue(iBuilder->getSizeTy());
    163163    } else if ((mBufferBlocks & (mBufferBlocks - 1)) == 0) { // is power of 2
    164         offset = iBuilder->CreateAnd(blockNo, ConstantInt::get(blockNo->getType(), mBufferBlocks - 1));
     164        offset = iBuilder->CreateAnd(blockIndex, ConstantInt::get(blockIndex->getType(), mBufferBlocks - 1));
    165165    } else {
    166         offset = iBuilder->CreateURem(blockNo, ConstantInt::get(blockNo->getType(), mBufferBlocks));
     166        offset = iBuilder->CreateURem(blockIndex, ConstantInt::get(blockIndex->getType(), mBufferBlocks));
    167167    }
    168168    return iBuilder->CreateGEP(self, offset);
     
    173173// Expandable Buffer
    174174
    175 Value * ExpandableBuffer::getStreamSetPtr(Value * self, Value * blockNo) const {
     175void ExpandableBuffer::ensureStreamCapacity(llvm::Value * self, llvm::Value * streamIndex) const {
     176
     177}
     178
     179llvm::Value * ExpandableBuffer::getStream(llvm::Value * self, Value * streamIndex, Value * blockIndex) const {
     180    ensureStreamCapacity(self, streamIndex);
     181
     182
     183
    176184    return nullptr;
    177185}
    178186
    179 llvm::Value * ExpandableBuffer::getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const {
     187llvm::Value * ExpandableBuffer::getStream(llvm::Value * self, llvm::Value * streamIndex, Value *blockIndex, Value *packIndex) const {
     188    ensureStreamCapacity(self, streamIndex);
     189
     190
    180191    return nullptr;
    181192}
    182193
    183 llvm::Value * ExpandableBuffer::getStream(llvm::Value * self, llvm::Value * blockNo, Value *index1, Value *index2) const {
    184     return nullptr;
     194Value * ExpandableBuffer::getStreamSetPtr(Value *, Value *) const {
     195    report_fatal_error("Expandable buffers: getStreamSetPtr not supported.");
     196}
     197
     198Value * ExpandableBuffer::getLinearlyAccessibleItems(llvm::Value *) const {
     199    report_fatal_error("Expandable buffers: getLinearlyAccessibleItems not supported.");
    185200}
    186201
     
    210225: StreamSetBuffer(BufferKind::ExpandableBuffer, b, type, bufferBlocks, AddressSpace) {
    211226
    212 }
    213 
    214 Value * ExpandableBuffer::getLinearlyAccessibleItems(llvm::Value * fromPosition) const {
    215     throw std::runtime_error("Expandable buffers: getLinearlyAccessibleItems not supported.");
    216227}
    217228
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5307 r5311  
    115115
    116116protected:
    117     llvm::Value * getStreamSetPtr(llvm::Value * bufferBasePtr, llvm::Value * blockNo) const override;
     117    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockIndex) const override;
    118118};
    119119   
     
    139139   
    140140protected:
    141     llvm::Value * getStreamSetPtr(llvm::Value * bufferBasePtr, llvm::Value * blockNo) const override;
     141    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockIndex) const override;
    142142private:
    143143    size_t mOverflowBlocks;
     
    154154    ExpandableBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
    155155
    156     llvm::Value * getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const override;
     156    llvm::Value * getStream(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex) const override;
    157157
    158     llvm::Value * getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index1, llvm::Value * index2) const override;
     158    llvm::Value * getStream(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex) const override;
    159159
    160160    llvm::Value * getLinearlyAccessibleItems(llvm::Value * fromPosition) const override;
     
    162162protected:
    163163
    164     llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
     164    void ensureStreamCapacity(llvm::Value * self, llvm::Value * streamIndex) const;
     165
     166    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockIndex) const override;
    165167};
    166168
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5310 r5311  
    6262        mKernel->addScalar(iBuilder->getInt32Ty(), "selector");
    6363    }
     64    if (mHasLongAdvance) {
     65        mKernel->addScalar(iBuilder->getInt64Ty(), "CarryBlockIndex");
     66    }
    6467}
    6568
     
    9295    if (mHasLoop) {
    9396        mKernel->setScalarField("selector", iBuilder->CreateXor(mLoopSelector, iBuilder->getInt32(1)));
     97    }
     98    if (mHasLongAdvance) {
     99        Value * idx = mKernel->getScalarField("CarryBlockIndex");
     100        idx = iBuilder->CreateAdd(idx, iBuilder->getInt64(1));
     101        mKernel->setScalarField("CarryBlockIndex", idx);
    94102    }
    95103}
     
    108116 ** ------------------------------------------------------------------------------------------------------------- */
    109117void CarryManager::enterLoopBody(BasicBlock * const entryBlock) {
     118
     119    assert (mHasLoop);
    110120
    111121    if (mCarryInfo->hasSummary()) {
     
    366376
    367377    assert (shiftAmount > mBitBlockWidth);
     378    assert (mHasLongAdvance);
    368379
    369380    Type * const streamVectorTy = iBuilder->getIntNTy(mBitBlockWidth);
     
    399410
    400411    // Create a mask to implement circular buffer indexing
    401     Value * indexMask = iBuilder->getSize(nearest_pow2(entries) - 1);
    402     Value * blockIndex = mKernel->getBlockNo();
     412    Value * indexMask = iBuilder->getSize(nearest_pow2(entries) - 1);   
     413    Value * blockIndex = mKernel->getScalarField("CarryBlockIndex");
    403414    Value * carryIndex0 = iBuilder->CreateSub(blockIndex, iBuilder->getSize(entries));
    404415    Value * loadIndex0 = iBuilder->CreateAnd(carryIndex0, indexMask);
     
    561572                    Type * carryType = ArrayType::get(mBitBlockType, ceil_udiv(amount, std::pow(mBitBlockWidth, 2)));
    562573                    type = StructType::get(carryType, type, nullptr);
    563                     hasLongAdvances = true;
     574                    hasLongAdvances = true;                   
    564575                }
     576                mHasLongAdvance = true;
    565577                state.push_back(type);
    566578            }
     
    627639, mCarryPackPtr(nullptr)
    628640, mIfDepth(0)
     641, mHasLongAdvance(false)
    629642, mHasLoop(false)
    630643, mLoopDepth(0)
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r5307 r5311  
    119119    unsigned                                        mIfDepth;
    120120
     121    bool                                            mHasLongAdvance;
     122
    121123    bool                                            mHasLoop;
    122124    unsigned                                        mLoopDepth;
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5310 r5311  
    474474
    475475        } else if (const Lookahead * l = dyn_cast<Lookahead>(stmt)) {
    476             PabloAST * const var = l->getExpr();
    477             if (LLVM_UNLIKELY(!isa<Var>(var))) {
    478                 throw std::runtime_error("Lookahead operations may only be applied to input streams");
    479             }
    480             unsigned index = 0;
    481             for (; index < mKernel->getNumOfInputs(); ++index) {
    482                 if (mKernel->getInput(index) == var) {
    483                     break;
     476            Var * var = nullptr;
     477            PabloAST * stream = l->getExpr();
     478            Value * index = iBuilder->getInt32(0);
     479
     480            if (LLVM_UNLIKELY(isa<Extract>(stream))) {
     481                stream = cast<Extract>(stream)->getArray();
     482                index = compileExpression(cast<Extract>(stream)->getIndex());
     483            }
     484            if (LLVM_LIKELY(isa<Var>(stream))) {
     485                var = cast<Var>(stream);
     486                if (!var->isKernelParameter() || var->isReadNone()) {
     487                    std::string tmp;
     488                    raw_string_ostream out(tmp);
     489                    out << "Lookahead operation cannot be applied to ";
     490                    stmt->print(out);
     491                    out << ": ";
     492                    var->print(out);
     493                    out << " is not an input stream";
     494                    report_fatal_error(out.str());
    484495                }
    485496            }
    486             if (LLVM_UNLIKELY(index >= mKernel->getNumOfInputs())) {
    487                 throw std::runtime_error("Lookahead has an illegal Var operand");
    488             }
    489             const unsigned bit_shift = (l->getAmount() % iBuilder->getBitBlockWidth());
    490             const unsigned block_shift = (l->getAmount() / iBuilder->getBitBlockWidth());
    491             std::string inputName = cast<Var>(var)->getName().str();
    492             Value * blockNo = mKernel->getBlockNo();
    493             Value * lookAhead_blockPtr  = mKernel->getInputStreamSetPtr(inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift)));
    494             Value * lookAhead_inputPtr = iBuilder->CreateGEP(lookAhead_blockPtr, {iBuilder->getInt32(0), iBuilder->getInt32(index)});
    495             Value * lookAhead = iBuilder->CreateBlockAlignedLoad(lookAhead_inputPtr);
     497
     498            const auto bit_shift = (l->getAmount() % iBuilder->getBitBlockWidth());
     499            const auto block_shift = (l->getAmount() / iBuilder->getBitBlockWidth());
     500
     501            Value * ptr = mKernel->getInputStream(iBuilder->getSize(block_shift), var->getName(), index);
     502            Value * lookAhead = iBuilder->CreateBlockAlignedLoad(ptr);
    496503            if (bit_shift == 0) {  // Simple case with no intra-block shifting.
    497504                value = lookAhead;
    498505            } else { // Need to form shift result from two adjacent blocks.
    499                 Value * lookAhead_blockPtr1  = mKernel->getInputStreamSetPtr(inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift + 1)));
    500                 Value * lookAhead_inputPtr1 = iBuilder->CreateGEP(lookAhead_blockPtr1, {iBuilder->getInt32(0), iBuilder->getInt32(index)});
    501                 Value * lookAhead1 = iBuilder->CreateBlockAlignedLoad(lookAhead_inputPtr1);
     506                Value * ptr = mKernel->getInputStream(iBuilder->getSize(block_shift + 1), var->getName(), index);
     507                Value * lookAhead1 = iBuilder->CreateBlockAlignedLoad(ptr);
    502508                if (LLVM_UNLIKELY((bit_shift % 8) == 0)) { // Use a single whole-byte shift, if possible.
    503509                    value = iBuilder->mvmd_dslli(8, lookAhead1, lookAhead, (bit_shift / 8));
Note: See TracChangeset for help on using the changeset viewer.