Ignore:
Timestamp:
Aug 26, 2016, 9:33:51 AM (3 years ago)
Author:
cameron
Message:

Defer binding of buffers to stream sets until kernel generation

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/deletion.h

    r5105 r5133  
    3838class deletionKernel : public kernel::KernelBuilder {
    3939public:
    40     deletionKernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount,
    41                    StreamSetBuffer & inputStreamSet,
    42                    StreamSetBuffer & outputStreamSet,
    43                    StreamSetBuffer & deletionCounts) :
     40    deletionKernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount) :
    4441    KernelBuilder(iBuilder, "del",
    45                   {StreamSetBinding{inputStreamSet, "inputStreamSet"}},
    46                   {StreamSetBinding{outputStreamSet, "outputStreamSet"},
    47                    StreamSetBinding{deletionCounts, "deletionCounts"}},
     42                  {StreamSetBinding{StreamSetType(streamCount + 2, 1), "inputStreamSet"}},
     43                  {StreamSetBinding{StreamSetType(streamCount, 1), "outputStreamSet"},
     44                   StreamSetBinding{StreamSetType(1, 1), "deletionCounts"}},
    4845                  {}, {}, {}),
    4946    mDeletionFieldWidth(fw),
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5111 r5133  
    1414#include "streamset.h"
    1515
    16    
    1716struct ScalarBinding {
    1817    llvm::Type * scalarType;
     
    2120
    2221struct StreamSetBinding {
    23     parabix::StreamSetBuffer & ssType;
     22    parabix::StreamSetType ssType;
    2423    std::string ssName;
    2524};
     
    5453    void addKernelDeclarations(Module * client);
    5554   
    56     llvm::Value * createInstance(std::vector<llvm::Value *> initialParameters);
     55    virtual llvm::Value * createInstance(std::vector<llvm::Value *> initialParameters);
    5756    llvm::Value * createInstance(std::vector<llvm::Value *> initialParameters, std::vector<parabix::StreamSetBuffer *> inputs, std::vector<parabix::StreamSetBuffer *> outputBuffers);
    5857    llvm::Value * createDoBlockCall(llvm::Value * kernelInstance);
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5127 r5133  
    3232
    3333void KernelBuilder::prepareKernel() {
     34    if (mStreamSetInputs.size() != mStreamSetInputBuffers.size()) {
     35        throw std::runtime_error("Kernel preparation: Incorrect number of input buffers");
     36    }
     37    if (mStreamSetOutputs.size() != mStreamSetOutputBuffers.size()) {
     38        throw std::runtime_error("Kernel preparation: Incorrect number of input buffers");
     39    }
    3440    addScalar(iBuilder->getSizeTy(), blockNoScalar);
    3541    int streamSetNo = 0;
    36     for (auto sSet : mStreamSetInputs) {
    37         mScalarInputs.push_back(ScalarBinding{sSet.ssType.getStreamBufferPointerType(), sSet.ssName + basePtrSuffix});
    38         mStreamSetNameMap.emplace(sSet.ssName, streamSetNo);
     42    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
     43        if (!(mStreamSetInputBuffers[i]->getBufferStreamSetType() == mStreamSetInputs[i].ssType)) {
     44             throw std::runtime_error("Kernel preparation: Incorrect input buffer type");
     45        }
     46        mScalarInputs.push_back(ScalarBinding{mStreamSetInputBuffers[i]->getStreamBufferPointerType(), mStreamSetInputs[i].ssName + basePtrSuffix});
     47        mStreamSetNameMap.emplace(mStreamSetInputs[i].ssName, streamSetNo);
    3948        streamSetNo++;
    4049    }
    41     for (auto sSet : mStreamSetOutputs) {
    42         mScalarInputs.push_back(ScalarBinding{sSet.ssType.getStreamBufferPointerType(), sSet.ssName + basePtrSuffix});
    43         mStreamSetNameMap.emplace(sSet.ssName, streamSetNo);
     50    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
     51        if (!(mStreamSetOutputBuffers[i]->getBufferStreamSetType() == mStreamSetOutputs[i].ssType)) {
     52             throw std::runtime_error("Kernel preparation: Incorrect input buffer type");
     53        }
     54        mScalarInputs.push_back(ScalarBinding{mStreamSetOutputBuffers[i]->getStreamBufferPointerType(), mStreamSetOutputs[i].ssName + basePtrSuffix});
     55        mStreamSetNameMap.emplace(mStreamSetOutputs[i].ssName, streamSetNo);
    4456        streamSetNo++;
    4557    }
     
    5668}
    5769
    58 std::unique_ptr<Module> KernelBuilder::createKernelModule() {
     70std::unique_ptr<Module> KernelBuilder::createKernelModule(std::vector<StreamSetBuffer *> input_buffers, std::vector<StreamSetBuffer *> output_buffers) {
    5971    Module * saveModule = iBuilder->getModule();
    6072    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
     
    6274    Module * m = theModule.get();
    6375    iBuilder->setModule(m);
    64     generateKernel();
     76    generateKernel(input_buffers, output_buffers);
    6577    iBuilder->setModule(saveModule);
    6678    iBuilder->restoreIP(savePoint);
     
    6880}
    6981
    70 void KernelBuilder::generateKernel() {
    71     IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    72     Module * m = iBuilder->getModule();
    73 
     82void KernelBuilder::generateKernel(std::vector<StreamSetBuffer *> input_buffers, std::vector<StreamSetBuffer*> output_buffers) {
     83    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
     84    Module * m = iBuilder->getModule();
     85    mStreamSetInputBuffers = input_buffers;
     86    mStreamSetOutputBuffers = output_buffers;
    7487    prepareKernel();  // possibly overriden by the KernelBuilder subtype
    7588    KernelInterface::addKernelDeclarations(m);
     
    200213    unsigned ssIndex = getStreamSetIndex(ssName);
    201214    if (ssIndex < mStreamSetInputs.size()) {
    202         return mStreamSetInputs[ssIndex].ssType.getBufferSize();
     215        return mStreamSetInputBuffers[ssIndex]->getBufferSize();
    203216    }
    204217    else {
    205         return mStreamSetOutputs[ssIndex - mStreamSetInputs.size()].ssType.getBufferSize();
     218        return mStreamSetOutputBuffers[ssIndex - mStreamSetInputs.size()]->getBufferSize();
    206219    }
    207220}
     
    215228    unsigned ssIndex = getStreamSetIndex(ssName);
    216229    if (ssIndex < mStreamSetInputs.size()) {
    217         return mStreamSetInputs[ssIndex].ssType.getStreamSetBlockPointer(basePtr, blockNo);
     230        return mStreamSetInputBuffers[ssIndex]->getStreamSetBlockPointer(basePtr, blockNo);
    218231    }
    219232    else {
    220         return mStreamSetOutputs[ssIndex - mStreamSetInputs.size()].ssType.getStreamSetBlockPointer(basePtr, blockNo);
    221     }
    222 }
    223 
    224 
    225 
    226 
     233        return mStreamSetOutputBuffers[ssIndex - mStreamSetInputs.size()]->getStreamSetBlockPointer(basePtr, blockNo);
     234    }
     235}
     236
     237Value * KernelBuilder::createInstance(std::vector<Value *> args) {
     238    Value * kernelInstance = iBuilder->CreateAlloca(mKernelStateType);
     239    Module * m = iBuilder->getModule();
     240    std::vector<Value *> init_args = {kernelInstance};
     241    for (auto a : args) {
     242        init_args.push_back(a);
     243    }
     244    for (auto b : mStreamSetInputBuffers) {
     245        init_args.push_back(b->getStreamSetBasePtr());
     246    }
     247    for (auto b : mStreamSetOutputBuffers) {
     248        init_args.push_back(b->getStreamSetBasePtr());
     249    }
     250    std::string initFnName = mKernelName + init_suffix;
     251    Function * initMethod = m->getFunction(initFnName);
     252    if (!initMethod) {
     253        throw std::runtime_error("Cannot find " + initFnName);
     254    }
     255    iBuilder->CreateCall(initMethod, init_args);
     256    return kernelInstance;
     257}
     258
     259
     260
     261
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5111 r5133  
    88
    99
     10#include "streamset.h"
    1011#include "interface.h"
    1112#include <vector>
     
    1819const std::string blkMaskSuffix = "_blkMask";
    1920
    20 
     21using namespace parabix;
    2122namespace kernel {
    2223   
     
    3637    // the full implementation of all required methods.     
    3738    //
    38     std::unique_ptr<llvm::Module> createKernelModule();
     39    std::unique_ptr<llvm::Module> createKernelModule(std::vector<StreamSetBuffer *> input_buffers, std::vector<StreamSetBuffer *> output_buffers);
    3940   
    4041    // Generate the Kernel to the current module (iBuilder->getModule()).
    41     void generateKernel();
     42    void generateKernel(std::vector<StreamSetBuffer *> input_buffers, std::vector<StreamSetBuffer *> output_buffers);
     43   
     44    llvm::Value * createInstance(std::vector<Value *> args) override;
    4245   
    4346protected:
     
    9699
    97100    llvm::Value * getStreamSetBlockPtr(Value * self, std::string ssName, Value * blockNo);
     101
    98102       
    99103protected:
     
    102106    NameMap                    mInternalStateNameMap;
    103107    NameMap                    mStreamSetNameMap;
     108    std::vector<StreamSetBuffer *> mStreamSetInputBuffers;
     109    std::vector<StreamSetBuffer *> mStreamSetOutputBuffers;
     110
    104111};
    105112}
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.h

    r5109 r5133  
    1919class p2sKernel : public KernelBuilder {
    2020public:
    21     p2sKernel(IDISA::IDISA_Builder * iBuilder, parabix::StreamSetBuffer& basisBits, parabix::StreamSetBuffer& byteStream) :
     21    p2sKernel(IDISA::IDISA_Builder * iBuilder) :
    2222    KernelBuilder(iBuilder, "p2s",
    23                   {StreamSetBinding{basisBits, "basisBits"}},
    24                   {StreamSetBinding{byteStream, "byteStream"}},
     23                  {StreamSetBinding{StreamSetType(8, 1), "basisBits"}},
     24                  {StreamSetBinding{StreamSetType(1, 8), "byteStream"}},
    2525                  {}, {}, {}) {}
    2626   
     
    3232class p2sKernel_withCompressedOutput : public KernelBuilder {
    3333public:
    34     p2sKernel_withCompressedOutput(IDISA::IDISA_Builder * iBuilder, parabix::StreamSetBuffer& basisBits, parabix::StreamSetBuffer& deletionCounts, parabix::StreamSetBuffer& byteStream) :
     34    p2sKernel_withCompressedOutput(IDISA::IDISA_Builder * iBuilder) :
    3535    KernelBuilder(iBuilder, "p2s_compress",
    36                   {StreamSetBinding{basisBits, "basisBits"}, StreamSetBinding{deletionCounts, "deletionCounts"}},
    37                   {StreamSetBinding{byteStream, "byteStream"}},
     36                  {StreamSetBinding{StreamSetType(8, 1), "basisBits"}, StreamSetBinding{StreamSetType(1, 1), "deletionCounts"}},
     37                  {StreamSetBinding{StreamSetType(1, 8), "byteStream"}},
    3838                  {}, {}, {}) {}
    3939   
     
    4646class p2s_16Kernel : public KernelBuilder {
    4747public:
    48     p2s_16Kernel(IDISA::IDISA_Builder * iBuilder, parabix::StreamSetBuffer& basisBits, parabix::StreamSetBuffer& i16Stream) :
     48    p2s_16Kernel(IDISA::IDISA_Builder * iBuilder) :
    4949    KernelBuilder(iBuilder, "p2s_16",
    50                   {StreamSetBinding{basisBits, "basisBits"}},
    51                   {StreamSetBinding{i16Stream, "i16Stream"}},
     50                  {StreamSetBinding{StreamSetType(16, 1), "basisBits"}},
     51                  {StreamSetBinding{StreamSetType(1, 16), "i16Stream"}},
    5252                  {}, {}, {}) {}
    5353   
     
    6060class p2s_16Kernel_withCompressedOutput : public KernelBuilder {
    6161public:
    62     p2s_16Kernel_withCompressedOutput(IDISA::IDISA_Builder * iBuilder, parabix::StreamSetBuffer& basisBits, parabix::StreamSetBuffer& deletionCounts, parabix::StreamSetBuffer& i16Stream) :
     62    p2s_16Kernel_withCompressedOutput(IDISA::IDISA_Builder * iBuilder) :
    6363    KernelBuilder(iBuilder, "p2s_16_compress",
    64                   {StreamSetBinding{basisBits, "basisBits"}, StreamSetBinding{deletionCounts, "deletionCounts"}},
    65                   {StreamSetBinding{i16Stream, "i16Stream"}},
     64                  {StreamSetBinding{StreamSetType(16, 1), "basisBits"}, StreamSetBinding{StreamSetType(1, 1), "deletionCounts"}},
     65                  {StreamSetBinding{StreamSetType(1, 16), "i16Stream"}},
    6666                  {},
    6767                  {},
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.h

    r5102 r5133  
    2525public:
    2626   
    27     s2pKernel(IDISA::IDISA_Builder * iBuilder, parabix::StreamSetBuffer& byteStream, parabix::StreamSetBuffer& basisBits) :
     27    s2pKernel(IDISA::IDISA_Builder * iBuilder) :
    2828    KernelBuilder(iBuilder, "s2p",
    29                   {StreamSetBinding{byteStream, "byteStream"}},
    30                   {StreamSetBinding{basisBits, "basisBits"}},
     29                  {StreamSetBinding{parabix::StreamSetType(1, parabix::i8), "byteStream"}},
     30                  {StreamSetBinding{parabix::StreamSetType(8, parabix::i1), "basisBits"}},
    3131                  {}, {}, {}) {}
    3232   
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r5106 r5133  
    1919class scanMatchKernel : public KernelBuilder {
    2020public:
    21     scanMatchKernel(IDISA::IDISA_Builder * iBuilder, parabix::StreamSetBuffer& matchResults, bool isNameExpression) :
     21    scanMatchKernel(IDISA::IDISA_Builder * iBuilder, bool isNameExpression) :
    2222    KernelBuilder(iBuilder, "scanMatch",
    23                   {StreamSetBinding{matchResults, "matchResults"}},
     23                  {StreamSetBinding{parabix::StreamSetType(2, parabix::i1), "matchResults"}},
    2424                    {},
    2525                    {ScalarBinding{iBuilder->getInt8PtrTy(), "FileBuf"}, ScalarBinding{iBuilder->getSizeTy(), "FileSize"}, ScalarBinding{iBuilder->getSizeTy(), "FileIdx"}},
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.h

    r5106 r5133  
    1616class stdOutKernel : public KernelBuilder {
    1717public:
    18     stdOutKernel(IDISA::IDISA_Builder * iBuilder, unsigned codeUnitWidth, parabix::StreamSetBuffer & codeUnitBuffer) :
     18    stdOutKernel(IDISA::IDISA_Builder * iBuilder, unsigned codeUnitWidth) :
    1919    KernelBuilder(iBuilder, "stdout",
    20                   {StreamSetBinding{codeUnitBuffer, "codeUnitBuffer"}}, {}, {}, {}, {}) {
     20                  {StreamSetBinding{parabix::StreamSetType(1, codeUnitWidth), "codeUnitBuffer"}}, {}, {}, {}, {}) {
    2121        mStreamType = PointerType::get(parabix::StreamSetType(1, codeUnitWidth).getStreamSetBlockType(iBuilder), 0);
    2222        mScalarInputs = {ScalarBinding{mStreamType , "bufferPtr"}};
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5123 r5133  
    2121    int StreamCount() { return mStreamCount;}
    2222    int StreamFieldWidth() { return mFieldWidth;}
     23    bool operator== (StreamSetType& other) {return (mStreamCount == other.mStreamCount) && (mFieldWidth == other.mFieldWidth);}
    2324   
    2425    llvm::Type * getStreamSetBlockType(IDISA::IDISA_Builder * iBuilder);
     
    3334    enum class BufferKind : unsigned {BlockBuffer, ExternalUnboundedBuffer, CircularBuffer, ExpandingBuffer};
    3435    inline BufferKind getBufferKind() const {return mBufferKind;}
    35    
     36    inline StreamSetType& getBufferStreamSetType() {return mStreamSetType;}
     37
    3638    virtual llvm::PointerType * getStreamBufferPointerType();
    3739
Note: See TracChangeset for help on using the changeset viewer.