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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.