Ignore:
Timestamp:
Feb 22, 2017, 4:23:51 PM (2 years ago)
Author:
nmedfort
Message:

Added a simple CreateAssert? function in CBuilder and ReadOnly? flag for getStreamSetBufferPtr method to prevent expanding input stream sets. Begun work on CarryManager? to preallocate variable-length carry data slots.

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

Legend:

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

    r5337 r5340  
    268268: BlockOrientedKernel(builder, "PrintableStreamSet", {}, {}, {}, {}, {})
    269269, mNames(names)
    270 , mNameWidth() {
     270, mNameWidth(0) {
    271271    auto width = minWidth;
    272272    for (const std::string & name : mNames) {
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5337 r5340  
    307307    Value * const blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
    308308    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
    309     return buf->getStreamBlockPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex);
     309    return buf->getStreamBlockPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, true);
    310310}
    311311
     
    317317    Value * const blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
    318318    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
    319     return buf->getStreamPackPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex);
     319    return buf->getStreamPackPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex, true);
    320320}
    321321
     
    332332    blockIndex = iBuilder->CreateAdd(blockIndex, blockAdjustment);
    333333    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
    334     return buf->getStreamBlockPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex);
     334    return buf->getStreamBlockPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, true);
    335335}
    336336
     
    338338    Value * const blockIndex = computeBlockIndex(mStreamSetOutputs, name, getProducedItemCount(name));
    339339    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    340     return buf->getStreamBlockPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex);
     340    return buf->getStreamBlockPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, false);
    341341}
    342342
     
    348348    Value * const blockIndex = computeBlockIndex(mStreamSetOutputs, name, getProducedItemCount(name));
    349349    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    350     return buf->getStreamPackPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex);
     350    return buf->getStreamPackPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex, false);
    351351}
    352352
     
    448448    CreateDoBlockMethodCall();
    449449}
    450 
    451 //Value * BlockOrientedKernel::loadBlock(const std::string & inputName, Value * const streamIndex) const {
    452 
    453 //}
    454 
    455 //Value * BlockOrientedKernel::loadPack(const std::string & inputName, Value * const streamIndex, Value * const packIndex) const {
    456 
    457 //}
    458 
    459450
    460451//  The default doSegment method dispatches to the doBlock routine for
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5337 r5340  
    1313#include <llvm/IR/Value.h>         // for Value
    1414#include <llvm/Support/raw_ostream.h>
     15#include <llvm/IR/CFG.h>
    1516
    1617namespace llvm { class Constant; }
     
    2930}
    3031
    31 Value * StreamSetBuffer::getStreamBlockPtr(Value * self, Value * streamIndex, Value * blockIndex) const {
     32Value * StreamSetBuffer::getStreamBlockPtr(Value * self, Value * streamIndex, Value * blockIndex, const bool /* readOnly */) const {
    3233    return iBuilder->CreateGEP(getStreamSetBlockPtr(self, blockIndex), {iBuilder->getInt32(0), streamIndex});
    3334}
    3435
    35 Value * StreamSetBuffer::getStreamPackPtr(Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex) const {
     36Value * StreamSetBuffer::getStreamPackPtr(Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex, const bool /* readOnly */) const {
    3637    return iBuilder->CreateGEP(getStreamSetBlockPtr(self, blockIndex), {iBuilder->getInt32(0), streamIndex, packIndex});
    3738}
     
    199200}
    200201
    201 std::pair<Value *, Value *> ExpandableBuffer::getExpandedStreamOffset(llvm::Value * self, llvm::Value * streamIndex, Value * blockIndex) const {
     202bool dominates(const Instruction * const x, const Instruction * const y) {
     203    // Are they in the same basic block?
     204    if (x->getParent() == y->getParent()) {
     205        if (y->getNextNode() == nullptr) {
     206            return true;
     207        }
     208        for (const Instruction * z = x; z; z = z->getNextNode()) {
     209            if (z == y) {
     210                return true;
     211            }
     212        }
     213        return false;
     214    } else {
     215        const BasicBlock * yp = y->getParent();
     216        for (auto pi = pred_begin(yp), pi_end = pred_end(yp); pi != pi_end; ++pi) {
     217            if (!dominates(x, (*pi)->getTerminator())) {
     218                return false;
     219            }
     220        }
     221        return true;
     222    }
     223}
     224
     225inline bool ExpandableBuffer::isGuaranteedCapacity(const llvm::Value * const index) const {
     226    if (LLVM_UNLIKELY(isa<ConstantInt>(index))) {
     227        if (LLVM_LIKELY(cast<ConstantInt>(index)->getLimitedValue() < mInitialCapacity)) {
     228            return true;
     229        }
     230    }
     231    return false;
     232}
     233
     234std::pair<Value *, Value *> ExpandableBuffer::getInternalStreamBuffer(llvm::Value * self, llvm::Value * streamIndex, Value * blockIndex, const bool readOnly) const {
    202235
    203236    // MDNode *Weights = MDBuilder(Ctx).createBranchWeights(42, 13);
    204 
    205     /// TODO: Check whether a dominating test with the same streamIndex exists or whether streamIndex is guaranteed to be < capacity
    206237
    207238    // ENTRY
     
    212243
    213244    // Are we guaranteed that we can access this stream?
    214     if (LLVM_UNLIKELY(isa<ConstantInt>(streamIndex))) {
    215         if (LLVM_LIKELY(cast<ConstantInt>(streamIndex)->getLimitedValue() < mInitialCapacity)) {
    216             return {streamSet, capacity};
    217         }
     245    if (isGuaranteedCapacity(streamIndex)) {
     246        return {streamSet, capacity};
     247    } else if (readOnly) {
     248        iBuilder->CreateAssert(iBuilder->CreateICmpULT(streamIndex, capacity), "ExpandableBuffer: out-of-bounds readonly stream access!");
     249        return {streamSet, capacity};
    218250    }
    219251
     
    267299}
    268300
    269 llvm::Value * ExpandableBuffer::getStreamBlockPtr(llvm::Value * self, Value * streamIndex, Value * blockIndex) const {
     301llvm::Value * ExpandableBuffer::getStreamBlockPtr(llvm::Value * self, Value * streamIndex, Value * blockIndex, const bool readOnly) const {
    270302    Value * ptr, * offset;
    271     std::tie(ptr, offset) = getExpandedStreamOffset(self, streamIndex, blockIndex);
     303    std::tie(ptr, offset) = getInternalStreamBuffer(self, streamIndex, blockIndex, readOnly);
    272304    return iBuilder->CreateGEP(ptr, offset);
    273305}
    274306
    275 llvm::Value * ExpandableBuffer::getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, Value * blockIndex, Value * packIndex) const {
     307llvm::Value * ExpandableBuffer::getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, Value * blockIndex, Value * packIndex, const bool readOnly) const {
    276308    Value * ptr, * offset;
    277     std::tie(ptr, offset) = getExpandedStreamOffset(self, streamIndex, blockIndex);
     309    std::tie(ptr, offset) = getInternalStreamBuffer(self, streamIndex, blockIndex, readOnly);
    278310    return iBuilder->CreateGEP(ptr, {offset, packIndex});
    279311}
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5329 r5340  
    4747    virtual void allocateBuffer();
    4848
    49     virtual llvm::Value * getStreamBlockPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex) const;
     49    virtual llvm::Value * getStreamBlockPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const;
    5050
    51     virtual llvm::Value * getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex) const;
     51    virtual llvm::Value * getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex, const bool readOnly) const;
    5252   
    5353    virtual llvm::Value * getStreamSetCount(llvm::Value * self) const;
     
    159159    ExpandableBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
    160160
    161     llvm::Value * getStreamBlockPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex) const override;
     161    llvm::Value * getStreamBlockPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const override;
    162162
    163     llvm::Value * getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex) const override;
     163    llvm::Value * getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex, const bool readOnly) const override;
    164164
    165165    llvm::Value * getLinearlyAccessibleItems(llvm::Value * fromPosition) const override;
     
    175175private:
    176176
    177     std::pair<llvm::Value *, llvm::Value *> getExpandedStreamOffset(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex) const;
     177    bool isGuaranteedCapacity(const llvm::Value * const index) const;
     178
     179    std::pair<llvm::Value *, llvm::Value *> getInternalStreamBuffer(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const;
    178180
    179181private:
Note: See TracChangeset for help on using the changeset viewer.