Ignore:
Timestamp:
May 3, 2016, 5:53:12 PM (3 years ago)
Author:
xuedongx
Message:

If '-c', ignore the scanmatch kernel.

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r5017 r5025  
    1616
    1717#include <llvm/Support/CommandLine.h>
     18#include <llvm/IR/Intrinsics.h>
    1819
    1920static cl::opt<unsigned> SegmentSize("segment-size", cl::desc("Segment Size"), cl::value_desc("positive integer"), cl::init(1));
     
    5758}
    5859
    59 Function * PipelineBuilder::ExecuteKernels() {
     60Value * generatePopcount(IDISA::IDISA_Builder * iBuilder, Value * bits) {
     61    Value * ctpopFunc = Intrinsic::getDeclaration(iBuilder->getModule(), Intrinsic::ctpop, bits->getType());
     62    return iBuilder->CreateCall(ctpopFunc, std::vector<Value *>({bits}));
     63}
     64
     65Value * Cal_Count(Instance * icGrepInstance, IDISA::IDISA_Builder * iBuilder, int mBlockSize) {
     66    const unsigned index = 0;
     67    const unsigned streamOffset = 0;
     68    Value * match = (icGrepInstance->getOutputStream(index, streamOffset));
     69    Value * temp = iBuilder->CreateLoad(match);
     70    Value * matches = iBuilder->CreateBitCast(temp, iBuilder->getIntNTy(mBlockSize));
     71    Value * popcount = generatePopcount(iBuilder, matches);
     72    return popcount;
     73}
     74
     75Function * PipelineBuilder::ExecuteKernels(bool CountOnly) {
    6076    Type * const int64ty = iBuilder->getInt64Ty();
    6177    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
     
    95111    BasicBlock * exitBlock = BasicBlock::Create(mMod->getContext(), "exit", main, 0);
    96112
     113    Value * count = iBuilder->CreateAlloca (Type::getIntNTy(mMod->getContext(), mBlockSize), nullptr, "count");
     114    Value * num = ConstantInt::get(iBuilder->getIntNTy(mBlockSize), 0);
     115    iBuilder->CreateStore(num, count, false);
     116
    97117    Instance * s2pInstance = mS2PKernel->instantiate(inputStream);
    98118    Instance * icGrepInstance = mICgrepKernel->instantiate(s2pInstance->getOutputStreamBuffer());
    99119    Instance * scanMatchInstance = mScanMatchKernel->instantiate(icGrepInstance->getOutputStreamBuffer());
    100 
    101     scanMatchInstance->setInternalState("FileBuf", iBuilder->CreateBitCast(inputStream, int8PtrTy));
    102     scanMatchInstance->setInternalState("FileSize", bufferSize);
    103     scanMatchInstance->setInternalState("FileIdx", fileIdx);
    104 
     120   
     121    if(!CountOnly) {
     122        scanMatchInstance->setInternalState("FileBuf", iBuilder->CreateBitCast(inputStream, int8PtrTy));
     123        scanMatchInstance->setInternalState("FileSize", bufferSize);
     124        scanMatchInstance->setInternalState("FileIdx", fileIdx);
     125    }
    105126    Value * initialBufferSize = nullptr;
    106127    BasicBlock * initialBlock = nullptr;
     
    120141        for (unsigned i = 0; i < segmentSize; ++i) {
    121142            icGrepInstance->CreateDoBlockCall();
     143            if(CountOnly){
     144                Value * popcount_for = Cal_Count(icGrepInstance, iBuilder, mBlockSize);
     145                Value * temp_countfor = iBuilder->CreateLoad(count);
     146                Value * add_for = iBuilder->CreateAdd(temp_countfor, popcount_for);
     147                iBuilder->CreateStore(add_for, count);
     148            }
    122149        }
    123         for (unsigned i = 0; i < segmentSize; ++i) {
    124             scanMatchInstance->CreateDoBlockCall();
    125         }
     150        if(!CountOnly) {
     151            for (unsigned i = 0; i < segmentSize; ++i) {
     152                scanMatchInstance->CreateDoBlockCall();
     153            }
     154        }
    126155        remainingBytes->addIncoming(iBuilder->CreateSub(remainingBytes, step), segmentBodyBlock);
    127156        iBuilder->CreateBr(segmentCondBlock);
     
    145174    s2pInstance->CreateDoBlockCall();
    146175    icGrepInstance->CreateDoBlockCall();
    147     scanMatchInstance->CreateDoBlockCall();
     176    if(CountOnly){
     177        Value * popcount = Cal_Count(icGrepInstance, iBuilder, mBlockSize);   
     178        Value * temp_count = iBuilder->CreateLoad(count);
     179        Value * add = iBuilder->CreateAdd(temp_count, popcount);
     180        iBuilder->CreateStore(add, count);
     181    }
     182
     183    if(!CountOnly) {
     184        scanMatchInstance->CreateDoBlockCall();
     185    }
    148186
    149187    remainingBytes->addIncoming(iBuilder->CreateSub(remainingBytes, step), fullBodyBlock);
     
    189227
    190228    icGrepInstance->CreateDoBlockCall();
    191     scanMatchInstance->CreateDoBlockCall();
    192     iBuilder->CreateRetVoid();
     229    if(CountOnly){
     230        Value * popcount1 = Cal_Count(icGrepInstance, iBuilder, mBlockSize);   
     231        Value * temp_count1 = iBuilder->CreateLoad(count);
     232        Value * add1 = iBuilder->CreateAdd(temp_count1, popcount1);
     233        iBuilder->CreateStore(add1, count);
     234    }
     235    if(!CountOnly) {
     236        scanMatchInstance->CreateDoBlockCall();
     237    }
     238    if(CountOnly){
     239        Value * Ret = iBuilder->CreateLoad(count);
     240        iBuilder->CreateRet(Ret);
     241    }
     242    else{
     243        iBuilder->CreateRetVoid();
     244    }
     245
    193246
    194247    return main;
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.h

    r4986 r5025  
    3131
    3232        void CreateKernels(pablo::PabloFunction * function, bool isNameExpression);
    33     llvm::Function * ExecuteKernels();
     33    llvm::Function * ExecuteKernels(bool CountOnly);
    3434
    3535private:
Note: See TracChangeset for help on using the changeset viewer.