source: icGREP/icgrep-devel/icgrep/kernels/kernel_builder.h @ 5706

Last change on this file since 5706 was 5706, checked in by nmedfort, 20 months ago

First stage of MultiBlockKernel? and pipeline restructuring

File size: 6.7 KB
Line 
1#ifndef KERNEL_BUILDER_H
2#define KERNEL_BUILDER_H
3
4#include <IR_Gen/idisa_builder.h>
5#include <kernels/kernel.h>
6
7namespace kernel {
8
9class Kernel;
10
11class KernelBuilder : public virtual IDISA::IDISA_Builder {
12    friend class Kernel;
13public:
14
15    // Get the value of a scalar field for the current instance.
16    llvm::Value * getScalarFieldPtr(llvm::Value * index);
17
18    llvm::Value * getScalarFieldPtr(const std::string & fieldName);
19
20    llvm::Value * getScalarField(const std::string & fieldName);
21
22    // Set the value of a scalar field for the current instance.
23    void setScalarField(const std::string & fieldName, llvm::Value * value);
24
25    // Synchronization actions for executing a kernel for a particular logical segment.
26    //
27    // Before the segment is processed, acquireLogicalSegmentNo must be used to load
28    // the segment number of the kernel state to ensure that the previous segment is
29    // complete (by checking that the acquired segment number is equal to the desired segment
30    // number).
31    // After all segment processing actions for the kernel are complete, and any necessary
32    // data has been extracted from the kernel for further pipeline processing, the
33    // segment number must be incremented and stored using releaseLogicalSegmentNo.
34    llvm::LoadInst * acquireLogicalSegmentNo();
35
36    void releaseLogicalSegmentNo(llvm::Value * nextSegNo);
37
38    llvm::Value * getProducedItemCount(const std::string & name) {
39        return getInternalItemCount(name, Kernel::PRODUCED_ITEM_COUNT_SUFFIX);
40    }
41
42    void setProducedItemCount(const std::string & name, llvm::Value * value) {
43        setInternalItemCount(name, Kernel::PRODUCED_ITEM_COUNT_SUFFIX, value);
44    }
45
46    llvm::Value * getProcessedItemCount(const std::string & name) {
47        return getInternalItemCount(name, Kernel::PROCESSED_ITEM_COUNT_SUFFIX);
48    }
49
50    void setProcessedItemCount(const std::string & name, llvm::Value * value) {
51        setInternalItemCount(name, Kernel::PROCESSED_ITEM_COUNT_SUFFIX, value);
52    }
53
54    llvm::Value * getConsumedItemCount(const std::string & name) {
55        return getInternalItemCount(name, Kernel::CONSUMED_ITEM_COUNT_SUFFIX);
56    }
57
58    void setConsumedItemCount(const std::string & name, llvm::Value * value) {
59        setInternalItemCount(name, Kernel::CONSUMED_ITEM_COUNT_SUFFIX, value);
60    }
61
62    llvm::Value * getTerminationSignal();
63
64    void setTerminationSignal() { setTerminationSignal(getTrue()); }
65
66    void setTerminationSignal(llvm::Value * const value);
67
68    llvm::Value * getCycleCountPtr();
69
70    // Run-time access of Kernel State and parameters of methods for
71    // use in implementing kernels.
72
73    llvm::Value * getInputStreamPtr(const std::string & name, llvm::Value * const blockIndex);
74
75    llvm::Value * getInputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex);
76
77    llvm::Value * loadInputStreamBlock(const std::string & name, llvm::Value * streamIndex);
78
79    llvm::Value * getInputStreamPackPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex);
80
81    llvm::Value * loadInputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex);
82
83    llvm::Value * getInputStreamSetCount(const std::string & name);
84
85    llvm::Value * getOutputStreamPtr(const std::string & name, llvm::Value * const blockIndex);
86
87    llvm::Value * getOutputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex);
88
89    llvm::StoreInst * storeOutputStreamBlock(const std::string & name, llvm::Value * streamIndex, llvm::Value * toStore);
90
91    llvm::Value * getOutputStreamPackPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex);
92
93    llvm::StoreInst * storeOutputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex, llvm::Value * toStore);
94
95    llvm::Value * getOutputStreamSetCount(const std::string & name);
96
97    llvm::Value * getAdjustedInputStreamBlockPtr(llvm::Value * blockAdjustment, const std::string & name, llvm::Value * streamIndex);
98
99    llvm::Value * getRawInputPointer(const std::string & name, llvm::Value * absolutePosition);
100
101    llvm::Value * getRawOutputPointer(const std::string & name, llvm::Value * absolutePosition);
102
103    llvm::Value * getBaseAddress(const std::string & name);
104
105    void CreateCopyBack(const std::string & name, llvm::Value * from, llvm::Value * to);
106
107    void setBaseAddress(const std::string & name, llvm::Value * addr);
108
109    llvm::Value * getBufferedSize(const std::string & name);
110   
111    void setBufferedSize(const std::string & name, llvm::Value * size);
112   
113    llvm::Value * getCapacity(const std::string & name);
114   
115    void setCapacity(const std::string & name, llvm::Value * c);
116   
117    llvm::Value * getAvailableItemCount(const std::string & name);
118
119    llvm::Value * getLinearlyAccessibleItems(const std::string & name, llvm::Value * fromPos, llvm::Value * avail, bool reverse = false);
120   
121    llvm::Value * getLinearlyWritableItems(const std::string & name, llvm::Value * fromPos, bool reverse = false);
122   
123    llvm::Value * copy(const std::string & name, llvm::Value * target, llvm::Value * source, llvm::Value * itemsToCopy, const unsigned alignment = 0);
124
125    llvm::BasicBlock * CreateConsumerWait();
126
127    llvm::Value * getStreamHandle(const std::string & name);
128
129    llvm::CallInst * createDoSegmentCall(const std::vector<llvm::Value *> & args);
130
131    llvm::Value * getAccumulator(const std::string & accumName);
132
133    llvm::Value * getConsumerLock(const std::string & name);
134
135    void setConsumerLock(const std::string & name, llvm::Value * value);
136
137    const Kernel * getKernel() const {
138        return mKernel;
139    }
140
141    void setKernel(const Kernel * const kernel) {
142        mKernel = kernel;
143    }
144
145protected:
146
147    KernelBuilder(llvm::LLVMContext & C, unsigned vectorWidth, unsigned stride)
148    : IDISA::IDISA_Builder(C, vectorWidth, stride)
149    , mKernel(nullptr) {
150
151    }
152
153    llvm::Value * getScalarFieldPtr(llvm::Value * instance, llvm::Value * index);
154
155    llvm::Value * getScalarFieldPtr(llvm::Value * instance, const std::string & fieldName);
156
157    llvm::Value * getInternalItemCount(const std::string & name, const std::string & suffix);
158
159    void setInternalItemCount(const std::string & name, const std::string & suffix, llvm::Value * const value);
160
161private:
162
163    llvm::Value * computeBlockIndex(llvm::Value * itemCount);
164
165protected:
166    const Kernel * mKernel;
167};
168
169template <class SpecifiedArchitectureBuilder>
170class KernelBuilderImpl final : public KernelBuilder, public SpecifiedArchitectureBuilder {
171public:
172    KernelBuilderImpl(llvm::LLVMContext & C, unsigned vectorWidth, unsigned stride)
173    : IDISA::IDISA_Builder(C, vectorWidth, stride)
174    , KernelBuilder(C, vectorWidth, stride)
175    , SpecifiedArchitectureBuilder(C, vectorWidth, stride) {
176
177    }
178};
179
180}
181
182#endif // KERNEL_BUILDER_H
Note: See TracBrowser for help on using the repository browser.