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

Last change on this file since 5257 was 5257, checked in by cameron, 2 years ago

finalSegment kernel methods initial check-in

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