source: icGREP/icgrep-devel/icgrep/kernels/streamset.h @ 5340

Last change on this file since 5340 was 5340, checked in by nmedfort, 3 years ago

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.

File size: 6.5 KB
RevLine 
[5044]1/*
2 *  Copyright (c) 2016 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
[4986]6#ifndef STREAMSET_H
7#define STREAMSET_H
8
[5260]9#include <llvm/IR/Type.h>  // for Type
10namespace IDISA { class IDISA_Builder; }
11namespace llvm { class Value; }
12namespace kernel { class KernelBuilder; }
[5191]13
[5100]14namespace parabix {
15   
[5044]16class StreamSetBuffer {
[5260]17    friend class kernel::KernelBuilder;
18
[5044]19public:
[5202]20
[5301]21    enum class BufferKind : unsigned {BlockBuffer, ExternalFileBuffer, CircularBuffer, CircularCopybackBuffer, ExpandableBuffer};
[5202]22
[5297]23    BufferKind getBufferKind() const {
[5217]24        return mBufferKind;
25    }
[5133]26
[5297]27    llvm::Type * getType() const {
[5307]28        return mType;
[5217]29    }
[5202]30
[5297]31    llvm::Type * getBaseType() const {
[5307]32        return mBaseType;
[5217]33    }
[4986]34
[5297]35    llvm::PointerType * getPointerType() const {
36        return getType()->getPointerTo(mAddressSpace);
37    }
[5260]38
[5301]39    size_t getBufferBlocks() const {
40        return mBufferBlocks;
[5297]41    }
[5260]42
[5297]43    llvm::Value * getStreamSetBasePtr() const {
44        return mStreamSetBufferPtr;
45    }
[5317]46   
[5217]47    virtual void allocateBuffer();
48
[5340]49    virtual llvm::Value * getStreamBlockPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const;
[5260]50
[5340]51    virtual llvm::Value * getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex, const bool readOnly) const;
[5044]52   
[5329]53    virtual llvm::Value * getStreamSetCount(llvm::Value * self) const;
54
[5307]55    llvm::Value * getRawItemPointer(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
[5135]56
[5301]57    // The number of items that cam be linearly accessed from a given logical stream position.
58    virtual llvm::Value * getLinearlyAccessibleItems(llvm::Value * fromPosition) const;
59   
[5217]60protected:
[5135]61
[5320]62    StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, llvm::Type * baseType, llvm::Type * resolvedType, unsigned blocks, unsigned AddressSpace);
[5260]63
64    // Get the buffer pointer for a given block of the stream.
[5317]65    virtual llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockNo) const = 0;
[5260]66
[5202]67protected:
[5260]68    const BufferKind                mBufferKind;
69    IDISA::IDISA_Builder * const    iBuilder;
[5307]70    llvm::Type * const              mType;
[5301]71    const size_t                    mBufferBlocks;
[5297]72    const unsigned                  mAddressSpace;
[5260]73    llvm::Value *                   mStreamSetBufferPtr;
[5307]74    llvm::Type * const              mBaseType;
[5100]75};   
[4986]76
[5100]77class SingleBlockBuffer : public StreamSetBuffer {
78public:
[5202]79    static inline bool classof(const StreamSetBuffer * b) {
80        return b->getBufferKind() == BufferKind::BlockBuffer;
81    }   
82
[5260]83    SingleBlockBuffer(IDISA::IDISA_Builder * b, llvm::Type * type);
84
85protected:
[5317]86    llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockNo) const override;
[5044]87};
[5202]88
[5142]89class ExternalFileBuffer : public StreamSetBuffer {
[5100]90public:
[5202]91    static inline bool classof(const StreamSetBuffer * b) {
92        return b->getBufferKind() == BufferKind::ExternalFileBuffer;
93    }
[5100]94   
[5260]95    ExternalFileBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0);
[5123]96
[5260]97    void setStreamSetBuffer(llvm::Value * ptr, llvm::Value * fileSize);
[5202]98
[5190]99    void setEmptyBuffer(llvm::Value * buffer_ptr);
[5202]100
[5100]101    // Can't allocate - raise an error. */
[5217]102    void allocateBuffer() override;
103
[5301]104    llvm::Value * getLinearlyAccessibleItems(llvm::Value * fromPosition) const override;
105   
[5260]106protected:
[5317]107    llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockNo) const override;
[5100]108};
[5191]109   
[5100]110class CircularBuffer : public StreamSetBuffer {
111public:
[5202]112    static inline bool classof(const StreamSetBuffer * b) {
113        return b->getBufferKind() == BufferKind::CircularBuffer;
114    }
[5301]115   
[5260]116    CircularBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
[5217]117
[5260]118protected:
[5317]119    llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockIndex) const override;
[5100]120};
[5185]121   
[5301]122
[5185]123//
[5301]124//  A CircularCopybackBuffer operates as a circular buffer buffer with an overflow area
125//  for temporary use by the kernel that writes to it.   If the kernel uses the overflow
126//  area, it must perform the doCopyBack action before releasing the buffer for use by
127//  subsequent kernels.
128//  Kernels that read from a CircularCopybackBuffer must not access the overflow area.
129//
130class CircularCopybackBuffer : public StreamSetBuffer {
[5185]131public:
[5301]132    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::CircularCopybackBuffer;}
[5185]133   
[5301]134    CircularCopybackBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, size_t overflowBlocks, unsigned AddressSpace = 0);
[5260]135
[5301]136    void allocateBuffer() override;
137   
138    // Generate copyback code for the given number of overflowItems.
[5303]139    void createCopyBack(llvm::Value * self, llvm::Value * overflowItems) const;
[5301]140   
141   
142protected:
[5317]143    llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockIndex) const override;
[5301]144private:
145    size_t mOverflowBlocks;
[5260]146
[5185]147};
[5100]148
[5260]149// ExpandableBuffers do not allow access to the base stream set but will automatically increase the number of streams
150// within their set whenever the index exceeds its capacity
151//
[5320]152// ExpandableBuffers do not allow access to the base stream set but will automatically increase the number of streams
153// within their set whenever the index exceeds its capacity
154//
[5260]155class ExpandableBuffer : public StreamSetBuffer {
156public:
157    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::ExpandableBuffer;}
158
159    ExpandableBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
160
[5340]161    llvm::Value * getStreamBlockPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const override;
[5260]162
[5340]163    llvm::Value * getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex, const bool readOnly) const override;
[5260]164
[5301]165    llvm::Value * getLinearlyAccessibleItems(llvm::Value * fromPosition) const override;
[5320]166
167    void allocateBuffer() override;
168
[5329]169    llvm::Value * getStreamSetCount(llvm::Value * self) const override;
170
[5260]171protected:
172
[5320]173    llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockIndex) const override;
[5311]174
[5320]175private:
176
[5340]177    bool isGuaranteedCapacity(const llvm::Value * const index) const;
[5320]178
[5340]179    std::pair<llvm::Value *, llvm::Value *> getInternalStreamBuffer(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const;
180
[5320]181private:
182
183    const uint64_t  mInitialCapacity;
184
[5260]185};
186
[4986]187}
188#endif // STREAMSET_H
Note: See TracBrowser for help on using the repository browser.