Ignore:
Timestamp:
Feb 4, 2017, 6:49:46 AM (2 years ago)
Author:
cameron
Message:

Ability to set input/output signatures for Pablo functions in the constructor

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
2 edited

Legend:

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

    r5298 r5299  
    5757}
    5858
     59void KernelBuilder::prepareKernelSignature() {
     60    unsigned blockSize = iBuilder->getBitBlockWidth();
     61    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
     62        mStreamSetNameMap.emplace(mStreamSetInputs[i].name, i);
     63    }
     64    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
     65        mStreamSetNameMap.emplace(mStreamSetOutputs[i].name, mStreamSetInputs.size() + i);
     66    }
     67}
     68   
    5969void KernelBuilder::prepareKernel() {
    6070    if (LLVM_UNLIKELY(mKernelStateType != nullptr)) {
    6171        llvm::report_fatal_error("Cannot prepare kernel after kernel state finalized");
    6272    }
    63     unsigned blockSize = iBuilder->getBitBlockWidth();
    6473    if (mStreamSetInputs.size() != mStreamSetInputBuffers.size()) {
    6574        std::string tmp;
    6675        raw_string_ostream out(tmp);
    6776        out << "kernel contains " << mStreamSetInputBuffers.size() << " input buffers for "
    68             << mStreamSetInputs.size() << " input stream sets.";
     77        << mStreamSetInputs.size() << " input stream sets.";
    6978        throw std::runtime_error(out.str());
    7079    }
     
    7382        raw_string_ostream out(tmp);
    7483        out << "kernel contains " << mStreamSetOutputBuffers.size() << " output buffers for "
    75             << mStreamSetOutputs.size() << " output stream sets.";
     84        << mStreamSetOutputs.size() << " output stream sets.";
    7685        throw std::runtime_error(out.str());
    7786    }
     87    unsigned blockSize = iBuilder->getBitBlockWidth();
    7888    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
    7989        if ((mStreamSetInputBuffers[i]->getBufferSize() > 0) && (mStreamSetInputBuffers[i]->getBufferSize() < codegen::SegmentSize + (blockSize + mLookAheadPositions - 1)/blockSize)) {
    80              llvm::report_fatal_error("Kernel preparation: Buffer size too small " + mStreamSetInputs[i].name);
     90            llvm::report_fatal_error("Kernel preparation: Buffer size too small " + mStreamSetInputs[i].name);
    8191        }
    8292        mScalarInputs.push_back(Binding{mStreamSetInputBuffers[i]->getPointerType(), mStreamSetInputs[i].name + BUFFER_PTR_SUFFIX});
    83         mStreamSetNameMap.emplace(mStreamSetInputs[i].name, i);
    8493        addScalar(iBuilder->getSizeTy(), mStreamSetInputs[i].name + PROCESSED_ITEM_COUNT_SUFFIX);
    8594    }
    8695    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    8796        mScalarInputs.push_back(Binding{mStreamSetOutputBuffers[i]->getPointerType(), mStreamSetOutputs[i].name + BUFFER_PTR_SUFFIX});
    88         mStreamSetNameMap.emplace(mStreamSetOutputs[i].name, mStreamSetInputs.size() + i);
    8997        addScalar(iBuilder->getSizeTy(), mStreamSetOutputs[i].name + PRODUCED_ITEM_COUNT_SUFFIX);
    9098    }
     
    95103        addScalar(binding.type, binding.name);
    96104    }
     105    if (mStreamSetNameMap.empty()) prepareKernelSignature();
    97106    for (auto binding : mInternalScalars) {
    98107        addScalar(binding.type, binding.name);
     
    275284}
    276285
    277 inline unsigned KernelBuilder::getStreamSetIndex(const std::string & name) const {
     286unsigned KernelBuilder::getStreamSetIndex(const std::string & name) const {
    278287    const auto f = mStreamSetNameMap.find(name);
    279288    if (LLVM_UNLIKELY(f == mStreamSetNameMap.end())) {
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5297 r5299  
    1212#include <boost/container/flat_map.hpp>
    1313#include <IR_Gen/idisa_builder.h>
     14#include "llvm/Support/Debug.h"
    1415namespace llvm { class ConstantInt; }
    1516namespace llvm { class Function; }
     
    128129    }
    129130   
     131    void prepareKernelSignature();
     132
    130133    virtual void prepareKernel();
    131        
     134
    132135    virtual void generateInitMethod() { }
    133136   
     
    223226
    224227    llvm::BasicBlock * CreateBasicBlock(std::string && name) const;
    225 
    226 private:
    227228
    228229    // Stream set helpers.
Note: See TracChangeset for help on using the changeset viewer.