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

Last change on this file since 5830 was 5830, checked in by nmedfort, 15 months ago

UntilN kernel rewritten to use new MultiBlock? system

File size: 6.9 KB
RevLine 
[5435]1#ifndef KERNEL_BUILDER_H
2#define KERNEL_BUILDER_H
3
4#include <IR_Gen/idisa_builder.h>
[5706]5#include <kernels/kernel.h>
[5435]6
7namespace kernel {
8
9class Kernel;
10
11class KernelBuilder : public virtual IDISA::IDISA_Builder {
[5706]12    friend class Kernel;
[5435]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
[5706]38    llvm::Value * getProducedItemCount(const std::string & name) {
39        return getInternalItemCount(name, Kernel::PRODUCED_ITEM_COUNT_SUFFIX);
40    }
[5435]41
[5706]42    void setProducedItemCount(const std::string & name, llvm::Value * value) {
43        setInternalItemCount(name, Kernel::PRODUCED_ITEM_COUNT_SUFFIX, value);
44    }
[5435]45
[5755]46    llvm::Value * getProcessedItemCount(const std::string & name) {       
[5706]47        return getInternalItemCount(name, Kernel::PROCESSED_ITEM_COUNT_SUFFIX);
48    }
[5435]49
[5706]50    void setProcessedItemCount(const std::string & name, llvm::Value * value) {
51        setInternalItemCount(name, Kernel::PROCESSED_ITEM_COUNT_SUFFIX, value);
52    }
[5435]53
[5706]54    llvm::Value * getConsumedItemCount(const std::string & name) {
55        return getInternalItemCount(name, Kernel::CONSUMED_ITEM_COUNT_SUFFIX);
56    }
[5435]57
[5706]58    void setConsumedItemCount(const std::string & name, llvm::Value * value) {
59        setInternalItemCount(name, Kernel::CONSUMED_ITEM_COUNT_SUFFIX, value);
60    }
[5435]61
62    llvm::Value * getTerminationSignal();
63
[5706]64    void setTerminationSignal() { setTerminationSignal(getTrue()); }
[5435]65
[5706]66    void setTerminationSignal(llvm::Value * const value);
67
68    llvm::Value * getCycleCountPtr();
69
[5435]70    // Run-time access of Kernel State and parameters of methods for
71    // use in implementing kernels.
72
[5830]73    llvm::Value * getInputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex) {
74        return getInputStreamBlockPtr(name, streamIndex, getInt32(0));
75    }
[5435]76
[5830]77    llvm::Value * getInputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * blockOffset);
78
[5435]79    llvm::Value * loadInputStreamBlock(const std::string & name, llvm::Value * streamIndex);
80
81    llvm::Value * getInputStreamPackPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex);
82
83    llvm::Value * loadInputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex);
84
85    llvm::Value * getInputStreamSetCount(const std::string & name);
86
[5830]87    llvm::Value * getOutputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex) {
88        return getOutputStreamBlockPtr(name, streamIndex, getInt32(0));
89    }
[5435]90
[5830]91    llvm::Value * getOutputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * blockOffset);
92
[5493]93    llvm::StoreInst * storeOutputStreamBlock(const std::string & name, llvm::Value * streamIndex, llvm::Value * toStore);
[5435]94
95    llvm::Value * getOutputStreamPackPtr(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex);
96
[5493]97    llvm::StoreInst * storeOutputStreamPack(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex, llvm::Value * toStore);
[5435]98
99    llvm::Value * getOutputStreamSetCount(const std::string & name);
100
[5706]101    llvm::Value * getRawInputPointer(const std::string & name, llvm::Value * absolutePosition);
[5435]102
[5706]103    llvm::Value * getRawOutputPointer(const std::string & name, llvm::Value * absolutePosition);
[5435]104
105    llvm::Value * getBaseAddress(const std::string & name);
106
[5755]107    llvm::Value * getBlockAddress(const std::string & name, llvm::Value * const blockIndex);
108
[5435]109    void setBaseAddress(const std::string & name, llvm::Value * addr);
110
111    llvm::Value * getBufferedSize(const std::string & name);
[5501]112   
[5435]113    void setBufferedSize(const std::string & name, llvm::Value * size);
[5501]114   
115    llvm::Value * getCapacity(const std::string & name);
116   
117    void setCapacity(const std::string & name, llvm::Value * c);
118   
[5435]119    llvm::Value * getAvailableItemCount(const std::string & name);
120
[5650]121    llvm::Value * getLinearlyAccessibleItems(const std::string & name, llvm::Value * fromPos, llvm::Value * avail, bool reverse = false);
[5501]122   
[5650]123    llvm::Value * getLinearlyWritableItems(const std::string & name, llvm::Value * fromPos, bool reverse = false);
[5501]124   
[5755]125    void CreateStreamCpy(const std::string & name, llvm::Value * const target, llvm::Value * const targetOffset, llvm::Value * const source, llvm::Value * const sourceOffset, llvm::Value * const itemsToCopy, const unsigned itemAlignment);
[5706]126
[5440]127    llvm::BasicBlock * CreateConsumerWait();
[5435]128
[5706]129    llvm::Value * getStreamHandle(const std::string & name);
[5435]130
[5440]131    llvm::CallInst * createDoSegmentCall(const std::vector<llvm::Value *> & args);
132
133    llvm::Value * getAccumulator(const std::string & accumName);
134
135    llvm::Value * getConsumerLock(const std::string & name);
136
137    void setConsumerLock(const std::string & name, llvm::Value * value);
138
[5446]139    const Kernel * getKernel() const {
[5435]140        return mKernel;
141    }
142
[5446]143    void setKernel(const Kernel * const kernel) {
[5435]144        mKernel = kernel;
145    }
146
[5755]147    void protectOutputStream(const std::string & name, const bool readOnly);
148
[5435]149protected:
150
[5489]151    KernelBuilder(llvm::LLVMContext & C, unsigned vectorWidth, unsigned stride)
152    : IDISA::IDISA_Builder(C, vectorWidth, stride)
[5454]153    , mKernel(nullptr) {
[5435]154
155    }
156
[5440]157    llvm::Value * getScalarFieldPtr(llvm::Value * instance, llvm::Value * index);
[5435]158
[5440]159    llvm::Value * getScalarFieldPtr(llvm::Value * instance, const std::string & fieldName);
[5435]160
[5706]161    llvm::Value * getInternalItemCount(const std::string & name, const std::string & suffix);
162
163    void setInternalItemCount(const std::string & name, const std::string & suffix, llvm::Value * const value);
164
[5435]165protected:
[5446]166    const Kernel * mKernel;
[5435]167};
168
[5436]169template <class SpecifiedArchitectureBuilder>
170class KernelBuilderImpl final : public KernelBuilder, public SpecifiedArchitectureBuilder {
[5435]171public:
[5489]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) {
[5435]176
177    }
178};
179
180}
181
182#endif // KERNEL_BUILDER_H
Note: See TracBrowser for help on using the repository browser.