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

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

Changes working towards simplifying accessing stream elements + some modifications to simplify include / forward declarations within the CodeGen? library.

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