Ignore:
Timestamp:
May 6, 2017, 4:05:05 PM (2 years ago)
Author:
nmedfort
Message:

Continued refactoring work.

File:
1 edited

Legend:

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

    r5431 r5435  
    44 */
    55
    6 #ifndef KERNEL_BUILDER_H
    7 #define KERNEL_BUILDER_H
     6#ifndef KERNEL_H
     7#define KERNEL_H
    88
    99#include "interface.h"
     
    2222namespace kernel {
    2323   
    24 class KernelBuilder : public KernelInterface {
     24class Kernel : public KernelInterface {
    2525protected:
    2626    using KernelMap = boost::container::flat_map<std::string, unsigned>;
     
    2929    using StreamMap = boost::container::flat_map<std::string, StreamPort>;
    3030    using StreamSetBuffers = std::vector<parabix::StreamSetBuffer *>;
    31     using Kernels = std::vector<KernelBuilder *>;
    32 
    33     friend void ::generateSegmentParallelPipeline(std::unique_ptr<IDISA::IDISA_Builder> &, const Kernels &);
    34     friend void ::generatePipelineLoop(std::unique_ptr<IDISA::IDISA_Builder> &, const Kernels &);
    35     friend void ::generateParallelPipeline(std::unique_ptr<IDISA::IDISA_Builder> &, const Kernels &);
     31    using Kernels = std::vector<Kernel *>;
     32
     33    friend class KernelBuilder;
     34    friend void ::generateSegmentParallelPipeline(IDISA::IDISA_Builder * const, const Kernels &);
     35    friend void ::generatePipelineLoop(IDISA::IDISA_Builder * const, const Kernels &);
     36    friend void ::generateParallelPipeline(IDISA::IDISA_Builder * const, const Kernels &);
     37
     38    static const std::string DO_BLOCK_SUFFIX;
     39    static const std::string FINAL_BLOCK_SUFFIX;
     40    static const std::string LOGICAL_SEGMENT_NO_SCALAR;
     41    static const std::string PROCESSED_ITEM_COUNT_SUFFIX;
     42    static const std::string CONSUMED_ITEM_COUNT_SUFFIX;
     43    static const std::string PRODUCED_ITEM_COUNT_SUFFIX;
     44    static const std::string TERMINATION_SIGNAL;
     45    static const std::string BUFFER_PTR_SUFFIX;
     46    static const std::string CONSUMER_SUFFIX;
     47
    3648public:
    3749   
     
    101113    void setConsumedItemCount(const std::string & name, llvm::Value * value) const final;
    102114
     115    llvm::Value * getTerminationSignal() const final;
     116
     117    void setTerminationSignal() const final;
     118
    103119    bool hasNoTerminateAttribute() const {
    104120        return mNoTerminateAttribute;
    105121    }
    106    
    107     llvm::Value * getTerminationSignal() const final;
    108 
    109     void setTerminationSignal() const final;
    110122
    111123    // Get the value of a scalar field for the current instance.
     
    115127
    116128    llvm::Value * getScalarFieldPtr(const std::string & fieldName) const {
    117         return getScalarFieldPtr(getScalarIndex(fieldName));
     129        return getScalarFieldPtr(iBuilder->getInt32(getScalarIndex(fieldName)));
    118130    }
    119131
     
    143155    llvm::Argument * getParameter(llvm::Function * f, const std::string & name) const;
    144156
    145     inline llvm::IntegerType * getSizeTy() const {
    146         return getBuilder()->getSizeTy();
    147     }
    148 
    149     inline llvm::Type * getStreamTy(const unsigned FieldWidth = 1) {
    150         return getBuilder()->getStreamTy(FieldWidth);
    151     }
    152    
    153     inline llvm::Type * getStreamSetTy(const unsigned NumElements = 1, const unsigned FieldWidth = 1) {
    154         return getBuilder()->getStreamSetTy(NumElements, FieldWidth);
    155     }
    156        
    157     const StreamSetBuffers & getStreamSetInputBuffers() const { return mStreamSetInputBuffers; }
    158 
    159     const parabix::StreamSetBuffer * getStreamSetInputBuffer(const unsigned i) const { return mStreamSetInputBuffers[i]; }
    160 
    161     const StreamSetBuffers & getStreamSetOutputBuffers() const { return mStreamSetOutputBuffers; }
    162 
    163     const parabix::StreamSetBuffer * getStreamSetOutputBuffer(const unsigned i) const { return mStreamSetOutputBuffers[i]; }
     157    const StreamSetBuffers & getStreamSetInputBuffers() const {
     158        return mStreamSetInputBuffers;
     159    }
     160
     161    const parabix::StreamSetBuffer * getStreamSetInputBuffer(const unsigned i) const {
     162        return mStreamSetInputBuffers[i];
     163    }
     164
     165    const StreamSetBuffers & getStreamSetOutputBuffers() const {
     166        return mStreamSetOutputBuffers;
     167    }
     168
     169    const parabix::StreamSetBuffer * getStreamSetOutputBuffer(const unsigned i) const {
     170        return mStreamSetOutputBuffers[i];
     171    }
    164172
    165173    llvm::CallInst * createDoSegmentCall(const std::vector<llvm::Value *> & args) const;
     
    167175    llvm::Value * getAccumulator(const std::string & accumName) const;
    168176
    169     virtual ~KernelBuilder() = 0;
     177    virtual ~Kernel() = 0;
    170178
    171179protected:
    172180
    173181    // Constructor
    174     KernelBuilder(IDISA::IDISA_Builder * builder,
    175                   std::string && kernelName,
     182    Kernel(std::string && kernelName,
    176183                  std::vector<Binding> && stream_inputs,
    177184                  std::vector<Binding> && stream_outputs,
     
    190197    // all scalar fields have been added.   If there are no fields to
    191198    // be added, the default method for preparing kernel state may be used.
    192    
     199
    193200    void setNoTerminateAttribute(const bool noTerminate = true) {
    194201        mNoTerminateAttribute = noTerminate;
     
    217224   
    218225    // Get the index of a named scalar field within the kernel state struct.
    219     llvm::ConstantInt * getScalarIndex(const std::string & name) const;
     226    unsigned getScalarIndex(const std::string & name) const;
    220227
    221228    llvm::Value * getInputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex) const;
     
    258265
    259266    llvm::Value * getLinearlyAccessibleItems(const std::string & name, llvm::Value * fromPosition) const;
     267
     268    llvm::BasicBlock * CreateWaitForConsumers() const;
     269
     270    llvm::BasicBlock * CreateBasicBlock(std::string && name) const;
     271
     272    llvm::Value * getStreamSetBufferPtr(const std::string & name) const;
    260273
    261274    llvm::Value * getIsFinal() const {
    262275        return mIsFinal;
    263276    }
    264 
    265     llvm::BasicBlock * CreateWaitForConsumers() const;
    266 
    267     llvm::BasicBlock * CreateBasicBlock(std::string && name) const;
    268 
    269     llvm::Value * getStreamSetBufferPtr(const std::string & name) const;
    270277
    271278    void callGenerateInitializeMethod();
     
    313320protected:
    314321
    315     llvm::Module *                      mModule;
    316322    llvm::Function *                    mCurrentMethod;
    317323    bool                                mNoTerminateAttribute;
     
    331337};
    332338
    333 class SegmentOrientedKernel : public KernelBuilder {
    334 protected:
    335 
    336     SegmentOrientedKernel(IDISA::IDISA_Builder * builder,
    337                           std::string && kernelName,
     339class SegmentOrientedKernel : public Kernel {
     340protected:
     341
     342    SegmentOrientedKernel(std::string && kernelName,
    338343                          std::vector<Binding> && stream_inputs,
    339344                          std::vector<Binding> && stream_outputs,
     
    344349};
    345350
    346 class BlockOrientedKernel : public KernelBuilder {
     351class BlockOrientedKernel : public Kernel {
    347352protected:
    348353
     
    364369    void generateDoSegmentMethod() override final;
    365370
    366     BlockOrientedKernel(IDISA::IDISA_Builder * builder,
    367                         std::string && kernelName,
     371    BlockOrientedKernel(std::string && kernelName,
    368372                        std::vector<Binding> && stream_inputs,
    369373                        std::vector<Binding> && stream_outputs,
Note: See TracChangeset for help on using the changeset viewer.