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

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

Partial removal of BlockNo?

File size: 4.1 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    // Add ExternalLinkage method declarations for the kernel to a given client module.
49    void addKernelDeclarations(llvm::Module * client);
50
51    virtual void createInstance() = 0;
52
53    void setInitialArguments(std::vector<llvm::Value *> args);
54
55    llvm::Value * getInstance() const { return mKernelInstance; }
56
57    unsigned getLookAhead() const {
58        return mLookAheadPositions;
59    }
60   
61    IDISA::IDISA_Builder * getBuilder() const {
62        return iBuilder;
63    }
64
65    virtual llvm::Value * getProcessedItemCount(llvm::Value * instance, const std::string & name) const = 0;
66
67    virtual void setProcessedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const = 0;
68
69    virtual llvm::Value * getProducedItemCount(llvm::Value * instance, const std::string & name) const = 0;
70
71    virtual void setProducedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const = 0;
72
73    virtual llvm::Value * getTerminationSignal(llvm::Value * instance) const = 0;
74
75    virtual void setTerminationSignal(llvm::Value * instance) const = 0;
76   
77    void setLookAhead(unsigned lookAheadPositions) {
78        mLookAheadPositions = lookAheadPositions;
79    }
80
81    llvm::Function * getInitFunction() const;
82
83    llvm::Function * getDoSegmentFunction() const;
84
85    llvm::Function * getAccumulatorFunction(const std::string & accumName) const;
86
87protected:
88
89    KernelInterface(IDISA::IDISA_Builder * builder,
90                    std::string && kernelName,
91                    std::vector<Binding> && stream_inputs,
92                    std::vector<Binding> && stream_outputs,
93                    std::vector<Binding> && scalar_inputs,
94                    std::vector<Binding> && scalar_outputs,
95                    std::vector<Binding> && internal_scalars)
96    : iBuilder(builder)
97    , mKernelName(kernelName)
98    , mStreamSetInputs(stream_inputs)
99    , mStreamSetOutputs(stream_outputs)
100    , mScalarInputs(scalar_inputs)
101    , mScalarOutputs(scalar_outputs)
102    , mInternalScalars(internal_scalars)
103    , mKernelStateType(nullptr)
104    , mKernelInstance(nullptr)
105    , mLookAheadPositions(0) {
106
107    }
108   
109    virtual void addAdditionalKernelDeclarations(llvm::Module * module, llvm::PointerType * selfType) {}
110
111protected:
112   
113    IDISA::IDISA_Builder * const iBuilder;
114    const std::string mKernelName;
115    std::vector<llvm::Value *> mInitialArguments;
116    std::vector<Binding> mStreamSetInputs;
117    std::vector<Binding> mStreamSetOutputs;
118    std::vector<Binding> mScalarInputs;
119    std::vector<Binding> mScalarOutputs;
120    std::vector<Binding> mInternalScalars;
121    llvm::StructType * mKernelStateType;
122    llvm::Value * mKernelInstance;
123    unsigned mLookAheadPositions;
124   
125};
126
127#endif
Note: See TracBrowser for help on using the repository browser.