Ignore:
Timestamp:
Mar 8, 2018, 10:50:56 AM (19 months ago)
Author:
cameron
Message:

Restructuring: integrating grep_engine and grep_pipeline

Location:
icGREP/icgrep-devel/icgrep/grep
Files:
1 added
1 moved

Legend:

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

    r5891 r5892  
    11/*
    2  *  Copyright (c) 2017 International Characters.
     2 *  Copyright (c) 2018 International Characters.
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 *  icgrep is a trademark of International Characters.
     
    6060static cl::opt<bool> PropertyKernels("enable-property-kernels", cl::desc("Enable Unicode property kernels."), cl::init(false));
    6161
     62
    6263namespace grep {
     64   
     65
     66void accumulate_match_wrapper(intptr_t accum_addr, const size_t lineNum, char * line_start, char * line_end) {
     67    reinterpret_cast<MatchAccumulator *>(accum_addr)->accumulate_match(lineNum, line_start, line_end);
     68}
     69
     70void finalize_match_wrapper(intptr_t accum_addr, char * buffer_end) {
     71    reinterpret_cast<MatchAccumulator *>(accum_addr)->finalize_match(buffer_end);
     72}
     73
     74void grepBuffer(re::RE * pattern, const char * search_buffer, size_t bufferLength, MatchAccumulator * accum) {
     75    const unsigned segmentSize = codegen::BufferSegments * codegen::SegmentSize * codegen::ThreadNum;
     76   
     77    pattern = resolveCaseInsensitiveMode(pattern, false);
     78    pattern = regular_expression_passes(pattern);
     79   
     80   
     81    ParabixDriver pxDriver("codepointEngine");
     82    auto & idb = pxDriver.getBuilder();
     83    Module * M = idb->getModule();
     84   
     85    Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", idb->getVoidTy(), idb->getInt8PtrTy(), idb->getSizeTy(), nullptr));
     86    mainFunc->setCallingConv(CallingConv::C);
     87    auto args = mainFunc->arg_begin();
     88    Value * const buffer = &*(args++);
     89    buffer->setName("buffer");
     90    Value * length = &*(args++);
     91    length->setName("length");
     92   
     93    idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
     94   
     95    StreamSetBuffer * ByteStream = pxDriver.addBuffer<SourceBuffer>(idb, idb->getStreamSetTy(1, 8));
     96    kernel::Kernel * sourceK = pxDriver.addKernelInstance<kernel::MemorySourceKernel>(idb, idb->getInt8PtrTy());
     97    sourceK->setInitialArguments({buffer, length});
     98    pxDriver.makeKernelCall(sourceK, {}, {ByteStream});
     99   
     100   
     101    StreamSetBuffer * BasisBits = pxDriver.addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(8, 1), segmentSize);
     102    kernel::Kernel * s2pk = pxDriver.addKernelInstance<kernel::S2PKernel>(idb);
     103    pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
     104   
     105    StreamSetBuffer * LineFeedStream = pxDriver.addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     106    kernel::Kernel * linefeedK = pxDriver.addKernelInstance<kernel::LineFeedKernelBuilder>(idb, Binding{idb->getStreamSetTy(8), "basis", FixedRate(), Principal()});
     107    pxDriver.makeKernelCall(linefeedK, {BasisBits}, {LineFeedStream});
     108   
     109    StreamSetBuffer * LineBreakStream = pxDriver.addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     110   
     111    kernel::Kernel * requiredStreamsK = pxDriver.addKernelInstance<kernel::RequiredStreams_UTF8>(idb);
     112    StreamSetBuffer * RequiredStreams = pxDriver.addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     113    pxDriver.makeKernelCall(requiredStreamsK, {BasisBits, LineFeedStream}, {RequiredStreams, LineBreakStream});
     114   
     115    StreamSetBuffer * MatchResults = pxDriver.addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     116    kernel::Kernel * icgrepK = pxDriver.addKernelInstance<kernel::ICGrepKernel>(idb, pattern, std::vector<std::string>{"UTF8_LB", "UTF8_nonfinal"});
     117    pxDriver.makeKernelCall(icgrepK, {BasisBits, LineBreakStream, RequiredStreams}, {MatchResults});
     118   
     119    StreamSetBuffer * MatchedLines = pxDriver.addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
     120    kernel::Kernel * matchedLinesK = pxDriver.addKernelInstance<kernel::MatchedLinesKernel>(idb);
     121    pxDriver.makeKernelCall(matchedLinesK, {MatchResults, LineBreakStream}, {MatchedLines});
     122   
     123    kernel::Kernel * scanMatchK = pxDriver.addKernelInstance<kernel::ScanMatchKernel>(idb);
     124    scanMatchK->setInitialArguments({ConstantInt::get(idb->getIntAddrTy(), reinterpret_cast<intptr_t>(accum))});
     125    pxDriver.makeKernelCall(scanMatchK, {MatchedLines, LineBreakStream, ByteStream}, {});
     126    pxDriver.LinkFunction(*scanMatchK, "accumulate_match_wrapper", &accumulate_match_wrapper);
     127    pxDriver.LinkFunction(*scanMatchK, "finalize_match_wrapper", &finalize_match_wrapper);
     128   
     129    pxDriver.generatePipelineIR();
     130    pxDriver.deallocateBuffers();
     131    idb->CreateRetVoid();
     132    pxDriver.finalizeObject();
     133   
     134    typedef void (*GrepFunctionType)(const char * buffer, const size_t length);
     135    auto f = reinterpret_cast<GrepFunctionType>(pxDriver.getMain());
     136    f(search_buffer, bufferLength);
     137}
     138
     139
    63140
    64141// Grep Engine construction and initialization.
Note: See TracChangeset for help on using the changeset viewer.