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

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

Separate processedItemCounts and producedItemCounts for each stream set

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::vector<Binding> getStreamInputs() {return mStreamSetInputs;}
41    std::vector<Binding> getStreamOutputs() {return mStreamSetOutputs;}
42    std::vector<Binding> getScalarInputs() { return mScalarInputs;}
43    std::vector<Binding> getScalarOutputs() { return mScalarOutputs;}
44   
45   
46    // Add ExternalLinkage method declarations for the kernel to a given client module.
47    void addKernelDeclarations(Module * client);
48    virtual void createInstance() = 0;
49    void setInitialArguments(std::vector<Value *> initialParameters);
50    llvm::Value * getInstance() const { return mKernelInstance; }
51
52    llvm::Value * createDoSegmentCall(llvm::Value * self, llvm::Value * blkCount) const;
53    llvm::Value * createFinalBlockCall(llvm::Value * self, llvm::Value * remainingBytes) const;
54    llvm::Value * createGetAccumulatorCall(llvm::Value * self, std::string accumName) const;
55   
56    unsigned getLookAhead() const {
57        return mLookAheadPositions;
58    }
59   
60    IDISA::IDISA_Builder * getBuilder() const {
61        return iBuilder;
62    }
63
64    virtual llvm::Value * getProcessedItemCount(llvm::Value * self, const std::string & ssName) const = 0;
65    virtual llvm::Value * getProducedItemCount(llvm::Value * self, const std::string & ssName) const = 0;
66    virtual llvm::Value * getTerminationSignal(llvm::Value * self) const = 0;
67   
68    void setLookAhead(unsigned lookAheadPositions) {
69        mLookAheadPositions = lookAheadPositions;
70    }
71
72    llvm::Value * createDoBlockCall(llvm::Value * self) const;
73
74protected:
75
76    KernelInterface(IDISA::IDISA_Builder * builder,
77                    std::string kernelName,
78                    std::vector<Binding> stream_inputs,
79                    std::vector<Binding> stream_outputs,
80                    std::vector<Binding> scalar_inputs,
81                    std::vector<Binding> scalar_outputs,
82                    std::vector<Binding> internal_scalars) :
83    iBuilder(builder),
84    mKernelName(kernelName),
85    mStreamSetInputs(stream_inputs),
86    mStreamSetOutputs(stream_outputs),
87    mScalarInputs(scalar_inputs),
88    mScalarOutputs(scalar_outputs),
89    mInternalScalars(internal_scalars),
90    mKernelStateType(nullptr),
91    mKernelInstance(nullptr),
92    mLookAheadPositions(0) {}
93   
94protected:
95   
96    IDISA::IDISA_Builder * const iBuilder;
97    std::string mKernelName;
98    std::vector<Value *> mInitialArguments;
99    std::vector<Binding> mStreamSetInputs;
100    std::vector<Binding> mStreamSetOutputs;
101    std::vector<Binding> mScalarInputs;
102    std::vector<Binding> mScalarOutputs;
103    std::vector<Binding> mInternalScalars;
104    llvm::StructType * mKernelStateType;
105    llvm::Value * mKernelInstance;
106    unsigned mLookAheadPositions;
107   
108};
109#endif
Note: See TracBrowser for help on using the repository browser.