Ignore:
Timestamp:
Nov 11, 2016, 11:21:23 AM (3 years ago)
Author:
lindanl
Message:

editd GPU kernel optimization.

File:
1 edited

Legend:

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

    r5212 r5214  
    1313
    1414
    15 Value * bitblock_advance_ci_co(IDISA::IDISA_Builder * iBuilder, Value * val, unsigned shift, Value * stideCarryArr, unsigned carryIdx){   
    16     Value * ptr = iBuilder->CreateGEP(stideCarryArr, {iBuilder->getInt32(0), iBuilder->getInt32(carryIdx)});
    17     Value * ci = iBuilder->CreateLoad(ptr);
    18     std::pair<Value *, Value *> rslt = iBuilder->bitblock_advance(val, ci, shift);
    19     iBuilder->CreateStore(std::get<0>(rslt), ptr);
    20     return std::get<1>(rslt);
     15void bitblock_advance_ci_co(IDISA::IDISA_Builder * iBuilder, Value * val, unsigned shift, Value * stideCarryArr, unsigned carryIdx, std::vector<std::vector<Value *>> & adv, std::vector<std::vector<int>> & calculated, int i, int j){   
     16    if(!calculated[i][j]){
     17        Value * ptr = iBuilder->CreateGEP(stideCarryArr, {iBuilder->getInt32(0), iBuilder->getInt32(carryIdx)});
     18        Value * ci = iBuilder->CreateLoad(ptr);
     19        std::pair<Value *, Value *> rslt = iBuilder->bitblock_advance(val, ci, shift);
     20        iBuilder->CreateStore(std::get<0>(rslt), ptr);
     21        adv[i][j] = std::get<1>(rslt);
     22        calculated[i][j] = 1;
     23    }
     24    return;
    2125}
    2226
     
    6973    unsigned carryIdx = 0;
    7074
    71     std::vector<std::vector<Value *>> e(mPatternLen+1, std::vector<Value *>(mEditDistance+1));
     75    std::vector<std::vector<Value *>> e(mPatternLen, std::vector<Value *>(mEditDistance+1));
     76    std::vector<std::vector<Value *>> adv(mPatternLen, std::vector<Value *>(mEditDistance+1));
     77    std::vector<std::vector<int>> calculated(mPatternLen, std::vector<int>(mEditDistance+1));
     78    for(unsigned i=0; i<mPatternLen; i++)
     79        for(unsigned j=0; j<=mEditDistance; j++)
     80            calculated[i][j] = 0;
    7281    Function * bidFunc = cast<Function>(m->getOrInsertFunction("llvm.nvvm.read.ptx.sreg.ctaid.x", int32ty, nullptr));
    7382    Value * bid = iBuilder->CreateCall(bidFunc);
     
    92101        pattStream = iBuilder->CreateLoad(pattStreamPtr);
    93102
    94         Value * adv = bitblock_advance_ci_co(iBuilder, e[i-1][0], 1, stideCarryArr, carryIdx++);
    95         e[i][0] = iBuilder->CreateAnd(adv, pattStream);
     103        bitblock_advance_ci_co(iBuilder, e[i-1][0], 1, stideCarryArr, carryIdx++, adv, calculated, i-1, 0);
     104        e[i][0] = iBuilder->CreateAnd(adv[i-1][0], pattStream);
    96105        for(unsigned j = 1; j<= mEditDistance; j++){
    97             Value * adv0 = bitblock_advance_ci_co(iBuilder, e[i-1][j], 1, stideCarryArr, carryIdx++);
    98             Value * adv1 = bitblock_advance_ci_co(iBuilder, e[i-1][j-1], 1, stideCarryArr, carryIdx++);
    99             Value * adv2 = bitblock_advance_ci_co(iBuilder, e[i][j-1], 1, stideCarryArr, carryIdx++);
    100             Value * tmp1 = iBuilder->CreateAnd(adv0, pattStream);
    101             Value * tmp2 = iBuilder->CreateAnd(adv1, iBuilder->CreateNot(pattStream));
    102             Value * tmp3 = iBuilder->CreateOr(adv2, e[i-1][j-1]);
     106            bitblock_advance_ci_co(iBuilder, e[i-1][j], 1, stideCarryArr, carryIdx++, adv, calculated, i-1, j);
     107            bitblock_advance_ci_co(iBuilder, e[i-1][j-1], 1, stideCarryArr, carryIdx++, adv, calculated, i-1, j-1);
     108            bitblock_advance_ci_co(iBuilder, e[i][j-1], 1, stideCarryArr, carryIdx++, adv, calculated, i, j-1);
     109            Value * tmp1 = iBuilder->CreateAnd(adv[i-1][j], pattStream);
     110            Value * tmp2 = iBuilder->CreateAnd(adv[i-1][j-1], iBuilder->CreateNot(pattStream));
     111            Value * tmp3 = iBuilder->CreateOr(adv[i][j-1], e[i-1][j-1]);
    103112            e[i][j] = iBuilder->CreateOr(iBuilder->CreateOr(tmp1, tmp2), tmp3);
    104113
Note: See TracChangeset for help on using the changeset viewer.