Ignore:
Timestamp:
Aug 7, 2017, 11:03:08 AM (23 months ago)
Author:
lindanl
Message:

editd:group pattern segments.

File:
1 edited

Legend:

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

    r5440 r5603  
    66#include <kernels/kernel_builder.h>
    77#include <llvm/IR/Module.h>
    8 
     8#include <iostream>
    99using namespace llvm;
    1010
     
    2222}
    2323
     24void reset_to_zero(std::vector<std::vector<int>> & calculated){
     25    for (auto & sub : calculated) {
     26        std::fill(sub.begin(), sub.end(), 0);
     27    }
     28}
     29
    2430void editdGPUKernel::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & idb) {
    2531
    2632    IntegerType * const int32ty = idb->getInt32Ty();
    27     IntegerType * const int8ty = idb->getInt8Ty();
    28     Value * pattLen = idb->getInt32(mPatternLen + 1);
     33    IntegerType * const int8ty = idb->getInt8Ty(); 
     34    Value * groupLen = idb->getInt32((mPatternLen + 1) * mGroupSize);
    2935    Value * pattPos = idb->getInt32(0);
    3036    Value * pattBuf = idb->getScalarField("pattStream");
     
    3339    unsigned carryIdx = 0;
    3440
    35     std::vector<std::vector<Value *>> e(mPatternLen, std::vector<Value *>(mEditDistance + 1));
     41    std::vector<std::vector<Value *>> e(mPatternLen + 1, std::vector<Value *>(mEditDistance + 1));
    3642    std::vector<std::vector<Value *>> adv(mPatternLen, std::vector<Value *>(mEditDistance + 1));
    3743    std::vector<std::vector<int>> calculated(mPatternLen, std::vector<int>(mEditDistance + 1, 0));
     
    4046    Function * bidFunc = cast<Function>(m->getOrInsertFunction("llvm.nvvm.read.ptx.sreg.ctaid.x", int32ty, nullptr));
    4147    Value * bid = idb->CreateCall(bidFunc);
    42     Value * pattStartPtr = idb->CreateGEP(pattBuf, idb->CreateMul(pattLen, bid));
    43     Value * pattPtr = idb->CreateGEP(pattStartPtr, pattPos);
    44     Value * pattCh = idb->CreateLoad(pattPtr);
    45     Value * pattIdx = idb->CreateAnd(idb->CreateLShr(pattCh, 1), ConstantInt::get(int8ty, 3));
    46     Value * pattStream = idb->loadInputStreamBlock("CCStream", idb->CreateZExt(pattIdx, int32ty));
    47     pattPos = idb->CreateAdd(pattPos, ConstantInt::get(int32ty, 1));
     48    Value * pattStartPtr = idb->CreateGEP(pattBuf, idb->CreateMul(groupLen, bid));
    4849
    49     e[0][0] = pattStream;
     50    for(unsigned j = 0; j <= mEditDistance; j++){
     51        e[mPatternLen][j] = idb->allZeroes();
     52    }
     53
    5054    for(unsigned j = 1; j <= mEditDistance; j++){
    5155        e[0][j] = idb->allOnes();
    5256    }
    53     for(unsigned i = 1; i < mPatternLen; i++){
    54         pattPtr = idb->CreateGEP(pattStartPtr, pattPos);
    55         pattCh = idb->CreateLoad(pattPtr);
    56         pattIdx = idb->CreateAnd(idb->CreateLShr(pattCh, 1), ConstantInt::get(int8ty, 3));
    57         pattStream = idb->loadInputStreamBlock("CCStream", idb->CreateZExt(pattIdx, int32ty));
    58         bitblock_advance_ci_co(idb, e[i-1][0], 1, strideCarryArr, carryIdx++, adv, calculated, i-1, 0);
    59         e[i][0] = idb->CreateAnd(adv[i-1][0], pattStream);
     57
     58    for(unsigned g = 0; g < mGroupSize; g++){
     59        Value * pattCh = idb->CreateLoad(idb->CreateGEP(pattStartPtr, pattPos));
     60        Value * pattIdx = idb->CreateAnd(idb->CreateLShr(pattCh, 1), ConstantInt::get(int8ty, 3));
     61        Value * pattStream = idb->loadInputStreamBlock("CCStream", idb->CreateZExt(pattIdx, int32ty));
     62        pattPos = idb->CreateAdd(pattPos, ConstantInt::get(int32ty, 1));
     63        e[0][0] = pattStream;
     64        for(unsigned i = 1; i < mPatternLen; i++){
     65            Value * pattCh = idb->CreateLoad(idb->CreateGEP(pattStartPtr, pattPos));
     66            pattIdx = idb->CreateAnd(idb->CreateLShr(pattCh, 1), ConstantInt::get(int8ty, 3));
     67            pattStream = idb->loadInputStreamBlock("CCStream", idb->CreateZExt(pattIdx, int32ty));
     68            pattPos = idb->CreateAdd(pattPos, ConstantInt::get(int32ty, 1));
     69            bitblock_advance_ci_co(idb, e[i-1][0], 1, strideCarryArr, carryIdx++, adv, calculated, i-1, 0);
     70            e[i][0] = idb->CreateAnd(adv[i-1][0], pattStream);
     71            for(unsigned j = 1; j<= mEditDistance; j++){
     72                bitblock_advance_ci_co(idb, e[i-1][j], 1, strideCarryArr, carryIdx++, adv, calculated, i-1, j);
     73                bitblock_advance_ci_co(idb, e[i-1][j-1], 1, strideCarryArr, carryIdx++, adv, calculated, i-1, j-1);
     74                bitblock_advance_ci_co(idb, e[i][j-1], 1, strideCarryArr, carryIdx++, adv, calculated, i, j-1);
     75                Value * tmp1 = idb->CreateAnd(adv[i-1][j], pattStream);
     76                Value * tmp2 = idb->CreateAnd(adv[i-1][j-1], idb->CreateNot(pattStream));
     77                Value * tmp3 = idb->CreateOr(adv[i][j-1], e[i-1][j-1]);
     78                e[i][j] = idb->CreateOr(idb->CreateOr(tmp1, tmp2), tmp3);
     79            }
     80        }
     81        e[mPatternLen][0] = idb->CreateOr(e[mPatternLen][0], e[mPatternLen-1][0]);
    6082        for(unsigned j = 1; j<= mEditDistance; j++){
    61             bitblock_advance_ci_co(idb, e[i-1][j], 1, strideCarryArr, carryIdx++, adv, calculated, i-1, j);
    62             bitblock_advance_ci_co(idb, e[i-1][j-1], 1, strideCarryArr, carryIdx++, adv, calculated, i-1, j-1);
    63             bitblock_advance_ci_co(idb, e[i][j-1], 1, strideCarryArr, carryIdx++, adv, calculated, i, j-1);
    64             Value * tmp1 = idb->CreateAnd(adv[i-1][j], pattStream);
    65             Value * tmp2 = idb->CreateAnd(adv[i-1][j-1], idb->CreateNot(pattStream));
    66             Value * tmp3 = idb->CreateOr(adv[i][j-1], e[i-1][j-1]);
    67             e[i][j] = idb->CreateOr(idb->CreateOr(tmp1, tmp2), tmp3);
     83            e[mPatternLen][j] = idb->CreateOr(e[mPatternLen][j], idb->CreateAnd(e[mPatternLen - 1][j], idb->CreateNot(e[mPatternLen - 1][j - 1])));
    6884        }
    6985        pattPos = idb->CreateAdd(pattPos, ConstantInt::get(int32ty, 1));
     86        reset_to_zero(calculated);
    7087    }
    71     idb->storeOutputStreamBlock("ResultStream", idb->getInt32(0), e[mPatternLen-1][0]);
    72     for(unsigned j = 1; j<= mEditDistance; j++){
    73         idb->storeOutputStreamBlock("ResultStream", idb->getInt32(j), idb->CreateAnd(e[mPatternLen - 1][j], idb->CreateNot(e[mPatternLen - 1][j - 1])));
     88
     89    for(unsigned j = 0; j<= mEditDistance; j++){
     90        idb->storeOutputStreamBlock("ResultStream", idb->getInt32(j), e[mPatternLen][j]);
    7491    }
    7592}
     
    8097}
    8198
    82 editdGPUKernel::editdGPUKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned dist, unsigned pattLen) :
     99editdGPUKernel::editdGPUKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned dist, unsigned pattLen, unsigned groupSize) :
    83100BlockOrientedKernel("editd_gpu",
    84101              {Binding{b->getStreamSetTy(4), "CCStream"}},
    85102              {Binding{b->getStreamSetTy(dist + 1), "ResultStream"}},
    86103              {Binding{PointerType::get(b->getInt8Ty(), 1), "pattStream"},
    87               Binding{PointerType::get(ArrayType::get(b->getBitBlockType(), pattLen * (dist + 1) * 4), 0), "strideCarry"}},
     104              Binding{PointerType::get(ArrayType::get(b->getBitBlockType(), pattLen * (dist + 1) * 4 * groupSize), 0), "strideCarry"}},
    88105              {},
    89106              {Binding{b->getBitBlockType(), "EOFmask"}})
    90107, mEditDistance(dist)
    91 , mPatternLen(pattLen) {
     108, mPatternLen(pattLen)
     109, mGroupSize(groupSize) {
    92110}
    93111
Note: See TracChangeset for help on using the changeset viewer.