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

Last change on this file since 5202 was 5202, checked in by nmedfort, 3 years ago

Initial work on adding types to PabloAST and mutable Var objects.

File size: 3.6 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 <IDISA/idisa_builder.h>
13#include <kernels/streamset.h>
14
15struct Binding {
16    llvm::Type * type;
17    std::string name;
18
19    Binding(llvm::Type * type, std::string name)
20    : type(type)
21    , name(std::move(name)) {
22
23    }
24};
25
26static const std::string init_suffix = "_Init";
27static const std::string doBlock_suffix = "_DoBlock";
28static const std::string doSegment_suffix = "_DoSegment";
29static const std::string finalBlock_suffix = "_FinalBlock";
30static const std::string accumulator_infix = "_get_";
31
32class KernelInterface {
33
34public:
35    /*
36     
37     This class defines the methods to be used to generate the code 
38     necessary for declaring, allocating, calling and synchronizing
39     kernels.   The methods to be used for constructing kernels are defined
40     within the KernelBuilder class of kernel.h
41     
42     */
43   
44    std::string & getName() { return mKernelName;}
45   
46    std::vector<Binding> getStreamInputs() {return mStreamSetInputs;}
47    std::vector<Binding> getStreamOutputs() {return mStreamSetOutputs;}
48    std::vector<Binding> getScalarInputs() { return mScalarInputs;}
49    std::vector<Binding> getScalarOutputs() { return mScalarOutputs;}
50   
51   
52    // Add ExternalLinkage method declarations for the kernel to a given client module.
53    void addKernelDeclarations(Module * client);
54   
55    virtual llvm::Value * createInstance(std::vector<llvm::Value *> initialParameters);
56
57    llvm::Value * createDoSegmentCall(llvm::Value * kernelInstance, llvm::Value * blkCount);
58    llvm::Value * createFinalBlockCall(llvm::Value * kernelInstance, llvm::Value * remainingBytes);
59    llvm::Value * createGetAccumulatorCall(llvm::Value * kernelInstance, std::string accumName);
60   
61    unsigned getLookAhead() const {
62        return mLookAheadPositions;
63    }
64   
65    IDISA::IDISA_Builder * getBuilder() const {
66        return iBuilder;
67    }
68
69    virtual llvm::Value * getLogicalSegmentNo(llvm::Value * kernelInstance) = 0;
70    virtual llvm::Value * getProcessedItemCount(llvm::Value * kernelInstance) = 0;
71    virtual llvm::Value * getProducedItemCount(llvm::Value * kernelInstance) = 0;
72    virtual llvm::Value * getTerminationSignal(llvm::Value * kernelInstance) = 0;
73   
74    void setLookAhead(unsigned lookAheadPositions) {
75        mLookAheadPositions = lookAheadPositions;
76    }
77
78    llvm::Value * createDoBlockCall(llvm::Value * kernelInstance);
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    mLookAheadPositions(0) {}
98   
99protected:
100   
101    IDISA::IDISA_Builder * const iBuilder;
102    std::string mKernelName;
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::Type * mKernelStateType;
109    unsigned mLookAheadPositions;
110   
111};
112#endif
Note: See TracBrowser for help on using the repository browser.