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

Last change on this file since 5276 was 5276, checked in by cameron, 2 years ago

Elimination of StreamSetStructs? wrapping StreamSetBuffers?

File size: 5.4 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   
17class StreamSetBuffer {
18    friend class kernel::KernelBuilder;
19
20public:
21
22    enum class BufferKind : unsigned {BlockBuffer, ExternalFileBuffer, CircularBuffer, LinearCopybackBuffer, ExpandableBuffer};
23
24    inline BufferKind getBufferKind() const {
25        return mBufferKind;
26    }
27
28    inline llvm::Type * getBufferStreamSetType() const {
29        return mStreamSetType;
30    }
31
32    llvm::PointerType * getStreamBufferPointerType() const {
33        return mStreamSetType->getPointerTo(mAddrSpace);
34    }
35
36    size_t getBufferSize() const { return mBufferBlocks; }
37
38    llvm::Value * getStreamSetBasePtr() const { return mStreamSetBufferPtr; }
39
40    virtual void allocateBuffer();
41
42    virtual llvm::Value * getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const;
43
44    virtual llvm::Value * getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index1, llvm::Value * index2) const;
45   
46    virtual llvm::Value * getStreamView(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const;
47
48    virtual llvm::Value * getStreamView(llvm::Type * type, llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const;
49
50    llvm::Type * resolveStreamTypes(llvm::Type * type);
51   
52protected:
53
54    StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, llvm::Type * type, unsigned blocks, unsigned AddressSpace);
55
56    // Get the buffer pointer for a given block of the stream.
57    virtual llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const = 0;
58
59protected:
60    const BufferKind                mBufferKind;
61    IDISA::IDISA_Builder * const    iBuilder;
62    llvm::Type * const              mStreamSetType;
63    const size_t                    mBufferBlocks;
64    const int                       mAddrSpace;
65    llvm::Value *                   mStreamSetBufferPtr;
66};   
67
68class SingleBlockBuffer : public StreamSetBuffer {
69public:
70    static inline bool classof(const StreamSetBuffer * b) {
71        return b->getBufferKind() == BufferKind::BlockBuffer;
72    }   
73
74    SingleBlockBuffer(IDISA::IDISA_Builder * b, llvm::Type * type);
75
76protected:
77    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
78};
79
80class ExternalFileBuffer : public StreamSetBuffer {
81public:
82    static inline bool classof(const StreamSetBuffer * b) {
83        return b->getBufferKind() == BufferKind::ExternalFileBuffer;
84    }
85   
86    ExternalFileBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0);
87
88    void setStreamSetBuffer(llvm::Value * ptr, llvm::Value * fileSize);
89
90    void setEmptyBuffer(llvm::Value * buffer_ptr);
91
92    // Can't allocate - raise an error. */
93    void allocateBuffer() override;
94
95protected:
96    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
97};
98   
99class CircularBuffer : public StreamSetBuffer {
100public:
101    static inline bool classof(const StreamSetBuffer * b) {
102        return b->getBufferKind() == BufferKind::CircularBuffer;
103    }
104 
105    CircularBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
106
107protected:
108    llvm::Value * getStreamSetPtr(llvm::Value * bufferBasePtr, llvm::Value * blockNo) const override;
109};
110   
111// Linear buffers extending from the current ConsumerPos forward.   Within the buffer, the
112// offset of the block containing the current consumer position is always zero.
113//
114class LinearCopybackBuffer : public StreamSetBuffer {
115public:
116    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::LinearCopybackBuffer;}
117   
118    LinearCopybackBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
119
120    // Reset the buffer to contain data starting at the base block of new_consumer_pos,
121    // copying back any data beyond that position.
122    //void setConsumerPos(llvm::Value * self, llvm::Value * newConsumerPos) const override;
123
124protected:
125    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
126};
127
128// ExpandableBuffers do not allow access to the base stream set but will automatically increase the number of streams
129// within their set whenever the index exceeds its capacity
130//
131class ExpandableBuffer : public StreamSetBuffer {
132public:
133    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::ExpandableBuffer;}
134
135    ExpandableBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
136
137    llvm::Value * getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const override;
138
139    llvm::Value * getStream(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index1, llvm::Value * index2) const override;
140
141    llvm::Value * getStreamView(llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const override;
142
143    llvm::Value * getStreamView(llvm::Type * type, llvm::Value * self, llvm::Value * blockNo, llvm::Value * index) const override;
144
145protected:
146
147    llvm::Value * getStreamSetPtr(llvm::Value * self, llvm::Value * blockNo) const override;
148};
149
150}
151#endif // STREAMSET_H
Note: See TracBrowser for help on using the repository browser.