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

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

Start of work to simplify kernel writing. Removed generateDoBlockLogic method.

File size: 4.0 KB
RevLine 
[5047]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
[5260]9#include <string>  // for string
10#include <vector>  // for vector
11namespace IDISA { class IDISA_Builder; }
[5285]12namespace llvm { class Function; }
[5260]13namespace llvm { class Module; }
14namespace llvm { class StructType; }
15namespace llvm { class Type; }
16namespace llvm { class Value; }
[5047]17
[5202]18struct Binding {
19    llvm::Type * type;
20    std::string name;
[5246]21    Binding(llvm::Type * type, const std::string & name) : type(type), name(name) {}
22    Binding(llvm::Type * type, std::string && name) : type(type), name(name) {}
[5047]23};
[5060]24
[5202]25static const std::string init_suffix = "_Init";
26static const std::string doBlock_suffix = "_DoBlock";
27static const std::string doSegment_suffix = "_DoSegment";
28static const std::string finalBlock_suffix = "_FinalBlock";
29static const std::string accumulator_infix = "_get_";
30
[5047]31class KernelInterface {
32
33public:
[5174]34    /*
35     
36     This class defines the methods to be used to generate the code 
37     necessary for declaring, allocating, calling and synchronizing
38     kernels.   The methods to be used for constructing kernels are defined
39     within the KernelBuilder class of kernel.h
40     
41     */
[5251]42   
[5267]43    const std::string & getName() const { return mKernelName;}
[5246]44       
[5267]45    const std::vector<Binding> & getStreamInputs() const {return mStreamSetInputs;}
[5285]46
[5267]47    const std::vector<Binding> & getStreamOutputs() const {return mStreamSetOutputs;}
[5285]48
[5267]49    const std::vector<Binding> & getScalarInputs() const { return mScalarInputs;}
[5285]50
[5267]51    const std::vector<Binding> & getScalarOutputs() const { return mScalarOutputs;}
[5174]52   
53   
54    // Add ExternalLinkage method declarations for the kernel to a given client module.
[5267]55    void addKernelDeclarations(llvm::Module * client) const;
[5285]56
[5246]57    virtual void createInstance() = 0;
[5285]58
[5260]59    void setInitialArguments(std::vector<llvm::Value *> args);
[5285]60
[5246]61    llvm::Value * getInstance() const { return mKernelInstance; }
[5174]62
[5263]63    llvm::Value * createDoSegmentCall(std::vector<llvm::Value *> args) const;
[5285]64
[5246]65    llvm::Value * createGetAccumulatorCall(llvm::Value * self, std::string accumName) const;
[5174]66   
[5202]67    unsigned getLookAhead() const {
68        return mLookAheadPositions;
69    }
[5174]70   
[5202]71    IDISA::IDISA_Builder * getBuilder() const {
72        return iBuilder;
73    }
74
[5247]75    virtual llvm::Value * getProcessedItemCount(llvm::Value * self, const std::string & ssName) const = 0;
[5285]76
[5247]77    virtual llvm::Value * getProducedItemCount(llvm::Value * self, const std::string & ssName) const = 0;
[5285]78
[5246]79    virtual llvm::Value * getTerminationSignal(llvm::Value * self) const = 0;
[5174]80   
[5202]81    void setLookAhead(unsigned lookAheadPositions) {
82        mLookAheadPositions = lookAheadPositions;
83    }
84
[5285]85    llvm::Function * getDoSegmentFunction() const;
[5202]86
[5174]87protected:
[5202]88
[5047]89    KernelInterface(IDISA::IDISA_Builder * builder,
[5267]90                    std::string && kernelName,
[5283]91                    std::vector<Binding> && stream_inputs,
92                    std::vector<Binding> && stream_outputs,
93                    std::vector<Binding> && scalar_inputs,
94                    std::vector<Binding> && scalar_outputs,
95                    std::vector<Binding> && internal_scalars)
[5267]96    : iBuilder(builder)
97    , mKernelName(kernelName)
98    , mStreamSetInputs(stream_inputs)
99    , mStreamSetOutputs(stream_outputs)
100    , mScalarInputs(scalar_inputs)
101    , mScalarOutputs(scalar_outputs)
102    , mInternalScalars(internal_scalars)
103    , mKernelStateType(nullptr)
104    , mKernelInstance(nullptr)
105    , mLookAheadPositions(0) {
106
107    }
[5047]108   
[5202]109protected:
[5053]110   
[5202]111    IDISA::IDISA_Builder * const iBuilder;
[5267]112    const std::string mKernelName;
[5260]113    std::vector<llvm::Value *> mInitialArguments;
[5202]114    std::vector<Binding> mStreamSetInputs;
115    std::vector<Binding> mStreamSetOutputs;
116    std::vector<Binding> mScalarInputs;
117    std::vector<Binding> mScalarOutputs;
118    std::vector<Binding> mInternalScalars;
[5227]119    llvm::StructType * mKernelStateType;
[5220]120    llvm::Value * mKernelInstance;
[5141]121    unsigned mLookAheadPositions;
122   
[5047]123};
[5285]124
[5047]125#endif
Note: See TracBrowser for help on using the repository browser.