Ignore:
Timestamp:
Sep 7, 2017, 4:56:56 PM (23 months ago)
Author:
nmedfort
Message:

Partial check-in for avoidance of compiling Pablo/LLVM code to determine the Kernel struct type when using a cached object. Inactive RE alternation minimization check in.

File:
1 edited

Legend:

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

    r5616 r5630  
    7070        throw std::runtime_error("Could not create ExecutionEngine: " + errMessage);
    7171    }
    72     mTarget = builder.selectTarget();
     72    mTarget = builder.selectTarget();   
    7373    if (LLVM_LIKELY(codegen::EnableObjectCache)) {
    7474        if (codegen::ObjectCacheDir) {
     
    8080    }
    8181    mMainModule->setTargetTriple(mTarget->getTargetTriple().getTriple());
    82 
    8382    iBuilder.reset(IDISA::GetIDISA_Builder(*mContext));
    8483    iBuilder->setDriver(this);
     
    8685}
    8786
    88 void ParabixDriver::makeKernelCall(Kernel * kb, const std::vector<StreamSetBuffer *> & inputs, const std::vector<StreamSetBuffer *> & outputs) {
    89     assert ("addKernelCall or makeKernelCall was already run on this kernel." && (kb->getModule() == nullptr));
    90     mPipeline.emplace_back(kb);
    91     kb->bindPorts(inputs, outputs);
    92     kb->makeModule(iBuilder);
     87void ParabixDriver::makeKernelCall(Kernel * kernel, const std::vector<StreamSetBuffer *> & inputs, const std::vector<StreamSetBuffer *> & outputs) {
     88    assert ("addKernelCall or makeKernelCall was already run on this kernel." && (kernel->getModule() == nullptr));
     89    mPipeline.emplace_back(kernel);
     90    kernel->bindPorts(inputs, outputs);
     91    if (!mCache || !mCache->loadCachedObjectFile(iBuilder, kernel)) {
     92        mUncachedKernel.push_back(kernel);
     93    }
     94    if (kernel->getModule() == nullptr) {
     95        kernel->makeModule(iBuilder);
     96    }
     97    assert (kernel->getModule());
    9398}
    9499
    95100void ParabixDriver::generatePipelineIR() {
    96     #ifndef NDEBUG
     101
    97102    if (LLVM_UNLIKELY(mPipeline.empty())) {
    98103        report_fatal_error("Pipeline cannot be empty");
     
    101106            for (auto j = i; ++j != mPipeline.end(); ) {
    102107                if (LLVM_UNLIKELY(*i == *j)) {
    103                     report_fatal_error("Kernel instances cannot occur twice in the pipeline");
     108                    report_fatal_error("Kernel " + (*i)->getName() + " occurs twice in the pipeline");
    104109                }
    105110            }
    106111        }
    107112    }
    108     #endif
     113
     114    for (Kernel * const kernel : mUncachedKernel) {
     115        kernel->prepareKernel(iBuilder);
     116    }
     117
    109118    // note: instantiation of all kernels must occur prior to initialization
    110119    for (const auto & k : mPipeline) {
     
    130139
    131140Function * ParabixDriver::addLinkFunction(Module * mod, llvm::StringRef name, FunctionType * type, void * functionPtr) const {
    132     assert ("addKernelCall or makeKernelCall must be called before LinkFunction" && (mod != nullptr));
     141    if (LLVM_UNLIKELY(mod == nullptr)) {
     142        report_fatal_error("addLinkFunction(" + name + ") cannot be called until after addKernelCall or makeKernelCall");
     143    }
    133144    Function * f = mod->getFunction(name);
    134145    if (LLVM_UNLIKELY(f == nullptr)) {
    135146        f = Function::Create(type, Function::ExternalLinkage, name, mod);
    136         mEngine->addGlobalMapping(f, functionPtr);
     147        mEngine->updateGlobalMapping(f, functionPtr);
    137148    } else if (LLVM_UNLIKELY(f->getType() != type->getPointerTo())) {
    138149        report_fatal_error("Cannot link " + name + ": a function with a different signature already exists with that name in " + mod->getName());
     
    193204
    194205    Module * module = nullptr;
    195 
    196206    try {
    197 
     207        for (Kernel * const kernel : mUncachedKernel) {
     208            iBuilder->setKernel(kernel);
     209            kernel->generateKernel(iBuilder);
     210            module = kernel->getModule(); assert (module);
     211            module->setTargetTriple(mMainModule->getTargetTriple());
     212            PM.run(*module);
     213        }
     214        module = mMainModule;
     215        iBuilder->setKernel(nullptr);
     216        PM.run(*mMainModule);
    198217        for (Kernel * const kernel : mPipeline) {
    199             iBuilder->setKernel(kernel);
    200             module = kernel->getModule();
    201             assert (module != mMainModule);
    202             bool uncachedObject = true;
    203             if (mCache && mCache->loadCachedObjectFile(iBuilder, kernel)) {
    204                 uncachedObject = false;
    205             }
    206             if (uncachedObject) {
    207                 module->setTargetTriple(mMainModule->getTargetTriple());
    208                 kernel->generateKernel(iBuilder);
    209                 PM.run(*module);
    210             }
    211             mEngine->addModule(std::unique_ptr<Module>(module));
    212         }
    213 
    214         iBuilder->setKernel(nullptr);
    215         module = mMainModule;
    216         PM.run(*mMainModule);
     218            if (LLVM_UNLIKELY(kernel->getModule() == nullptr)) {
     219                report_fatal_error(kernel->getName() + " was neither loaded from cache nor generated prior to finalizeObject");
     220            }
     221            mEngine->addModule(std::unique_ptr<Module>(kernel->getModule()));
     222        }
    217223        mEngine->finalizeObject();
    218 
    219224        if (mCache) mCache->cleanUpObjectCacheFiles();
    220 
    221225    } catch (const std::exception & e) {
    222         report_fatal_error(e.what());
     226        report_fatal_error(module->getName() + ": " + e.what());
    223227    }
    224228
Note: See TracChangeset for help on using the changeset viewer.