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

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

Partial removal of BlockNo?

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