Changeset 5474 for icGREP/icgrep-devel


Ignore:
Timestamp:
May 24, 2017, 12:06:43 PM (2 years ago)
Author:
nmedfort
Message:

Eliminated ExecutionEngine? memory leak. Intentionally broke compatibility with prior versions to ensure unchecked in projects are restructured.

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

Legend:

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

    r5472 r5474  
    193193IF (STDLIB_HAS_ALIGNED_ALLOC)
    194194SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTDLIB_HAS_ALIGNED_ALLOC")
     195ELSE()
     196CHECK_FUNCTION_EXISTS(posix_memalign STDLIB_HAS_POSIX_MEMALIGN)
     197IF (!STDLIB_HAS_POSIX_MEMALIGN)
     198MESSAGE(FATAL_ERROR "stdlib.h does not contain either aligned_alloc or posix_memalign" )
     199ENDIF()
    195200ENDIF()
    196201
     
    216221
    217222SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
    218 SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -fno-omit-frame-pointer -fsanitize=address")
     223SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize=address")
    219224
    220225add_test(
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.cpp

    r5472 r5474  
    280280    CreateAssert(ptr, "CreateAlignedMalloc: returned null pointer.");
    281281    return ptr;
     282}
     283
     284
     285Value * CBuilder::CreateRealloc(Value * const ptr, Value * size) {
     286    Module * const m = getModule();
     287    IntegerType * const sizeTy = getSizeTy();
     288    PointerType * const voidPtrTy = getVoidPtrTy();
     289    Function * f = m->getFunction("realloc");
     290    if (f == nullptr) {
     291        FunctionType * fty = FunctionType::get(voidPtrTy, {voidPtrTy, sizeTy}, false);
     292        f = Function::Create(fty, Function::ExternalLinkage, "realloc", m);
     293        f->setCallingConv(CallingConv::C);
     294        f->setDoesNotAlias(0);
     295        f->setDoesNotAlias(1);
     296        // f = LinkFunction("realloc", &realloc);
     297    }
     298    Value * const addr = CreatePointerCast(ptr, voidPtrTy);
     299    size = CreateZExtOrTrunc(size, sizeTy);
     300    CallInst * const ci = CreateCall(f, {addr, size});
     301    ci->setTailCall();
     302    return CreatePointerCast(ci, ptr->getType());
     303}
     304
     305void CBuilder::CreateFree(Value * ptr) {
     306    assert (ptr->getType()->isPointerTy());
     307    Module * const m = getModule();
     308    Type * const voidPtrTy =  getVoidPtrTy();
     309    Function * f = m->getFunction("free");
     310    if (f == nullptr) {
     311        FunctionType * fty = FunctionType::get(getVoidTy(), {voidPtrTy}, false);
     312        f = Function::Create(fty, Function::ExternalLinkage, "free", m);
     313        f->setCallingConv(CallingConv::C);
     314        // f = LinkFunction("free", &std::free);
     315    }
     316    ptr = CreatePointerCast(ptr, voidPtrTy);
     317    CreateCall(f, ptr)->setTailCall();
    282318}
    283319
     
    446482}
    447483
    448 void CBuilder::CreateFree(Value * ptr) {
    449     assert (ptr->getType()->isPointerTy());
    450     Module * const m = getModule();
    451     Type * const voidPtrTy =  getVoidPtrTy();
    452     Function * f = m->getFunction("free");
    453     if (f == nullptr) {
    454         FunctionType * fty = FunctionType::get(getVoidTy(), {voidPtrTy}, false);
    455         f = Function::Create(fty, Function::ExternalLinkage, "free", m);
    456         f->setCallingConv(CallingConv::C);
    457         // f = LinkFunction("free", &std::free);
    458     }
    459     ptr = CreatePointerCast(ptr, voidPtrTy);
    460     CreateCall(f, ptr)->setTailCall();
    461 }
    462 
    463 Value * CBuilder::CreateRealloc(Value * const ptr, Value * size) {
    464     Module * const m = getModule();
    465     IntegerType * const sizeTy = getSizeTy();
    466     PointerType * const voidPtrTy = getVoidPtrTy();
    467     Function * f = m->getFunction("realloc");
    468     if (f == nullptr) {
    469         FunctionType * fty = FunctionType::get(voidPtrTy, {voidPtrTy, sizeTy}, false);
    470         f = Function::Create(fty, Function::ExternalLinkage, "realloc", m);
    471         f->setCallingConv(CallingConv::C);
    472         f->setDoesNotAlias(0);
    473         f->setDoesNotAlias(1);
    474         // f = LinkFunction("realloc", &realloc);
    475     }
    476     Value * const addr = CreatePointerCast(ptr, voidPtrTy);
    477     size = CreateZExtOrTrunc(size, sizeTy);
    478     CallInst * const ci = CreateCall(f, {addr, size});
    479     ci->setTailCall();
    480     return CreatePointerCast(ci, ptr->getType());
    481 }
    482 
    483484PointerType * CBuilder::getVoidPtrTy() const {
    484485    return TypeBuilder<void *, true>::get(getContext());
  • icGREP/icgrep-devel/icgrep/array-test.cpp

    r5464 r5474  
    183183    iBuilder->CreateRetVoid();
    184184
    185     pxDriver.linkAndFinalize();
     185    pxDriver.finalizeObject();
    186186}
    187187
    188188typedef void (*MatchParens)(char * byteStream, size_t fileSize);
    189 
    190 MatchParens generateAlgorithm() {
    191     ParabixDriver pxDriver("mp");
    192     pipeline(pxDriver, 3);
    193     return reinterpret_cast<MatchParens>(pxDriver.getPointerToMain());
    194 }
    195189
    196190template <typename T>
     
    254248int main(int argc, char *argv[]) {
    255249    cl::ParseCommandLineOptions(argc, argv);
    256     auto f = generateAlgorithm();
     250    ParabixDriver pxDriver("mp");
     251    pipeline(pxDriver, 3);
     252    auto main = reinterpret_cast<MatchParens>(pxDriver.getMain());
    257253    for (const auto & inputFile : inputFiles) {
    258         run(f, inputFile);
     254        run(main, inputFile);
    259255    }
    260256    return 0;
  • icGREP/icgrep-devel/icgrep/base64.cpp

    r5464 r5474  
    9696    iBuilder->CreateRetVoid();
    9797
    98     pxDriver.linkAndFinalize();
     98    pxDriver.finalizeObject();
    9999}
    100100
    101101
    102102typedef void (*base64FunctionType)(const uint32_t fd, char * outputBuffer);
    103 
    104 base64FunctionType base64CodeGen(void) {
    105     ParabixDriver pxDriver("base64");
    106     base64PipelineGen(pxDriver);
    107     return reinterpret_cast<base64FunctionType>(pxDriver.getPointerToMain());
    108 }
    109103
    110104size_t file_size(const int fd) {
     
    142136}
    143137
    144 
    145138int main(int argc, char *argv[]) {
    146139    AddParabixVersionPrinter();
     
    148141    cl::ParseCommandLineOptions(argc, argv);
    149142
    150     base64FunctionType fn_ptr = base64CodeGen();
     143    ParabixDriver pxDriver("base64");
     144    base64PipelineGen(pxDriver);
     145    auto main = reinterpret_cast<base64FunctionType>(pxDriver.getMain());
    151146
    152147    for (unsigned i = 0; i != inputFiles.size(); ++i) {
    153         base64(fn_ptr, inputFiles[i]);
     148        base64(main, inputFiles[i]);
    154149    }
    155150
  • icGREP/icgrep-devel/icgrep/editd/editd.cpp

    r5464 r5474  
    237237    idb->CreateRetVoid();
    238238
    239     pxDriver.linkAndFinalize();
     239    pxDriver.finalizeObject();
    240240}
    241241
     
    309309    iBuilder->CreateRetVoid();
    310310
    311     pxDriver.linkAndFinalize();
     311    pxDriver.finalizeObject();
    312312}
    313313
     
    315315typedef void (*preprocessFunctionType)(const int fd, char * output_data);
    316316
    317 preprocessFunctionType preprocessCodeGen() {
    318     ParabixDriver pxDriver("preprocess");
    319     preprocessPipeline(pxDriver);
    320     return reinterpret_cast<preprocessFunctionType>(pxDriver.getPointerToMain());
    321 }
    322 
    323317typedef void (*editdFunctionType)(char * byte_data, size_t filesize);
    324 
    325 editdFunctionType editdCodeGen(const std::vector<std::string> & patterns) {
    326     ParabixDriver pxDriver("editd");
    327     editdPipeline(pxDriver, patterns);
    328     return reinterpret_cast<editdFunctionType>(pxDriver.getPointerToMain());
    329 }
    330318
    331319static char * chStream;
     
    373361
    374362    while (groupIdx < pattGroups.size()){
    375         editdFunctionType editd_ptr = editdCodeGen(pattGroups[groupIdx]);
     363
     364        ParabixDriver pxDriver("editd");
     365        editdPipeline(pxDriver, pattGroups[groupIdx]);
     366        auto editd_ptr = reinterpret_cast<editdFunctionType>(pxDriver.getMain());
    376367        editd(editd_ptr, chStream, size);
    377368
     
    601592#endif
    602593
    603     preprocessFunctionType preprocess_ptr = preprocessCodeGen();
     594    ParabixDriver pxDriver("preprocess");
     595    preprocessPipeline(pxDriver);
     596    auto preprocess_ptr = reinterpret_cast<preprocessFunctionType>(pxDriver.getMain());
    604597    preprocess(preprocess_ptr);
    605598
     
    632625
    633626    if(pattVector.size() == 1){
    634         editdFunctionType editd_ptr = editdCodeGen(pattVector);
     627
     628        ParabixDriver pxDriver("editd");
     629        editdPipeline(pxDriver, pattVector);
     630        auto editd_ptr = reinterpret_cast<editdFunctionType>(pxDriver.getMain());
    635631        editd(editd_ptr, chStream, size);
    636632    }
     
    638634        if (Threads == 1) {
    639635            for(unsigned i=0; i<pattGroups.size(); i++){
    640                 editdFunctionType editd_ptr = editdCodeGen(pattGroups[i]);
     636
     637                ParabixDriver pxDriver("editd");
     638                editdPipeline(pxDriver, pattGroups[i]);
     639                auto editd_ptr = reinterpret_cast<editdFunctionType>(pxDriver.getMain());
    641640                editd(editd_ptr, chStream, size);
    642641            }
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5473 r5474  
    174174static std::vector<std::string> parsedPropertyValues;
    175175
    176 std::string PTXFilename = "icgrep.ptx";
    177176size_t * startPoints = nullptr;
    178177size_t * accumBytes = nullptr;
     
    236235
    237236uint64_t GrepEngine::doGrep(const int32_t fileDescriptor, const uint32_t fileIdx) const {
    238     assert (mGrepFunction);
     237    assert (mGrepDriver);
    239238    typedef uint64_t (*GrepFunctionType)(int32_t fileDescriptor, const uint32_t fileIdx);
    240     return reinterpret_cast<GrepFunctionType>(mGrepFunction)(fileDescriptor, fileIdx);
     239    auto f = reinterpret_cast<GrepFunctionType>(mGrepDriver->getMain());
     240    return f(fileDescriptor, fileIdx);
    241241}
    242242
    243243void GrepEngine::doGrep(const char * buffer, const uint64_t length, const uint32_t fileIdx) const {
    244     assert (mGrepFunction);
     244    assert (mGrepDriver);
    245245    typedef uint64_t (*GrepFunctionType)(const char * buffer, const uint64_t length, const uint32_t fileIdx);
    246     reinterpret_cast<GrepFunctionType>(mGrepFunction)(buffer, length, fileIdx);
     246    auto f = reinterpret_cast<GrepFunctionType>(mGrepDriver->getMain());
     247    f(buffer, length, fileIdx);
    247248}
    248249
     
    391392void GrepEngine::grepCodeGen_nvptx(std::vector<re::RE *> REs, const GrepModeType grepMode, const bool UTF_16) {
    392393
    393     NVPTXDriver pxDriver("engine");
    394     auto & idb = pxDriver.getBuilder();
     394    assert (mGrepDriver == nullptr);
     395
     396    mGrepDriver = new NVPTXDriver("engine");
     397    auto & idb = mGrepDriver->getBuilder();
    395398    Module * M = idb->getModule();
    396399
     
    432435    Value * bufferSize = idb->CreateLoad(idb->CreateGEP(bufferSizesPtr, bid));
    433436
    434     StreamSetBuffer * ByteStream = pxDriver.addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(1, 8), 1));
    435     kernel::Kernel * sourceK = pxDriver.addKernelInstance(make_unique<kernel::MemorySourceKernel>(idb, inputStreamType, segmentSize));
     437    StreamSetBuffer * ByteStream = mGrepDriver->addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(1, 8), 1));
     438    kernel::Kernel * sourceK = mGrepDriver->addKernelInstance(make_unique<kernel::MemorySourceKernel>(idb, inputStreamType, segmentSize));
    436439    sourceK->setInitialArguments({inputStream, bufferSize});
    437     pxDriver.makeKernelCall(sourceK, {}, {ByteStream});
    438 
    439     StreamSetBuffer * BasisBits = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(8, 1), segmentSize * bufferSegments));   
    440     kernel::Kernel * s2pk = pxDriver.addKernelInstance(make_unique<kernel::S2PKernel>(idb));
    441     pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
     440    mGrepDriver->makeKernelCall(sourceK, {}, {ByteStream});
     441
     442    StreamSetBuffer * BasisBits = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(8, 1), segmentSize * bufferSegments));
     443    kernel::Kernel * s2pk = mGrepDriver->addKernelInstance(make_unique<kernel::S2PKernel>(idb));
     444    mGrepDriver->makeKernelCall(s2pk, {ByteStream}, {BasisBits});
    442445 
    443     StreamSetBuffer * LineBreakStream = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));   
    444     kernel::Kernel * linebreakK = pxDriver.addKernelInstance(make_unique<kernel::LineBreakKernelBuilder>(idb, encodingBits));
    445     pxDriver.makeKernelCall(linebreakK, {BasisBits}, {LineBreakStream});
     446    StreamSetBuffer * LineBreakStream = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     447    kernel::Kernel * linebreakK = mGrepDriver->addKernelInstance(make_unique<kernel::LineBreakKernelBuilder>(idb, encodingBits));
     448    mGrepDriver->makeKernelCall(linebreakK, {BasisBits}, {LineBreakStream});
    446449   
    447450    const auto n = REs.size();
     
    450453
    451454    for(unsigned i = 0; i < n; ++i){
    452         StreamSetBuffer * MatchResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    453         kernel::Kernel * icgrepK = pxDriver.addKernelInstance(make_unique<kernel::ICGrepKernel>(idb, REs[i]));
    454         pxDriver.makeKernelCall(icgrepK, {BasisBits, LineBreakStream}, {MatchResults});
     455        StreamSetBuffer * MatchResults = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     456        kernel::Kernel * icgrepK = mGrepDriver->addKernelInstance(make_unique<kernel::ICGrepKernel>(idb, REs[i]));
     457        mGrepDriver->makeKernelCall(icgrepK, {BasisBits, LineBreakStream}, {MatchResults});
    455458        MatchResultsBufs[i] = MatchResults;
    456459    }
    457460    StreamSetBuffer * MergedResults = MatchResultsBufs[0];
    458461    if (REs.size() > 1) {
    459         MergedResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    460         kernel::Kernel * streamsMergeK = pxDriver.addKernelInstance(make_unique<kernel::StreamsMerge>(idb, 1, REs.size()));
    461         pxDriver.makeKernelCall(streamsMergeK, MatchResultsBufs, {MergedResults});
     462        MergedResults = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     463        kernel::Kernel * streamsMergeK = mGrepDriver->addKernelInstance(make_unique<kernel::StreamsMerge>(idb, 1, REs.size()));
     464        mGrepDriver->makeKernelCall(streamsMergeK, MatchResultsBufs, {MergedResults});
    462465    }
    463466
    464467    kernel::MatchCount matchCountK(idb);
    465     pxDriver.addKernelCall(matchCountK, {MergedResults}, {});
    466     pxDriver.generatePipelineIR();
     468    mGrepDriver->addKernelCall(matchCountK, {MergedResults}, {});
     469    mGrepDriver->generatePipelineIR();
    467470
    468471    idb->setKernel(&matchCountK);
     
    475478    idb->CreateRetVoid();
    476479
    477     pxDriver.finalizeAndCompile(mainFunc, PTXFilename);
     480    mGrepDriver->finalizeObject();
    478481}
    479482
    480483void GrepEngine::grepCodeGen(std::vector<re::RE *> REs, const GrepModeType grepMode, const bool UTF_16, GrepSource grepSource, const GrepType grepType) {
    481484
    482     ParabixDriver pxDriver("engine");
    483     auto & idb = pxDriver.getBuilder();
     485    assert (mGrepDriver == nullptr);
     486    mGrepDriver = new ParabixDriver("engine");
     487    auto & idb = mGrepDriver->getBuilder();
    484488    Module * M = idb->getModule();
    485489
     
    515519        fileIdx->setName("fileIdx");
    516520
    517         ByteStream = pxDriver.addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(1, 8)));
    518 
    519         sourceK = pxDriver.addKernelInstance(make_unique<kernel::MemorySourceKernel>(idb, idb->getInt8PtrTy(), segmentSize));
     521        ByteStream = mGrepDriver->addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(1, 8)));
     522
     523        sourceK = mGrepDriver->addKernelInstance(make_unique<kernel::MemorySourceKernel>(idb, idb->getInt8PtrTy(), segmentSize));
    520524        sourceK->setInitialArguments({buffer, length});
    521525
     
    532536        fileIdx->setName("fileIdx");
    533537
    534         ByteStream = pxDriver.addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(1, 8)));
     538        ByteStream = mGrepDriver->addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(1, 8)));
    535539
    536540        if (grepSource == GrepSource::File) {
    537             sourceK = pxDriver.addKernelInstance(make_unique<kernel::MMapSourceKernel>(idb, segmentSize));
     541            sourceK = mGrepDriver->addKernelInstance(make_unique<kernel::MMapSourceKernel>(idb, segmentSize));
    538542            sourceK->setInitialArguments({fileDescriptor});
    539543        } else { // if (grepSource == GrepSource::StdIn) {
    540             sourceK = pxDriver.addKernelInstance(make_unique<kernel::ReadSourceKernel>(idb, segmentSize));
     544            sourceK = mGrepDriver->addKernelInstance(make_unique<kernel::ReadSourceKernel>(idb, segmentSize));
    541545            sourceK->setInitialArguments({idb->getInt32(STDIN_FILENO)});
    542546        }
    543547    }
    544548
    545     pxDriver.makeKernelCall(sourceK, {}, {ByteStream});
    546     StreamSetBuffer * BasisBits = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(8, 1), segmentSize * bufferSegments));
    547    
    548     kernel::Kernel * s2pk = pxDriver.addKernelInstance(make_unique<kernel::S2PKernel>(idb));
    549     pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
    550    
    551     kernel::Kernel * linebreakK = pxDriver.addKernelInstance(make_unique<kernel::LineBreakKernelBuilder>(idb, encodingBits));
    552     StreamSetBuffer * LineBreakStream = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    553     pxDriver.makeKernelCall(linebreakK, {BasisBits}, {LineBreakStream});
     549    mGrepDriver->makeKernelCall(sourceK, {}, {ByteStream});
     550    StreamSetBuffer * BasisBits = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(8, 1), segmentSize * bufferSegments));
     551   
     552    kernel::Kernel * s2pk = mGrepDriver->addKernelInstance(make_unique<kernel::S2PKernel>(idb));
     553    mGrepDriver->makeKernelCall(s2pk, {ByteStream}, {BasisBits});
     554   
     555    kernel::Kernel * linebreakK = mGrepDriver->addKernelInstance(make_unique<kernel::LineBreakKernelBuilder>(idb, encodingBits));
     556    StreamSetBuffer * LineBreakStream = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     557    mGrepDriver->makeKernelCall(linebreakK, {BasisBits}, {LineBreakStream});
    554558   
    555559    const auto n = REs.size();
     
    558562
    559563    for(unsigned i = 0; i < n; ++i){
    560         StreamSetBuffer * MatchResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    561         kernel::Kernel * icgrepK = pxDriver.addKernelInstance(make_unique<kernel::ICGrepKernel>(idb, REs[i]));
    562         pxDriver.makeKernelCall(icgrepK, {BasisBits, LineBreakStream}, {MatchResults});
     564        StreamSetBuffer * MatchResults = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     565        kernel::Kernel * icgrepK = mGrepDriver->addKernelInstance(make_unique<kernel::ICGrepKernel>(idb, REs[i]));
     566        mGrepDriver->makeKernelCall(icgrepK, {BasisBits, LineBreakStream}, {MatchResults});
    563567        MatchResultsBufs[i] = MatchResults;
    564568    }
    565569    StreamSetBuffer * MergedResults = MatchResultsBufs[0];
    566570    if (REs.size() > 1) {
    567         MergedResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    568         kernel::Kernel * streamsMergeK = pxDriver.addKernelInstance(make_unique<kernel::StreamsMerge>(idb, 1, REs.size()));
    569         pxDriver.makeKernelCall(streamsMergeK, MatchResultsBufs, {MergedResults});
     571        MergedResults = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     572        kernel::Kernel * streamsMergeK = mGrepDriver->addKernelInstance(make_unique<kernel::StreamsMerge>(idb, 1, REs.size()));
     573        mGrepDriver->makeKernelCall(streamsMergeK, MatchResultsBufs, {MergedResults});
    570574    }
    571575   
    572576    if (InvertMatch) {
    573         kernel::Kernel * invertK = pxDriver.addKernelInstance(make_unique<kernel::InvertMatchesKernel>(idb));
     577        kernel::Kernel * invertK = mGrepDriver->addKernelInstance(make_unique<kernel::InvertMatchesKernel>(idb));
    574578        StreamSetBuffer * OriginalMatches = MergedResults;
    575         MergedResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    576         pxDriver.makeKernelCall(invertK, {OriginalMatches, LineBreakStream}, {MergedResults});
     579        MergedResults = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     580        mGrepDriver->makeKernelCall(invertK, {OriginalMatches, LineBreakStream}, {MergedResults});
    577581    }
    578582    if (MatchLimit > 0) {
    579         kernel::Kernel * untilK = pxDriver.addKernelInstance(make_unique<kernel::UntilNkernel>(idb));
     583        kernel::Kernel * untilK = mGrepDriver->addKernelInstance(make_unique<kernel::UntilNkernel>(idb));
    580584        untilK->setInitialArguments({idb->getSize(MatchLimit)});
    581585        StreamSetBuffer * AllMatches = MergedResults;
    582         MergedResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    583         pxDriver.makeKernelCall(untilK, {AllMatches}, {MergedResults});
     586        MergedResults = mGrepDriver->addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     587        mGrepDriver->makeKernelCall(untilK, {AllMatches}, {MergedResults});
    584588    }
    585589    if (grepMode != NormalMode) {
    586         kernel::MatchCount matchCountK(idb);
    587         pxDriver.addKernelCall(matchCountK, {MergedResults}, {});
    588         pxDriver.generatePipelineIR();
    589         idb->setKernel(&matchCountK);
     590        kernel::Kernel * matchCountK = mGrepDriver->addKernelInstance(make_unique<kernel::MatchCount>(idb));
     591        mGrepDriver->makeKernelCall(matchCountK, {MergedResults}, {});
     592        mGrepDriver->generatePipelineIR();
     593        idb->setKernel(matchCountK);
    590594        Value * matchedLineCount = idb->getScalarField("matchedLineCount");
    591595        matchedLineCount = idb->CreateZExt(matchedLineCount, int64Ty);
    592596        idb->CreateRet(matchedLineCount);
    593         pxDriver.linkAndFinalize();
    594597    } else {
    595         kernel::ScanMatchKernel scanMatchK(idb, grepType, encodingBits);
    596         scanMatchK.setInitialArguments({fileIdx});
    597         pxDriver.addKernelCall(scanMatchK, {MergedResults, LineBreakStream, ByteStream}, {});
     598        kernel::Kernel * scanMatchK = mGrepDriver->addKernelInstance(make_unique<kernel::ScanMatchKernel>(idb, grepType, encodingBits));
     599        scanMatchK->setInitialArguments({fileIdx});
     600        mGrepDriver->makeKernelCall(scanMatchK, {MergedResults, LineBreakStream, ByteStream}, {});
    598601        switch (grepType) {
    599602            case GrepType::Normal:
    600603                if (UTF_16) {
    601                     pxDriver.LinkFunction(scanMatchK, "matcher", &wrapped_report_match<uint16_t>);
     604                    mGrepDriver->LinkFunction(*scanMatchK, "matcher", &wrapped_report_match<uint16_t>);
    602605                } else {
    603                     pxDriver.LinkFunction(scanMatchK, "matcher", &wrapped_report_match<uint8_t>);
     606                    mGrepDriver->LinkFunction(*scanMatchK, "matcher", &wrapped_report_match<uint8_t>);
    604607                }
    605608                break;
    606609            case GrepType::NameExpression:
    607                 pxDriver.LinkFunction(scanMatchK, "matcher", &insert_codepoints);
     610                mGrepDriver->LinkFunction(*scanMatchK, "matcher", &insert_codepoints);
    608611                break;
    609612            case GrepType::PropertyValue:
    610                 pxDriver.LinkFunction(scanMatchK, "matcher", &insert_property_values);
     613                mGrepDriver->LinkFunction(*scanMatchK, "matcher", &insert_property_values);
    611614                break;
    612615        }
    613         pxDriver.generatePipelineIR();
     616        mGrepDriver->generatePipelineIR();
    614617        idb->CreateRet(idb->getInt64(0));
    615         pxDriver.linkAndFinalize();
    616     }
    617 
    618     mGrepFunction = pxDriver.getPointerToMain();
    619 }
    620 
     618    }
     619    mGrepDriver->finalizeObject();
     620}
    621621
    622622re::CC * GrepEngine::grepCodepoints() {
     
    645645
    646646GrepEngine::GrepEngine()
    647 : mGrepFunction(nullptr) {
    648 
    649 }
    650 }
     647: mGrepDriver(nullptr) {
     648
     649}
     650
     651GrepEngine::~GrepEngine() {
     652    delete mGrepDriver;
     653}
     654
     655}
  • icGREP/icgrep-devel/icgrep/grep_engine.h

    r5473 r5474  
    1414namespace re { class RE; }
    1515namespace llvm { namespace cl { class OptionCategory; } }
     16class Driver;
     17
    1618
    1719namespace grep {
     
    4244    GrepEngine();
    4345
     46
     47    ~GrepEngine();
     48
    4449    void grepCodeGen(std::vector<re::RE *> REs, GrepModeType grepMode, bool UTF_16, GrepSource grepSource, GrepType grepType = GrepType::Normal);
    4550
     
    6065private:
    6166   
    62     void * mGrepFunction;
     67    Driver * mGrepDriver;
    6368};
    6469
  • icGREP/icgrep-devel/icgrep/icgrep-devel.includes

    r5464 r5474  
    22../boost/include/
    33../libllvm/include/
    4 IR_Gen
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r5473 r5474  
    243243        setNVPTXOption();
    244244       
    245         if(codegen::NVPTX){
     245        if (codegen::NVPTX) {
    246246            grepEngine.grepCodeGen_nvptx(REs, grep::Mode, UTF_16);
    247247            for (unsigned i = 0; i != allFiles.size(); ++i) {
    248248                grepEngine.doGrep(allFiles[i]);
    249             }         
     249            }
    250250            return 0;
    251         }
    252         else{
     251        } else {
    253252            grepEngine.grepCodeGen(REs, grep::Mode, UTF_16, GrepSource::File);
    254253        }
  • icGREP/icgrep-devel/icgrep/kernels/source_kernel.cpp

    r5464 r5474  
    9393    const auto pageSize = getpagesize();
    9494    if (LLVM_LIKELY((pageSize & (pageSize - 1)) == 0)) {
    95         consumed = iBuilder->CreateAnd(consumed, ConstantExpr::getNot(ConstantInt::get(consumedTy, pageSize - 1)));
     95        consumed = iBuilder->CreateAnd(consumed, ConstantExpr::getNeg(ConstantInt::get(consumedTy, pageSize)));
    9696    } else {
    9797        consumed = iBuilder->CreateSub(consumed, iBuilder->CreateURem(consumed, ConstantInt::get(consumedTy, pageSize)));
  • icGREP/icgrep-devel/icgrep/lz4d.cpp

    r5464 r5474  
    108108    iBuilder->CreateRetVoid();
    109109 
    110     pxDriver.linkAndFinalize();
     110    pxDriver.finalizeObject();
    111111}
    112112
     
    115115    ParabixDriver pxDriver("lz4d");
    116116    generatePipeline(pxDriver);
    117     return reinterpret_cast<MainFunctionType>(pxDriver.getPointerToMain());
     117    return reinterpret_cast<MainFunctionType>(pxDriver.getMain());
    118118}
    119119
     
    149149    char *fileBuffer = const_cast<char *>(mappedFile.data()) + lz4Frame.getBlocksStart();
    150150
    151     MainFunctionType fn_ptr = codeGen();
    152     fn_ptr(fileBuffer, lz4Frame.getBlocksLength(), lz4Frame.hasBlockChecksum());
     151    ParabixDriver pxDriver("lz4d");
     152    generatePipeline(pxDriver);
     153    auto main = reinterpret_cast<MainFunctionType>(pxDriver.getMain());
     154
     155    main(fileBuffer, lz4Frame.getBlocksLength(), lz4Frame.hasBlockChecksum());
    153156
    154157    mappedFile.close();
  • icGREP/icgrep-devel/icgrep/preprocess.cpp

    r5461 r5474  
    7272
    7373    pxDriver.LinkFunction(*scanMatchK, "wrapped_report_pos", &wrapped_report_pos);
    74     pxDriver.linkAndFinalize();
     74    pxDriver.finalizeObject();
    7575
    7676}
     
    7878typedef void (*preprocessFunctionType)(char * byte_data, size_t filesize);
    7979
    80 preprocessFunctionType preprocessCodeGen() {
    81                            
     80std::vector<size_t> preprocess(char * fileBuffer, size_t fileSize) {
    8281    ParabixDriver pxDriver("preprocess");
    83 
    8482    preprocessPipeline(pxDriver);
    85    
    86     preprocessFunctionType main = reinterpret_cast<preprocessFunctionType>(pxDriver.getPointerToMain());
    87 
    88     return main;
    89 }
    90 
    91 std::vector<size_t> preprocess(char * fileBuffer, size_t fileSize) {
    92     preprocessFunctionType preprocess_ptr = preprocessCodeGen();
    93     preprocess_ptr(fileBuffer, fileSize);
     83    auto main = reinterpret_cast<preprocessFunctionType>(pxDriver.getPointerToMain());
     84    main(fileBuffer, fileSize);
    9485    return LFPositions;
    9586}
  • icGREP/icgrep-devel/icgrep/toolchain/NVPTXDriver.cpp

    r5464 r5474  
    195195}
    196196
    197 void NVPTXDriver::finalizeAndCompile(Function * mainFunc, std::string PTXFilename) {
     197void NVPTXDriver::finalizeObject() {
    198198
    199199    legacy::PassManager PM;
     
    209209    }
    210210
     211    Function * mainFunc = mMainModule->getFunction("Main");
     212
    211213    MDNode * Node = MDNode::get(mMainModule->getContext(),
    212214                                {llvm::ValueAsMetadata::get(mainFunc),
     
    222224    }
    223225
     226    const auto PTXFilename = mMainModule->getModuleIdentifier() + ".ptx";
     227
    224228    llvm2ptx(mMainModule, PTXFilename);
    225229}
    226230
     231void * NVPTXDriver::getMain() {
     232    report_fatal_error("NVPTX must be executed by calling RunPTX");
     233}
     234
    227235NVPTXDriver::~NVPTXDriver() {
    228236}
  • icGREP/icgrep-devel/icgrep/toolchain/NVPTXDriver.h

    r5464 r5474  
    2121    void makeKernelCall(kernel::Kernel * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) override;
    2222
    23     void finalizeAndCompile(llvm::Function * mainFunc, std::string PTXFilename);
     23    void finalizeObject() override;
    2424
    25     void * getPointerToMain();
     25    void * getMain() override; // "main" exists until the driver is deleted
    2626
    2727private:
  • icGREP/icgrep-devel/icgrep/toolchain/cpudriver.cpp

    r5464 r5474  
    137137}
    138138
    139 void ParabixDriver::linkAndFinalize() {
     139void ParabixDriver::finalizeObject() {
    140140
    141141    legacy::PassManager PM;
     
    219219}
    220220
    221 void * ParabixDriver::getPointerToMain() {
     221void * ParabixDriver::getMain() {
    222222    return mEngine->getPointerToNamedFunction("Main");
    223223}
    224224
    225225ParabixDriver::~ParabixDriver() {
    226 //    delete mEngine;
     226    delete mEngine;
    227227    delete mCache;
    228228    delete mTarget;
  • icGREP/icgrep-devel/icgrep/toolchain/cpudriver.h

    r5464 r5474  
    1919    void makeKernelCall(kernel::Kernel * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) override;
    2020
    21     void linkAndFinalize();
     21    void finalizeObject() override;
    2222
    23     void * getPointerToMain();
     23    void * getMain() override; // "main" exists until the driver is deleted
    2424
    2525private:
  • icGREP/icgrep-devel/icgrep/toolchain/driver.cpp

    r5464 r5474  
    3333    return mOwnedKernels.back().get();
    3434}
     35
  • icGREP/icgrep-devel/icgrep/toolchain/driver.h

    r5464 r5474  
    4040    llvm::Function * LinkFunction(kernel::Kernel & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const;
    4141
    42     llvm::GenericValue getPointerToMain(llvm::Function * f, const std::vector<llvm::GenericValue> & ArgValues);
     42    virtual void finalizeObject() = 0;
     43
     44    virtual void * getMain() = 0; // "main" exists until the driver is deleted
    4345
    4446protected:
  • icGREP/icgrep-devel/icgrep/toolchain/pipeline.cpp

    r5464 r5474  
    7777    }
    7878    Value * const segOffset = iBuilder->CreateLoad(iBuilder->CreateGEP(threadStruct, {iBuilder->getInt32(0), iBuilder->getInt32(1)}));
    79 
    80 
    81 
    8279
    8380    BasicBlock * segmentLoop = BasicBlock::Create(iBuilder->getContext(), "segmentLoop", threadFunc);
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5464 r5474  
    357357    iBuilder->CreateRetVoid();
    358358   
    359     pxDriver.linkAndFinalize();
     359    pxDriver.finalizeObject();
    360360}
    361361
     
    430430    iBuilder->CreateRetVoid();
    431431
    432     pxDriver.linkAndFinalize();
     432    pxDriver.finalizeObject();
    433433}
    434434
    435435typedef void (*u8u16FunctionType)(uint32_t fd, char * output_data);
    436 
    437 u8u16FunctionType u8u16CodeGen() {
    438     ParabixDriver pxDriver("u8u16");
    439     if (enableAVXdel && AVX2_available() && codegen::BlockSize==256) {
    440         u8u16PipelineAVX2Gen(pxDriver);
    441     } else{
    442         u8u16PipelineGen(pxDriver);
    443     }
    444     return reinterpret_cast<u8u16FunctionType>(pxDriver.getPointerToMain());
    445 }
    446436
    447437size_t file_size(const int fd) {
     
    483473    cl::HideUnrelatedOptions(ArrayRef<const cl::OptionCategory *>{&u8u16Options, pablo::pablo_toolchain_flags(), codegen::codegen_flags()});
    484474    cl::ParseCommandLineOptions(argc, argv);
    485     u8u16(u8u16CodeGen(), inputFile);
     475    ParabixDriver pxDriver("u8u16");
     476    if (enableAVXdel && AVX2_available() && codegen::BlockSize==256) {
     477        u8u16PipelineAVX2Gen(pxDriver);
     478    } else {
     479        u8u16PipelineGen(pxDriver);
     480    }
     481    auto u8u16Function = reinterpret_cast<u8u16FunctionType>(pxDriver.getMain());
     482    u8u16(u8u16Function, inputFile);
    486483    return 0;
    487484}
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5464 r5474  
    192192    iBuilder->CreateRetVoid();
    193193
    194     pxDriver.linkAndFinalize();
    195 }
    196 
    197 
    198 WordCountFunctionType wcCodeGen() {
    199     ParabixDriver pxDriver("wc");
    200     wcPipelineGen(pxDriver);
    201     return reinterpret_cast<WordCountFunctionType>(pxDriver.getPointerToMain());
     194    pxDriver.finalizeObject();
    202195}
    203196
     
    236229    }
    237230   
    238     WordCountFunctionType wordCountFunctionPtr = wcCodeGen();
     231    ParabixDriver pxDriver("wc");
     232    wcPipelineGen(pxDriver);
     233    auto wordCountFunctionPtr = reinterpret_cast<WordCountFunctionType>(pxDriver.getMain());
    239234
    240235    const auto fileCount = inputFiles.size();
Note: See TracChangeset for help on using the changeset viewer.