Ignore:
Timestamp:
Jun 13, 2016, 11:24:46 AM (3 years ago)
Author:
cameron
Message:

Revert test version of pipeline,...

File:
1 edited

Legend:

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

    r5051 r5052  
    66
    77#include <toolchain.h>
    8 #include "streamset.h"
    9 #include "interface.h"
    10 
    118#include "pipeline.h"
    129#include "utf_encoding.h"
     
    2118
    2219#include <llvm/IR/Intrinsics.h>
    23 #include "llvm/Support/SourceMgr.h"
    24 #include "llvm/IRReader/IRReader.h"
    25 #include "llvm/Linker/Linker.h"
    2620
    2721using namespace pablo;
     
    3731
    3832PipelineBuilder::~PipelineBuilder() {
     33    delete mS2PKernel;
     34    delete mICgrepKernel;
     35    delete mScanMatchKernel;
    3936}
    4037
    4138void PipelineBuilder::CreateKernels(PabloFunction * function, bool UTF_16, bool isNameExpression){
    42     //mS2PKernel = new KernelBuilder(iBuilder, "s2p", codegen::SegmentSize);
     39    mS2PKernel = new KernelBuilder(iBuilder, "s2p", codegen::SegmentSize);
    4340    mICgrepKernel = new KernelBuilder(iBuilder, "icgrep", codegen::SegmentSize);
    4441    mScanMatchKernel = new KernelBuilder(iBuilder, "scanMatch", codegen::SegmentSize);
    45 //#define LOAD_S2P_LL
    46 #ifdef LOAD_S2P_LL
    47     SMDiagnostic Err;
    48     std::unique_ptr<Module> s2p_Module = parseIRFile("s2p.ll", Err, mMod->getContext());
    49     if (!s2p_Module) {
    50          Err.print("icgrep", errs());
    51          exit(1);
    52     }
    53     Linker L(*mMod);
    54     //s2p_Module->dump();
     42    if (UTF_16) {
     43        generateS2P_16Kernel(mMod, iBuilder, mS2PKernel);
     44    }
     45    else {
     46        generateS2PKernel(mMod, iBuilder, mS2PKernel);
     47    }
    5548    generateScanMatch(mMod, iBuilder, 64, mScanMatchKernel, isNameExpression);
    56     L.linkInModule(std::move(s2p_Module));
    57     errs() << "s2p.ll loaded\n";
    58 #else
    59     errs() << "A\n";
    60     //mS2PKernel = new KernelBuilder(iBuilder, "s2p", codegen::SegmentSize);
    61     s2pKernel  s2pk(iBuilder);
    62     //s2pk.addKernelDeclarations(mMod);
    63     //mMod->dump();
    64     std::unique_ptr<Module> s2pM = s2pk.createKernelModule();
    65     Linker L(*mMod);
    66     L.linkInModule(std::move(s2pM));
    67     errs() << "b\n";
    68    
    69    
    70     generateScanMatch(mMod, iBuilder, 64, mScanMatchKernel, isNameExpression);
    71 #endif
    72    
    7349    pablo_function_passes(function);
    7450    PabloCompiler pablo_compiler(mMod, iBuilder);
     
    9167}
    9268
    93 inline Value * Cal_Count(Value * match_ptr, IDISA::IDISA_Builder * iBuilder) {
    94     Value * matches = iBuilder->CreateLoad(match_ptr, false, "match");
     69inline Value * Cal_Count(Instance * icGrepInstance, IDISA::IDISA_Builder * iBuilder) {
     70    Value * match = icGrepInstance->getOutputStream(0, 0);
     71    Value * matches = iBuilder->CreateLoad(match, false, "match");
    9572    return generatePopcount(iBuilder, matches);
    9673}
    9774
    9875Function * PipelineBuilder::ExecuteKernels(bool CountOnly, bool UTF_16) {
    99 
    10076    Type * const int64ty = iBuilder->getInt64Ty();
    10177    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
    102     Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(mBitBlockType, (UTF_16 ? 16 : 8)), 1), 0);
     78    Type * const inputType = PointerType::get(ArrayType::get(StructType::get(mMod->getContext(), std::vector<Type *>({ArrayType::get(mBitBlockType, (UTF_16 ? 16 : 8))})), 1), 0);
    10379    Type * const resultTy = CountOnly ? int64ty : iBuilder->getVoidTy();
    10480    Function * const main = cast<Function>(mMod->getOrInsertFunction("Main", resultTy, inputType, int64ty, int64ty, nullptr));
     
    11288    Value * const fileIdx = &*(args++);
    11389    fileIdx->setName("fileIdx");
    114     errs() << "B\n";
    11590
    11691    iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", main,0));
    117     iBuilder->CallPrintInt("bufferSize", bufferSize);
     92
     93
    11894    BasicBlock * entryBlock = iBuilder->GetInsertBlock();
    11995    BasicBlock * segmentCondBlock = nullptr;
     
    127103    BasicBlock * fullBodyBlock = BasicBlock::Create(mMod->getContext(), "fullBody", main, 0);
    128104    BasicBlock * finalBlock = BasicBlock::Create(mMod->getContext(), "final", main, 0);
     105    BasicBlock * finalPartialBlock = BasicBlock::Create(mMod->getContext(), "partial", main, 0);
     106    BasicBlock * finalEmptyBlock = BasicBlock::Create(mMod->getContext(), "empty", main, 0);
     107    BasicBlock * exitBlock = BasicBlock::Create(mMod->getContext(), "exit", main, 0);
    129108
    130109    Value * count = nullptr;
     
    133112        iBuilder->CreateStore(ConstantInt::getNullValue(mBitBlockType), count);
    134113    }
    135     errs() << "C\n";
    136 
    137     Value * s2pI = make_New(iBuilder,  "s2p", {});
    138     errs() << "D\n";
    139 
    140     StreamSetBuffer ByteStream(iBuilder, StreamSetType(1, (UTF_16 ? 16 : 8)), 0);
    141     ByteStream.setStreamSetBuffer(inputStream);
    142    
    143     StreamSetBuffer BasisBits(iBuilder, StreamSetType((UTF_16 ? 16 : 8), 1), codegen::SegmentSize);
    144     Value * basis_bits_ptr = BasisBits.allocateBuffer();
    145    
    146     Value * grepI = make_New(iBuilder,  "icgrep", {});
    147    
    148     StreamSetBuffer MatchResults(iBuilder, StreamSetType(2, 1), codegen::SegmentSize);
    149     Value * match_results_ptr = MatchResults.allocateBuffer();
    150 
     114
     115    Instance * s2pInstance = mS2PKernel->instantiate(inputStream);
     116    Instance * icGrepInstance = mICgrepKernel->instantiate(s2pInstance->getOutputStreamBuffer());
    151117    Instance * scanMatchInstance = nullptr;
    152118   
    153119    if (!CountOnly) {
    154         scanMatchInstance = mScanMatchKernel->instantiate(match_results_ptr);
     120        scanMatchInstance = mScanMatchKernel->instantiate(icGrepInstance->getOutputStreamBuffer());
    155121        scanMatchInstance->setInternalState("FileBuf", iBuilder->CreateBitCast(inputStream, int8PtrTy));
    156122        scanMatchInstance->setInternalState("FileSize", bufferSize);
     
    158124    }
    159125    Value * initialBufferSize = nullptr;
    160     Value * initialBlockNo = nullptr;
    161126    BasicBlock * initialBlock = nullptr;
    162127
     
    166131        PHINode * remainingBytes = iBuilder->CreatePHI(int64ty, 2, "remainingBytes");
    167132        remainingBytes->addIncoming(bufferSize, entryBlock);
    168         PHINode * blockNo = iBuilder->CreatePHI(int64ty, 2, "blockNo");
    169         blockNo->addIncoming(iBuilder->getInt64(0), entryBlock);
    170133        Constant * const step = ConstantInt::get(int64ty, mBlockSize * segmentSize * (UTF_16 ? 2 : 1));
    171134        Value * segmentCondTest = iBuilder->CreateICmpULT(remainingBytes, step);
     
    173136        iBuilder->SetInsertPoint(segmentBodyBlock);
    174137        for (unsigned i = 0; i < segmentSize; ++i) {
    175             Value * blkNo = iBuilder->CreateAdd(blockNo, iBuilder->getInt64(i));
    176             make_DoBlock_Call(iBuilder, "s2p", {s2pI, ByteStream.getBlockPointer(blkNo), BasisBits.getBlockPointer(blkNo)});
     138            s2pInstance->CreateDoBlockCall();
    177139        }
    178140        for (unsigned i = 0; i < segmentSize; ++i) {
    179             Value * blkNo = iBuilder->CreateAdd(blockNo, iBuilder->getInt64(i));
    180             match_results_ptr = MatchResults.getBlockPointer(blkNo);
    181             make_DoBlock_Call(iBuilder, "icgrep", {grepI, BasisBits.getBlockPointer(blkNo), match_results_ptr});
    182             if (CountOnly) {
    183                 Value * matchptr = iBuilder->CreateGEP(mBitBlockType, match_results_ptr, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(0)});
    184                 Value * temp = iBuilder->CreateLoad(matchptr);
    185                 Value * matches = iBuilder->CreateBitCast(temp, iBuilder->getIntNTy(mBlockSize));
    186                 Value * popcount_for = generatePopcount(iBuilder, matches);
    187                 Value * temp_count = iBuilder->CreateLoad(count);
    188                 Value * prev_count = iBuilder->CreateBitCast(temp_count, iBuilder->getIntNTy(mBlockSize));
    189                 Value * add_for = iBuilder->CreateAdd(prev_count, popcount_for);
    190                 Value * add = iBuilder->CreateBitCast(add_for, mBitBlockType);
    191                 iBuilder->CreateStore(add, count);
    192             }
     141            Value * match = (icGrepInstance->getOutputStream(0, 0));
     142            icGrepInstance->CreateDoBlockCall();
     143            Value * temp = iBuilder->CreateLoad(match);
     144            Value * matches = iBuilder->CreateBitCast(temp, iBuilder->getIntNTy(mBlockSize));
     145            Value * popcount_for = generatePopcount(iBuilder, matches);
     146            if(CountOnly){
     147                Value * temp_count = iBuilder->CreateLoad(count);
     148                Value * prev_count = iBuilder->CreateBitCast(temp_count, iBuilder->getIntNTy(mBlockSize));
     149                Value * add_for = iBuilder->CreateAdd(prev_count, popcount_for);
     150                Value * add = iBuilder->CreateBitCast(add_for, mBitBlockType);
     151                iBuilder->CreateStore(add, count);
     152            }
    193153        }
    194154        if (!CountOnly) {
    195155            for (unsigned i = 0; i < segmentSize; ++i) {
    196                 Value * blkNo = iBuilder->CreateAdd(blockNo, iBuilder->getInt64(i));
    197                 match_results_ptr = MatchResults.getBlockPointer(blkNo);
    198                 make_DoBlock_Call(iBuilder, "scanMatch", {scanMatchInstance->getKernelState(), match_results_ptr});
     156                scanMatchInstance->CreateDoBlockCall();
    199157            }
    200158        }
    201159        remainingBytes->addIncoming(iBuilder->CreateSub(remainingBytes, step), segmentBodyBlock);
    202         blockNo->addIncoming(iBuilder->CreateAdd(blockNo, iBuilder->getInt64(segmentSize)), segmentBodyBlock);
    203160        iBuilder->CreateBr(segmentCondBlock);
    204161        initialBufferSize = remainingBytes;
    205162        initialBlock = segmentCondBlock;
    206         initialBlockNo = blockNo;
    207163    } else {
    208164        initialBufferSize = bufferSize;
    209165        initialBlock = entryBlock;
    210         initialBlockNo = iBuilder->getInt64(0);
    211166        iBuilder->CreateBr(fullCondBlock);
    212167    }
     
    215170    PHINode * remainingBytes = iBuilder->CreatePHI(int64ty, 2, "remainingBytes");
    216171    remainingBytes->addIncoming(initialBufferSize, initialBlock);
    217     PHINode * blockNo = iBuilder->CreatePHI(int64ty, 2, "blockNo");
    218     blockNo->addIncoming(initialBlockNo, initialBlock);
    219    
     172
    220173    Constant * const step = ConstantInt::get(int64ty, mBlockSize * (UTF_16 ? 2 : 1));
    221174    Value * fullCondTest = iBuilder->CreateICmpULT(remainingBytes, step);
     
    223176
    224177    iBuilder->SetInsertPoint(fullBodyBlock);
    225     errs() << "E\n";
    226 
    227     make_DoBlock_Call(iBuilder, "s2p", {s2pI, ByteStream.getBlockPointer(blockNo), BasisBits.getBlockPointer(blockNo)});
    228     errs() << "F\n";
    229     make_DoBlock_Call(iBuilder, "icgrep", {grepI, BasisBits.getBlockPointer(blockNo), MatchResults.getBlockPointer(blockNo)});
     178    s2pInstance->CreateDoBlockCall();
     179    icGrepInstance->CreateDoBlockCall();
    230180    if (CountOnly) {
    231         Value * matchptr = iBuilder->CreateGEP(mBitBlockType, match_results_ptr, {iBuilder->getInt64(0), iBuilder->getInt32(0)});
    232         Value * popcount = Cal_Count(matchptr, iBuilder);
     181        Value * popcount = Cal_Count(icGrepInstance, iBuilder);
    233182        Value * temp_count = iBuilder->CreateLoad(count);
    234183        Value * add = iBuilder->CreateAdd(temp_count, popcount);
    235184        iBuilder->CreateStore(add, count);
    236185    } else {
    237         make_DoBlock_Call(iBuilder, "scanMatch", {scanMatchInstance->getKernelState(), MatchResults.getBlockPointer(blockNo)});
     186        scanMatchInstance->CreateDoBlockCall();
    238187    }
    239188
    240189    remainingBytes->addIncoming(iBuilder->CreateSub(remainingBytes, step), fullBodyBlock);
    241     blockNo->addIncoming(iBuilder->CreateAdd(blockNo, iBuilder->getInt64(1)), fullBodyBlock);
    242190    iBuilder->CreateBr(fullCondBlock);
    243191
    244192    iBuilder->SetInsertPoint(finalBlock);
    245     basis_bits_ptr = BasisBits.getBlockPointer(blockNo);
    246 
    247     make_FinalBlock_Call(iBuilder, "s2p", {s2pI, remainingBytes, ByteStream.getBlockPointer(blockNo), basis_bits_ptr});
    248    
    249     errs() << "G\n";
     193    Value * emptyBlockCond = iBuilder->CreateICmpEQ(remainingBytes, ConstantInt::get(int64ty, 0));
     194    iBuilder->CreateCondBr(emptyBlockCond, finalEmptyBlock, finalPartialBlock);
     195
     196
     197    iBuilder->SetInsertPoint(finalPartialBlock);
     198    s2pInstance->CreateDoBlockCall();
     199    iBuilder->CreateBr(exitBlock);
     200
     201    iBuilder->SetInsertPoint(finalEmptyBlock);
     202    s2pInstance->clearOutputStreamSet();
     203    iBuilder->CreateBr(exitBlock);
     204
     205    iBuilder->SetInsertPoint(exitBlock);
    250206
    251207    Value * remainingByte = iBuilder->CreateZExt(remainingBytes, iBuilder->getIntNTy(mBlockSize));
    252208    Value * remainingUnit = iBuilder->CreateLShr(remainingByte, ConstantInt::get(iBuilder->getIntNTy(mBlockSize), 1));
    253209    Value * EOFmark = iBuilder->CreateShl(ConstantInt::get(iBuilder->getIntNTy(mBlockSize), 1), UTF_16 ? remainingUnit : remainingByte);
    254     //icGrepInstance->setInternalState("EOFmark", iBuilder->CreateBitCast(EOFmark, mBitBlockType));
    255     match_results_ptr = MatchResults.getBlockPointer(blockNo);
    256     make_DoBlock_Call(iBuilder, "icgrep", {grepI, basis_bits_ptr, match_results_ptr});
    257     errs() << "H\n";
     210    icGrepInstance->setInternalState("EOFmark", iBuilder->CreateBitCast(EOFmark, mBitBlockType));
     211
     212    icGrepInstance->CreateDoBlockCall();
    258213    if (CountOnly) {
    259         Value * matchptr = iBuilder->CreateGEP(mBitBlockType, match_results_ptr, {iBuilder->getInt64(0), iBuilder->getInt32(0)});
    260         Value * popcount1 = Cal_Count(matchptr, iBuilder);
     214        Value * popcount1 = Cal_Count(icGrepInstance, iBuilder);
    261215        Value * temp_count1 = iBuilder->CreateLoad(count);
    262216        Value * result = iBuilder->CreateAdd(temp_count1, popcount1);
     
    276230        iBuilder->CreateRet(iBuilder->CreateExtractElement(result, iBuilder->getInt32(0)));
    277231    } else {
    278         make_DoBlock_Call(iBuilder, "scanMatch", {scanMatchInstance->getKernelState(), match_results_ptr});
     232        scanMatchInstance->CreateDoBlockCall();
    279233        iBuilder->CreateRetVoid();
    280234    }
Note: See TracChangeset for help on using the changeset viewer.