Ignore:
Timestamp:
May 7, 2017, 4:34:48 PM (2 years ago)
Author:
nmedfort
Message:

Continued refactoring work. PabloKernel? now abstract base type with a 'generatePabloMethod' hook to generate Pablo code.

Location:
icGREP/icgrep-devel/icgrep/toolchain
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/toolchain/pipeline.cpp

    r5435 r5436  
    1111#include <boost/container/flat_set.hpp>
    1212#include <boost/container/flat_map.hpp>
     13#include <kernels/kernel_builder.h>
    1314
    1415using namespace kernel;
     
    1617using namespace llvm;
    1718
     19
    1820template <typename Value>
    1921using StreamSetBufferMap = boost::container::flat_map<const StreamSetBuffer *, Value>;
     
    2224using FlatSet = boost::container::flat_set<Value>;
    2325
    24 Function * makeThreadFunction(IDISA::IDISA_Builder * const b, const std::string & name) {
     26Function * makeThreadFunction(const std::unique_ptr<kernel::KernelBuilder> & b, const std::string & name) {
    2527    Function * const f = Function::Create(FunctionType::get(b->getVoidTy(), {b->getVoidPtrTy()}, false), Function::InternalLinkage, name, b->getModule());
    2628    f->setCallingConv(CallingConv::C);
     
    3840 * fashion such that processing of segment S_i by the full pipeline is carried out by thread i mod T.
    3941 ** ------------------------------------------------------------------------------------------------------------- */
    40 void generateSegmentParallelPipeline(IDISA::IDISA_Builder * const iBuilder, const std::vector<Kernel *> & kernels) {
     42void generateSegmentParallelPipeline(const std::unique_ptr<KernelBuilder> & iBuilder, const std::vector<Kernel *> & kernels) {
    4143
    4244    const unsigned n = kernels.size();
     
    256258 * @brief generateParallelPipeline
    257259 ** ------------------------------------------------------------------------------------------------------------- */
    258 void generateParallelPipeline(IDISA::IDISA_Builder * const iBuilder, const std::vector<Kernel *> &kernels) {
     260void generateParallelPipeline(const std::unique_ptr<KernelBuilder> & iBuilder, const std::vector<Kernel *> &kernels) {
    259261
    260262    Module * const m = iBuilder->getModule();
     
    450452 * @brief generatePipelineLoop
    451453 ** ------------------------------------------------------------------------------------------------------------- */
    452 void generatePipelineLoop(IDISA::IDISA_Builder * const iBuilder, const std::vector<Kernel *> & kernels) {
     454void generatePipelineLoop(const std::unique_ptr<KernelBuilder> & iBuilder, const std::vector<Kernel *> & kernels) {
    453455
    454456    BasicBlock * entryBlock = iBuilder->GetInsertBlock();
  • icGREP/icgrep-devel/icgrep/toolchain/pipeline.h

    r5435 r5436  
    1111namespace IDISA { class IDISA_Builder; }
    1212namespace kernel { class Kernel; }
     13namespace kernel { class KernelBuilder; }
    1314
    14 void generateSegmentParallelPipeline(IDISA::IDISA_Builder * const iBuilder, const std::vector<kernel::Kernel *> & kernels);
    15 void generatePipelineLoop(IDISA::IDISA_Builder * const iBuilder, const std::vector<kernel::Kernel *> & kernels);
    16 void generateParallelPipeline(IDISA::IDISA_Builder * const iBuilder, const std::vector<kernel::Kernel *> & kernels);
     15void generateSegmentParallelPipeline(const std::unique_ptr<kernel::KernelBuilder> &iBuilder, const std::vector<kernel::Kernel *> & kernels);
     16void generateParallelPipeline(const std::unique_ptr<kernel::KernelBuilder> &iBuilder, const std::vector<kernel::Kernel *> & kernels);
     17void generatePipelineLoop(const std::unique_ptr<kernel::KernelBuilder> &iBuilder, const std::vector<kernel::Kernel *> & kernels);
    1718
    1819#endif // PIPELINE_H
  • icGREP/icgrep-devel/icgrep/toolchain/toolchain.cpp

    r5435 r5436  
    2929#include <toolchain/object_cache.h>
    3030#include <toolchain/pipeline.h>
     31#include <kernels/kernel_builder.h>
    3132#include <kernels/kernel.h>
    3233#include <sys/stat.h>
     
    181182    iBuilder.reset(IDISA::GetIDISA_Builder(mMainModule));
    182183    iBuilder->setDriver(this);
     184    iBuilder->setModule(mMainModule);
    183185}
    184186
     
    199201}
    200202
    201 void ParabixDriver::addKernelCall(kernel::Kernel & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) {
     203void ParabixDriver::addKernelCall(kernel::Kernel & kb, const std::vector<StreamSetBuffer *> & inputs, const std::vector<StreamSetBuffer *> & outputs) {
    202204    assert ("addKernelCall or makeKernelCall was already run on this kernel." && (kb.getModule() == nullptr));
    203205    mPipeline.emplace_back(&kb);
    204     kb.setBuilder(iBuilder.get());
     206    assert (mMainModule);
     207    kb.setBuilder(iBuilder);
    205208    kb.createKernelStub(inputs, outputs);
    206209}
    207210
    208 void ParabixDriver::makeKernelCall(kernel::Kernel * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) {
     211void ParabixDriver::makeKernelCall(kernel::Kernel * kb, const std::vector<StreamSetBuffer *> & inputs, const std::vector<StreamSetBuffer *> & outputs) {
    209212    assert ("addKernelCall or makeKernelCall was already run on this kernel." && (kb->getModule() == nullptr));
    210     mPipeline.emplace_back(kb);
    211     kb->setBuilder(iBuilder.get());
     213    mPipeline.emplace_back(kb);   
     214    kb->setBuilder(iBuilder);
    212215    kb->createKernelStub(inputs, outputs);
    213216}
     
    227230    // note: instantiation of all kernels must occur prior to initialization
    228231    for (const auto & k : mPipeline) {
    229         k->setBuilder(iBuilder.get());
    230232        k->addKernelDeclarations();
    231233    }
    232234    for (const auto & k : mPipeline) {
    233         k->setBuilder(iBuilder.get());
    234235        k->createInstance();
    235236    }
    236237    for (const auto & k : mPipeline) {
    237         k->setBuilder(iBuilder.get());
    238238        k->initializeInstance();
    239239    }
    240240    if (codegen::pipelineParallel) {
    241         generateParallelPipeline(iBuilder.get(), mPipeline);
     241        generateParallelPipeline(iBuilder, mPipeline);
    242242    } else if (codegen::segmentPipelineParallel) {
    243         generateSegmentParallelPipeline(iBuilder.get(), mPipeline);
     243        generateSegmentParallelPipeline(iBuilder, mPipeline);
    244244    } else {
    245245        codegen::ThreadNum = 1;
    246         generatePipelineLoop(iBuilder.get(), mPipeline);
     246        generatePipelineLoop(iBuilder, mPipeline);
    247247    }
    248248    for (const auto & k : mPipeline) {
    249         k->setBuilder(iBuilder.get());
     249        k->setBuilder(iBuilder);
    250250        k->finalizeInstance();
    251251    }
     
    310310        if (uncachedObject) {
    311311            iBuilder->setModule(m);
    312             k->setBuilder(iBuilder.get());
     312            k->setBuilder(iBuilder);
    313313            k->generateKernel();
    314314            PM.run(*m);
     
    327327    } catch (...) { m->dump(); throw; }
    328328    #endif
     329}
     330
     331const std::unique_ptr<kernel::KernelBuilder> & ParabixDriver::getBuilder() {
     332    return iBuilder;
    329333}
    330334
  • icGREP/icgrep-devel/icgrep/toolchain/toolchain.h

    r5435 r5436  
    1010#include <IR_Gen/FunctionTypeBuilder.h>
    1111#include <kernels/kernel.h>
    12 #include <kernels/kernel_builder.h>
    1312#include <kernels/streamset.h>
    1413
    1514namespace llvm { class ExecutionEngine; }
     15namespace llvm { class Function; }
    1616namespace llvm { class Module; }
    1717namespace llvm { class TargetMachine; }
    1818namespace llvm { class formatted_raw_ostream; }
    1919namespace llvm { namespace cl { class OptionCategory; } }
     20namespace kernel { class Kernel; }
     21namespace kernel { class KernelBuilder; }
    2022namespace IDISA { class IDISA_Builder; }
    21 namespace kernel { class Kernel; }
    2223
    2324class ParabixObjectCache;
     
    6768    ~ParabixDriver();
    6869   
    69     const std::unique_ptr<IDISA::IDISA_Builder> & getBuilder() { return iBuilder; }
     70    const std::unique_ptr<kernel::KernelBuilder> & getBuilder();
    7071   
    7172    parabix::ExternalBuffer * addExternalBuffer(std::unique_ptr<parabix::ExternalBuffer> b);
     
    9394
    9495private:
    95     std::unique_ptr<llvm::LLVMContext>      mContext;
    96     llvm::Module * const                    mMainModule;
    97     std::unique_ptr<IDISA::IDISA_Builder>   iBuilder;
    98     llvm::TargetMachine *                   mTarget;
    99     llvm::ExecutionEngine *                 mEngine;
    100     ParabixObjectCache *                    mCache;
     96    std::unique_ptr<llvm::LLVMContext>                      mContext;
     97    llvm::Module * const                                    mMainModule;
     98    std::unique_ptr<kernel::KernelBuilder>                  iBuilder;
     99    llvm::TargetMachine *                                   mTarget;
     100    llvm::ExecutionEngine *                                 mEngine;
     101    ParabixObjectCache *                                    mCache;
    101102
    102     std::vector<kernel::Kernel *>    mPipeline;
     103    std::vector<kernel::Kernel *>                           mPipeline;
    103104    // Owned kernels and buffers that will persist with this ParabixDriver instance.
    104     std::vector<std::unique_ptr<kernel::Kernel>> mOwnedKernels;
    105     std::vector<std::unique_ptr<parabix::StreamSetBuffer>> mOwnedBuffers;
     105    std::vector<std::unique_ptr<kernel::Kernel>>            mOwnedKernels;
     106    std::vector<std::unique_ptr<parabix::StreamSetBuffer>>  mOwnedBuffers;
    106107};
    107108
    108109template <typename ExternalFunctionType>
    109110llvm::Function * ParabixDriver::LinkFunction(kernel::Kernel & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const {
    110     llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(iBuilder->getContext());
     111    llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(*mContext.get());
    111112    assert ("FunctionTypeBuilder did not resolve a function type." && type);
    112113    return LinkFunction(kb.getModule(), name, type, reinterpret_cast<void *>(functionPtr));
Note: See TracChangeset for help on using the changeset viewer.