Ignore:
Timestamp:
Apr 15, 2017, 4:42:33 PM (2 years ago)
Author:
nmedfort
Message:

First attempt to allow Kernels to wait for consumers to finish processing before performing a realloc.

File:
1 edited

Legend:

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

    r5403 r5408  
    1212#include <boost/container/flat_map.hpp>
    1313#include <IR_Gen/idisa_builder.h>
     14#include <kernels/pipeline.h>
    1415
    1516//namespace llvm { class ConstantInt; }
     
    3132    using StreamMap = boost::container::flat_map<std::string, StreamPort>;
    3233    using StreamSetBuffers = std::vector<parabix::StreamSetBuffer *>;
     34
     35    friend void ::generateSegmentParallelPipeline(IDISA::IDISA_Builder *, const std::vector<KernelBuilder *> &);
     36    friend void ::generatePipelineLoop(IDISA::IDISA_Builder *, const std::vector<KernelBuilder *> &);
     37    friend void ::generateParallelPipeline(IDISA::IDISA_Builder *, const std::vector<KernelBuilder *> &);
    3338public:
    3439   
     
    6873    llvm::Module * createKernelStub(const StreamSetBuffers & inputs, const StreamSetBuffers & outputs);
    6974     
    70     void setCallParameters(const StreamSetBuffers & inputs, const StreamSetBuffers & outputs);
    71 
    7275    // Generate the Kernel to the current module (iBuilder->getModule()).
    7376    void generateKernel();
    7477   
    75     void createInstance() override;
    76 
    77     llvm::Value * getProducedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * doFinal = nullptr) const final;
    78 
    79     void setProducedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const final;
    80 
    81     llvm::Value * getProcessedItemCount(llvm::Value * instance, const std::string & name) const final;
    82 
    83     void setProcessedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const final;
    84 
    85     bool hasNoTerminateAttribute() { return mNoTerminateAttribute;}
    86    
    87     llvm::Value * getTerminationSignal(llvm::Value * instance) const final;
    88 
    89     void setTerminationSignal(llvm::Value * instance) const final;
    90 
    91     // Get the value of a scalar field for a given instance.
    92     llvm::Value * getScalarField(llvm::Value * instance, const std::string & fieldName) const;
    93 
    94     llvm::Value * getScalarField(llvm::Value * instance, llvm::Value * index) const;
    95 
    96     // Set the value of a scalar field for a given instance.
    97     void setScalarField(llvm::Value *instance, const std::string & fieldName, llvm::Value * value) const;
    98 
    99     void setScalarField(llvm::Value * instance, llvm::Value * index, llvm::Value * value) const;
     78    llvm::Value * createInstance() final;
     79
     80    void initializeInstance() final;
     81
     82    llvm::Value * getProducedItemCount(const std::string & name, llvm::Value * doFinal = nullptr) const final;
     83
     84    void setProducedItemCount(const std::string & name, llvm::Value * value) const final;
     85
     86    llvm::Value * getProcessedItemCount(const std::string & name) const final;
     87
     88    void setProcessedItemCount(const std::string & name, llvm::Value * value) const final;
     89
     90    bool hasNoTerminateAttribute() const {
     91        return mNoTerminateAttribute;
     92    }
     93   
     94    llvm::Value * getTerminationSignal() const final;
     95
     96    void setTerminationSignal() const final;
     97
     98    // Get the value of a scalar field for the current instance.
     99    llvm::Value * getScalarFieldPtr(llvm::Value * index) const {
     100        return getScalarFieldPtr(getInstance(), index);
     101    }
     102
     103    llvm::Value * getScalarFieldPtr(const std::string & fieldName) const {
     104        return getScalarFieldPtr(getInstance(), fieldName);
     105    }
     106
     107    llvm::Value * getScalarField(const std::string & fieldName) const {
     108        return iBuilder->CreateLoad(getScalarFieldPtr(fieldName));
     109    }
     110
     111    llvm::Value * getScalarField(llvm::Value * index) const {
     112        return iBuilder->CreateLoad(getScalarFieldPtr(index));
     113    }
     114
     115    // Set the value of a scalar field for the current instance.
     116    void setScalarField(const std::string & fieldName, llvm::Value * value) const {
     117        iBuilder->CreateStore(value, getScalarFieldPtr(fieldName));
     118    }
     119
     120    void setScalarField(llvm::Value * index, llvm::Value * value) const {
     121        iBuilder->CreateStore(value, getScalarFieldPtr(index));
     122    }
     123
    100124
    101125    // Synchronization actions for executing a kernel for a particular logical segment.
     
    108132    // data has been extracted from the kernel for further pipeline processing, the
    109133    // segment number must be incremented and stored using releaseLogicalSegmentNo.
    110     llvm::LoadInst * acquireLogicalSegmentNo(llvm::Value * instance) const;
    111 
    112     void releaseLogicalSegmentNo(llvm::Value * instance, llvm::Value * newFieldVal) const;
     134    llvm::LoadInst * acquireLogicalSegmentNo() const;
     135
     136    void releaseLogicalSegmentNo(llvm::Value * nextSegNo) const;
     137
     138    llvm::Value * getConsumerState(const std::string & name) const;
    113139
    114140    // Get a parameter by name.
     
    126152        return getBuilder()->getStreamSetTy(NumElements, FieldWidth);
    127153    }
    128    
     154       
     155    const StreamSetBuffers & getStreamSetInputBuffers() const { return mStreamSetInputBuffers; }
     156
     157    const parabix::StreamSetBuffer * getStreamSetInputBuffer(const unsigned i) const { return mStreamSetInputBuffers[i]; }
     158
     159    const StreamSetBuffers & getStreamSetOutputBuffers() const { return mStreamSetOutputBuffers; }
     160
     161    const parabix::StreamSetBuffer * getStreamSetOutputBuffer(const unsigned i) const { return mStreamSetOutputBuffers[i]; }
     162
     163    llvm::CallInst * createDoSegmentCall(const std::vector<llvm::Value *> & args) const;
     164
     165    llvm::CallInst * createGetAccumulatorCall(llvm::Value * self, const std::string & accumName) const;
     166
    129167    virtual ~KernelBuilder() = 0;
    130    
    131     const std::vector<const parabix::StreamSetBuffer *> & getStreamSetInputBuffers() const { return mStreamSetInputBuffers; }
    132 
    133     const parabix::StreamSetBuffer * getStreamSetInputBuffer(const unsigned i) const { return mStreamSetInputBuffers[i]; }
    134 
    135     const std::vector<const parabix::StreamSetBuffer *> & getStreamSetOutputBuffers() const { return mStreamSetOutputBuffers; }
    136 
    137     const parabix::StreamSetBuffer * getStreamSetOutputBuffer(const unsigned i) const { return mStreamSetOutputBuffers[i]; }
    138 
    139     llvm::CallInst * createDoSegmentCall(const std::vector<llvm::Value *> & args) const;
    140 
    141     llvm::CallInst * createGetAccumulatorCall(llvm::Value * self, const std::string & accumName) const;
    142168
    143169protected:
     
    181207    unsigned addUnnamedScalar(llvm::Type * type);
    182208
    183     unsigned getScalarCount() const;
    184 
    185209    // Run-time access of Kernel State and parameters of methods for
    186210    // use in implementing kernels.
     
    189213    llvm::ConstantInt * getScalarIndex(const std::string & name) const;
    190214
    191     // Get the value of a scalar field for a given instance.
    192     llvm::Value * getScalarField(const std::string & fieldName) const {
    193         return getScalarField(getSelf(), fieldName);
    194     }
    195 
    196     llvm::Value * getScalarField(llvm::Value * index) const {
    197         return getScalarField(getSelf(), index);
    198     }
    199 
    200     // Set the value of a scalar field for a given instance.
    201     void setScalarField(const std::string & fieldName, llvm::Value * value) const {
    202         return setScalarField(getSelf(), fieldName, value);
    203     }
    204 
    205     void setScalarField(llvm::Value * index, llvm::Value * value) const {
    206         return setScalarField(getSelf(), index, value);
    207     }
    208 
    209215    llvm::Value * getInputStreamBlockPtr(const std::string & name, llvm::Value * streamIndex) const;
    210216
     
    241247    void reserveBytes(const std::string & name, llvm::Value * requested) const;
    242248
    243     llvm::Value * getScalarFieldPtr(const std::string & name) const {
    244         return getScalarFieldPtr(getSelf(), name);
    245     }
    246 
    247     llvm::Value * getScalarFieldPtr(llvm::Value * index) const {
    248         return getScalarFieldPtr(getSelf(), index);
    249     }
    250 
    251     inline llvm::Value * getProducedItemCount(const std::string & name) const {
    252         return getProducedItemCount(getSelf(), name);
    253     }
    254 
    255     inline void setProducedItemCount(const std::string & name, llvm::Value * value) const {
    256         setProducedItemCount(getSelf(), name, value);
    257     }
    258 
    259249    llvm::Value * getAvailableItemCount(const std::string & name) const;
    260250
    261     inline llvm::Value * getProcessedItemCount(const std::string & name) const {
    262         return getProcessedItemCount(getSelf(), name);
    263     }
    264 
    265     inline void setProcessedItemCount(const std::string & name, llvm::Value * value) const {
    266         setProcessedItemCount(getSelf(), name, value);
    267     }
    268 
    269     llvm::Value * getConsumedItemCount(const std::string & name) const;
    270 
    271     llvm::Value * getTerminationSignal() const {
    272         return getTerminationSignal(getSelf());
    273     }
    274 
    275     void setTerminationSignal() const {
    276         return setTerminationSignal(getSelf());
    277     }
    278 
    279     llvm::Value * getSelf() const {
    280         return mSelf;
    281     }
    282 
    283251    llvm::BasicBlock * CreateBasicBlock(std::string && name) const;
    284252
     
    287255    llvm::Value * getStreamSetBufferPtr(const std::string & name) const;
    288256
    289     llvm::Value * getScalarFieldPtr(llvm::Value * instance, const std::string & name) const;
    290 
    291     llvm::Value * getScalarFieldPtr(llvm::Value * instance, llvm::Value * index) const;
     257    llvm::Value * getScalarFieldPtr(llvm::Value * const instance, llvm::Value * index) const {
     258        assert ("instance cannot be null!" && instance);
     259        return iBuilder->CreateGEP(getInstance(), {iBuilder->getInt32(0), index});
     260    }
     261
     262    llvm::Value * getScalarFieldPtr(llvm::Value * const instance, const std::string & fieldName) const {
     263        return getScalarFieldPtr(instance, getScalarIndex(fieldName));
     264    }
    292265
    293266    StreamPort getStreamPort(const std::string & name) const;
     
    311284    void callGenerateDoSegmentMethod();
    312285
     286
    313287private:
    314288
     289    void setConsumerState(const std::string & name, llvm::Value * value) const;
     290
    315291    llvm::Value * computeBlockIndex(const std::vector<Binding> & binding, const std::string & name, llvm::Value * itemCount) const;
    316292
    317293protected:
    318294
    319     llvm::Value *                                   mSelf;
    320     llvm::Function *                                mCurrentMethod;
    321 
    322     std::vector<llvm::Type *>                       mKernelFields;
    323     KernelMap                                       mKernelMap;
    324     StreamMap                                       mStreamMap;
    325     std::vector<const parabix::StreamSetBuffer *>   mStreamSetInputBuffers;
    326     std::vector<const parabix::StreamSetBuffer *>   mStreamSetOutputBuffers;
    327     bool                                            mNoTerminateAttribute;
    328     bool                                            mIsGenerated;
     295    llvm::Function *                mCurrentMethod;
     296    std::vector<llvm::Type *>       mKernelFields;
     297    KernelMap                       mKernelMap;
     298    StreamMap                       mStreamMap;
     299    StreamSetBuffers                mStreamSetInputBuffers;
     300    StreamSetBuffers                mStreamSetOutputBuffers;
     301    bool                            mNoTerminateAttribute;
     302    bool                            mIsGenerated;
    329303
    330304};
Note: See TracChangeset for help on using the changeset viewer.