Changeset 5341 for icGREP


Ignore:
Timestamp:
Feb 22, 2017, 4:51:39 PM (3 years ago)
Author:
xuedongx
Message:

LineBreak? Kernel for GPU.

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

Legend:

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

    r5339 r5341  
    9696            if(codegen::NVPTX){
    9797                codegen::BlockSize = 128;
    98                 std::vector<size_t> LFPositions = preprocess(fileBuffer, fileSize);
     98                char * LineBreak;
     99                if (posix_memalign((void**)&LineBreak, 32, fileSize)) {
     100                    std::cerr << "Cannot allocate memory for linebreak.\n";
     101                    exit(-1);
     102                }
     103                std::vector<size_t> LFPositions = preprocess(fileBuffer, fileSize, LineBreak);
    99104
    100105                const unsigned numOfGroups = codegen::GroupNum;
     
    111116                else{
    112117                    size_t intputSize = startPoints[numOfGroups]-accumBytes[numOfGroups]+accumBytes[numOfGroups-1];
    113                     mGrepFunction_CPU((char *)rslt, fileBuffer, intputSize, fileIdx);
     118                    mGrepFunction_CPU((char *)rslt, LineBreak, fileBuffer, intputSize, fileIdx);
    114119                    return;
    115120                }
     
    203208    Type * const size_ty = iBuilder->getSizeTy();
    204209    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
    205     Type * const rsltType = PointerType::get(ArrayType::get(iBuilder->getBitBlockType(), 2), 0);
    206     Function * const mainCPUFn = cast<Function>(m->getOrInsertFunction("CPU_Main", iBuilder->getVoidTy(), rsltType, int8PtrTy, size_ty, size_ty, nullptr));
     210    Type * const rsltType = PointerType::get(ArrayType::get(iBuilder->getBitBlockType(), 1), 0);
     211    Function * const mainCPUFn = cast<Function>(m->getOrInsertFunction("CPU_Main", iBuilder->getVoidTy(), rsltType, rsltType, int8PtrTy, size_ty, size_ty, nullptr));
    207212    mainCPUFn->setCallingConv(CallingConv::C);
    208213    iBuilder->SetInsertPoint(BasicBlock::Create(m->getContext(), "entry", mainCPUFn, 0));
     
    211216    Value * const rsltStream = &*(args++);
    212217    rsltStream->setName("rslt");
     218    Value * const lbStream = &*(args++);
     219    lbStream->setName("lb");
    213220    Value * const inputStream = &*(args++);
    214221    inputStream->setName("input");
     
    220227    const unsigned segmentSize = codegen::SegmentSize;
    221228
    222     ExternalFileBuffer MatchResults(iBuilder, iBuilder->getStreamSetTy(2, 1));
     229    ExternalFileBuffer MatchResults(iBuilder, iBuilder->getStreamSetTy(1, 1));
    223230    MatchResults.setStreamSetBuffer(rsltStream, fileSize);
    224231
    225     kernel::MMapSourceKernel mmapK(iBuilder, segmentSize);
    226     mmapK.generateKernel({}, {&MatchResults});
    227     mmapK.setInitialArguments({fileSize});
    228 
    229 
     232    kernel::MMapSourceKernel mmapK1(iBuilder, segmentSize);
     233    mmapK1.generateKernel({}, {&MatchResults});
     234    mmapK1.setInitialArguments({fileSize});
     235
     236
     237    ExternalFileBuffer LineBreak(iBuilder, iBuilder->getStreamSetTy(1, 1));
     238    LineBreak.setStreamSetBuffer(lbStream, fileSize);
     239   
     240    kernel::MMapSourceKernel mmapK2(iBuilder, segmentSize);
     241    mmapK2.generateKernel({}, {&LineBreak});
     242    mmapK2.setInitialArguments({fileSize});
    230243
    231244    kernel::ScanMatchKernel scanMatchK(iBuilder, grepType);
    232     scanMatchK.generateKernel({&MatchResults}, {});
     245    scanMatchK.generateKernel({&MatchResults, &LineBreak}, {});
    233246           
    234247    scanMatchK.setInitialArguments({inputStream, fileSize, fileIdx});
    235248   
    236     generatePipelineLoop(iBuilder, {&mmapK, &scanMatchK});
     249    generatePipelineLoop(iBuilder, {&mmapK1, &mmapK2, &scanMatchK});
    237250    iBuilder->CreateRetVoid();
    238251
  • icGREP/icgrep-devel/icgrep/grep_engine.h

    r5338 r5341  
    1717    typedef void (*GrepFunctionType)(char * byte_data, size_t filesize, const int fileIdx);
    1818    typedef uint64_t (*GrepFunctionType_CountOnly)(char * byte_data, size_t filesize, const int fileIdx);
    19     typedef void (*GrepFunctionType_CPU)(char * rslt, char * byte_data, size_t filesize, const int fileIdx);
     19    typedef void (*GrepFunctionType_CPU)(char * rslt, char * LineBreak, char * byte_data, size_t filesize, const int fileIdx);
    2020public:
    2121
  • icGREP/icgrep-devel/icgrep/preprocess.cpp

    r5318 r5341  
    2929using namespace parabix;
    3030
     31
    3132std::vector<size_t> LFPositions;
    3233extern "C" {
     
    5354    Type * const inputType = PointerType::get(ArrayType::get(iBuilder->getBitBlockType(), 1), 0);
    5455
    55     Function * const mainFn = cast<Function>(m->getOrInsertFunction("LF", iBuilder->getVoidTy(), inputType, size_ty, nullptr));
     56    Function * const mainFn = cast<Function>(m->getOrInsertFunction("LF", iBuilder->getVoidTy(), inputType, size_ty, inputType, nullptr));
    5657    mainFn->setCallingConv(CallingConv::C);
    5758    iBuilder->SetInsertPoint(BasicBlock::Create(m->getContext(), "entry", mainFn, 0));
    5859    Function::arg_iterator args = mainFn->arg_begin();
    59    
    6060    Value * const inputStream = &*(args++);
    6161    inputStream->setName("input");
    6262    Value * const fileSize = &*(args++);
    6363    fileSize->setName("fileSize");
     64    Value * const lineBreak = &*(args++);
     65    lineBreak->setName("lineBreak");
    6466
    6567    const unsigned segmentSize = codegen::SegmentSize;
     
    6870    ExternalFileBuffer ByteStream(iBuilder, iBuilder->getStreamSetTy(1, 8));
    6971    ByteStream.setStreamSetBuffer(inputStream, fileSize);
    70     CircularBuffer MatchResults(iBuilder, iBuilder->getStreamSetTy(1, 1), segmentSize * bufferSegments);
    71     MatchResults.allocateBuffer();
     72    ExternalFileBuffer MatchResults(iBuilder, iBuilder->getStreamSetTy(1, 1), segmentSize * bufferSegments);
     73    MatchResults.setStreamSetBuffer(lineBreak, fileSize);
    7274
    7375    kernel::MMapSourceKernel mmapK(iBuilder, segmentSize);
     
    7779    std::vector<re::CC *> charClasses;
    7880    charClasses.push_back(re::makeCC(0x0A));
    79     kernel::DirectCharacterClassKernelBuilder ccK(iBuilder, "LF", charClasses, 1);
    80     ccK.generateKernel({&ByteStream}, {&MatchResults});
    81 
     81    kernel::DirectCharacterClassKernelBuilder linefeedK(iBuilder, "linefeed", charClasses, 1);
     82    linefeedK.generateKernel({&ByteStream}, {&MatchResults});
     83   
    8284    kernel::CCScanKernel scanMatchK(iBuilder, 1);
    8385    scanMatchK.generateKernel({&MatchResults}, {});
    8486   
    85     generatePipelineLoop(iBuilder, {&mmapK, &ccK, &scanMatchK});
     87    generatePipelineLoop(iBuilder, {&mmapK, &linefeedK, &scanMatchK});
    8688    iBuilder->CreateRetVoid();
    8789
     
    9092}
    9193
    92 typedef void (*preprocessFunctionType)(char * byte_data, size_t filesize);
     94typedef void (*preprocessFunctionType)(char * byte_data, size_t filesize, char * lb);
    9395
    9496preprocessFunctionType preprocessCodeGen() {
     
    111113}
    112114
    113 std::vector<size_t> preprocess(char * fileBuffer, size_t fileSize) {
     115std::vector<size_t> preprocess(char * fileBuffer, size_t fileSize, char * LineBreak) {
    114116    preprocessFunctionType preprocess_ptr = preprocessCodeGen();
    115     preprocess_ptr(fileBuffer, fileSize);
     117    preprocess_ptr(fileBuffer, fileSize, LineBreak);
    116118    return LFPositions;
    117119}
Note: See TracChangeset for help on using the changeset viewer.