Ignore:
Timestamp:
Nov 6, 2016, 8:37:11 PM (3 years ago)
Author:
nmedfort
Message:

Initial work on adding types to PabloAST and mutable Var objects.

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

Legend:

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

    r5177 r5202  
    162162}
    163163
    164 Function * editdPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, pablo::PabloFunction * function) {
    165     Type * mBitBlockType = iBuilder->getBitBlockType();
    166    
    167     ExternalFileBuffer ChStream(iBuilder, StreamSetType(4, i1));
    168     SingleBlockBuffer MatchResults(iBuilder, StreamSetType(editDistance+1, i1));
     164Function * editdPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, PabloFunction * function) {
     165   
     166    ExternalFileBuffer ChStream(iBuilder, StreamSetType(iBuilder, 4, i1));
     167    SingleBlockBuffer MatchResults(iBuilder, StreamSetType(iBuilder, editDistance + 1, i1));
    169168
    170169    pablo_function_passes(function);
    171     pablo::PabloKernel  editdk(iBuilder, "editd", function, {});
     170    PabloKernel editdk(iBuilder, "editd", function);
    172171    kernel::editdScanKernel editdScanK(iBuilder, editDistance);
    173172   
     
    180179    Type * const size_ty = iBuilder->getSizeTy();
    181180    Type * const voidTy = Type::getVoidTy(mMod->getContext());
    182     Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(mBitBlockType, 8), 1), 0);
     181    Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(iBuilder->getBitBlockType(), 8), 1), 0);
    183182   
    184183    Function * const main = cast<Function>(mMod->getOrInsertFunction("Main", voidTy, inputType, size_ty, nullptr));
     
    210209}
    211210
    212 Function * preprocessPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, pablo::PabloFunction * function) {
     211Function * preprocessPipeline(Module * mMod, IDISA::IDISA_Builder * iBuilder, PabloFunction * function) {
    213212    Type * mBitBlockType = iBuilder->getBitBlockType();
    214213   
    215     ExternalFileBuffer ByteStream(iBuilder, StreamSetType(1, i8));
    216     SingleBlockBuffer BasisBits(iBuilder, StreamSetType(8, i1));
    217     ExternalFileBuffer CCResults(iBuilder, StreamSetType(4, i1));
     214    ExternalFileBuffer ByteStream(iBuilder, StreamSetType(iBuilder,1, i8));
     215    SingleBlockBuffer BasisBits(iBuilder, StreamSetType(iBuilder,8, i1));
     216    ExternalFileBuffer CCResults(iBuilder, StreamSetType(iBuilder,4, i1));
    218217
    219218    s2pKernel  s2pk(iBuilder);
     
    221220
    222221    pablo_function_passes(function);
    223     pablo::PabloKernel  ccck(iBuilder, "ccc", function, {});
     222    PabloKernel  ccck(iBuilder, "ccc", function);
    224223   
    225224    std::unique_ptr<Module> cccM = ccck.createKernelModule({&BasisBits}, {&CCResults});
     
    274273    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    275274
    276     PabloFunction * function = PabloFunction::Create("preprocess", 8, 4);
     275    PabloFunction * function = PabloFunction::Create("preprocess"); // , 8, 4
    277276    cc::CC_Compiler ccc(*function);
    278     pablo::PabloBuilder pBuilder(ccc.getBuilder().getPabloBlock(), ccc.getBuilder());
    279 
    280     pablo::PabloAST * A = ccc.compileCC(re::makeCC(re::makeCC(0x41), re::makeCC(0x61)));
    281     pablo::PabloAST * C = ccc.compileCC(re::makeCC(re::makeCC(0x43), re::makeCC(0x63)));
    282     pablo::PabloAST * T = ccc.compileCC(re::makeCC(re::makeCC(0x54), re::makeCC(0x74)));
    283     pablo::PabloAST * G = ccc.compileCC(re::makeCC(re::makeCC(0x47), re::makeCC(0x67)));
    284 
    285     function->setResult(0, pBuilder.createAssign("A", A));
    286     function->setResult(1, pBuilder.createAssign("C", C));
    287     function->setResult(2, pBuilder.createAssign("T", T));
    288     function->setResult(3, pBuilder.createAssign("G", G));
     277    PabloBuilder & pb = ccc.getBuilder();
     278
     279    PabloAST * A = ccc.compileCC(re::makeCC(re::makeCC(0x41), re::makeCC(0x61)), pb);
     280    PabloAST * C = ccc.compileCC(re::makeCC(re::makeCC(0x43), re::makeCC(0x63)), pb);
     281    PabloAST * T = ccc.compileCC(re::makeCC(re::makeCC(0x54), re::makeCC(0x74)), pb);
     282    PabloAST * G = ccc.compileCC(re::makeCC(re::makeCC(0x47), re::makeCC(0x67)), pb);
     283
     284    Var * pat = function->addResult("pat", getStreamTy(1, 4));
     285
     286    pb.createAssign(pb.createExtract(pat, 0), A);
     287    pb.createAssign(pb.createExtract(pat, 1), C);
     288    pb.createAssign(pb.createExtract(pat, 2), T);
     289    pb.createAssign(pb.createExtract(pat, 3), G);
    289290
    290291    llvm::Function * main_IR = preprocessPipeline(M, idb, function);
     
    307308    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    308309
    309     PabloFunction * function = PabloFunction::Create("editd", 4, editDistance+1);
    310     pablo::PabloBuilder main (function->getEntryBlock());
    311 
    312     const PabloType * streamType = getPabloType(PabloType::Stream, 1);
    313 
    314     std::vector<pablo::Var *>   basisBits(4);
    315     function->setParameter(0, basisBits[0] = main.createVar("PatA", streamType));
    316     function->setParameter(1, basisBits[1] = main.createVar("PatC", streamType));
    317     function->setParameter(2, basisBits[2] = main.createVar("PatT", streamType));
    318     function->setParameter(3, basisBits[3] = main.createVar("PatG", streamType));
     310    PabloFunction * function = PabloFunction::Create("editd"); // , 4, editDistance + 1
     311    PabloBuilder main (function->getEntryBlock());
     312
     313    Var * pat = function->addParameter("pat", getStreamTy(1, 4));
     314
     315    PabloAST * basisBits[4];
     316
     317    basisBits[0] = main.createExtract(pat, 0, "A");
     318    basisBits[1] = main.createExtract(pat, 1, "C");
     319    basisBits[2] = main.createExtract(pat, 2, "T");
     320    basisBits[3] = main.createExtract(pat, 3, "G");
    319321
    320322    re::Pattern_Compiler pattern_compiler(*function);
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.cpp

    r5173 r5202  
    2121
    2222void editdScanKernel::generateDoBlockMethod() {
    23     IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
     23    auto savePoint = iBuilder->saveIP();
    2424    Module * m = iBuilder->getModule();
    2525    Function * scanWordFunction = generateScanWordRoutine(m);
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.h

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

    r5172 r5202  
    4343
    4444
    45 std::vector<Assign *> optimizer(std::string patt, std::vector<pablo::Var *> basisBits, std::vector<std::vector<Assign*>>  & e, int i, PabloAST * cond, PabloBuilder & pb, int dist, int stepSize){
     45void optimizer(const std::string & patt, PabloAST * basisBits[], std::vector<std::vector<PabloAST *>> & e, unsigned i, PabloAST * cond, PabloBuilder & main, PabloBuilder & pb, int dist, int stepSize){
    4646    PabloBuilder it = PabloBuilder::Create(pb);
    47     std::vector<Assign *> var_list;
     47
     48    Zeroes * zeroes = pb.createZeroes();
     49
    4850    for(int n = 0; n < stepSize; n++){
    49         // PabloAST * name = cast<Name>(seq->at(i))->getCompiled();
    50         int pi = (patt[i] >> 1) & 0x3;
    51         PabloAST * name = basisBits[pi];       
     51
     52        PabloAST * name = basisBits[(patt[i] >> 1) & 0x3];
    5253       
    53         e[i][0] = it.createAssign(make_e(i,0), it.createAnd(it.createAdvance(e[i-1][0],1), name));
    54         for(int j = 1; j <= dist; j++){ 
    55             auto tmp1 = it.createAssign("tmp1", it.createAnd(it.createAdvance(e[i-1][j],1), name));
    56             auto tmp2 = it.createAssign("tmp2", it.createAnd(it.createAdvance(e[i-1][j-1],1), it.createNot(name)));
    57             auto tmp3 = it.createAssign("tmp3", it.createOr(it.createAdvance(e[i][j-1],1), e[i-1][j-1]));
    58             e[i][j] = it.createAssign(make_e(i,j), it.createOr(it.createOr(tmp1,tmp2),tmp3));
     54        e[i][0] = it.createAnd(it.createAdvance(e[i - 1][0], 1), name, make_e(i, 0));
     55        for(int j = 1; j <= dist; j++){
     56            auto tmp1 = it.createAnd(it.createAdvance(e[i-1][j],1), name);
     57            auto tmp2 = it.createAnd(it.createAdvance(e[i-1][j-1],1), it.createNot(name));
     58            auto tmp3 = it.createOr(it.createAdvance(e[i][j-1],1), e[i-1][j-1]);
     59            e[i][j] = it.createOr(it.createOr(tmp1, tmp2), tmp3, make_e(i, j));
    5960        }
    6061       
    6162        i++;
    62         if(i >= patt.length()) break;
     63        if (i >= patt.length()) break;
    6364    }
    64     i--; 
    6565
    66     if(i < patt.length()-1){
    67         var_list = optimizer(patt, basisBits, e, i+1, e[i][dist], it, dist, stepSize);
     66    if (i < patt.length()) {
     67       optimizer(patt, basisBits, e, i, e[i - 1][dist], main, it, dist, stepSize);
     68    } else {
     69        const auto i = patt.length() - 1;
     70        for(int j = 0; j <= dist; j++){
     71            auto eij = main.createVar("m" + std::to_string(j), zeroes);
     72            it.createAssign(eij, e[i][j]);
     73            e[i][j] = eij;
     74        }
    6875    }
    6976
    70     for(int j = 0; j <= dist; j++){
    71         var_list.push_back(e[i][j]);
    72     }
    73 
    74     std::vector<Assign *> new_var_list = var_list;
    75     pb.createIf(cond, std::move(var_list), it);
    76     return new_var_list;
     77    pb.createIf(cond, it);
    7778}
    7879
    79 void Pattern_Compiler::compile(std::vector<std::string> patts, PabloBuilder & pb, std::vector<pablo::Var *> basisBits, int dist, int optPosition, int stepSize) {
    80     std::vector<std::vector<Assign*>> e(patts[0].length()*2, std::vector<Assign*>(dist+1));
    81     std::vector<PabloAST*> E(dist+1);
    82     int i = 0;
    83     int pi = 0;
     80void Pattern_Compiler::compile(const std::vector<std::string> & patts, PabloBuilder & pb, PabloAST * basisBits[], int dist, unsigned optPosition, int stepSize) {
     81    std::vector<std::vector<PabloAST *>> e(patts[0].length() * 2, std::vector<PabloAST *>(dist+1));
     82    std::vector<PabloAST*> E(dist + 1);
    8483
    8584    for(int d=0; d<=dist; d++){
     
    8786    }
    8887
    89     for(int r=0; r< patts.size(); r++){
    90         std::string patt = patts[r];
    91         pi = (patt[0] >> 1) & 0x3;
    92         PabloAST * name = basisBits[pi];
     88    for(unsigned r = 0; r < patts.size(); r++){
     89        const std::string & patt = patts[r];
    9390
    94         e[0][0] = pb.createAssign(make_e(0, 0), name);
     91        PabloAST * name = basisBits[(patt[0] >> 1) & 0x3];
     92
     93        e[0][0] = name;
    9594        for(int j = 1; j <= dist; j++){
    96           e[0][j] = pb.createAssign(make_e(0, j), pb.createOnes());
     95          e[0][j] = pb.createOnes();
    9796        }
    9897
    99         i++;
    100         while (i < patt.length()) {
    101             pi = (patt[i] >> 1) & 0x3;
    102             name = basisBits[pi];
     98        unsigned i = 1;
     99        while (i < patt.length() && i < optPosition) {
    103100
    104             e[i][0] = pb.createAssign(make_e(i,0), pb.createAnd(pb.createAdvance(e[i-1][0],1), name));
     101            name = basisBits[(patt[i] >> 1) & 0x3];
     102
     103            e[i][0] = pb.createAnd(pb.createAdvance(e[i-1][0], 1), name, make_e(i, 0));
    105104            for(int j = 1; j <= dist; j++){     
    106                 auto tmp1 = pb.createAssign("tmp1", pb.createAnd(pb.createAdvance(e[i-1][j],1), name));
    107                 auto tmp2 = pb.createAssign("tmp2", pb.createAnd(pb.createAdvance(e[i-1][j-1],1), pb.createNot(name)));
    108                 auto tmp3 = pb.createAssign("tmp3", pb.createOr(pb.createAdvance(e[i][j-1],1), e[i-1][j-1]));
    109                 e[i][j] = pb.createAssign(make_e(i,j), pb.createOr(pb.createOr(tmp1,tmp2),tmp3));
     105                auto tmp1 = pb.createAnd(pb.createAdvance(e[i-1][j],1), name);
     106                auto tmp2 = pb.createAnd(pb.createAdvance(e[i-1][j-1],1), pb.createNot(name));
     107                auto tmp3 = pb.createOr(pb.createAdvance(e[i][j-1],1), e[i-1][j-1]);
     108                e[i][j] = pb.createOr(pb.createOr(tmp1,tmp2),tmp3, make_e(i, j));
    110109            }
    111110           
    112111            i++;
    113             if(i >= optPosition) break;
    114112        }
    115113
    116114        //Optimize from optPosition
    117         if(i >= optPosition){
    118             optimizer(patt, basisBits, e, i, e[i-1][dist], pb, dist, stepSize);
     115        if (i >= optPosition) {
     116            optimizer(patt, basisBits, e, i, e[i-1][dist], pb, pb, dist, stepSize);
    119117        }
    120118
    121         E[0] = pb.createOr(E[0], e[patt.length()-1][0]);
     119        E[0] = pb.createOr(E[0], e[patt.length() - 1][0]);
    122120        for(int d=1; d<=dist; d++){
    123121            E[d] = pb.createOr(E[d], pb.createAnd(e[patt.length()-1][d], pb.createNot(e[patt.length()-1][d-1])));
    124122        }
    125123
    126         i = 0;
    127124    }
     125
     126    Var * output = mFunction.addResult("E", getStreamTy(1, dist + 1));
     127
    128128    for(int d=0; d<=dist; d++){
    129         mFunction.setResult(d, pb.createAssign("E" + std::to_string(d), E[d]));
     129        pb.createAssign(pb.createExtract(output, d), E[d]);
     130        // mFunction.setResult(d, pb.createAssign("E" + std::to_string(d), E[d]));
    130131    }
    131132}
  • icGREP/icgrep-devel/icgrep/editd/pattern_compiler.h

    r5172 r5202  
    3030    Pattern_Compiler(pablo::PabloFunction & function);
    3131
    32     void compile(std::vector<std::string> patterns, pablo::PabloBuilder & pb, std::vector<pablo::Var *> basisBits, int dist, int optPosition, int stepSize);
     32    void compile(const std::vector<std::string> & patterns, pablo::PabloBuilder & pb, pablo::PabloAST *basisBits[], int dist, unsigned optPosition, int stepSize);
    3333
    3434
Note: See TracChangeset for help on using the changeset viewer.