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

Last change on this file since 5287 was 5287, checked in by nmedfort, 2 years ago

More changes towards simplifying the KernelBuilder?

File size: 3.8 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>  // for string
10#include <vector>  // for vector
11namespace IDISA { class IDISA_Builder; }
12namespace llvm { class Function; }
13namespace llvm { class Module; }
14namespace llvm { class PointerType; }
15namespace llvm { class StructType; }
16namespace llvm { class Type; }
17namespace llvm { class Value; }
18
19struct Binding {
20    llvm::Type * type;
21    std::string name;
22    Binding(llvm::Type * type, const std::string & name) : type(type), name(name) {}
23    Binding(llvm::Type * type, std::string && name) : type(type), name(name) {}
24};
25
26class KernelInterface {
27
28public:
29    /*
30     
31     This class defines the methods to be used to generate the code 
32     necessary for declaring, allocating, calling and synchronizing
33     kernels.   The methods to be used for constructing kernels are defined
34     within the KernelBuilder class of kernel.h
35     
36     */
37   
38    const std::string & getName() const { return mKernelName;}
39       
40    const std::vector<Binding> & getStreamInputs() const {return mStreamSetInputs;}
41
42    const std::vector<Binding> & getStreamOutputs() const {return mStreamSetOutputs;}
43
44    const std::vector<Binding> & getScalarInputs() const { return mScalarInputs;}
45
46    const std::vector<Binding> & getScalarOutputs() const { return mScalarOutputs;}
47   
48   
49    // Add ExternalLinkage method declarations for the kernel to a given client module.
50    void addKernelDeclarations(llvm::Module * client) const;
51
52    virtual void createInstance() = 0;
53
54    void setInitialArguments(std::vector<llvm::Value *> args);
55
56    llvm::Value * getInstance() const { return mKernelInstance; }
57
58    unsigned getLookAhead() const {
59        return mLookAheadPositions;
60    }
61   
62    IDISA::IDISA_Builder * getBuilder() const {
63        return iBuilder;
64    }
65
66    virtual llvm::Value * getProcessedItemCount(llvm::Value * self, const std::string & ssName) const = 0;
67
68    virtual llvm::Value * getProducedItemCount(llvm::Value * self, const std::string & ssName) const = 0;
69
70    virtual llvm::Value * getTerminationSignal(llvm::Value * self) const = 0;
71   
72    void setLookAhead(unsigned lookAheadPositions) {
73        mLookAheadPositions = lookAheadPositions;
74    }
75
76    llvm::Function * getInitFunction() const;
77
78    llvm::Function * getDoSegmentFunction() const;
79
80    llvm::Function * getAccumulatorFunction(const std::string & accumName) const;
81
82protected:
83
84    KernelInterface(IDISA::IDISA_Builder * builder,
85                    std::string && kernelName,
86                    std::vector<Binding> && stream_inputs,
87                    std::vector<Binding> && stream_outputs,
88                    std::vector<Binding> && scalar_inputs,
89                    std::vector<Binding> && scalar_outputs,
90                    std::vector<Binding> && internal_scalars)
91    : iBuilder(builder)
92    , mKernelName(kernelName)
93    , mStreamSetInputs(stream_inputs)
94    , mStreamSetOutputs(stream_outputs)
95    , mScalarInputs(scalar_inputs)
96    , mScalarOutputs(scalar_outputs)
97    , mInternalScalars(internal_scalars)
98    , mKernelStateType(nullptr)
99    , mKernelInstance(nullptr)
100    , mLookAheadPositions(0) {
101
102    }
103   
104    virtual void addAdditionalKernelDeclarations(llvm::Module * module, llvm::PointerType * selfType) const;
105
106protected:
107   
108    IDISA::IDISA_Builder * const iBuilder;
109    const std::string mKernelName;
110    std::vector<llvm::Value *> mInitialArguments;
111    std::vector<Binding> mStreamSetInputs;
112    std::vector<Binding> mStreamSetOutputs;
113    std::vector<Binding> mScalarInputs;
114    std::vector<Binding> mScalarOutputs;
115    std::vector<Binding> mInternalScalars;
116    llvm::StructType * mKernelStateType;
117    llvm::Value * mKernelInstance;
118    unsigned mLookAheadPositions;
119   
120};
121
122#endif
Note: See TracBrowser for help on using the repository browser.