Ignore:
Timestamp:
Aug 7, 2017, 11:03:08 AM (23 months ago)
Author:
lindanl
Message:

editd:group pattern segments.

File:
1 edited

Legend:

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

    r5597 r5603  
    3030#include <mutex>
    3131#include <boost/uuid/sha1.hpp>
     32#include <editd/editd_cpu_kernel.h>
    3233
    3334#include <toolchain/NVPTXDriver.h>
     
    5051static cl::opt<int> stepSize("step-size", cl::desc("Step Size"), cl::init(3));
    5152static cl::opt<int> prefixLen("prefix", cl::desc("Prefix length"), cl::init(3));
     53static cl::opt<int> groupSize("groupPatterns", cl::desc("Number of pattern segments per group."), cl::init(1));
    5254static cl::opt<bool> ShowPositions("display", cl::desc("Display the match positions."), cl::init(false));
    5355
     
    5557
    5658static cl::opt<bool> MultiEditdKernels("enable-multieditd-kernels", cl::desc("Construct multiple editd kernels in one pipeline."));
     59static cl::opt<bool> EditdIndexPatternKernels("enable-index-kernels", cl::desc("Use pattern index method."));
    5760
    5861using namespace kernel;
     
    154157            pattFile.close();
    155158        }
    156         codegen::GroupNum = pattVector.size();
     159        codegen::GroupNum = pattVector.size()/groupSize;
    157160    }
    158161
     
    404407}
    405408
     409
     410void editdIndexPatternPipeline(ParabixDriver & pxDriver, unsigned patternLen) {
     411
     412    auto & idb = pxDriver.getBuilder();
     413    Module * const m = idb->getModule();
     414    Type * const sizeTy = idb->getSizeTy();
     415    Type * const voidTy = idb->getVoidTy();
     416    Type * const inputType = PointerType::get(ArrayType::get(ArrayType::get(idb->getBitBlockType(), 8), 1), 0);
     417    Type * const patternPtrTy = PointerType::get(idb->getInt8Ty(), 0);
     418
     419    idb->LinkFunction("wrapped_report_pos", &wrapped_report_pos);
     420
     421    const unsigned segmentSize = codegen::SegmentSize;
     422    const unsigned bufferSegments = codegen::BufferSegments * codegen::ThreadNum;
     423
     424    Function * const main = cast<Function>(m->getOrInsertFunction("Main", voidTy, inputType, sizeTy, patternPtrTy, nullptr));
     425    main->setCallingConv(CallingConv::C);
     426    auto args = main->arg_begin();
     427    Value * const inputStream = &*(args++);
     428    inputStream->setName("input");
     429    Value * const fileSize = &*(args++);
     430    fileSize->setName("fileSize");
     431    Value * const pattStream = &*(args++);
     432    pattStream->setName("pattStream");
     433    idb->SetInsertPoint(BasicBlock::Create(m->getContext(), "entry", main,0));
     434
     435    auto ChStream = pxDriver.addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(4)));
     436    auto mmapK = pxDriver.addKernelInstance(make_unique<MemorySourceKernel>(idb, inputType, segmentSize));
     437    mmapK->setInitialArguments({inputStream, fileSize});
     438    pxDriver.makeKernelCall(mmapK, {}, {ChStream});
     439
     440    auto MatchResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(editDistance + 1), segmentSize * bufferSegments));
     441    auto editdk = pxDriver.addKernelInstance(make_unique<kernel::editdCPUKernel>(idb, editDistance, patternLen, groupSize));
     442
     443    const unsigned numOfCarries = patternLen * (editDistance + 1) * 4 * groupSize;
     444    Type * strideCarryTy = ArrayType::get(idb->getBitBlockType(), numOfCarries);
     445    Value * strideCarry = idb->CreateAlloca(strideCarryTy);
     446    idb->CreateStore(Constant::getNullValue(strideCarryTy), strideCarry);
     447
     448    editdk->setInitialArguments({pattStream, strideCarry});
     449    pxDriver.makeKernelCall(editdk, {ChStream}, {MatchResults});
     450
     451    auto editdScanK = pxDriver.addKernelInstance(make_unique<editdScanKernel>(idb, editDistance));
     452    pxDriver.makeKernelCall(editdScanK, {MatchResults}, {});
     453
     454    pxDriver.generatePipelineIR();
     455
     456    idb->CreateRetVoid();
     457
     458    pxDriver.finalizeObject();
     459}
     460
    406461typedef void (*preprocessFunctionType)(const int fd, char * output_data);
    407462
     
    409464
    410465typedef void (*multiEditdFunctionType)(const int fd);
     466
     467typedef void (*editdIndexFunctionType)(char * byte_data, size_t filesize, const char * pattern);
    411468
    412469static char * chStream;
     
    468525    pthread_exit(NULL);
    469526}
    470 
    471 #define GROUPTHREADS 64
    472527
    473528void editdGPUCodeGen(unsigned patternLen){
     
    511566    Value * inputThreadPtr = iBuilder->CreateGEP(inputStream, tid);
    512567    Value * strides = iBuilder->CreateLoad(stridesPtr);
    513     Value * outputBlocks = iBuilder->CreateMul(strides, ConstantInt::get(int32ty, GROUPTHREADS));
     568    Value * outputBlocks = iBuilder->CreateMul(strides, ConstantInt::get(int32ty, iBuilder->getStride() / iBuilder->getBitBlockWidth()));
    514569    Value * resultStreamPtr = iBuilder->CreateGEP(resultStream, iBuilder->CreateAdd(iBuilder->CreateMul(bid, outputBlocks), tid));
    515570    Value * inputSize = iBuilder->CreateLoad(inputSizePtr);
     
    521576
    522577    ExternalBuffer * ResultStream = pxDriver.addExternalBuffer(make_unique<ExternalBuffer>(iBuilder, iBuilder->getStreamSetTy(editDistance+1), resultStreamPtr, 1));   
    523     kernel::Kernel * editdk = pxDriver.addKernelInstance(make_unique<kernel::editdGPUKernel>(iBuilder, editDistance, patternLen));
     578    kernel::Kernel * editdk = pxDriver.addKernelInstance(make_unique<kernel::editdGPUKernel>(iBuilder, editDistance, patternLen, groupSize));
    524579     
    525     const unsigned numOfCarries = patternLen * (editDistance + 1) * 4;
     580    const unsigned numOfCarries = patternLen * (editDistance + 1) * 4 * groupSize;
    526581    Type * strideCarryTy = ArrayType::get(mBitBlockType, numOfCarries);
    527582    Value * strideCarry = iBuilder->CreateAlloca(strideCarryTy);
     
    607662
    608663    const unsigned segmentSize = codegen::SegmentSize;
     664    const unsigned bufferSegments = codegen::BufferSegments * codegen::ThreadNum;
    609665
    610666    Type * mBitBlockType = iBuilder->getBitBlockType();
     
    622678    fileSize->setName("fileSize");
    623679
    624 
    625680    StreamSetBuffer * MatchResults = pxDriver.addBuffer(make_unique<SourceBuffer>(iBuilder, iBuilder->getStreamSetTy(editDistance+1)));
    626     kernel::Kernel * sourceK = pxDriver.addKernelInstance(make_unique<kernel::MemorySourceKernel>(iBuilder, inputType, segmentSize));
     681    kernel::Kernel * sourceK = pxDriver.addKernelInstance(make_unique<kernel::MemorySourceKernel>(iBuilder, inputType, segmentSize * bufferSegments));
    627682    sourceK->setInitialArguments({inputStream, fileSize});
    628683    pxDriver.makeKernelCall(sourceK, {}, {MatchResults});
     
    667722
    668723#ifdef CUDA_ENABLED
    669     codegen::BlockSize = 64;
     724    if (codegen::NVPTX)
     725        codegen::BlockSize = 64;
    670726#endif
    671727
     
    685741        std::string patterns((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
    686742
    687         editdGPUCodeGen(patterns.length()/codegen::GroupNum - 1);
     743        editdGPUCodeGen(pattVector[0].length());
    688744        mergeGPUCodeGen();
    689745        ulong * rslt = RunPTX(PTXFilename, chStream, size, patterns.c_str(), patterns.length(), editDistance);
     
    708764    }
    709765    else{
    710         if (Threads == 1) {     
    711             for(unsigned i=0; i<pattGroups.size(); i++){
    712 
     766        if (Threads == 1) {
     767            if (EditdIndexPatternKernels) {
    713768                ParabixDriver pxDriver("editd");
    714                 editdPipeline(pxDriver, pattGroups[i]);
    715                 auto editd_ptr = reinterpret_cast<editdFunctionType>(pxDriver.getMain());
    716                 editd(editd_ptr, chStream, size);
     769                editdIndexPatternPipeline(pxDriver, pattVector[0].length());
     770                auto editd_ptr = reinterpret_cast<editdIndexFunctionType>(pxDriver.getMain());
     771
     772                for(unsigned i=0; i<pattVector.size(); i+=groupSize){
     773                    std::string pattern = "";
     774                    for (int j=0; j<groupSize; j++){
     775                        pattern += pattVector[i+j];
     776                    }
     777                    editd_ptr(chStream, size, pattern.c_str());
     778                }
     779            }
     780            else {
     781                for(unsigned i=0; i<pattGroups.size(); i++){
     782
     783                    ParabixDriver pxDriver("editd");
     784                    editdPipeline(pxDriver, pattGroups[i]);
     785                    auto editd_ptr = reinterpret_cast<editdFunctionType>(pxDriver.getMain());
     786                    editd(editd_ptr, chStream, size);
     787                }
    717788            }
    718789        }
Note: See TracChangeset for help on using the changeset viewer.