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

Last change on this file since 5123 was 5123, checked in by cameron, 3 years ago

Including addrSpace as part of basePtr type

File size: 3.9 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 <string>
10#include <vector>
11#include <IDISA/idisa_builder.h>
12#include <llvm/IR/Type.h>
13   
14namespace parabix {
15   
16enum FieldType {i1 = 1, i2 = 2, i4 = 4, i8 = 8, i16 = 16, i32 = 32, i64 = 64, i128 = 128, i256 = 256};
17
18class StreamSetType {
19public:
20    StreamSetType(int count, int width) : mStreamCount(count), mFieldWidth(width) {}
21    int StreamCount() { return mStreamCount;}
22    int StreamFieldWidth() { return mFieldWidth;}
23   
24    llvm::Type * getStreamSetBlockType(IDISA::IDISA_Builder * iBuilder);
25   
26private:
27    int mStreamCount;
28    int mFieldWidth;
29};
30
31class StreamSetBuffer {
32public:
33    enum class BufferKind : unsigned {BlockBuffer, ExternalUnboundedBuffer, CircularBuffer, ExpandingBuffer};
34    inline BufferKind getBufferKind() const {return mBufferKind;}
35   
36    virtual llvm::PointerType * getStreamBufferPointerType();
37
38    virtual size_t getBufferSize() = 0;
39   
40    virtual llvm::Value * allocateBuffer() = 0;
41   
42    llvm::Value * getStreamSetBasePtr() {return mStreamSetBufferPtr;}
43   
44    // Get the buffer pointer for a given block of the stream.
45    virtual llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) = 0;
46   
47   
48   
49protected:
50    StreamSetBuffer(BufferKind k, IDISA::IDISA_Builder * b, StreamSetType ss_type) :
51        mBufferKind(k), iBuilder(b), mStreamSetType(ss_type), mBufferBlocks(1), mAddrSpace(0), mStreamSetBufferPtr(nullptr) {
52    }
53    const BufferKind       mBufferKind;
54    IDISA::IDISA_Builder * iBuilder;
55    StreamSetType mStreamSetType;
56    size_t mBufferBlocks;
57    int mAddrSpace;
58    llvm::Value * mStreamSetBufferPtr;
59
60};   
61   
62
63class SingleBlockBuffer : public StreamSetBuffer {
64public:
65    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::BlockBuffer;}
66   
67    SingleBlockBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type) :
68    StreamSetBuffer(BufferKind::BlockBuffer, b, ss_type) {}
69   
70    size_t getBufferSize() override;
71    llvm::Value * allocateBuffer() override;
72    llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) override;
73};
74   
75class ExternalUnboundedBuffer : public StreamSetBuffer {
76public:
77    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::ExternalUnboundedBuffer;}
78   
79    ExternalUnboundedBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type, unsigned AddressSpace = 0) :
80        StreamSetBuffer(BufferKind::ExternalUnboundedBuffer, b, ss_type) {
81            mBufferBlocks = 0;
82            mAddrSpace = AddressSpace;
83        }
84    llvm::PointerType * getStreamBufferPointerType() override;
85
86    void setStreamSetBuffer(llvm::Value * ptr);
87   
88    size_t getBufferSize() override;
89    // Can't allocate - raise an error. */
90    llvm::Value * allocateBuffer() override;
91    llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) override;
92
93private:
94    unsigned mAddrSpace;
95};
96
97class CircularBuffer : public StreamSetBuffer {
98public:
99    static inline bool classof(const StreamSetBuffer * b) {return b->getBufferKind() == BufferKind::CircularBuffer;}
100 
101    CircularBuffer(IDISA::IDISA_Builder * b, StreamSetType ss_type, size_t bufferBlocks) :
102        StreamSetBuffer(BufferKind::CircularBuffer, b, ss_type) {
103            mBufferBlocks = bufferBlocks;
104            if (((bufferBlocks - 1) & bufferBlocks) != 0) {
105                throw std::runtime_error("CircularStreamSetBuffer: number of blocks must be a power of 2!");
106            }
107        }
108
109    size_t getBufferSize() override;
110    llvm::Value * allocateBuffer() override;
111    llvm::Value * getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) override;
112};
113
114}
115#endif // STREAMSET_H
Note: See TracBrowser for help on using the repository browser.