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

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

Continued refactoring work.

File size: 5.1 KB
Line 
1#ifndef KERNEL_BUILDER_H
2#define KERNEL_BUILDER_H
3
4#include <kernels/interface.h>
5#include <IR_Gen/idisa_builder.h>
6
7namespace kernel {
8
9class Kernel;
10
11class KernelBuilder : public virtual IDISA::IDISA_Builder {
12public:
13
14    // Get the value of a scalar field for the current instance.
15    llvm::Value * getScalarFieldPtr(llvm::Value * index);
16
17    llvm::Value * getScalarFieldPtr(const std::string & fieldName);
18
19    llvm::Value * getScalarField(const std::string & fieldName);
20
21    // Set the value of a scalar field for the current instance.
22    void setScalarField(const std::string & fieldName, llvm::Value * value);
23
24    // Synchronization actions for executing a kernel for a particular logical segment.
25    //
26    // Before the segment is processed, acquireLogicalSegmentNo must be used to load
27    // the segment number of the kernel state to ensure that the previous segment is
28    // complete (by checking that the acquired segment number is equal to the desired segment
29    // number).
30    // After all segment processing actions for the kernel are complete, and any necessary
31    // data has been extracted from the kernel for further pipeline processing, the
32    // segment number must be incremented and stored using releaseLogicalSegmentNo.
33    llvm::LoadInst * acquireLogicalSegmentNo();
34
35    void releaseLogicalSegmentNo(llvm::Value * nextSegNo);
36
37    llvm::Value * getProducedItemCount(const std::string & name, llvm::Value * doFinal = nullptr);
38
39    void setProducedItemCount(const std::string & name, llvm::Value * value);
40
41    llvm::Value * getProcessedItemCount(const std::string & name);
42
43    void setProcessedItemCount(const std::string & name, llvm::Value * value);
44
45    llvm::Value * getConsumedItemCount(const std::string & name);
46
47    void setConsumedItemCount(const std::string & name, llvm::Value * value);
48
49    llvm::Value * getTerminationSignal();
50
51    void setTerminationSignal();
52
53    // Run-time access of Kernel State and parameters of methods for
54    // use in implementing kernels.
55
56    // Get the index of a named scalar field within the kernel state struct.
57    llvm::ConstantInt * getScalarIndex(const std::string & name);
58
59    llvm::Value * getInputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex);
60
61    llvm::Value * loadInputStreamBlock(const std::string & name, llvm::Value * streamIndex);
62
63    llvm::Value * getInputStreamPackPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex);
64
65    llvm::Value * loadInputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex);
66
67    llvm::Value * getInputStreamSetCount(const std::string & name);
68
69    llvm::Value * getOutputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex);
70
71    void storeOutputStreamBlock(const std::string & name, llvm::Value * streamIndex, llvm::Value * toStore);
72
73    llvm::Value * getOutputStreamPackPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex);
74
75    void storeOutputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex, llvm::Value * toStore);
76
77    llvm::Value * getOutputStreamSetCount(const std::string & name);
78
79    llvm::Value * getAdjustedInputStreamBlockPtr(llvm::Value * blockAdjustment, const std::string & name, llvm::Value * streamIndex);
80
81    llvm::Value * getRawInputPointer(const std::string & name, llvm::Value * streamIndex, llvm::Value * absolutePosition);
82
83    llvm::Value * getRawOutputPointer(const std::string & name, llvm::Value * streamIndex, llvm::Value * absolutePosition);
84
85    llvm::Value * getBaseAddress(const std::string & name);
86
87    void setBaseAddress(const std::string & name, llvm::Value * addr);
88
89    llvm::Value * getBufferedSize(const std::string & name);
90
91    void setBufferedSize(const std::string & name, llvm::Value * size);
92
93    llvm::Value * getAvailableItemCount(const std::string & name);
94
95    llvm::Value * getLinearlyAccessibleItems(const std::string & name, llvm::Value * fromPosition);
96
97    llvm::BasicBlock * CreateWaitForConsumers();
98
99    llvm::Value * getStreamSetBufferPtr(const std::string & name);
100
101    Kernel * getKernel() const {
102        return mKernel;
103    }
104
105    void setKernel(Kernel * const kernel) {
106        mKernel = kernel;
107    }
108
109protected:
110
111    KernelBuilder(llvm::Module * const module, unsigned registerWidth, unsigned blockWidth, unsigned stride)
112    : IDISA::IDISA_Builder(module, registerWidth, blockWidth, stride) {
113
114    }
115
116private:
117
118    llvm::Value * getConsumerLock(const std::string & name);
119
120    void setConsumerLock(const std::string & name, llvm::Value * value);
121
122    llvm::Value * computeBlockIndex(llvm::Value * itemCount);
123
124protected:
125    Kernel * mKernel;
126};
127
128template <class IBuilder>
129class KernelBuilderImpl final : public KernelBuilder, public IBuilder {
130public:
131    KernelBuilderImpl(llvm::Module * const module, unsigned registerWidth, unsigned blockWidth, unsigned stride)
132    : IDISA::IDISA_Builder(module, registerWidth, blockWidth, stride)
133    , KernelBuilder(module, registerWidth, blockWidth, stride)
134    , IBuilder(module, registerWidth, blockWidth, stride) {
135
136    }
137};
138
139}
140
141#endif // KERNEL_BUILDER_H
Note: See TracBrowser for help on using the repository browser.