source: icGREP/icgrep-devel/icgrep/kernels/interface.h @ 5245

Last change on this file since 5245 was 5245, checked in by nmedfort, 18 months ago

Work on bracket matching problem

File size: 3.7 KB
Line 
1/*
2 *  Copyright (c) 2016 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
6#ifndef KERNEL_INTERFACE_H
7#define KERNEL_INTERFACE_H
8
9#include <string>
10#include <vector>
11#include <llvm/IR/Type.h>
12#include <IR_Gen/idisa_builder.h>
13#include <kernels/streamset.h>
14
15struct Binding {
16    llvm::Type * type;
17    std::string name;
18
19    Binding(llvm::Type * type, std::string name)
20    : type(type)
21    , name(std::move(name)) {
22
23    }
24};
25
26static const std::string init_suffix = "_Init";
27static const std::string doBlock_suffix = "_DoBlock";
28static const std::string doSegment_suffix = "_DoSegment";
29static const std::string finalBlock_suffix = "_FinalBlock";
30static const std::string accumulator_infix = "_get_";
31
32class KernelInterface {
33
34public:
35    /*
36     
37     This class defines the methods to be used to generate the code 
38     necessary for declaring, allocating, calling and synchronizing
39     kernels.   The methods to be used for constructing kernels are defined
40     within the KernelBuilder class of kernel.h
41     
42     */
43   
44    std::string & getName() { return mKernelName;}
45   
46    std::vector<Binding> getStreamInputs() {return mStreamSetInputs;}
47    std::vector<Binding> getStreamOutputs() {return mStreamSetOutputs;}
48    std::vector<Binding> getScalarInputs() { return mScalarInputs;}
49    std::vector<Binding> getScalarOutputs() { return mScalarOutputs;}
50   
51   
52    // Add ExternalLinkage method declarations for the kernel to a given client module.
53    void addKernelDeclarations(Module * client);
54   
55    void setInitialArguments(std::vector<llvm::Value *> initialParameters);
56    virtual void createInstance();
57    llvm::Value * getInstance() {return mKernelInstance;};
58
59    llvm::Value * createDoSegmentCall(llvm::Value * kernelInstance, llvm::Value * blkCount);
60    llvm::Value * createFinalBlockCall(llvm::Value * kernelInstance, llvm::Value * remainingBytes);
61    llvm::Value * createGetAccumulatorCall(llvm::Value * kernelInstance, std::string accumName);
62   
63    unsigned getLookAhead() const {
64        return mLookAheadPositions;
65    }
66   
67    IDISA::IDISA_Builder * getBuilder() const {
68        return iBuilder;
69    }
70
71    virtual llvm::Value * getProcessedItemCount(llvm::Value * kernelInstance) = 0;
72    virtual llvm::Value * getProducedItemCount(llvm::Value * kernelInstance) = 0;
73    virtual llvm::Value * getTerminationSignal(llvm::Value * kernelInstance) = 0;
74   
75    void setLookAhead(unsigned lookAheadPositions) {
76        mLookAheadPositions = lookAheadPositions;
77    }
78
79    llvm::Value * createDoBlockCall(llvm::Value * kernelInstance);
80
81protected:
82
83    KernelInterface(IDISA::IDISA_Builder * builder,
84                    std::string kernelName,
85                    std::vector<Binding> stream_inputs,
86                    std::vector<Binding> stream_outputs,
87                    std::vector<Binding> scalar_inputs,
88                    std::vector<Binding> scalar_outputs,
89                    std::vector<Binding> internal_scalars) :
90    iBuilder(builder),
91    mKernelName(kernelName),
92    mStreamSetInputs(stream_inputs),
93    mStreamSetOutputs(stream_outputs),
94    mScalarInputs(scalar_inputs),
95    mScalarOutputs(scalar_outputs),
96    mInternalScalars(internal_scalars),
97    mKernelStateType(nullptr),
98    mKernelInstance(nullptr),
99    mLookAheadPositions(0) {}
100   
101protected:
102   
103    IDISA::IDISA_Builder * const iBuilder;
104    std::string mKernelName;
105    std::vector<Value *> mInitialArguments;
106    std::vector<Binding> mStreamSetInputs;
107    std::vector<Binding> mStreamSetOutputs;
108    std::vector<Binding> mScalarInputs;
109    std::vector<Binding> mScalarOutputs;
110    std::vector<Binding> mInternalScalars;
111    llvm::StructType * mKernelStateType;
112    llvm::Value * mKernelInstance;
113    unsigned mLookAheadPositions;
114   
115};
116#endif
Note: See TracBrowser for help on using the repository browser.