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

Last change on this file since 6297 was 6274, checked in by nmedfort, 8 months ago

Fixed cycle counter logic and moved counters into pipeline struct

File size: 6.8 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;
13    friend class MultiBlockKernel;
14    friend class PipelineGenerator;
15public:
16
17    // Get the value of a scalar field for the current instance.
18    llvm::Value * getScalarFieldPtr(llvm::Value * index);
19
20    llvm::Value * getScalarFieldPtr(const llvm::StringRef fieldName);
21
22    llvm::Value * getScalarField(const llvm::StringRef fieldName);
23
24    // Set the value of a scalar field for the current instance.
25    void setScalarField(const llvm::StringRef fieldName, llvm::Value * value);
26
27    llvm::Value * getAvailableItemCount(const llvm::StringRef name) {
28        return mKernel->getAvailableInputItems(name);
29    }
30
31    llvm::Value * getAccessibleItemCount(const llvm::StringRef name) {
32        return mKernel->getAccessibleInputItems(name);
33    }
34
35    llvm::Value * getProcessedItemCount(const llvm::StringRef name);
36
37    void setProcessedItemCount(const llvm::StringRef name, llvm::Value * value);
38
39    llvm::Value * getProducedItemCount(const llvm::StringRef name);
40
41    void setProducedItemCount(const llvm::StringRef name, llvm::Value * value);
42
43    llvm::Value * getConsumedItemCount(const llvm::StringRef name) const;
44
45    llvm::Value * getTerminationSignal();
46
47    void setTerminationSignal() { setTerminationSignal(getTrue()); }
48
49    void setTerminationSignal(llvm::Value * const value);
50
51    // Run-time access of Kernel State and parameters of methods for
52    // use in implementing kernels.
53
54    llvm::Value * getInputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex) {
55        return getInputStreamBlockPtr(name, streamIndex, nullptr);
56    }
57
58    llvm::Value * getInputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * blockOffset);
59
60    llvm::Value * getInputStreamLogicalBasePtr(const Binding & input);
61
62    llvm::Value * loadInputStreamBlock(const std::string & name, llvm::Value * streamIndex) {
63        return loadInputStreamBlock(name, streamIndex, nullptr);
64    }
65
66    llvm::Value * loadInputStreamBlock(const std::string & name, llvm::Value * streamIndex, llvm::Value * blockOffset);
67
68    llvm::Value * getInputStreamPackPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex) {
69        return getInputStreamPackPtr(name, streamIndex, packIndex, nullptr);
70    }
71
72    llvm::Value * getInputStreamPackPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex, llvm::Value * blockOffset);
73
74    llvm::Value * loadInputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex) {
75        return loadInputStreamPack(name, streamIndex, packIndex, nullptr);
76    }
77
78    llvm::Value * loadInputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex, llvm::Value * blockOffset);
79
80    llvm::Value * getInputStreamSetCount(const std::string & name);
81
82    llvm::Value * getOutputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex) {
83        return getOutputStreamBlockPtr(name, streamIndex, nullptr);
84    }
85
86    llvm::Value * getOutputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * blockOffset);
87
88    llvm::Value * getOutputStreamLogicalBasePtr(const Binding & output);
89
90    llvm::StoreInst * storeOutputStreamBlock(const std::string & name, llvm::Value * streamIndex, llvm::Value * toStore) {
91        return storeOutputStreamBlock(name, streamIndex, nullptr, toStore);
92    }
93
94    llvm::StoreInst * storeOutputStreamBlock(const std::string & name, llvm::Value * streamIndex, llvm::Value * blockOffset, llvm::Value * toStore);
95
96    llvm::Value * getOutputStreamPackPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex) {
97        return getOutputStreamPackPtr(name, streamIndex, packIndex, nullptr);
98    }
99
100    llvm::Value * getOutputStreamPackPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex, llvm::Value * blockOffset);
101
102    llvm::StoreInst * storeOutputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex, llvm::Value * toStore) {
103        return storeOutputStreamPack(name, streamIndex, packIndex, nullptr, toStore);
104    }
105
106    llvm::StoreInst * storeOutputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex, llvm::Value * blockOffset, llvm::Value * toStore);
107
108    llvm::Value * getOutputStreamSetCount(const std::string & name);
109
110    llvm::Value * getRawInputPointer(const std::string & name, llvm::Value * absolutePosition);
111
112    llvm::Value * getRawOutputPointer(const std::string & name, llvm::Value * absolutePosition);
113
114    llvm::Value * getBaseAddress(const std::string & name);
115
116    void setBaseAddress(const std::string & name, llvm::Value * addr);
117
118    llvm::Value * getCapacity(const std::string & name);
119
120    void setCapacity(const std::string & name, llvm::Value * capacity);
121
122    llvm::CallInst * createDoSegmentCall(const std::vector<llvm::Value *> & args);
123
124    const Kernel * getKernel() const {
125        return mKernel;
126    }
127
128    void setKernel(const Kernel * const kernel) {
129        mKernel = kernel;
130    }
131
132    // overloading wrongly subsitutes this for CBuilder function. renamed for now until I can investigate why.
133    llvm::Value * CreateUDiv2(llvm::Value * const number, const ProcessingRate::RateValue & divisor, const llvm::Twine & Name = "");
134
135    llvm::Value * CreateCeilUDiv2(llvm::Value * const number, const ProcessingRate::RateValue & divisor, const llvm::Twine & Name = "");
136
137    llvm::Value * CreateMul2(llvm::Value * const number, const ProcessingRate::RateValue & factor, const llvm::Twine & Name = "");
138
139    llvm::Value * CreateCeilUMul2(llvm::Value * const number, const ProcessingRate::RateValue & factor, const llvm::Twine & Name = "");
140
141    unsigned getStride() const {
142        return mStride;
143    }
144
145protected:
146
147    KernelBuilder(llvm::LLVMContext & C, unsigned nativeVectorWidth, unsigned vectorWidth, unsigned laneWidth)
148    : IDISA::IDISA_Builder(C, nativeVectorWidth, vectorWidth, laneWidth)
149    , mStride(vectorWidth)
150    , mKernel(nullptr) {
151
152    }
153
154    const unsigned mStride;
155
156    std::string getKernelName() const final;
157
158protected:
159    const Kernel * mKernel;
160
161};
162
163template <class SpecifiedArchitectureBuilder>
164class KernelBuilderImpl final : public KernelBuilder, public SpecifiedArchitectureBuilder {
165public:
166    KernelBuilderImpl(llvm::LLVMContext & C, unsigned vectorWidth, unsigned laneWidth)
167    : IDISA::IDISA_Builder(C, SpecifiedArchitectureBuilder::NativeBitBlockWidth, vectorWidth, laneWidth)
168    , KernelBuilder(C, SpecifiedArchitectureBuilder::NativeBitBlockWidth, vectorWidth, laneWidth)
169    , SpecifiedArchitectureBuilder(C, vectorWidth, laneWidth) {
170
171    }
172};
173
174}
175
176#endif // KERNEL_BUILDER_H
Note: See TracBrowser for help on using the repository browser.