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

Last change on this file since 5513 was 5501, checked in by cameron, 2 years ago

setCapacity/getCapacity/getLinearlyAvailableItems for SourceBuffer?

File size: 5.7 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    llvm::Value * getInputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex);
57
58    llvm::Value * loadInputStreamBlock(const std::string & name, llvm::Value * streamIndex);
59
60    llvm::Value * getInputStreamPackPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex);
61
62    llvm::Value * loadInputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex);
63
64    llvm::Value * getInputStreamSetCount(const std::string & name);
65
66    llvm::Value * getOutputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex);
67
68    llvm::StoreInst * storeOutputStreamBlock(const std::string & name, llvm::Value * streamIndex, llvm::Value * toStore);
69
70    llvm::Value * getOutputStreamPackPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex);
71
72    llvm::StoreInst * storeOutputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex, llvm::Value * toStore);
73
74    llvm::Value * getOutputStreamSetCount(const std::string & name);
75
76    llvm::Value * getAdjustedInputStreamBlockPtr(llvm::Value * blockAdjustment, const std::string & name, llvm::Value * streamIndex);
77
78    llvm::Value * getRawInputPointer(const std::string & name, llvm::Value * streamIndex, llvm::Value * absolutePosition);
79
80    llvm::Value * getRawOutputPointer(const std::string & name, llvm::Value * streamIndex, llvm::Value * absolutePosition);
81
82    llvm::Value * getBaseAddress(const std::string & name);
83
84    void setBaseAddress(const std::string & name, llvm::Value * addr);
85
86    llvm::Value * getBufferedSize(const std::string & name);
87   
88    void setBufferedSize(const std::string & name, llvm::Value * size);
89   
90    llvm::Value * getCapacity(const std::string & name);
91   
92    void setCapacity(const std::string & name, llvm::Value * c);
93   
94    llvm::Value * getAvailableItemCount(const std::string & name);
95
96    llvm::Value * getLinearlyAccessibleItems(const std::string & name, llvm::Value * fromPosition);
97   
98    llvm::Value * getLinearlyAccessibleBlocks(const std::string & name, llvm::Value * fromBlock);
99   
100    llvm::Value * getLinearlyWritableItems(const std::string & name, llvm::Value * fromPosition);
101   
102    llvm::Value * getLinearlyWritableBlocks(const std::string & name, llvm::Value * fromBlock);
103   
104    llvm::BasicBlock * CreateConsumerWait();
105
106    llvm::Value * getStreamSetBufferPtr(const std::string & name);
107
108    llvm::CallInst * createDoSegmentCall(const std::vector<llvm::Value *> & args);
109
110    llvm::Value * getAccumulator(const std::string & accumName);
111
112    llvm::Value * getConsumerLock(const std::string & name);
113
114    void setConsumerLock(const std::string & name, llvm::Value * value);
115
116    const Kernel * getKernel() const {
117        return mKernel;
118    }
119
120    void setKernel(const Kernel * const kernel) {
121        mKernel = kernel;
122    }
123
124protected:
125
126    KernelBuilder(llvm::LLVMContext & C, unsigned vectorWidth, unsigned stride)
127    : IDISA::IDISA_Builder(C, vectorWidth, stride)
128    , mKernel(nullptr) {
129
130    }
131
132    llvm::Value * getScalarFieldPtr(llvm::Value * instance, llvm::Value * index);
133
134    llvm::Value * getScalarFieldPtr(llvm::Value * instance, const std::string & fieldName);
135
136private:
137
138    llvm::Value * computeBlockIndex(llvm::Value * itemCount);
139
140protected:
141    const Kernel * mKernel;
142};
143
144template <class SpecifiedArchitectureBuilder>
145class KernelBuilderImpl final : public KernelBuilder, public SpecifiedArchitectureBuilder {
146public:
147    KernelBuilderImpl(llvm::LLVMContext & C, unsigned vectorWidth, unsigned stride)
148    : IDISA::IDISA_Builder(C, vectorWidth, stride)
149    , KernelBuilder(C, vectorWidth, stride)
150    , SpecifiedArchitectureBuilder(C, vectorWidth, stride) {
151
152    }
153};
154
155}
156
157#endif // KERNEL_BUILDER_H
Note: See TracBrowser for help on using the repository browser.