source: icGREP/icgrep-devel/icgrep/kernels/kernel.h @ 4991

Last change on this file since 4991 was 4991, checked in by nmedfort, 3 years ago

Symbol table work and untested kernel instatiate method for multiple input streams

File size: 6.5 KB
RevLine 
[4924]1#ifndef KERNEL_H
2#define KERNEL_H
3/*
4 *  Copyright (c) 2016 International Characters.
5 *  This software is licensed to the public under the Open Software License 3.0.
6 */
7
[4959]8#include <string>
9#include <vector>
[4970]10#include <boost/container/flat_map.hpp>
[4924]11
12namespace llvm {
13    class Value;
14    class Module;
15    class ExecutionEngine;
16    class VectorType;
17    class PointerType;
18    class Constant;
19    class FunctionType;
20    class Function;
21    class BasicBlock;
22    class Type;
23}
24
[4959]25namespace pablo {
26    class PabloAST;
27    class PabloFunction;
28}
[4926]29
[4959]30namespace IDISA {
31    class IDISA_Builder;
32}
[4926]33
[4974]34namespace kernel {
35
36class Instance;
37
[4959]38class KernelBuilder {
[4974]39    friend class Instance;
40    friend llvm::Function * generateScanWordRoutine(llvm::Module *, IDISA::IDISA_Builder *, unsigned, KernelBuilder *, bool);
[4970]41    using NameMap = boost::container::flat_map<std::string, unsigned>;
[4924]42public:
43    // sets name & sets internal state to the kernel superclass state
[4986]44    KernelBuilder(std::string name, llvm::Module * m, IDISA::IDISA_Builder * b, const unsigned bufferSize = 1);
[4924]45
[4970]46    unsigned addInternalState(llvm::Type * const type);
[4974]47    unsigned addInternalState(llvm::Type * const type, std::string && name);
[4970]48
49    void addInputStream(const unsigned fields);
[4974]50    void addInputStream(const unsigned fields, std::string && name);
[4970]51
52    void addInputScalar(llvm::Type * const type);
[4974]53    void addInputScalar(llvm::Type * const type, std::string && name);
[4959]54
[4974]55    unsigned addOutputStream(const unsigned fields);
56    unsigned addOutputScalar(llvm::Type * const type);
[4970]57
[4959]58    llvm::Function * prepareFunction();
59
[4974]60    inline llvm::Value * getInputStream(const unsigned index, const unsigned streamOffset = 0) {
[4991]61        return getInputStream(mKernelState, index, streamOffset);
[4974]62    }
[4970]63
[4974]64    inline llvm::Value * getInputScalar(const unsigned index) {
[4991]65        return getInputScalar(mKernelState, index);
[4974]66    }
[4970]67
[4974]68    llvm::Value * getInternalState(const std::string & name) {
[4991]69        return getInternalState(mKernelState, name);
[4974]70    }
[4970]71
[4974]72    void setInternalState(const std::string & name, llvm::Value * value) {
[4991]73        setInternalState(mKernelState, name, value);
[4974]74    }
[4970]75
[4974]76    llvm::Value * getInternalState(const unsigned index) {
[4991]77        return getInternalState(mKernelState, index);
[4974]78    }
[4970]79
[4974]80    void setInternalState(const unsigned index, llvm::Value * value) {
[4991]81        setInternalState(mKernelState, index, value);
[4974]82    }
[4959]83
[4974]84    llvm::Value * getOutputStream(const unsigned index, const unsigned streamOffset = 0) {
[4991]85        return getOutputStream(mKernelState, index, streamOffset);
[4974]86    }
[4986]87
88    inline unsigned getNumOfOutputStreams() const {
89        return mOutputStream.size();
[4974]90    }
91
92    llvm::Value * getOutputScalar(const unsigned index) {
[4991]93        return getOutputScalar(mKernelState, index);
[4974]94    }
95
[4986]96    inline unsigned getNumOfOutputScalars() const {
97        return mOutputScalar.size();
98    }
99
[4974]100    llvm::Value * getBlockNo() {
[4991]101        return getBlockNo(mKernelState);
[4974]102    }
103
104    llvm::Type * getInputStreamType() const;
105
[4986]106    void setInputBufferSize(const unsigned bufferSize);
107
108    unsigned getInputBufferSize() const;
109
110    unsigned getBufferSize() const;
111
[4959]112    void finalize();
113
[4986]114    kernel::Instance * instantiate(llvm::Value * const inputStream);
[4924]115
[4991]116    kernel::Instance * instantiate(std::initializer_list<llvm::Value *> inputStreams);
[4974]117
[4991]118    kernel::Instance * instantiate(std::pair<llvm::Value *, unsigned> && inputStream);
119
[4974]120    llvm::Type * getKernelStateType() const;
121
122    llvm::Value * getKernelState() const;
123
[4959]124    llvm::Function * getDoBlockFunction() const;
[4926]125
[4991]126    void clearOutputStreamSet(llvm::Value * const instance, const unsigned streamOffset = 0);
[4986]127
[4974]128protected:
[4959]129
[4974]130    llvm::Value * getInputStream(llvm::Value * const instance, const unsigned index, const unsigned streamOffset);
[4970]131
[4974]132    llvm::Value * getInputScalar(llvm::Value * const instance, const unsigned index);
[4959]133
[4974]134    llvm::Value * getInternalState(llvm::Value * const instance, const std::string & name);
[4959]135
[4974]136    void setInternalState(llvm::Value * const instance, const std::string & name, llvm::Value * const value);
137
138    llvm::Value * getInternalState(llvm::Value * const instance, const unsigned index);
139
140    void setInternalState(llvm::Value * const instance, const unsigned index, llvm::Value * const value);
141
142    llvm::Value * getOutputStream(llvm::Value * const instance, const unsigned index, const unsigned streamOffset);
143
144    llvm::Value * getOutputScalar(llvm::Value * const instance, const unsigned index);
145
146    llvm::Value * getOffset(llvm::Value * const instance, const unsigned value);
147
148    llvm::Value * getBlockNo(llvm::Value * const instance);
149
[4986]150    llvm::Function * getOutputStreamSetFunction() const;
[4974]151
[4986]152    void CreateDoBlockCall(llvm::Value * const instance);
153
154    llvm::Function * CreateModFunction(const unsigned size);
155
[4991]156    void eliminateRedundantMemoryOperations(llvm::Function * const function);
157
[4926]158private:
[4959]159    llvm::Module *                      mMod;
[4924]160    IDISA::IDISA_Builder *              iBuilder;
161    std::string                                                 mKernelName;
[4959]162    llvm::Type *                        mBitBlockType;
[4986]163    llvm::Function *                                    mConstructor;
164    llvm::Function *                                    mDoBlock;
165
166    unsigned                            mBufferSize;
167
168    llvm::Type *                        mKernelStateType;
[4959]169    llvm::Type *                        mInputStreamType;
170    llvm::Type *                        mInputScalarType;
[4986]171    llvm::Type *                        mOutputStreamType;
172
[4991]173    llvm::Value *                       mKernelState;
[4986]174    unsigned                            mBlockNoIndex;
175
[4974]176    std::vector<llvm::Type *>           mInputStream;
177    std::vector<std::string>            mInputStreamName;
178    std::vector<llvm::Type *>           mInputScalar;
[4986]179    std::vector<std::string>            mInputScalarName;   
[4974]180    std::vector<llvm::Type *>           mOutputStream;
181    std::vector<llvm::Type *>           mOutputScalar;
182    std::vector<llvm::Type *>                   mInternalState;
183    NameMap                             mInternalStateNameMap;
[4924]184};
185
[4959]186inline llvm::Function * KernelBuilder::getDoBlockFunction() const {
[4986]187    return mDoBlock;
[4959]188}
189
[4974]190inline llvm::Type * KernelBuilder::getKernelStateType() const{
[4986]191    return mKernelStateType;
[4959]192}
193
[4974]194inline llvm::Value * KernelBuilder::getKernelState() const {
[4991]195    return mKernelState;
[4959]196}
197
[4974]198inline llvm::Type * KernelBuilder::getInputStreamType() const {
199    return mInputStreamType;
200}
201
[4986]202inline llvm::Value * KernelBuilder::getBlockNo(llvm::Value * const instance) {
203    return getInternalState(instance, mBlockNoIndex);
[4959]204}
205
[4986]206inline unsigned KernelBuilder::getBufferSize() const {
207    return mBufferSize;
[4970]208}
209
[4974]210} // end of namespace kernel
211
[4924]212#endif // KERNEL_H
Note: See TracBrowser for help on using the repository browser.