Changeset 5579


Ignore:
Timestamp:
Jul 24, 2017, 6:48:18 PM (5 months ago)
Author:
lindanl
Message:

multiple editd kernels in one pipeline

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r5568 r5579  
    107107add_executable(base64 base64.cpp kernels/radix64.cpp)
    108108add_executable(wc wc.cpp)
    109 add_executable(editd editd/editd.cpp editd/pattern_compiler.cpp editd/editdscan_kernel.cpp editd/editd_gpu_kernel.cpp editd/editd_cpu_kernel.cpp)
     109add_executable(editd editd/editd.cpp editd/pattern_compiler.cpp editd/editdscan_kernel.cpp editd/editd_gpu_kernel.cpp editd/editd_cpu_kernel.cpp kernels/streams_merge.cpp)
    110110add_executable(array-test array-test.cpp kernels/alignedprint.cpp)
    111111add_executable(lz4d lz4d.cpp lz4FrameDecoder.cpp kernels/cc_kernel.cpp kernels/lz4_index_decoder.cpp kernels/lz4_bytestream_decoder.cpp)
  • icGREP/icgrep-devel/icgrep/editd/editd.cpp

    r5577 r5579  
    2222#include <kernels/s2p_kernel.h>
    2323#include <editd/editdscan_kernel.h>
     24#include <kernels/streams_merge.h>
    2425#include <editd/pattern_compiler.h>
    2526#include <toolchain/cpudriver.h>
     
    5051
    5152static cl::opt<int> Threads("threads", cl::desc("Total number of threads."), cl::init(1));
     53
     54static cl::opt<bool> MultiEditdKernels("enable-multieditd-kernels", cl::desc("Construct multiple editd kernels in one pipeline."));
    5255
    5356using namespace kernel;
     
    247250}
    248251
     252
     253void multiEditdPipeline(ParabixDriver & pxDriver) {
     254
     255    auto & idb = pxDriver.getBuilder();
     256    Module * const m = idb->getModule();
     257    Type * const sizeTy = idb->getSizeTy();
     258    Type * const voidTy = idb->getVoidTy();
     259    Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(idb->getBitBlockType(), 8), 1), 0);
     260
     261    idb->LinkFunction("wrapped_report_pos", &wrapped_report_pos);
     262
     263    const unsigned segmentSize = codegen::SegmentSize;
     264    const unsigned bufferSegments = codegen::BufferSegments;
     265
     266    Function * const main = cast<Function>(m->getOrInsertFunction("Main", voidTy, inputType, sizeTy, nullptr));
     267    main->setCallingConv(CallingConv::C);
     268    auto args = main->arg_begin();
     269    Value * const inputStream = &*(args++);
     270    inputStream->setName("input");
     271    Value * const fileSize = &*(args++);
     272    fileSize->setName("fileSize");
     273    idb->SetInsertPoint(BasicBlock::Create(m->getContext(), "entry", main,0));
     274
     275    auto ChStream = pxDriver.addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(4)));
     276    auto mmapK = pxDriver.addKernelInstance(make_unique<MemorySourceKernel>(idb, inputType));
     277    mmapK->setInitialArguments({inputStream, fileSize});
     278    pxDriver.makeKernelCall(mmapK, {}, {ChStream});
     279
     280    const auto n = pattGroups.size();
     281   
     282    std::vector<StreamSetBuffer *> MatchResultsBufs(n);
     283   
     284    for(unsigned i = 0; i < n; ++i){
     285        auto MatchResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(editDistance + 1), segmentSize * bufferSegments));
     286        auto editdk = pxDriver.addKernelInstance(make_unique<PatternKernel>(idb, pattGroups[i]));
     287        pxDriver.makeKernelCall(editdk, {ChStream}, {MatchResults});
     288        MatchResultsBufs[i] = MatchResults;
     289    }
     290    StreamSetBuffer * MergedResults = MatchResultsBufs[0];
     291    if (n > 1) {
     292        MergedResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(editDistance + 1), segmentSize * bufferSegments));
     293        kernel::Kernel * streamsMergeK = pxDriver.addKernelInstance(make_unique<kernel::StreamsMerge>(idb, editDistance + 1, n));
     294        pxDriver.makeKernelCall(streamsMergeK, MatchResultsBufs, {MergedResults});
     295    }
     296
     297    auto editdScanK = pxDriver.addKernelInstance(make_unique<editdScanKernel>(idb, editDistance));
     298    pxDriver.makeKernelCall(editdScanK, {MergedResults}, {});
     299
     300    pxDriver.generatePipelineIR();
     301
     302    idb->CreateRetVoid();
     303
     304    pxDriver.finalizeObject();
     305}
     306
    249307class PreprocessKernel final: public pablo::PabloKernel {
    250308public:
     
    604662    else{
    605663        if (Threads == 1) {
    606             for(unsigned i=0; i<pattGroups.size(); i++){
    607 
     664            if (MultiEditdKernels) {
    608665                ParabixDriver pxDriver("editd");
    609                 editdPipeline(pxDriver, pattGroups[i]);
     666                multiEditdPipeline(pxDriver);
    610667                auto editd_ptr = reinterpret_cast<editdFunctionType>(pxDriver.getMain());
    611668                editd(editd_ptr, chStream, size);
     669            }
     670            else{               
     671                for(unsigned i=0; i<pattGroups.size(); i++){
     672
     673                    ParabixDriver pxDriver("editd");
     674                    editdPipeline(pxDriver, pattGroups[i]);
     675                    auto editd_ptr = reinterpret_cast<editdFunctionType>(pxDriver.getMain());
     676                    editd(editd_ptr, chStream, size);
     677                }
    612678            }
    613679        }
Note: See TracChangeset for help on using the changeset viewer.