Ignore:
Timestamp:
Nov 18, 2016, 1:46:55 PM (3 years ago)
Author:
nmedfort
Message:

Merged PabloFunction? and PabloKernel? classes. Updated projects where necessary.

Location:
icGREP/icgrep-devel/icgrep/editd
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/editd/editd.cpp

    r5215 r5217  
    2525#include <re/re_cc.h>
    2626#include <cc/cc_compiler.h>
    27 #include <pablo/function.h>
     27#include <pablo/prototype.h>
    2828#include <pablo/pablo_compiler.h>
    2929#include <pablo/pablo_kernel.h>
     
    192192}
    193193
    194 Function * editdPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, PabloFunction * function) {
    195    
    196     ExternalFileBuffer ChStream(iBuilder, StreamSetType(iBuilder, 4, i1));
    197     SingleBlockBuffer MatchResults(iBuilder, StreamSetType(iBuilder, editDistance + 1, i1));
    198 
    199     pablo_function_passes(function);
    200     PabloKernel editdk(iBuilder, "editd", function);
     194void buildPatternKernel(PabloKernel & kernel, IDISA::IDISA_Builder * iBuilder, const std::vector<std::string> & patterns) {
     195    PabloBuilder entry(kernel.getEntryBlock());
     196
     197    Var * pat = kernel.addInput("pat", iBuilder->getStreamSetTy(4));
     198
     199    PabloAST * basisBits[4];
     200
     201    basisBits[0] = entry.createExtract(pat, 0, "A");
     202    basisBits[1] = entry.createExtract(pat, 1, "C");
     203    basisBits[2] = entry.createExtract(pat, 2, "T");
     204    basisBits[3] = entry.createExtract(pat, 3, "G");
     205
     206    re::Pattern_Compiler pattern_compiler(kernel);
     207    pattern_compiler.compile(patterns, entry, basisBits, editDistance, optPosition, stepSize);
     208
     209    pablo_function_passes(&kernel);
     210}
     211
     212Function * editdPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, const std::vector<std::string> & patterns) {
     213   
     214    ExternalFileBuffer ChStream(iBuilder, iBuilder->getStreamSetTy(4));
     215    SingleBlockBuffer MatchResults(iBuilder, iBuilder->getStreamSetTy(editDistance + 1));
     216
     217    PabloKernel editdk(iBuilder, "editd");
     218
     219    buildPatternKernel(editdk, iBuilder, patterns);
     220
    201221    kernel::editdScanKernel editdScanK(iBuilder, editDistance);
    202222   
     
    239259}
    240260
    241 Function * preprocessPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, PabloFunction * function) {
     261void buildPreprocessKernel(PabloKernel & kernel, IDISA::IDISA_Builder * iBuilder) {
     262    cc::CC_Compiler ccc(&kernel);
     263    PabloBuilder & pb = ccc.getBuilder();
     264
     265    PabloAST * A = ccc.compileCC(re::makeCC(re::makeCC(0x41), re::makeCC(0x61)), pb);
     266    PabloAST * C = ccc.compileCC(re::makeCC(re::makeCC(0x43), re::makeCC(0x63)), pb);
     267    PabloAST * T = ccc.compileCC(re::makeCC(re::makeCC(0x54), re::makeCC(0x74)), pb);
     268    PabloAST * G = ccc.compileCC(re::makeCC(re::makeCC(0x47), re::makeCC(0x67)), pb);
     269
     270    Var * const pat = kernel.addOutput("pat", iBuilder->getStreamSetTy(4));
     271
     272    pb.createAssign(pb.createExtract(pat, 0), A);
     273    pb.createAssign(pb.createExtract(pat, 1), C);
     274    pb.createAssign(pb.createExtract(pat, 2), T);
     275    pb.createAssign(pb.createExtract(pat, 3), G);
     276
     277    pablo_function_passes(&kernel);
     278}
     279
     280Function * preprocessPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder) {
    242281    Type * mBitBlockType = iBuilder->getBitBlockType();
    243282   
    244     ExternalFileBuffer ByteStream(iBuilder, StreamSetType(iBuilder,1, 8));
    245     SingleBlockBuffer BasisBits(iBuilder, StreamSetType(iBuilder,8, 1));
    246     ExternalFileBuffer CCResults(iBuilder, StreamSetType(iBuilder,4, 1));
     283    ExternalFileBuffer ByteStream(iBuilder, iBuilder->getStreamSetTy(1, 8));
     284    SingleBlockBuffer BasisBits(iBuilder, iBuilder->getStreamSetTy(8));
     285    ExternalFileBuffer CCResults(iBuilder, iBuilder->getStreamSetTy(4));
    247286
    248287    s2pKernel  s2pk(iBuilder);
    249288    std::unique_ptr<Module> s2pM = s2pk.createKernelModule({&ByteStream}, {&BasisBits});
    250289
    251     pablo_function_passes(function);
    252     PabloKernel  ccck(iBuilder, "ccc", function);
     290    PabloKernel  ccck(iBuilder, "ccc");
     291
     292    buildPreprocessKernel(ccck, iBuilder);
    253293   
    254294    std::unique_ptr<Module> cccM = ccck.createKernelModule({&BasisBits}, {&CCResults});
     
    301341    Module * M = new Module("preprocess", TheContext);
    302342    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    303     ExecutionEngine * preprocessEngine = nullptr;
    304 
    305     PabloFunction * function = PabloFunction::Create("preprocess"); // , 8, 4
    306     cc::CC_Compiler ccc(*function);
    307     PabloBuilder & pb = ccc.getBuilder();
    308 
    309     PabloAST * A = ccc.compileCC(re::makeCC(re::makeCC(0x41), re::makeCC(0x61)), pb);
    310     PabloAST * C = ccc.compileCC(re::makeCC(re::makeCC(0x43), re::makeCC(0x63)), pb);
    311     PabloAST * T = ccc.compileCC(re::makeCC(re::makeCC(0x54), re::makeCC(0x74)), pb);
    312     PabloAST * G = ccc.compileCC(re::makeCC(re::makeCC(0x47), re::makeCC(0x67)), pb);
    313 
    314     Var * pat = function->addResult("pat", getStreamTy(1, 4));
    315 
    316     pb.createAssign(pb.createExtract(pat, 0), A);
    317     pb.createAssign(pb.createExtract(pat, 1), C);
    318     pb.createAssign(pb.createExtract(pat, 2), T);
    319     pb.createAssign(pb.createExtract(pat, 3), G);
    320 
    321     llvm::Function * main_IR = preprocessPipeline(M, idb, function);
    322 
    323     preprocessEngine = JIT_to_ExecutionEngine(M);
     343
     344    llvm::Function * main_IR = preprocessPipeline(M, idb);
     345
     346    ExecutionEngine * preprocessEngine = JIT_to_ExecutionEngine(M);
    324347   
    325348    preprocessEngine->finalizeObject();
     
    331354typedef void (*editdFunctionType)(char * byte_data, size_t filesize);
    332355
    333 editdFunctionType editdCodeGen(std::vector<std::string> patterns) {
     356editdFunctionType editdCodeGen(const std::vector<std::string> & patterns) {
    334357                           
    335358    LLVMContext TheContext;
    336359    Module * M = new Module("editd", TheContext);
    337360    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    338     ExecutionEngine * editdEngine = nullptr;
    339 
    340     PabloFunction * function = PabloFunction::Create("editd"); // , 4, editDistance + 1
    341     PabloBuilder main (function->getEntryBlock());
    342 
    343     Var * pat = function->addParameter("pat", getStreamTy(1, 4));
    344 
    345     PabloAST * basisBits[4];
    346 
    347     basisBits[0] = main.createExtract(pat, 0, "A");
    348     basisBits[1] = main.createExtract(pat, 1, "C");
    349     basisBits[2] = main.createExtract(pat, 2, "T");
    350     basisBits[3] = main.createExtract(pat, 3, "G");
    351 
    352     re::Pattern_Compiler pattern_compiler(*function);
    353     pattern_compiler.compile(patterns, main, basisBits, editDistance, optPosition, stepSize);
    354 
    355     llvm::Function * main_IR = editdPipeline(M, idb, function);
    356 
    357     editdEngine = JIT_to_ExecutionEngine(M);
     361
     362    llvm::Function * main_IR = editdPipeline(M, idb, patterns);
     363
     364    ExecutionEngine * editdEngine = JIT_to_ExecutionEngine(M);
    358365   
    359366    editdEngine->finalizeObject();
     
    442449    Type * const stridesTy = PointerType::get(int32ty, 1);
    443450
    444     ExternalFileBuffer CCStream(iBuilder, StreamSetType(iBuilder, 4, 1), addrSpace);
    445     ExternalFileBuffer ResultStream(iBuilder, StreamSetType(iBuilder, editDistance+1, 1), addrSpace);
     451    ExternalFileBuffer CCStream(iBuilder, iBuilder->getStreamSetTy( 4, 1), addrSpace);
     452    ExternalFileBuffer ResultStream(iBuilder, iBuilder->getStreamSetTy( editDistance+1, 1), addrSpace);
    446453
    447454    kernel::editdGPUKernel editdk(iBuilder, editDistance, patternLen);
     
    584591    Type * const inputType = PointerType::get(ArrayType::get(mBitBlockType, editDistance+1), 0);
    585592
    586     ExternalFileBuffer MatchResults(iBuilder, StreamSetType(iBuilder, editDistance+1, 1));
     593    ExternalFileBuffer MatchResults(iBuilder, iBuilder->getStreamSetTy( editDistance+1, 1));
    587594    kernel::editdScanKernel editdScanK(iBuilder, editDistance);
    588595    editdScanK.generateKernel({&MatchResults}, {});               
  • icGREP/icgrep-devel/icgrep/editd/editd_cpu_kernel.h

    r5212 r5217  
    1919public:
    2020   
    21     editdCPUKernel(IDISA::IDISA_Builder * iBuilder, unsigned dist, unsigned pattLen) :
    22     KernelBuilder(iBuilder, "editd_cpu",
    23                   {Binding{parabix::StreamSetType(iBuilder, 4, 1), "CCStream"}},
    24                   {Binding{parabix::StreamSetType(iBuilder, dist+1, 1), "ResultStream"}},
    25                   {Binding{PointerType::get(iBuilder->getInt8Ty(), 1), "pattStream"},
    26                   Binding{PointerType::get(ArrayType::get(iBuilder->getBitBlockType(), pattLen * (dist + 1) * 4), 0), "srideCarry"}},
     21    editdCPUKernel(IDISA::IDISA_Builder * b, unsigned dist, unsigned pattLen) :
     22    KernelBuilder(b, "editd_cpu",
     23                  {Binding{b->getStreamSetTy(4), "CCStream"}},
     24                  {Binding{b->getStreamSetTy(dist + 1), "ResultStream"}},
     25                  {Binding{PointerType::get(b->getInt8Ty(), 1), "pattStream"},
     26                  Binding{PointerType::get(ArrayType::get(b->getBitBlockType(), pattLen * (dist + 1) * 4), 0), "srideCarry"}},
    2727                  {},
    28                   {Binding{iBuilder->getBitBlockType(), "EOFmask"}}),
     28                  {Binding{b->getBitBlockType(), "EOFmask"}}),
    2929    mEditDistance(dist),
    3030    mPatternLen(pattLen){}
  • icGREP/icgrep-devel/icgrep/editd/editd_gpu_kernel.h

    r5212 r5217  
    1919public:
    2020   
    21     editdGPUKernel(IDISA::IDISA_Builder * iBuilder, unsigned dist, unsigned pattLen) :
    22     KernelBuilder(iBuilder, "editd_gpu",
    23                   {Binding{parabix::StreamSetType(iBuilder, 4, 1), "CCStream"}},
    24                   {Binding{parabix::StreamSetType(iBuilder, dist+1, 1), "ResultStream"}},
    25                   {Binding{PointerType::get(iBuilder->getInt8Ty(), 1), "pattStream"},
    26                   Binding{PointerType::get(ArrayType::get(iBuilder->getBitBlockType(), pattLen * (dist + 1) * 4), 0), "srideCarry"}},
     21    editdGPUKernel(IDISA::IDISA_Builder * b, unsigned dist, unsigned pattLen) :
     22    KernelBuilder(b, "editd_gpu",
     23                  {Binding{b->getStreamSetTy(4), "CCStream"}},
     24                  {Binding{b->getStreamSetTy(dist + 1), "ResultStream"}},
     25                  {Binding{PointerType::get(b->getInt8Ty(), 1), "pattStream"},
     26                  Binding{PointerType::get(ArrayType::get(b->getBitBlockType(), pattLen * (dist + 1) * 4), 0), "srideCarry"}},
    2727                  {},
    28                   {Binding{iBuilder->getBitBlockType(), "EOFmask"}}),
     28                  {Binding{b->getBitBlockType(), "EOFmask"}}),
    2929    mEditDistance(dist),
    3030    mPatternLen(pattLen){}
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.h

    r5204 r5217  
    2121    editdScanKernel(IDISA::IDISA_Builder * iBuilder, unsigned dist) :
    2222    KernelBuilder(iBuilder, "scanMatch",
    23                   {Binding{parabix::StreamSetType(iBuilder,dist+1, parabix::i1), "matchResults"}},
     23                  {Binding{iBuilder->getStreamSetTy(dist + 1), "matchResults"}},
    2424                  {}, {}, {}, {}),
    2525    mEditDistance(dist),
  • icGREP/icgrep-devel/icgrep/editd/pattern_compiler.cpp

    r5202 r5217  
    2020#include <re/re_analysis.h>
    2121#include <pablo/codegenstate.h>
    22 #include <pablo/function.h>
     22#include <pablo/prototype.h>
    2323
    2424#include <assert.h>
     
    3333
    3434
    35 Pattern_Compiler::Pattern_Compiler(pablo::PabloFunction & function)
    36 : mFunction(function)
     35Pattern_Compiler::Pattern_Compiler(PabloKernel & kernel)
     36: mKernel(kernel)
    3737{
    3838
     
    124124    }
    125125
    126     Var * output = mFunction.addResult("E", getStreamTy(1, dist + 1));
    127126
    128     for(int d=0; d<=dist; d++){
     127    Var * output = mKernel.addOutput("E", mKernel.getBuilder()->getStreamSetTy(dist + 1));
     128    for (int d = 0; d <= dist; d++) {
    129129        pb.createAssign(pb.createExtract(output, d), E[d]);
    130         // mFunction.setResult(d, pb.createAssign("E" + std::to_string(d), E[d]));
    131130    }
    132131}
  • icGREP/icgrep-devel/icgrep/editd/pattern_compiler.h

    r5202 r5217  
    1818namespace pablo {
    1919class PabloBlock;
     20class PabloKernel;
    2021class PabloAST;
    2122class Assign;
     
    2829public:
    2930
    30     Pattern_Compiler(pablo::PabloFunction & function);
     31    Pattern_Compiler(pablo::PabloKernel & kernel);
    3132
    3233    void compile(const std::vector<std::string> & patterns, pablo::PabloBuilder & pb, pablo::PabloAST *basisBits[], int dist, unsigned optPosition, int stepSize);
    3334
    34 
    3535private:
    3636
    37     pablo::PabloFunction &                          mFunction;
     37    pablo::PabloKernel & mKernel;
    3838};
    3939
Note: See TracChangeset for help on using the changeset viewer.