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

Last change on this file since 5263 was 5263, checked in by cameron, 9 months ago

New doSegment partial progress

File size: 3.9 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 finalBlock_suffix = "_FinalBlock";
28static const std::string accumulator_infix = "_get_";
29
30class KernelInterface {
31
32public:
33    /*
34     
35     This class defines the methods to be used to generate the code 
36     necessary for declaring, allocating, calling and synchronizing
37     kernels.   The methods to be used for constructing kernels are defined
38     within the KernelBuilder class of kernel.h
39     
40     */
41   
42    std::string getName() const { return mKernelName;}
43       
44    std::vector<Binding> getStreamInputs() {return mStreamSetInputs;}
45    std::vector<Binding> getStreamOutputs() {return mStreamSetOutputs;}
46    std::vector<Binding> getScalarInputs() { return mScalarInputs;}
47    std::vector<Binding> getScalarOutputs() { return mScalarOutputs;}
48   
49   
50    // Add ExternalLinkage method declarations for the kernel to a given client module.
51    void addKernelDeclarations(llvm::Module * client);
52    virtual void createInstance() = 0;
53    void setInitialArguments(std::vector<llvm::Value *> args);
54    llvm::Value * getInstance() const { return mKernelInstance; }
55
56    llvm::Value * createDoSegmentCall(std::vector<llvm::Value *> args) 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<llvm::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.