Ignore:
Timestamp:
Nov 2, 2018, 7:18:31 PM (12 months ago)
Author:
nmedfort
Message:

Initial version of PipelineKernel? + revised StreamSet? model.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/toolchain/driver.h

    r6047 r6184  
    44#include <IR_Gen/FunctionTypeBuilder.h>
    55#include <llvm/ExecutionEngine/GenericValue.h>
     6#include <kernels/kernel.h>
    67#include <kernels/streamset.h>
    7 #include <kernels/kernel.h>
     8#include <kernels/relationship.h>
     9#include <toolchain/object_cache_manager.h>
     10#include <util/slab_allocator.h>
    811#include <string>
    912#include <vector>
     
    1215namespace llvm { class Function; }
    1316namespace kernel { class KernelBuilder; }
     17namespace kernel { class PipelineBuilder; }
     18class CBuilder;
    1419
    15 class Driver {
     20class ObjectCacheManager;
     21
     22class BaseDriver {
    1623    friend class CBuilder;
     24    friend class kernel::PipelineBuilder;
     25    using Kernel = kernel::Kernel;
     26    using Relationship = kernel::Relationship;
     27    using Bindings = kernel::Bindings;
     28    using OwnedKernels = std::vector<std::unique_ptr<Kernel>>;
     29
    1730public:
    18     Driver(std::string && moduleName);
     31
     32    std::unique_ptr<kernel::PipelineBuilder> makePipelineWithIO(Bindings stream_inputs = {}, Bindings stream_outputs = {}, Bindings scalar_inputs = {}, Bindings scalar_outputs = {});
     33
     34    std::unique_ptr<kernel::PipelineBuilder> makePipeline(Bindings scalar_inputs = {}, Bindings scalar_outputs = {});
    1935
    2036    const std::unique_ptr<kernel::KernelBuilder> & getBuilder() {
     
    2238    }
    2339
    24     template<typename BufferType, typename... Args>
    25     parabix::StreamSetBuffer * addBuffer(Args &&... args) {
    26         BufferType * const b = new BufferType(std::forward<Args>(args) ...);
    27         mOwnedBuffers.emplace_back(b);
    28         mOwnedBuffers.back()->allocateBuffer(iBuilder);
    29         return b;
    30     }
     40    kernel::StreamSet * CreateStreamSet(const unsigned NumElements = 1, const unsigned FieldWidth = 1);
    3141
    32     template<typename KernelType, typename... Args>
    33     kernel::Kernel * addKernelInstance(Args &&... args) {
    34         KernelType * const k = new KernelType(std::forward<Args>(args) ...);
    35         mOwnedKernels.emplace_back(k);
    36         return k;
    37     }
     42    kernel::Scalar * CreateScalar(llvm::Type * scalarType);
    3843
    39     virtual void makeKernelCall(kernel::Kernel * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) = 0;
     44    kernel::Scalar * CreateConstant(llvm::Constant * value);
    4045
    41     virtual void generatePipelineIR() = 0;
     46    void addKernel(Kernel * const kernel);
    4247
    4348    template <typename ExternalFunctionType>
    44     llvm::Function * LinkFunction(kernel::Kernel & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const;
     49    llvm::Function * LinkFunction(not_null<Kernel *> kb, llvm::StringRef name, ExternalFunctionType & functionPtr) const;
    4550
    4651    virtual bool hasExternalFunction(const llvm::StringRef functionName) const = 0;
    4752
    48     void deallocateBuffers();
     53    virtual void generateUncachedKernels() = 0;
     54
     55    virtual void * finalizeObject(llvm::Function * mainMethod) = 0;
    4956   
    50     virtual void finalizeObject() = 0;
    51    
    52     virtual void * getMain() = 0; // "main" exists until the driver is deleted
    53    
    54     virtual void performIncrementalCacheCleanupStep() = 0;
     57    virtual ~BaseDriver();
    5558
    56     virtual ~Driver() = 0;
     59    llvm::LLVMContext & getContext() const {
     60        return *mContext.get();
     61    }
     62
     63    llvm::Module * getMainModule() const {
     64        return mMainModule;
     65    }
    5766
    5867protected:
     68
     69    BaseDriver(std::string && moduleName);
    5970
    6071    virtual llvm::Function * addLinkFunction(llvm::Module * mod, llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const = 0;
    6172
    6273protected:
     74
    6375    std::unique_ptr<llvm::LLVMContext>                      mContext;
    6476    llvm::Module * const                                    mMainModule;
    6577    std::unique_ptr<kernel::KernelBuilder>                  iBuilder;
    66     std::vector<std::unique_ptr<kernel::Kernel>>            mOwnedKernels;
    67     std::vector<std::unique_ptr<parabix::StreamSetBuffer>>  mOwnedBuffers;
    68     std::vector<kernel::Kernel *>                           mPipeline;
     78    OwnedKernels                                            mUncachedKernel;
     79    OwnedKernels                                            mCachedKernel;
     80    SlabAllocator<>                                         mAllocator;
    6981};
    7082
    7183template <typename ExternalFunctionType>
    72 llvm::Function * Driver::LinkFunction(kernel::Kernel & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const {
    73     llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(*mContext.get());
     84llvm::Function * BaseDriver::LinkFunction(not_null<Kernel *> kb, llvm::StringRef name, ExternalFunctionType & functionPtr) const {
     85    llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(getContext());
    7486    assert ("FunctionTypeBuilder did not resolve a function type." && type);
    75     return addLinkFunction(kb.getModule(), name, type, reinterpret_cast<void *>(functionPtr));
     87    return addLinkFunction(kb->getModule(), name, type, reinterpret_cast<void *>(functionPtr));
    7688}
    7789
Note: See TracChangeset for help on using the changeset viewer.