Changeset 5100 for icGREP


Ignore:
Timestamp:
Jul 20, 2016, 10:06:34 AM (3 years ago)
Author:
cameron
Message:

Buffer class hierarchy; s2p kernel demonstrates specialization for different buffer strategies

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5087 r5100  
    118118}
    119119
     120using namespace parabix;
    120121
    121122void GrepEngine::grepCodeGen(std::string moduleName, re::RE * re_ast, bool CountOnly, bool UTF_16, bool isNameExpression) {
     
    125126    IDISA::IDISA_Builder * iBuilder = IDISA::GetIDISA_Builder(M);
    126127
     128    const unsigned segmentSize = codegen::SegmentSize;
    127129
    128130    Encoding::Type type;
     
    133135    Encoding encoding(type, bits);
    134136
     137    ExternalUnboundedBuffer ByteStream(iBuilder, StreamSetType(1, i8));
     138    CircularBuffer BasisBits(iBuilder, StreamSetType(8, i1), segmentSize);
     139
    135140    mIsNameExpression = isNameExpression;
    136141    re_ast = re::regular_expression_passes(encoding, re_ast);   
    137142    pablo::PabloFunction * function = re::re2pablo_compiler(encoding, re_ast);
    138143   
    139     kernel::s2pKernel  s2pk(iBuilder);
     144    kernel::s2pKernel  s2pk(iBuilder, ByteStream, BasisBits);
    140145    kernel::scanMatchKernel scanMatchK(iBuilder, 64, false);
    141146   
     
    172177    fileIdx->setName("fileIdx");
    173178
    174     const unsigned segmentSize = codegen::SegmentSize;
    175 
    176     kernel::StreamSetBuffer ByteStream(iBuilder, kernel::StreamSetType(1, (UTF_16 ? 16 : 8)), 0);
    177     kernel::StreamSetBuffer BasisBits(iBuilder, kernel::StreamSetType((UTF_16 ? 16 : 8), 1), segmentSize);
     179
    178180    ByteStream.setStreamSetBuffer(inputStream);
    179181    BasisBits.allocateBuffer();
     
    188190    }
    189191    else {
    190         kernel::StreamSetBuffer MatchResults(iBuilder, kernel::StreamSetType(2, 1), segmentSize);
     192       
     193        CircularBuffer MatchResults(iBuilder, StreamSetType(2, i1), segmentSize);
    191194        ByteStream.setStreamSetBuffer(inputStream);
    192195        BasisBits.allocateBuffer();
  • icGREP/icgrep-devel/icgrep/kernels/interface.cpp

    r5096 r5100  
    1111
    1212using namespace llvm;
    13 using namespace kernel;
     13using namespace parabix;
    1414
    1515void KernelInterface::addKernelDeclarations(Module * client) {
     
    155155    }
    156156    for (auto b : inputBuffers) {
    157         init_args.push_back(b->getStreamSetBufferPtr());
    158         init_args.push_back(iBuilder->getInt64(b->getSegmentSize() - 1));
     157        init_args.push_back(b->getStreamSetBasePtr());
     158        init_args.push_back(iBuilder->getInt64(b->getBufferSize() - 1));
    159159    }
    160160    for (auto b : outputBuffers) {
    161         init_args.push_back(b->getStreamSetBufferPtr());
    162         init_args.push_back(iBuilder->getInt64(b->getSegmentSize() - 1));
     161        init_args.push_back(b->getStreamSetBasePtr());
     162        init_args.push_back(iBuilder->getInt64(b->getBufferSize() - 1));
    163163    }
    164164    std::string initFnName = mKernelName + init_suffix;
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5097 r5100  
    2121
    2222struct StreamSetBinding {
    23     kernel::StreamSetType ssType;
     23    parabix::StreamSetType ssType;
    2424    std::string ssName;
    2525};
     
    5656   
    5757    llvm::Value * createInstance(std::vector<llvm::Value *> initialParameters);
    58     llvm::Value * createInstance(std::vector<llvm::Value *> initialParameters, std::vector<kernel::StreamSetBuffer *> inputs, std::vector<kernel::StreamSetBuffer *> outputBuffers);
     58    llvm::Value * createInstance(std::vector<llvm::Value *> initialParameters, std::vector<parabix::StreamSetBuffer *> inputs, std::vector<parabix::StreamSetBuffer *> outputBuffers);
    5959    llvm::Value * createDoBlockCall(llvm::Value * kernelInstance);
    6060    llvm::Value * createDoSegmentCall(llvm::Value * kernelInstance, llvm::Value * blkCount);
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5099 r5100  
    190190    }
    191191    iBuilder->restoreIP(savePoint);
    192     doSegmentFunction->dump();
     192    //doSegmentFunction->dump();
    193193}
    194194
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.cpp

    r5097 r5100  
    166166   
    167167    Value * self = getParameter(doBlockFunction, "self");
     168    Value * byteStreamBase_ptr = getScalarField(self, mStreamSetInputs[0].ssName + basePtrSuffix);
     169    Value * basisBitsBase_ptr = getScalarField(self, mStreamSetOutputs[0].ssName + basePtrSuffix);
    168170    Value * blockNo = getScalarField(self, blockNoScalar);
    169     Value * byteStreamBlock_ptr = getCircularBufferBlockPointer(self, mStreamSetInputs[0].ssName, blockNo);
    170     Value * basisBitsBlock_ptr = getCircularBufferBlockPointer(self, mStreamSetOutputs[0].ssName, blockNo);   
     171   
     172   
     173    Value * byteStreamBlock_ptr = mByteStream.getStreamSetBlockPointer(byteStreamBase_ptr, blockNo);
     174    Value * basisBitsBlock_ptr = mBasisBits.getStreamSetBlockPointer(basisBitsBase_ptr, blockNo);
    171175   
    172176    Value * s_bytepack[8];
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.h

    r5074 r5100  
    2424class s2pKernel : public KernelBuilder {
    2525public:
    26     s2pKernel(IDISA::IDISA_Builder * iBuilder) :
     26   
     27    s2pKernel(IDISA::IDISA_Builder * iBuilder, parabix::StreamSetBuffer& byteStream, parabix::StreamSetBuffer& basisBits) :
    2728    KernelBuilder(iBuilder, "s2p",
    28                   {StreamSetBinding{StreamSetType(1, 8), "byteStream"}},
    29                   {StreamSetBinding{StreamSetType(8, 1), "basisBits"}},
    30                   {}, {}, {}) {}
    31 
     29                  {StreamSetBinding{parabix::StreamSetType(1, parabix::i8), "byteStream"}},
     30                  {StreamSetBinding{parabix::StreamSetType(8, parabix::i1), "basisBits"}},
     31                  {}, {}, {}), mByteStream(byteStream), mBasisBits(basisBits) {}
     32   
     33   
    3234private:
     35    parabix::StreamSetBuffer& mByteStream;
     36    parabix::StreamSetBuffer& mBasisBits;
    3337    void generateDoBlockMethod() override;
    3438    void generateFinalBlockMethod() override;
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r5074 r5100  
    1919    scanMatchKernel(IDISA::IDISA_Builder * iBuilder, unsigned scanwordBitWidth, bool isNameExpression) :
    2020    KernelBuilder(iBuilder, "scanMatch",
    21                     {StreamSetBinding{StreamSetType(2, 1), "matchResults"}},
     21                  {StreamSetBinding{parabix::StreamSetType(2, parabix::i1), "matchResults"}},
    2222                    {},
    2323                    {ScalarBinding{iBuilder->getInt8PtrTy(), "FileBuf"}, ScalarBinding{iBuilder->getInt64Ty(), "FileSize"}, ScalarBinding{iBuilder->getInt64Ty(), "FileIdx"}},
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.cpp

    r5097 r5100  
    4141    Value * inputStreamBlock = getCircularBufferBlockPointer(self, "inputStreamSet", blockNo);
    4242
    43     Value * bufferPtr = getParameter(doBlockFunction, "bufferPtr");
     43    Value * bufferPtr = getScalarField(self, "bufferPtr");
    4444    Value * bufferFinalBlockPtr = getScalarField(self, "bufferFinalBlockPtr");
    4545    //iBuilder->CallPrintInt("bufferPtr", iBuilder->CreatePtrToInt(bufferPtr, iBuilder->getInt64Ty()));
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.h

    r5076 r5100  
    1818    stdOutKernel(IDISA::IDISA_Builder * iBuilder, unsigned codeUnitWidth) :
    1919    KernelBuilder(iBuilder, "stdout",
    20                   {StreamSetBinding{StreamSetType(1, codeUnitWidth), "bufferPtr"}}, {}, {}, {}, {}) {
     20                  {StreamSetBinding{StreamSetType(1, codeUnitWidth), "codeUnitBuffer"}}, {}, {}, {}, {}) {
    2121        mStreamType = PointerType::get(StreamSetType(1, codeUnitWidth).getStreamSetBlockType(iBuilder), 0);
    22         mScalarInputs = {ScalarBinding{mStreamType , "bufferBasePtr"}, ScalarBinding{mStreamType, "bufferFinalBlockPtr"}};
     22        mScalarInputs = {ScalarBinding{mStreamType , "bufferPtr"}};
    2323    }
    2424   
     
    2727    void generateDoBlockMethod() override;
    2828    void generateFinalBlockMethod() override;
     29    void generateDoSegmentMethod() override;
    2930   
    3031    llvm::Type * mStreamType;
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5077 r5100  
    1010#include <llvm/IR/Type.h>
    1111   
    12 using namespace kernel;
     12using namespace parabix;
    1313
    1414llvm::Type * StreamSetType::getStreamSetBlockType(IDISA::IDISA_Builder * iBuilder) {
     
    2121}
    2222
    23 llvm::Type * StreamSetBuffer::getStreamSetBufferType() {
    24     if (mSegmentSize == 1) return getStreamSetBlockType();
    25     return ArrayType::get(getStreamSetBlockType(), mSegmentSize);
     23// Single Block Buffer
     24
     25uint64_t SingleBlockBuffer::getBufferSize() {
     26    return 1; //iBuilder->getBitBlockWidth();
    2627}
    2728
    28 llvm::Value * StreamSetBuffer::allocateBuffer() {
    29     if (mStreamSetBufferPtr == nullptr) {
    30         mStreamSetBufferPtr = iBuilder->CreateAlloca(getStreamSetBlockType(), iBuilder->getInt32(mSegmentSize));
    31     }
     29llvm::Value * SingleBlockBuffer::allocateBuffer() {
     30    mStreamSetBufferPtr = iBuilder->CreateAlloca(getStreamSetBlockType());
    3231    return mStreamSetBufferPtr;
    3332}
    3433
    35 llvm::Value * StreamSetBuffer::getBlockPointer(llvm::Value * blockNo) {
    36     if (mSegmentSize == 1) return mStreamSetBufferPtr;
    37     if (mSegmentSize == 0) return
    38         iBuilder->CreateGEP(getStreamSetBlockType(), mStreamSetBufferPtr, {blockNo});
    39     Value * offset = iBuilder->CreateURem(blockNo, iBuilder->getInt64(mSegmentSize));
    40     return iBuilder->CreateGEP(getStreamSetBlockType(), mStreamSetBufferPtr, {offset});
     34// For a single block buffer, the block pointer is always the buffer base pointer.
     35llvm::Value * SingleBlockBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
     36    return bufferBasePtr;
    4137}
    4238
     39
     40// External Unbounded Buffer
     41
     42uint64_t ExternalUnboundedBuffer::getBufferSize() {
     43    return 0;
     44}
     45
     46llvm::Value * ExternalUnboundedBuffer::allocateBuffer() {
     47    throw std::runtime_error("External buffers cannot be allocated.");
     48}
     49
     50llvm::Value * ExternalUnboundedBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
     51    return iBuilder->CreateGEP(getStreamSetBlockType(), bufferBasePtr, {blockNo});
     52}
     53
     54
     55// Circular Stack Allocated Buffer
     56
     57uint64_t CircularBuffer::getBufferSize() {
     58    return mBufferBlocks; // * iBuilder->getBitBlockWidth();
     59}
     60
     61llvm::Value * CircularBuffer::allocateBuffer() {
     62    mStreamSetBufferPtr = iBuilder->CreateAlloca(getStreamSetBlockType(), iBuilder->getInt64(mBufferBlocks));
     63    return mStreamSetBufferPtr;
     64}
     65
     66llvm::Value * CircularBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
     67    return iBuilder->CreateGEP(getStreamSetBlockType(), bufferBasePtr, {iBuilder->CreateAnd(blockNo, iBuilder->getInt64(mBufferBlocks-1))});
     68}
     69
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5085 r5100  
    1212#include <llvm/IR/Type.h>
    1313   
    14 namespace kernel {
     14namespace parabix {
     15   
     16enum FieldType {i1 = 1, i2 = 2, i4 = 4, i8 = 8, i16 = 16, i32 = 32, i64 = 64, i128 = 128, i256 = 256};
    1517
    1618class StreamSetType {
     
    2931class StreamSetBuffer {
    3032public:
    31     StreamSetBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type, unsigned SegmentSize) :
    32     iBuilder(b), mStreamSetType(ss_type), mSegmentSize(SegmentSize), mStreamSetBufferPtr(nullptr) {
    33         if (((SegmentSize - 1) & SegmentSize) != 0) {
    34             throw std::runtime_error("Segment size must be a power of 2!");
     33    enum class BufferKind : unsigned {BlockBuffer, ExternalUnboundedBuffer, CircularBuffer, ExpandingBuffer};
     34    inline BufferKind getBufferKind() const {return mBufferKind;}
     35   
     36    llvm::Type * getStreamSetBlockType();
     37
     38    virtual uint64_t getBufferSize() = 0;
     39   
     40    virtual llvm::Value * allocateBuffer() = 0;
     41   
     42    llvm::Value * getStreamSetBasePtr() {return mStreamSetBufferPtr;}
     43   
     44    // Get the buffer pointer for a given block of the stream.
     45    virtual llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) = 0;
     46   
     47   
     48   
     49protected:
     50    StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, StreamSetType ss_type) :
     51        mBufferKind(k), iBuilder(b), mStreamSetType(ss_type), mBufferBlocks(1), mAddrSpace(0), mStreamSetBufferPtr(nullptr) {
     52    }
     53    const BufferKind       mBufferKind;
     54    IDISA::IDISA_Builder * iBuilder;
     55    StreamSetType mStreamSetType;
     56    uint64_t mBufferBlocks;
     57    int mAddrSpace;
     58    llvm::Value * mStreamSetBufferPtr;
     59
     60};   
     61   
     62
     63class SingleBlockBuffer : public StreamSetBuffer {
     64public:
     65    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::BlockBuffer;}
     66   
     67    SingleBlockBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type) :
     68    StreamSetBuffer(BufferKind::BlockBuffer, b, ss_type) {}
     69   
     70    uint64_t getBufferSize() override;
     71    llvm::Value * allocateBuffer() override;
     72    llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) override;
     73};
     74   
     75class ExternalUnboundedBuffer : public StreamSetBuffer {
     76public:
     77    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::ExternalUnboundedBuffer;}
     78   
     79    ExternalUnboundedBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type) :
     80        StreamSetBuffer(BufferKind::ExternalUnboundedBuffer, b, ss_type) {
     81            mBufferBlocks = 0;
    3582        }
    36     }
    37 
    38     llvm::Type * getStreamSetBlockType();
    39    
    40     llvm::Type * getStreamSetBufferType();
    4183   
    4284    void setStreamSetBuffer(llvm::Value * ptr) {mStreamSetBufferPtr = ptr;}
    4385   
    44     llvm::Value * allocateBuffer();
    45    
    46     llvm::Value * getStreamSetBufferPtr() {return mStreamSetBufferPtr;}
    47    
    48     unsigned getSegmentSize() { return mSegmentSize; }
     86    uint64_t getBufferSize() override;
     87    // Can't allocate - raise an error. */
     88    llvm::Value * allocateBuffer() override;
     89    llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) override;
     90};
    4991
    50     llvm::Value * getBlockPointer(llvm::Value * blockNo);
    51    
    52 private:
    53     IDISA::IDISA_Builder * iBuilder;
    54     StreamSetType mStreamSetType;
    55     unsigned mSegmentSize;
    56     llvm::Value * mStreamSetBufferPtr;
    57    
     92class CircularBuffer : public StreamSetBuffer {
     93public:
     94    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::CircularBuffer;}
     95 
     96    CircularBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type, uint64_t bufferBlocks) :
     97        StreamSetBuffer(BufferKind::CircularBuffer, b, ss_type) {
     98            mBufferBlocks = bufferBlocks;
     99            if (((bufferBlocks - 1) & bufferBlocks) != 0) {
     100                throw std::runtime_error("CircularStreamSetBuffer: number of blocks must be a power of 2!");
     101            }
     102        }
    58103
     104    uint64_t getBufferSize() override;
     105    llvm::Value * allocateBuffer() override;
     106    llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) override;
    59107};
     108
    60109}
    61110#endif // STREAMSET_H
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp

    r5096 r5100  
    1111using namespace pablo;
    1212using namespace kernel;
     13using namespace parabix;
    1314
    1415PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder,
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5088 r5100  
    3030#include <IDISA/idisa_builder.h>
    3131#include <IDISA/idisa_target.h>
     32#include <kernels/streamset.h>
    3233#include <kernels/interface.h>
    3334#include <kernels/kernel.h>
     
    138139
    139140using namespace kernel;
     141using namespace parabix;
    140142
    141143
     
    143145    Type * mBitBlockType = iBuilder->getBitBlockType();
    144146   
    145     s2pKernel  s2pk(iBuilder);
     147    ExternalUnboundedBuffer ByteStream(iBuilder, StreamSetType(1, i8));
     148    SingleBlockBuffer BasisBits(iBuilder, StreamSetType(8, i1));
     149   
     150    s2pKernel  s2pk(iBuilder, ByteStream, BasisBits);
    146151    std::unique_ptr<Module> s2pM = s2pk.createKernelModule();
    147152    pablo_function_passes(function);
     
    170175   
    171176    iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", main,0));
    172     kernel::StreamSetBuffer ByteStream(iBuilder, kernel::StreamSetType(1, 8), 0);
    173     kernel::StreamSetBuffer BasisBits(iBuilder, kernel::StreamSetType(8, 1), codegen::SegmentSize);
    174177
    175178    ByteStream.setStreamSetBuffer(inputStream);
Note: See TracChangeset for help on using the changeset viewer.