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

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

Continued work on eliminating BlockNo?

File size: 4.2 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; }
[5307]12namespace llvm { class ConstantInt; }
[5285]13namespace llvm { class Function; }
[5260]14namespace llvm { class Module; }
[5287]15namespace llvm { class PointerType; }
[5260]16namespace llvm { class StructType; }
17namespace llvm { class Type; }
18namespace llvm { class Value; }
[5047]19
[5307]20
[5202]21struct Binding {
[5307]22    Binding(llvm::Type * type, const std::string & name, const unsigned step = 0)
23    : type(type), name(name), step(step) {
24
25    }
26
27    llvm::Type *        type;
28    std::string         name;
29    const unsigned      step;
[5047]30};
[5060]31
[5047]32class KernelInterface {
33
34public:
[5174]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     */
[5251]43   
[5297]44    const std::string & getName() const { return mKernelName; }
[5246]45       
[5297]46    const std::vector<Binding> & getStreamInputs() const { return mStreamSetInputs; }
[5285]47
[5297]48    const std::vector<Binding> & getStreamOutputs() const { return mStreamSetOutputs; }
[5285]49
[5297]50    const std::vector<Binding> & getScalarInputs() const { return mScalarInputs; }
[5285]51
[5297]52    const std::vector<Binding> & getScalarOutputs() const { return mScalarOutputs; }
[5292]53       
[5174]54    // Add ExternalLinkage method declarations for the kernel to a given client module.
[5292]55    void addKernelDeclarations(llvm::Module * client);
[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
[5202]63    unsigned getLookAhead() const {
64        return mLookAheadPositions;
65    }
[5174]66   
[5202]67    IDISA::IDISA_Builder * getBuilder() const {
68        return iBuilder;
69    }
70
[5292]71    virtual llvm::Value * getProcessedItemCount(llvm::Value * instance, const std::string & name) const = 0;
[5285]72
[5292]73    virtual void setProcessedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const = 0;
[5285]74
[5292]75    virtual llvm::Value * getProducedItemCount(llvm::Value * instance, const std::string & name) const = 0;
76
77    virtual void setProducedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const = 0;
78
79    virtual llvm::Value * getTerminationSignal(llvm::Value * instance) const = 0;
80
81    virtual void setTerminationSignal(llvm::Value * instance) const = 0;
[5174]82   
[5202]83    void setLookAhead(unsigned lookAheadPositions) {
84        mLookAheadPositions = lookAheadPositions;
85    }
86
[5287]87    llvm::Function * getInitFunction() const;
88
[5285]89    llvm::Function * getDoSegmentFunction() const;
[5202]90
[5287]91    llvm::Function * getAccumulatorFunction(const std::string & accumName) const;
92
[5174]93protected:
[5202]94
[5047]95    KernelInterface(IDISA::IDISA_Builder * builder,
[5267]96                    std::string && kernelName,
[5283]97                    std::vector<Binding> && stream_inputs,
98                    std::vector<Binding> && stream_outputs,
99                    std::vector<Binding> && scalar_inputs,
100                    std::vector<Binding> && scalar_outputs,
101                    std::vector<Binding> && internal_scalars)
[5267]102    : iBuilder(builder)
103    , mKernelName(kernelName)
104    , mStreamSetInputs(stream_inputs)
105    , mStreamSetOutputs(stream_outputs)
106    , mScalarInputs(scalar_inputs)
107    , mScalarOutputs(scalar_outputs)
108    , mInternalScalars(internal_scalars)
109    , mKernelStateType(nullptr)
110    , mKernelInstance(nullptr)
111    , mLookAheadPositions(0) {
112
113    }
[5047]114   
[5292]115    virtual void addAdditionalKernelDeclarations(llvm::Module * module, llvm::PointerType * selfType) {}
[5287]116
[5202]117protected:
[5053]118   
[5202]119    IDISA::IDISA_Builder * const iBuilder;
[5267]120    const std::string mKernelName;
[5260]121    std::vector<llvm::Value *> mInitialArguments;
[5202]122    std::vector<Binding> mStreamSetInputs;
123    std::vector<Binding> mStreamSetOutputs;
124    std::vector<Binding> mScalarInputs;
125    std::vector<Binding> mScalarOutputs;
126    std::vector<Binding> mInternalScalars;
[5227]127    llvm::StructType * mKernelStateType;
[5220]128    llvm::Value * mKernelInstance;
[5141]129    unsigned mLookAheadPositions;
130   
[5047]131};
[5285]132
[5047]133#endif
Note: See TracBrowser for help on using the repository browser.