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

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

Stream set buffer maps

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