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

Last change on this file since 5260 was 5260, checked in by nmedfort, 2 years ago

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

File size: 6.5 KB
Line 
1/*
2 *  Copyright (c) 2016 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
6#ifndef STREAMSET_H
7#define STREAMSET_H
8
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; }
14
15namespace parabix {
16   
17// Stream Set Structs hold information about the current state of a stream set buffer.
18
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);
23
24class StreamSetBuffer {
25    friend class kernel::KernelBuilder;
26
27public:
28
29    enum class BufferKind : unsigned {BlockBuffer, ExternalFileBuffer, CircularBuffer, LinearCopybackBuffer, ExpandableBuffer};
30
31    inline BufferKind getBufferKind() const {
32        return mBufferKind;
33    }
34
35    inline llvm::Type * getBufferStreamSetType() const {
36        return mStreamSetType;
37    }
38
39    llvm::PointerType * getStreamBufferPointerType() const {
40        return mStreamSetType->getPointerTo(mAddrSpace);
41    }
42
43    llvm::PointerType * getStreamSetStructPointerType() const {
44        return mStreamSetStructType->getPointerTo();
45    }
46
47    size_t getBufferSize() const { return mBufferBlocks; }
48
49    llvm::Value * getStreamSetBasePtr() const { return mStreamSetBufferPtr; }
50
51    llvm::Value * getStreamSetStructPtr() const { return mStreamSetStructPtr; }
52
53    virtual void allocateBuffer();
54
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;
58   
59    virtual llvm::Value * getStreamView(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const;
60
61    virtual llvm::Value * getStreamView(llvm::Type * type, llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const;
62
63    llvm::Value * getProducerPosPtr(llvm::Value * self) const;
64
65    void setProducerPos(llvm::Value * self, llvm::Value * pos) const;
66
67    llvm::Value * getConsumerPosPtr(llvm::Value * self) const;
68
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;
74   
75    llvm::Type * resolveStreamTypes(llvm::Type * type);
76   
77protected:
78
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
84protected:
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;
93};   
94
95class SingleBlockBuffer : public StreamSetBuffer {
96public:
97    static inline bool classof(const StreamSetBuffer * b) {
98        return b->getBufferKind() == BufferKind::BlockBuffer;
99    }   
100
101    SingleBlockBuffer(IDISA::IDISA_Builder * b, llvm::Type * type);
102
103protected:
104    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
105};
106
107class ExternalFileBuffer : public StreamSetBuffer {
108public:
109    static inline bool classof(const StreamSetBuffer * b) {
110        return b->getBufferKind() == BufferKind::ExternalFileBuffer;
111    }
112   
113    ExternalFileBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0);
114
115    void setStreamSetBuffer(llvm::Value * ptr, llvm::Value * fileSize);
116
117    void setEmptyBuffer(llvm::Value * buffer_ptr);
118
119    // Can't allocate - raise an error. */
120    void allocateBuffer() override;
121
122protected:
123    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
124};
125   
126class CircularBuffer : public StreamSetBuffer {
127public:
128    static inline bool classof(const StreamSetBuffer * b) {
129        return b->getBufferKind() == BufferKind::CircularBuffer;
130    }
131 
132    CircularBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
133
134protected:
135    llvm::Value * getStreamSetPtr(llvm::Value * bufferBasePtr, llvm::Value * blockNo) const override;
136};
137   
138// Linear buffers extending from the current ConsumerPos forward.   Within the buffer, the
139// offset of the block containing the current consumer position is always zero.
140//
141class LinearCopybackBuffer : public StreamSetBuffer {
142public:
143    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::LinearCopybackBuffer;}
144   
145    LinearCopybackBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
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(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;
175};
176
177}
178#endif // STREAMSET_H
Note: See TracBrowser for help on using the repository browser.