Ignore:
Timestamp:
Apr 22, 2017, 4:03:25 PM (2 years ago)
Author:
nmedfort
Message:

Removed non-functional CUDA code from icgrep and consolidated grep and multigrep mode into a single function; allowed segment parallel pipeline to utilize process as its initial thread; modified MMapSourceKernel to map and perform mmap directly and advise the OS to drop consumed data streams.

File:
1 edited

Legend:

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

    r5411 r5418  
    77#define KERNEL_BUILDER_H
    88
    9 #include <string>           // for string
    10 #include <memory>           // for unique_ptr
    119#include "interface.h"      // for KernelInterface
    1210#include <boost/container/flat_map.hpp>
    1311#include <IR_Gen/idisa_builder.h>
    1412#include <kernels/pipeline.h>
    15 
    16 //namespace llvm { class ConstantInt; }
    1713#include <llvm/IR/Constants.h>
     14
     15//#include <string>           // for string
     16//#include <memory>           // for unique_ptr
     17
    1818namespace llvm { class Function; }
    1919namespace llvm { class IntegerType; }
     
    3232    using StreamMap = boost::container::flat_map<std::string, StreamPort>;
    3333    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 *> &);
     34    using Kernels = std::vector<KernelBuilder *>;
     35
     36    friend void ::generateSegmentParallelPipeline(IDISA::IDISA_Builder *, const Kernels &);
     37    friend void ::generatePipelineLoop(IDISA::IDISA_Builder *, const Kernels &);
     38    friend void ::generateParallelPipeline(IDISA::IDISA_Builder *, const Kernels &);
    3839public:
    3940   
     
    7172    // Create a module stub for the kernel, populated only with its Module ID.     
    7273    //
    73     llvm::Module * createKernelStub(const StreamSetBuffers & inputs, const StreamSetBuffers & outputs);
    74      
     74    void createKernelStub(const StreamSetBuffers & inputs, const StreamSetBuffers & outputs);
     75
     76    llvm::Module * getModule() const {
     77        return mModule;
     78    }
     79
    7580    // Generate the Kernel to the current module (iBuilder->getModule()).
    7681    void generateKernel();
     
    8085    void initializeInstance() final;
    8186
    82     void terminateInstance() final;
     87    void finalizeInstance() final;
    8388
    8489    llvm::Value * getProducedItemCount(const std::string & name, llvm::Value * doFinal = nullptr) const final;
     
    8994
    9095    void setProcessedItemCount(const std::string & name, llvm::Value * value) const final;
     96
     97    llvm::Value * getConsumedItemCount(const std::string & name) const final;
     98
     99    void setConsumedItemCount(const std::string & name, llvm::Value * value) const final;
    91100
    92101    bool hasNoTerminateAttribute() const {
     
    164173    llvm::CallInst * createDoSegmentCall(const std::vector<llvm::Value *> & args) const;
    165174
    166     llvm::CallInst * createGetAccumulatorCall(const std::string & accumName) const;
     175    llvm::Value * getAccumulator(const std::string & accumName) const;
    167176
    168177    virtual ~KernelBuilder() = 0;
     
    198207    virtual void prepareKernel();
    199208
    200     virtual void generateInitMethod() { }
    201    
    202     virtual void generateDoSegmentMethod(llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) = 0;
    203 
    204     virtual void generateTerminateMethod() { }
     209    virtual void generateInitializeMethod() { }
     210   
     211    virtual void generateDoSegmentMethod() = 0;
     212
     213    virtual void generateFinalizeMethod() { }
    205214
    206215    // Add an additional scalar field to the KernelState struct.
     
    242251    llvm::Value * getRawOutputPointer(const std::string & name, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
    243252
     253    llvm::Value * getBaseAddress(const std::string & name) const;
     254
    244255    void setBaseAddress(const std::string & name, llvm::Value * addr) const;
    245256
     
    251262
    252263    llvm::Value * getAvailableItemCount(const std::string & name) const;
     264
     265    llvm::Value * getIsFinal() const {
     266        return mIsFinal;
     267    }
     268
    253269
    254270    llvm::BasicBlock * CreateBasicBlock(std::string && name) const;
     
    266282        return getScalarFieldPtr(instance, getScalarIndex(fieldName));
    267283    }
     284
     285    void callGenerateInitializeMethod();
     286
     287    void callGenerateDoSegmentMethod();
     288
     289    void callGenerateFinalizeMethod();
    268290
    269291    StreamPort getStreamPort(const std::string & name) const;
     
    283305    }
    284306
    285     void callGenerateInitMethod();
    286 
    287     void callGenerateDoSegmentMethod();
    288 
    289     void callGenerateTerminateMethod();
     307    const parabix::StreamSetBuffer * getAnyStreamSetBuffer(const std::string & name) const {
     308        unsigned index; Port port;
     309        std::tie(port, index) = getStreamPort(name);
     310        if (port == Port::Input) {
     311            assert (index < mStreamSetInputBuffers.size());
     312            return mStreamSetInputBuffers[index];
     313        } else {
     314            assert (index < mStreamSetOutputBuffers.size());
     315            return mStreamSetOutputBuffers[index];
     316        }
     317    }
    290318
    291319private:
     
    297325protected:
    298326
    299     llvm::Function *                mCurrentMethod;
    300     std::vector<llvm::Type *>       mKernelFields;
    301     KernelMap                       mKernelMap;
    302     StreamMap                       mStreamMap;
    303     StreamSetBuffers                mStreamSetInputBuffers;
    304     StreamSetBuffers                mStreamSetOutputBuffers;
    305     bool                            mNoTerminateAttribute;
    306     bool                            mIsGenerated;
     327    llvm::Module *                      mModule;
     328    llvm::Function *                    mCurrentMethod;
     329    bool                                mNoTerminateAttribute;
     330    bool                                mIsGenerated;
     331
     332    llvm::Value *                       mIsFinal;
     333    std::vector<llvm::Value *>          mAvailableItemCount;
     334    llvm::Value *                       mOutputScalarResult;
     335
     336
     337    std::vector<llvm::Type *>           mKernelFields;
     338    KernelMap                           mKernelMap;
     339    StreamMap                           mStreamMap;
     340    StreamSetBuffers                    mStreamSetInputBuffers;
     341    StreamSetBuffers                    mStreamSetOutputBuffers;
    307342
    308343};
     
    339374    virtual void generateFinalBlockMethod(llvm::Value * remainingItems);
    340375
    341     void generateDoSegmentMethod(llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) override final;
     376    void generateDoSegmentMethod() override final;
    342377
    343378    BlockOrientedKernel(IDISA::IDISA_Builder * builder,
Note: See TracChangeset for help on using the changeset viewer.