Ignore:
Timestamp:
Oct 8, 2016, 7:33:08 PM (3 years ago)
Author:
cameron
Message:

Linear buffers; stdout_kernel; cache-aligned alloca, restructured u8u16, clean-ups

File:
1 edited

Legend:

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

    r5184 r5185  
    3030};
    3131
     32   
     33// Stream Set Structs hold information about the current state
     34// of a stream set buffer.
     35   
     36llvm::Value * getProducerPosPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);   
     37llvm::Value * getConsumerPosPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);
     38llvm::Value * hasEndOfInputPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);   
     39llvm::Value * getStreamSetBufferPtr(IDISA::IDISA_Builder * b, Value * bufferStructPtr);   
     40   
    3241class StreamSetBuffer {
    3342public:
    34     enum class BufferKind : unsigned {BlockBuffer, ExternalFileBuffer, CircularBuffer, ExpandingBuffer};
     43    enum class BufferKind : unsigned {BlockBuffer, ExternalFileBuffer, CircularBuffer, LinearBuffer, ExpandingBuffer};
    3544    inline BufferKind getBufferKind() const {return mBufferKind;}
    3645    inline StreamSetType& getBufferStreamSetType() {return mStreamSetType;}
     
    3847    llvm::PointerType * getStreamBufferPointerType();
    3948
    40     virtual size_t getBufferSize() = 0;
     49    size_t getBufferSize() { return mBufferBlocks;}
    4150   
    42     virtual llvm::Value * allocateBuffer() = 0;
     51    virtual llvm::Value * allocateBuffer();
    4352   
    4453    llvm::Value * getStreamSetBasePtr() {return mStreamSetBufferPtr;}
    4554   
    4655    // Get the buffer pointer for a given block of the stream.
    47     virtual llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) = 0;
     56    virtual llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) = 0;
    4857   
    49     virtual llvm::Value * getProducerPosPtr(Value * ptr);
     58    llvm::Value * getProducerPosPtr(Value * bufferStructPtr);
    5059
    51     virtual void setProducerPos(Value * ptr, Value * pos);
     60    void setProducerPos(Value * bufferStructPtr, Value * pos);
    5261
    53     virtual llvm::Value * getConsumerPosPtr(Value * ptr);
     62    llvm::Value * getConsumerPosPtr(Value * bufferStructPtr);
    5463
    55     virtual void setConsumerPos(Value * ptr, Value * pos);
     64    virtual void setConsumerPos(Value * bufferStructPtr, Value * pos);
    5665
    57     virtual llvm::Value * hasEndOfInputPtr(Value * ptr);
     66    llvm::Value * hasEndOfInputPtr(Value * bufferStructPtr);
    5867
    59     virtual void setEndOfInput(Value * ptr);
     68    void setEndOfInput(Value * bufferStructPtr);
     69   
     70    llvm::Value * getStreamSetBufferPtrPtr(Value * bufferStructPtr);
    6071
    6172    virtual llvm::PointerType * getStreamSetStructPointerType();
     
    6475   
    6576protected:
    66     StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, StreamSetType ss_type, int AddressSpace = 0) :
    67         mBufferKind(k), iBuilder(b), mStreamSetType(ss_type), mBufferBlocks(1), mAddrSpace(AddressSpace), mStreamSetBufferPtr(nullptr) {
     77    StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, StreamSetType ss_type, unsigned blocks, unsigned AddressSpace = 0) :
     78        mBufferKind(k), iBuilder(b), mStreamSetType(ss_type), mBufferBlocks(blocks), mAddrSpace(AddressSpace), mStreamSetBufferPtr(nullptr) {
    6879            mStreamSetStructType =
    6980                StructType::get(iBuilder->getContext(),
     
    7889    StreamSetType mStreamSetType;
    7990    size_t mBufferBlocks;
    80     int mAddrSpace;
     91    unsigned mAddrSpace;
    8192    llvm::Value * mStreamSetBufferPtr;
    8293    llvm::Value * mStreamSetStructPtr;
     
    90101   
    91102    SingleBlockBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type) :
    92     StreamSetBuffer(BufferKind::BlockBuffer, b, ss_type, 0) { }
    93    
    94     size_t getBufferSize() override;
    95     llvm::Value * allocateBuffer() override;
    96     llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) override;
     103    StreamSetBuffer(BufferKind::BlockBuffer, b, ss_type, 1, 0) {}
     104    llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) override;
    97105};
    98106   
     
    101109    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::ExternalFileBuffer;}
    102110   
    103     ExternalFileBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type, int AddressSpace = 0) :
    104         StreamSetBuffer(BufferKind::ExternalFileBuffer, b, ss_type, AddressSpace) {}
     111    ExternalFileBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type, unsigned AddressSpace = 0) :
     112        StreamSetBuffer(BufferKind::ExternalFileBuffer, b, ss_type, 0, AddressSpace) {}
    105113
    106114    void setStreamSetBuffer(llvm::Value * ptr, llvm::Value * fileSize);
    107115   
    108     size_t getBufferSize() override;
    109116    // Can't allocate - raise an error. */
    110117    llvm::Value * allocateBuffer() override;
    111     llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) override;
     118    llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) override;
    112119
    113120};
     
    117124    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::CircularBuffer;}
    118125 
    119     CircularBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type, size_t bufferBlocks) :
    120         StreamSetBuffer(BufferKind::CircularBuffer, b, ss_type) {
    121             mBufferBlocks = bufferBlocks;
     126    CircularBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type, size_t bufferBlocks, unsigned AddressSpace = 0) :
     127        StreamSetBuffer(BufferKind::CircularBuffer, b, ss_type, bufferBlocks, AddressSpace) {
    122128            if (((bufferBlocks - 1) & bufferBlocks) != 0) {
    123129                throw std::runtime_error("CircularStreamSetBuffer: number of blocks must be a power of 2!");
    124130            }
    125131        }
    126 
    127     size_t getBufferSize() override;
    128     llvm::Value * allocateBuffer() override;
    129     llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) override;
     132    llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) override;
    130133};
     134   
     135// Linear buffers extending from the current ConsumerPos forward.   Within the buffer, the
     136// offset of the block containing the current consumer position is always zero.
     137//
     138class LinearBuffer : public StreamSetBuffer {
     139public:
     140    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::LinearBuffer;}
     141   
     142    LinearBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type, size_t bufferBlocks, unsigned AddressSpace = 0) :
     143        StreamSetBuffer(BufferKind::CircularBuffer, b, ss_type, bufferBlocks, AddressSpace) {}
     144   
     145    llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferStructPtr, llvm::Value * blockNo) override;
     146   
     147    // Reset the buffer to contain data starting at the base block of new_consumer_pos,
     148    // copying back any data beyond that position.
     149    void setConsumerPos(Value * bufferStructPtr, Value * new_consumer_pos) override;
     150};
     151   
     152   
    131153
    132154}
Note: See TracChangeset for help on using the changeset viewer.