Changeset 5299


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

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

Location:
icGREP/icgrep-devel/icgrep
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r5283 r5299  
    1919namespace cc {
    2020
    21 CC_Compiler::CC_Compiler(PabloKernel * kernel, const unsigned encodingBits, const std::string prefix)
    22 : mBuilder(kernel->getEntryBlock())
    23 , mBasisBit(encodingBits)
    24 , mEncodingBits(encodingBits) {
    25 
    26     // TODO: basisBits should be defined prior and only retrieved here.
    27     Var * const basisBits = kernel->addInput(prefix, kernel->getStreamSetTy(encodingBits));
    28     for (unsigned i = 0; i != mEncodingBits; i++) {
    29         mBasisBit[i] = mBuilder.createExtract(basisBits, mBuilder.getInteger(i)); assert (mBasisBit[i]);
    30     }
    31     mEncodingMask = (static_cast<unsigned>(1) << encodingBits) - static_cast<unsigned>(1);
    32 }
     21    CC_Compiler::CC_Compiler(PabloKernel * kernel, const unsigned encodingBits, const std::string prefix)
     22    : mBuilder(kernel->getEntryBlock())
     23    , mEncodingBits(encodingBits)
     24    , mBasisBit(encodingBits) {
     25       
     26        // TODO: basisBits should be defined prior and only retrieved here.
     27        Var * const basisBits = kernel->addInput(prefix, kernel->getStreamSetTy(encodingBits));
     28        for (unsigned i = 0; i != mEncodingBits; i++) {
     29            mBasisBit[i] = mBuilder.createExtract(basisBits, mBuilder.getInteger(i)); assert (mBasisBit[i]);
     30        }
     31        mEncodingMask = (static_cast<unsigned>(1) << encodingBits) - static_cast<unsigned>(1);
     32    }
     33   
     34   
     35    CC_Compiler::CC_Compiler(pablo::PabloKernel * kernel, pablo::Var * basisBits)
     36    : mBuilder(kernel->getEntryBlock())
     37    , mEncodingBits(dyn_cast<ArrayType>(basisBits->getType())->getNumElements())
     38    , mBasisBit(mEncodingBits) {
     39        for (unsigned i = 0; i != mEncodingBits; i++) {
     40            mBasisBit[i] = mBuilder.createExtract(basisBits, mBuilder.getInteger(i)); assert (mBasisBit[i]);
     41        }
     42        mEncodingMask = (static_cast<unsigned>(1) << mEncodingBits) - static_cast<unsigned>(1);
     43    }
     44   
     45   
    3346
    3447PabloAST * CC_Compiler::compileCC(const std::string & canonicalName, const CC *cc, PabloBlock & block) {
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r5267 r5299  
    1111#include <re/re_cc.h>
    1212#include <pablo/builder.hpp>
     13#include <kernels/interface.h>
    1314#include <string>
    1415
     
    2425
    2526    CC_Compiler(pablo::PabloKernel * kernel, const unsigned encodingBits = 8, const std::string prefix = "basis");
    26 
     27   
     28    CC_Compiler(pablo::PabloKernel * kernel, pablo::Var * basisBitSet);
     29   
    2730    pablo::PabloAST * compileCC(const re::CC *cc);
    2831
     
    6366private:   
    6467    pablo::PabloBuilder             mBuilder;
     68    const unsigned                  mEncodingBits;
    6569    std::vector<pablo::PabloAST *>  mBasisBit;
    66     const unsigned                  mEncodingBits;
    6770    unsigned                        mEncodingMask;
    6871};
  • 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.
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp

    r5298 r5299  
    1313//#include <llvm/IR/Verifier.h>
    1414//#include <IR_Gen/idisa_builder.h>
     15#include "llvm/Support/Debug.h"
    1516
    1617using namespace pablo;
     
    2930    return false;
    3031}
     32
     33Var * PabloKernel::getInputSet(std::string inputSetName) {
     34    unsigned ssIndex = getStreamSetIndex(inputSetName);
     35    return mInputs[ssIndex];
     36}
     37
     38Var * PabloKernel::getOutputSet(std::string outputSetName) {
     39    unsigned ssIndex = getStreamSetIndex(outputSetName);
     40    return mOutputs[ssIndex - mInputs.size()];
     41}
     42
    3143
    3244Var * PabloKernel::addInput(const std::string & name, Type * const type) {
     
    118130}
    119131
     132PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder, std::string kernelName,
     133                         std::vector<Binding> && stream_inputs,
     134                         std::vector<Binding> && stream_outputs,
     135                         std::vector<Binding> && scalar_outputs)
     136: BlockOrientedKernel(builder, std::move(kernelName),
     137                      std::move(stream_inputs), std::move(stream_outputs),
     138                      {}, std::move(scalar_outputs),
     139                      {Binding{builder->getBitBlockType(), "EOFbit"}, Binding{builder->getBitBlockType(), "EOFmask"}})
     140, PabloAST(PabloAST::ClassTypeId::Kernel, nullptr, mAllocator)
     141, mPabloCompiler(new PabloCompiler(this))
     142, mSymbolTable(new SymbolGenerator(mAllocator))
     143, mEntryBlock(PabloBlock::Create(this)) {
     144    setDoBlockUpdatesProducedItemCountsAttribute(false);
     145    prepareKernelSignature();
     146    for (auto ss : mStreamSetInputs) {
     147        Var * param = new (mAllocator) Var(mSymbolTable->makeString(ss.name, iBuilder), ss.type, mAllocator, Var::ReadOnly);
     148        param->addUser(this);
     149        mInputs.push_back(param);
     150        mVariables.push_back(param);
     151    }
     152    for (auto ss : mStreamSetOutputs) {
     153        Var * result = new (mAllocator) Var(mSymbolTable->makeString(ss.name, iBuilder), ss.type, mAllocator, Var::ReadNone);
     154        result->addUser(this);
     155        mOutputs.push_back(result);
     156        mVariables.push_back(result);
     157    }
     158    for (auto ss : mScalarOutputs) {
     159        Var * result = new (mAllocator) Var(mSymbolTable->makeString(ss.name, iBuilder), ss.type, mAllocator, Var::ReadNone);
     160        result->addUser(this);
     161        mOutputs.push_back(result);
     162        mVariables.push_back(result);
     163    }
     164}
     165
    120166PabloKernel::~PabloKernel() {
    121167    delete mPabloCompiler;
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.h

    r5297 r5299  
    4747    PabloKernel(IDISA::IDISA_Builder * builder, std::string kernelName);
    4848   
     49    PabloKernel(IDISA::IDISA_Builder * builder, std::string kernelName,                     
     50                    std::vector<Binding> && stream_inputs,
     51                    std::vector<Binding> && stream_outputs,
     52                    std::vector<Binding> && scalar_outputs);
     53
    4954    virtual ~PabloKernel();
    5055
     
    6267        return entryBlock;
    6368    }
     69   
     70    Var * getInputSet(std::string inputSetName);
    6471
    6572    Var * getInput(const unsigned index) {
     
    7683        return mInputs.size();
    7784    }
     85   
     86    Var * getOutputSet(std::string inputSetName);
    7887
    7988    Var * getOutput(const unsigned index) {
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5284 r5299  
    5151void u8u16_pablo(PabloKernel * kernel) {
    5252    //  input: 8 basis bit streams
     53   
     54    const auto u8bitSet = kernel->getInputSet("u8bit");
     55   
    5356    //  output: 16 u8-indexed streams, + delmask stream + error stream
    54 
    55     cc::CC_Compiler ccc(kernel);
     57   
     58    cc::CC_Compiler ccc(kernel, u8bitSet);
    5659   
    5760    PabloBuilder & main = ccc.getBuilder();
    5861    const auto u8_bits = ccc.getBasisBits();
    59 
     62   
    6063    Zeroes * zeroes = main.createZeroes();
    6164
     
    233236    main.createAssign(u16_lo[7], main.createOr(main.createAnd(last_byte, u8_bits[7]), s43_lo7));
    234237   
    235     Var * output = kernel->addOutput("output", kernel->getStreamSetTy(16));
    236     Var * delmask_out = kernel->addOutput("delmask_out", kernel->getStreamSetTy());
    237     Var * error_mask_out = kernel->addOutput("error_mask_out", kernel->getStreamSetTy());
     238    Var * output = kernel->getOutputSet("u16bit");
     239    Var * delmask_out = kernel->getOutputSet("delMask");
     240    Var * error_mask_out = kernel->getOutputSet("errMask");
     241   
    238242    for (unsigned i = 0; i < 8; i++) {
    239243        main.createAssign(main.createExtract(output, i), u16_hi[i]);
     
    296300    s2pk.generateKernel({&ByteStream}, {&BasisBits});
    297301
    298     PabloKernel u8u16k(iBuilder, "u8u16");
     302    PabloKernel u8u16k(iBuilder, "u8u16",
     303                       {Binding{iBuilder->getStreamSetTy(8, 1), "u8bit"}},
     304                       {Binding{iBuilder->getStreamSetTy(16, 1), "u16bit"},
     305                        Binding{iBuilder->getStreamSetTy(1, 1), "delMask"},
     306                        Binding{iBuilder->getStreamSetTy(1, 1), "errMask"}}, {});
    299307
    300308    u8u16_pablo(&u8u16k);
Note: See TracChangeset for help on using the changeset viewer.