Ignore:
Timestamp:
Jan 14, 2017, 3:49:56 PM (2 years ago)
Author:
nmedfort
Message:

Changes working towards simplifying accessing stream elements + some modifications to simplify include / forward declarations within the CodeGen? library.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5246 r5260  
    77#define STREAMSET_H
    88
    9 #include <string>
    10 #include <vector>
    11 #include <IR_Gen/idisa_builder.h>
    12 #include <llvm/IR/Type.h>
     9#include <llvm/IR/Type.h>  // for Type
     10namespace IDISA { class IDISA_Builder; }
     11namespace llvm { class PointerType; }
     12namespace llvm { class Value; }
     13namespace kernel { class KernelBuilder; }
    1314
    1415namespace parabix {
    1516   
    16 enum FieldType {i1 = 1, i2 = 2, i4 = 4, i8 = 8, i16 = 16, i32 = 32, i64 = 64, i128 = 128, i256 = 256};
    17 
    1817// Stream Set Structs hold information about the current state of a stream set buffer.
    1918
    20 llvm::Value * getProducerPosPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
    21 llvm::Value * getConsumerPosPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
    22 llvm::Value * getEndOfInputPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
    23 llvm::Value * getStreamSetBufferPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
     19llvm::Value * getProducerPosPtr(IDISA::IDISA_Builder * b, llvm::Value * self);
     20llvm::Value * getConsumerPosPtr(IDISA::IDISA_Builder * b, llvm::Value * self);
     21llvm::Value * getEndOfInputPtr(IDISA::IDISA_Builder * b, llvm::Value * self);
     22llvm::Value * getStreamSetBufferPtr(IDISA::IDISA_Builder * b, llvm::Value * self);
    2423
    2524class StreamSetBuffer {
     25    friend class kernel::KernelBuilder;
     26
    2627public:
    2728
    28     enum class BufferKind : unsigned {BlockBuffer, ExternalFileBuffer, CircularBuffer, LinearCopybackBuffer};
     29    enum class BufferKind : unsigned {BlockBuffer, ExternalFileBuffer, CircularBuffer, LinearCopybackBuffer, ExpandableBuffer};
    2930
    3031    inline BufferKind getBufferKind() const {
     
    4546
    4647    size_t getBufferSize() const { return mBufferBlocks; }
    47        
     48
    4849    llvm::Value * getStreamSetBasePtr() const { return mStreamSetBufferPtr; }
    49    
     50
    5051    llvm::Value * getStreamSetStructPtr() const { return mStreamSetStructPtr; }
    5152
    5253    virtual void allocateBuffer();
    5354
    54     // Get the buffer pointer for a given block of the stream.
    55     virtual llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) = 0;
     55    virtual llvm::Value * getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const;
     56
     57    virtual llvm::Value * getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index1, llvm::Value * index2) const;
    5658   
    57     llvm::Value * getProducerPosPtr(Value * bufferStructPtr);
     59    virtual llvm::Value * getStreamView(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const;
    5860
    59     void setProducerPos(Value * bufferStructPtr, Value * pos);
     61    virtual llvm::Value * getStreamView(llvm::Type * type, llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const;
    6062
    61     llvm::Value * getConsumerPosPtr(Value * bufferStructPtr);
     63    llvm::Value * getProducerPosPtr(llvm::Value * self) const;
    6264
    63     virtual void setConsumerPos(Value * bufferStructPtr, Value * pos);
     65    void setProducerPos(llvm::Value * self, llvm::Value * pos) const;
    6466
    65     llvm::Value * getEndOfInputPtr(Value * bufferStructPtr);
     67    llvm::Value * getConsumerPosPtr(llvm::Value * self) const;
    6668
    67     void setEndOfInput(Value * bufferStructPtr);
     69    virtual void setConsumerPos(llvm::Value * self, llvm::Value * pos) const;
     70
     71    llvm::Value * getEndOfInputPtr(llvm::Value * self) const;
     72
     73    void setEndOfInput(llvm::Value * self) const;
    6874   
    69     llvm::Type * resolveStreamTypes(llvm::Type * type) {
    70         if (auto ty = dyn_cast<ArrayType>(type)) {
    71             unsigned numElems = ty->getNumElements();
    72             auto elemTy = ty->getElementType();
    73             if (isa<IDISA::StreamType>(elemTy)) {
    74                 return ArrayType::get(cast<IDISA::StreamType>(elemTy)->resolveType(iBuilder), numElems);
    75             }
    76         }
    77         else if (auto ty = dyn_cast<IDISA::StreamType>(type)) {
    78             return ty->resolveType(iBuilder);
    79         }
    80         return type;
    81     }
     75    llvm::Type * resolveStreamTypes(llvm::Type * type);
    8276   
    8377protected:
    84     StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, llvm::Type * type, unsigned blocks, unsigned AddressSpace = 0)
    85     : mBufferKind(k)
    86     , iBuilder(b)
    87     , mStreamSetType(resolveStreamTypes(type))
    88     , mBufferBlocks(blocks)
    89     , mAddrSpace(AddressSpace)
    90     , mStreamSetBufferPtr(nullptr)
    91     , mStreamSetStructPtr(nullptr)
    92     , mStreamSetStructType(StructType::get(b->getContext(),
    93                             {{b->getSizeTy(),
    94                               b->getSizeTy(),
    95                               b->getInt1Ty(),
    96                               PointerType::get(mStreamSetType, AddressSpace)}})) {
    9778
    98     }
     79    StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, llvm::Type * type, unsigned blocks, unsigned AddressSpace);
     80
     81    // Get the buffer pointer for a given block of the stream.
     82    virtual llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const = 0;
     83
    9984protected:
    100     const BufferKind        mBufferKind;
    101     IDISA::IDISA_Builder * iBuilder;
    102     llvm::Type * const      mStreamSetType;
    103     size_t                  mBufferBlocks;
    104     int                     mAddrSpace;
    105     llvm::Value *           mStreamSetBufferPtr;
    106     llvm::Value *           mStreamSetStructPtr;
    107     llvm::Type * const      mStreamSetStructType;
     85    const BufferKind                mBufferKind;
     86    IDISA::IDISA_Builder * const    iBuilder;
     87    llvm::Type * const              mStreamSetType;
     88    const size_t                    mBufferBlocks;
     89    const int                       mAddrSpace;
     90    llvm::Value *                   mStreamSetBufferPtr;
     91    llvm::Value *                   mStreamSetStructPtr;
     92    llvm::Type * const              mStreamSetStructType;
    10893};   
    10994
     
    11398        return b->getBufferKind() == BufferKind::BlockBuffer;
    11499    }   
    115     SingleBlockBuffer(IDISA::IDISA_Builder * b, llvm::Type * type)
    116     : StreamSetBuffer(BufferKind::BlockBuffer, b, type, 1, 0) {
    117100
    118     }
    119     llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) override;
     101    SingleBlockBuffer(IDISA::IDISA_Builder * b, llvm::Type * type);
     102
     103protected:
     104    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
    120105};
    121106
     
    126111    }
    127112   
    128     ExternalFileBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0)
    129     : StreamSetBuffer(BufferKind::ExternalFileBuffer, b, type, 0, AddressSpace) {
    130 
    131     }
     113    ExternalFileBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0);
    132114
    133115    void setStreamSetBuffer(llvm::Value * ptr, llvm::Value * fileSize);
     116
    134117    void setEmptyBuffer(llvm::Value * buffer_ptr);
    135118
     
    137120    void allocateBuffer() override;
    138121
    139     llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) override;
     122protected:
     123    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
    140124};
    141125   
     
    146130    }
    147131 
    148     CircularBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0)
    149     : StreamSetBuffer(BufferKind::CircularBuffer, b, type, bufferBlocks, AddressSpace) {
     132    CircularBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
    150133
    151     }
    152 
    153     llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) override;
     134protected:
     135    llvm::Value * getStreamSetPtr(llvm::Value * bufferBasePtr, llvm::Value * blockNo) const override;
    154136};
    155137   
     
    161143    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::LinearCopybackBuffer;}
    162144   
    163     LinearCopybackBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0) :
    164         StreamSetBuffer(BufferKind::LinearCopybackBuffer, b, type, bufferBlocks, AddressSpace) {}
    165    
    166     llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) override;
    167    
     145    LinearCopybackBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
     146
    168147    // Reset the buffer to contain data starting at the base block of new_consumer_pos,
    169148    // copying back any data beyond that position.
    170     void setConsumerPos(Value * bufferStructPtr, Value * newConsumerPos) override;
     149    void setConsumerPos(llvm::Value * self, llvm::Value * newConsumerPos) const override;
     150
     151protected:
     152    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
     153};
     154
     155// ExpandableBuffers do not allow access to the base stream set but will automatically increase the number of streams
     156// within their set whenever the index exceeds its capacity
     157//
     158class ExpandableBuffer : public StreamSetBuffer {
     159public:
     160    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::ExpandableBuffer;}
     161
     162    ExpandableBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
     163
     164    llvm::Value * getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const override;
     165
     166    llvm::Value * getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index1, llvm::Value * index2) const override;
     167
     168    llvm::Value * getStreamView(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const override;
     169
     170    llvm::Value * getStreamView(llvm::Type * type, llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const override;
     171
     172protected:
     173
     174    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
    171175};
    172176
Note: See TracChangeset for help on using the changeset viewer.