Ignore:
Timestamp:
Jan 5, 2017, 3:54:40 PM (2 years ago)
Author:
nmedfort
Message:

Code clean up to enforce proper calling order of KernelBuilder? methods

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5240 r5246  
    66#ifndef KERNEL_BUILDER_H
    77#define KERNEL_BUILDER_H
    8 
    98
    109#include "streamset.h"
     
    2827class KernelBuilder : public KernelInterface {
    2928    using NameMap = boost::container::flat_map<std::string, unsigned>;
    30 
    3129public:
    32     KernelBuilder(IDISA::IDISA_Builder * builder,
    33                     std::string kernelName,
    34                     std::vector<Binding> stream_inputs,
    35                     std::vector<Binding> stream_outputs,
    36                     std::vector<Binding> scalar_parameters,
    37                     std::vector<Binding> scalar_outputs,
    38                     std::vector<Binding> internal_scalars);
    3930   
    4031    // Create a module for the kernel, including the kernel state type declaration and
    4132    // the full implementation of all required methods.     
    4233    //
    43     std::unique_ptr<llvm::Module> createKernelModule(std::vector<StreamSetBuffer *> input_buffers, std::vector<StreamSetBuffer *> output_buffers);
     34    std::unique_ptr<Module> createKernelModule(const std::vector<StreamSetBuffer *> & inputs, const std::vector<StreamSetBuffer *> & outputs);
    4435   
    4536    // Generate the Kernel to the current module (iBuilder->getModule()).
    46     void generateKernel(std::vector<StreamSetBuffer *> input_buffers, std::vector<StreamSetBuffer *> output_buffers);
     37    void generateKernel(const std::vector<StreamSetBuffer *> & inputs, const std::vector<StreamSetBuffer *> & outputs);
    4738   
    4839    void createInstance() override;
    4940
    50     Function * generateThreadFunction(std::string name);
     41    Function * generateThreadFunction(const std::string & name) const;
    5142
    52     Value * getBlockNo(Value * self);
    53     virtual llvm::Value * getProcessedItemCount(llvm::Value * kernelInstance) override;
    54     virtual llvm::Value * getProducedItemCount(llvm::Value * kernelInstance) override;
    55     virtual void initializeKernelState(Value * self);
    56     llvm::Value * getTerminationSignal(llvm::Value * kernelInstance) override;
     43    Value * getBlockNo(Value * self) const;
     44    virtual Value * getProcessedItemCount(Value * self) const override;
     45    virtual Value * getProducedItemCount(Value * self) const override;
     46    virtual void initializeKernelState(Value * self) const;
     47    Value * getTerminationSignal(Value * self) const override;
    5748   
    58     inline llvm::IntegerType * getSizeTy() {
     49    inline IntegerType * getSizeTy() const {
    5950        return getBuilder()->getSizeTy();
    6051    }
     
    7768    // data has been extracted from the kernel for further pipeline processing, the
    7869    // segment number must be incremented and stored using releaseLogicalSegmentNo.
    79     llvm::Value * acquireLogicalSegmentNo(llvm::Value * kernelInstance);
    80     void releaseLogicalSegmentNo(llvm::Value * kernelInstance, Value * newFieldVal);
     70    LoadInst * acquireLogicalSegmentNo(Value * self) const;
    8171
     72    void releaseLogicalSegmentNo(Value * self, Value * newFieldVal) const;
     73
     74    virtual ~KernelBuilder() = 0;
    8275
    8376protected:
     77
     78    // Constructor
     79    KernelBuilder(IDISA::IDISA_Builder * builder,
     80                    std::string kernelName,
     81                    std::vector<Binding> stream_inputs,
     82                    std::vector<Binding> stream_outputs,
     83                    std::vector<Binding> scalar_parameters,
     84                    std::vector<Binding> scalar_outputs,
     85                    std::vector<Binding> internal_scalars);
     86
    8487    //
    8588    // Kernel builder subtypes define their logic of kernel construction
     
    97100    // Each kernel builder subtype must provide its own logic for generating
    98101    // doBlock calls.
    99     virtual void generateDoBlockMethod() = 0;
    100     virtual void generateDoBlockLogic(Value * self, Value * blockNo);
     102    virtual void generateDoBlockMethod() const = 0;
     103
     104    virtual void generateDoBlockLogic(Value * self, Value * blockNo) const;
    101105
    102106    // Each kernel builder subtypre must also specify the logic for processing the
     
    107111    // not be overridden.
    108112   
    109     virtual void generateFinalBlockMethod();
    110    
    111     virtual void generateDoSegmentMethod();
     113    virtual void generateFinalBlockMethod() const;
     114
     115    virtual void generateDoSegmentMethod() const;
    112116   
    113117    // Add an additional scalar field to the KernelState struct.
    114118    // Must occur before any call to addKernelDeclarations or createKernelModule.
    115     unsigned addScalar(llvm::Type * type, std::string name);
     119    unsigned addScalar(Type * type, const std::string & name);
    116120
    117121    unsigned getScalarCount() const;
     
    124128   
    125129    // Get the value of a scalar field for a given instance.
    126     llvm::Value * getScalarField(llvm::Value * self, std::string fieldName);
     130    Value * getScalarField(Value * self, const std::string & fieldName) const;
    127131
    128132    // Set the value of a scalar field for a given instance.
    129     void setScalarField(llvm::Value * self, std::string fieldName, llvm::Value * newFieldVal);
     133    void setScalarField(Value * self, const std::string & fieldName, Value * newFieldVal) const;
    130134   
    131135    // Get a parameter by name.
    132     llvm::Value * getParameter(llvm::Function * f, std::string paramName);
     136    Value * getParameter(Function * f, const std::string & paramName) const;
     137
     138    Value * getStream(Value * self, const std::string & name, Value * blockNo, const unsigned index) {
     139        return getStream(self, name, blockNo, iBuilder->getInt32(index));
     140    }
     141
     142    Value * getStream(Value * self, const std::string & name, Value * blockNo, Value * index);
    133143   
    134144    // Stream set helpers.
    135     unsigned getStreamSetIndex(std::string name);
     145    unsigned getStreamSetIndex(const std::string & name) const;
    136146   
    137     llvm::Value * getScalarFieldPtr(Value * self, const std::string & name);
     147    Value * getScalarFieldPtr(Value * self, const std::string & name) const;
    138148
    139     llvm::Value * getStreamSetStructPtr(Value * self, std::string name);
    140     size_t getStreamSetBufferSize(Value * self, std::string name);
     149    Value * getStreamSetStructPtr(Value * self, const std::string & name) const;
    141150
    142     llvm::Value * getStreamSetBlockPtr(Value * self, std::string name, Value * blockNo);
     151    size_t getStreamSetBufferSize(Value * self, const std::string & name) const;
     152
     153    Value * getStreamSetBlockPtr(Value * self, const std::string & name, Value * blockNo) const;
    143154   
    144     void setBlockNo(Value * self, Value * newFieldVal);
    145     virtual void setProcessedItemCount(llvm::Value * self, Value * newFieldVal);
    146     virtual void setProducedItemCount(llvm::Value * self, Value * newFieldVal);
    147     void setTerminationSignal(llvm::Value * self);
     155    void setBlockNo(Value * self, Value * newFieldVal) const;
     156
     157    virtual void setProcessedItemCount(Value * self, Value * newFieldVal) const;
     158
     159    virtual void setProducedItemCount(Value * self, Value * newFieldVal) const;
     160
     161    void setTerminationSignal(Value * self) const;
    148162
    149163protected:
    150164
    151     std::vector<llvm::Type *>  mKernelFields;
    152     NameMap                    mKernelMap;
    153     NameMap                    mStreamSetNameMap;
    154     std::vector<StreamSetBuffer *> mStreamSetInputBuffers;
    155     std::vector<StreamSetBuffer *> mStreamSetOutputBuffers;
     165    std::vector<Type *>             mKernelFields;
     166    NameMap                         mKernelMap;
     167    NameMap                         mStreamSetNameMap;
     168    std::vector<StreamSetBuffer *>  mStreamSetInputBuffers;
     169    std::vector<StreamSetBuffer *>  mStreamSetOutputBuffers;
    156170
    157171};
Note: See TracChangeset for help on using the changeset viewer.