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

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

File:
1 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}, {});               
Note: See TracChangeset for help on using the changeset viewer.