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

Last change on this file since 5489 was 5489, checked in by nmedfort, 22 months ago

Bug fix for memory check and issues found parsing internal 'files'. Added backtrace option from execinfo.h

File size: 5.2 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    void 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    void 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 * getAvailableItemCount(const std::string & name);
91
92    llvm::Value * getLinearlyAccessibleItems(const std::string & name, llvm::Value * fromPosition);
93
94    llvm::BasicBlock * CreateConsumerWait();
95
96    llvm::Value * getStreamSetBufferPtr(const std::string & name);
97
98    llvm::CallInst * createDoSegmentCall(const std::vector<llvm::Value *> & args);
99
100    llvm::Value * getAccumulator(const std::string & accumName);
101
102    llvm::Value * getConsumerLock(const std::string & name);
103
104    void setConsumerLock(const std::string & name, llvm::Value * value);
105
106    const Kernel * getKernel() const {
107        return mKernel;
108    }
109
110    void setKernel(const Kernel * const kernel) {
111        mKernel = kernel;
112    }
113
114protected:
115
116    KernelBuilder(llvm::LLVMContext & C, unsigned vectorWidth, unsigned stride)
117    : IDISA::IDISA_Builder(C, vectorWidth, stride)
118    , mKernel(nullptr) {
119
120    }
121
122    llvm::Value * getScalarFieldPtr(llvm::Value * instance, llvm::Value * index);
123
124    llvm::Value * getScalarFieldPtr(llvm::Value * instance, const std::string & fieldName);
125
126private:
127
128    llvm::Value * computeBlockIndex(llvm::Value * itemCount);
129
130protected:
131    const Kernel * mKernel;
132};
133
134template <class SpecifiedArchitectureBuilder>
135class KernelBuilderImpl final : public KernelBuilder, public SpecifiedArchitectureBuilder {
136public:
137    KernelBuilderImpl(llvm::LLVMContext & C, unsigned vectorWidth, unsigned stride)
138    : IDISA::IDISA_Builder(C, vectorWidth, stride)
139    , KernelBuilder(C, vectorWidth, stride)
140    , SpecifiedArchitectureBuilder(C, vectorWidth, stride) {
141
142    }
143};
144
145}
146
147#endif // KERNEL_BUILDER_H
Note: See TracBrowser for help on using the repository browser.