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

Last change on this file since 5283 was 5283, checked in by nmedfort, 2 years ago

Optimized Symbol Generation (and fixed potential bug that could allow duplicate names being constructed); made PabloKernel? extend PabloAST (temporarily removed PabloAST::getName() to avoid diamond problem); added an internal scalar to PabloKernel? struct for each Count to avoid InOut? output scalar variable problem; allowed CodeMotionPass? to move code within the same scope but across a branch statement. Began work on separating Kernels into either Block-Oriented or Segment-Oriented kernels.

File size: 4.1 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    const std::string & getName() const { return mKernelName;}
43       
44    const std::vector<Binding> & getStreamInputs() const {return mStreamSetInputs;}
45    const std::vector<Binding> & getStreamOutputs() const {return mStreamSetOutputs;}
46    const std::vector<Binding> & getScalarInputs() const { return mScalarInputs;}
47    const std::vector<Binding> & getScalarOutputs() const { return mScalarOutputs;}
48   
49   
50    // Add ExternalLinkage method declarations for the kernel to a given client module.
51    void addKernelDeclarations(llvm::Module * client) const;
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
98    }
99   
100protected:
101   
102    IDISA::IDISA_Builder * const iBuilder;
103    const std::string mKernelName;
104    std::vector<llvm::Value *> mInitialArguments;
105    std::vector<Binding> mStreamSetInputs;
106    std::vector<Binding> mStreamSetOutputs;
107    std::vector<Binding> mScalarInputs;
108    std::vector<Binding> mScalarOutputs;
109    std::vector<Binding> mInternalScalars;
110    llvm::StructType * mKernelStateType;
111    llvm::Value * mKernelInstance;
112    unsigned mLookAheadPositions;
113   
114};
115#endif
Note: See TracBrowser for help on using the repository browser.