Ignore:
Timestamp:
Jul 15, 2016, 10:05:58 PM (3 years ago)
Author:
cameron
Message:

icgrep using doSegment; pipeline generation

File:
1 edited

Legend:

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

    r5082 r5087  
    2626#include <UCD/UnicodeNameData.h>
    2727
     28
     29#include <kernels/streamset.h>
     30#include <kernels/scanmatchgen.h>
     31#include <kernels/s2p_kernel.h>
     32#include <kernels/pipeline.h>
     33
     34#include <pablo/function.h>
     35#include <pablo/pablo_kernel.h>
     36#include <pablo/pablo_toolchain.h>
     37
     38#include <llvm/IR/Intrinsics.h>
     39#include "llvm/Support/SourceMgr.h"
     40#include "llvm/IRReader/IRReader.h"
     41#include "llvm/Linker/Linker.h"
     42
     43
    2844#include <fstream>
    2945#include <sstream>
     
    107123    Module * M = new Module(moduleName, getGlobalContext());
    108124   
    109     IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    110 
    111     kernel::PipelineBuilder pipelineBuilder(M, idb);
     125    IDISA::IDISA_Builder * iBuilder = IDISA::GetIDISA_Builder(M);
     126
    112127
    113128    Encoding::Type type;
     
    122137    pablo::PabloFunction * function = re::re2pablo_compiler(encoding, re_ast);
    123138   
    124     llvm::Function * grepIR = pipelineBuilder.ExecuteKernels(function, isNameExpression, CountOnly, UTF_16);
    125 
     139    kernel::s2pKernel  s2pk(iBuilder);
     140    kernel::scanMatchKernel scanMatchK(iBuilder, 64, false);
     141   
     142    s2pk.generateKernel();
     143    scanMatchK.generateKernel();
     144   
     145    //std::unique_ptr<Module> s2pM = s2pk.createKernelModule();
     146    //std::unique_ptr<Module> scanMatchM = scanMatchK.createKernelModule();
     147   
     148    //s2pk.addKernelDeclarations(mMod);
     149    //scanMatchK.addKernelDeclarations(mMod);
     150   
     151    pablo_function_passes(function);
     152    pablo::PabloKernel  icgrepK(iBuilder, "icgrep", function, {"matchedLineCount"});
     153    icgrepK.generateKernel();
     154   
     155    //std::unique_ptr<Module> icgrepM = icgrepK.createKernelModule();
     156    //icgrepK.addKernelDeclarations(mMod);
     157   
     158    Type * const int64ty = iBuilder->getInt64Ty();
     159    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
     160    Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(iBuilder->getBitBlockType(), (UTF_16 ? 16 : 8)), 1), 0);
     161    Type * const resultTy = CountOnly ? int64ty : iBuilder->getVoidTy();
     162    Function * const mainFn = cast<Function>(M->getOrInsertFunction("Main", resultTy, inputType, int64ty, int64ty, nullptr));
     163    mainFn->setCallingConv(CallingConv::C);
     164    iBuilder->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFn, 0));
     165    Function::arg_iterator args = mainFn->arg_begin();
     166   
     167    Value * const inputStream = &*(args++);
     168    inputStream->setName("input");
     169    Value * const fileSize = &*(args++);
     170    fileSize->setName("fileSize");
     171    Value * const fileIdx = &*(args++);
     172    fileIdx->setName("fileIdx");
     173
     174    const unsigned segmentSize = codegen::SegmentSize;
     175
     176    kernel::StreamSetBuffer ByteStream(iBuilder, kernel::StreamSetType(1, (UTF_16 ? 16 : 8)), 0);
     177    kernel::StreamSetBuffer BasisBits(iBuilder, kernel::StreamSetType((UTF_16 ? 16 : 8), 1), segmentSize);
     178    ByteStream.setStreamSetBuffer(inputStream);
     179    BasisBits.allocateBuffer();
     180
     181    if (CountOnly) {
     182        Value * s2pInstance = s2pk.createInstance({}, {&ByteStream}, {&BasisBits});
     183        Value * icgrepInstance = icgrepK.createInstance({}, {&BasisBits}, {});
     184       
     185        generatePipelineLoop(iBuilder, {&s2pk, &icgrepK}, {s2pInstance, icgrepInstance}, fileSize);
     186        Value * matchCount = icgrepK.createGetAccumulatorCall(icgrepInstance, "matchedLineCount");
     187        iBuilder->CreateRet(matchCount);
     188    }
     189    else {
     190        kernel::StreamSetBuffer MatchResults(iBuilder, kernel::StreamSetType(2, 1), segmentSize);
     191        ByteStream.setStreamSetBuffer(inputStream);
     192        BasisBits.allocateBuffer();
     193        MatchResults.allocateBuffer();
     194       
     195       
     196        Value * s2pInstance = s2pk.createInstance({}, {&ByteStream}, {&BasisBits});
     197        Value * icgrepInstance = icgrepK.createInstance({}, {&BasisBits}, {&MatchResults});
     198        Value * scanMatchInstance = scanMatchK.createInstance({iBuilder->CreateBitCast(inputStream, int8PtrTy), fileSize, fileIdx}, {&MatchResults}, {});
     199       
     200        generatePipelineLoop(iBuilder, {&s2pk, &icgrepK, &scanMatchK}, {s2pInstance, icgrepInstance, scanMatchInstance}, fileSize);
     201        iBuilder->CreateRetVoid();
     202    }
     203   
    126204    mEngine = JIT_to_ExecutionEngine(M);
    127205    ApplyObjectCache(mEngine);
     
    133211
    134212    mEngine->finalizeObject();
    135     delete idb;
    136 
     213    delete iBuilder;
     214   
    137215    if (CountOnly) {
    138         mGrepFunction_CountOnly = reinterpret_cast<GrepFunctionType_CountOnly>(mEngine->getPointerToFunction(grepIR));
     216        mGrepFunction_CountOnly = reinterpret_cast<GrepFunctionType_CountOnly>(mEngine->getPointerToFunction(mainFn));
    139217    } else {
    140         mGrepFunction = reinterpret_cast<GrepFunctionType>(mEngine->getPointerToFunction(grepIR));
     218        mGrepFunction = reinterpret_cast<GrepFunctionType>(mEngine->getPointerToFunction(mainFn));
    141219    }
    142220
Note: See TracChangeset for help on using the changeset viewer.