Changeset 5406 for icGREP


Ignore:
Timestamp:
Apr 13, 2017, 11:37:36 AM (2 years ago)
Author:
cameron
Message:

Progress towards adapting GPU code to ParabixDriver? framework, but need NVPTX_Driver subclass

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

Legend:

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

    r5404 r5406  
    160160
    161161#ifdef CUDA_ENABLED
    162 Function * generateGPUKernel(Module * m, IDISA::IDISA_Builder * iBuilder, bool CountOnly){
     162Function * generateGPUKernel(ParabixDriver & nvptxDriver, bool CountOnly){
     163    IDISA::IDISA_Builder * iBuilder = nvptxDriver.getIDISA_Builder();
     164    Module * m = iBuilder->getModule();
    163165    Type * const int64ty = iBuilder->getInt64Ty();
    164166    Type * const size_ty = iBuilder->getSizeTy();
     
    168170    Type * const inputType = PointerType::get(iBuilder->getInt8Ty(), 1);
    169171    Type * const resultTy = iBuilder->getVoidTy();
    170     Function * kernelFunc = cast<Function>(m->getOrInsertFunction("GPU_Main", resultTy, inputType, sizeTyPtr, sizeTyPtr, int64tyPtr, nullptr));
     172    Function * kernelFunc = cast<Function>(m->getOrInsertFunction("Main", resultTy, inputType, sizeTyPtr, sizeTyPtr, int64tyPtr, nullptr));
    171173    kernelFunc->setCallingConv(CallingConv::C);
    172174    Function::arg_iterator args = kernelFunc->arg_begin();
     
    211213
    212214    iBuilder->CreateRetVoid();
     215
    213216    return kernelFunc;
    214217}
    215218
    216 Function * generateCPUKernel(Module * m, IDISA::IDISA_Builder * iBuilder, GrepType grepType){
     219void generateCPUKernel(ParabixDriver & pxDriver, GrepType grepType){
     220    IDISA::IDISA_Builder * iBuilder = pxDriver.getIDISA_Builder();
     221    Module * m = iBuilder->getModule();
     222
    217223    Type * const size_ty = iBuilder->getSizeTy();
    218224    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
    219225    Type * const rsltType = PointerType::get(ArrayType::get(iBuilder->getBitBlockType(), 1), 0);
    220     Function * const mainCPUFn = cast<Function>(m->getOrInsertFunction("CPU_Main", iBuilder->getVoidTy(), rsltType, rsltType, int8PtrTy, size_ty, size_ty, nullptr));
     226    Function * const mainCPUFn = cast<Function>(m->getOrInsertFunction("Main", iBuilder->getVoidTy(), rsltType, rsltType, int8PtrTy, size_ty, size_ty, nullptr));
    221227    mainCPUFn->setCallingConv(CallingConv::C);
    222228    iBuilder->SetInsertPoint(BasicBlock::Create(m->getContext(), "entry", mainCPUFn, 0));
     
    242248    MatchResults.setStreamSetBuffer(rsltStream);
    243249
     250    kernel::MMapSourceKernel mmapK0(iBuilder, segmentSize);
     251    mmapK0.setName("mmap0");
     252    mmapK0.setInitialArguments({fileSize});
     253    pxDriver.addKernelCall(mmapK0, {}, {&InputStream});
     254
     255
    244256    kernel::MMapSourceKernel mmapK1(iBuilder, segmentSize);
    245257    mmapK1.setName("mmap1");
    246     mmapK1.generateKernel({}, {&MatchResults});
    247258    mmapK1.setInitialArguments({fileSize});
     259    pxDriver.addKernelCall(mmapK1, {}, {&MatchResults});
    248260
    249261    ExternalFileBuffer LineBreak(iBuilder, iBuilder->getStreamSetTy(1, 1));
     
    252264    kernel::MMapSourceKernel mmapK2(iBuilder, segmentSize);
    253265    mmapK2.setName("mmap2");
    254     mmapK2.generateKernel({}, {&LineBreak});
    255266    mmapK2.setInitialArguments({fileSize});
     267    pxDriver.addKernelCall(mmapK2, {}, {&LineBreak});
    256268
    257269    kernel::ScanMatchKernel scanMatchK(iBuilder, grepType, 8);
    258     scanMatchK.generateKernel({&InputStream, &MatchResults, &LineBreak}, {});
    259270    scanMatchK.setInitialArguments({fileIdx});
    260    
    261     generatePipeline(iBuilder, {&mmapK1, &mmapK2, &scanMatchK});
     271    pxDriver.addKernelCall(scanMatchK, {&InputStream, &MatchResults, &LineBreak}, {});
     272    pxDriver.generatePipelineIR();
    262273    iBuilder->CreateRetVoid();
    263274
    264     return mainCPUFn;
     275    pxDriver.linkAndFinalize();
    265276}
    266277#endif
     
    570581    #ifdef CUDA_ENABLED
    571582    if(codegen::NVPTX){
    572         Function * kernelFunction = generateGPUKernel(M, iBuilder, CountOnly);
     583        ParabixDriver nvptxDriver(iBuilder);
     584        Function * kernelFunction = generateGPUKernel(nvptxDriver, CountOnly);
     585       
    573586        MDNode * Node = MDNode::get(M->getContext(),
    574587                                    {llvm::ValueAsMetadata::get(kernelFunction),
     
    579592
    580593        Compile2PTX(M, IRFilename, PTXFilename);
    581         Function * mainCPUFn = generateCPUKernel(cpuM, CPUBuilder, mGrepType);
     594       
     595        ParabixDriver pxDriver(CPUBuilder);
     596        generateCPUKernel(pxDriver, grepType);
     597       
     598        mGrepFunction_CPU = reinterpret_cast<GrepFunctionType_CPU>(pxDriver.getPointerToMain());
    582599        if (CountOnly) return;
    583600    }
     
    591608        mGrepFunction_CountOnly = reinterpret_cast<GrepFunctionType_CountOnly>(pxDriver.getPointerToMain());
    592609    } else {
    593         #ifdef CUDA_ENABLED
    594         if(codegen::NVPTX){
    595             mGrepFunction_CPU = reinterpret_cast<GrepFunctionType_CPU>(pxDriver.getPointerToMain());
    596         }
    597         #endif
    598610        if (CPU_Only) {
    599611            mGrepFunction = reinterpret_cast<GrepFunctionType>(pxDriver.getPointerToMain());
  • icGREP/icgrep-devel/icgrep/grep_engine.h

    r5401 r5406  
    1414namespace re { class RE; }
    1515
    16 class GrepEngine {
    1716    typedef void (*GrepFunctionType)(char * byte_data, size_t filesize, const int fileIdx);
    1817    typedef uint64_t (*GrepFunctionType_CountOnly)(char * byte_data, size_t filesize, const int fileIdx);
    1918    typedef void (*GrepFunctionType_CPU)(char * rslt, char * LineBreak, char * byte_data, size_t filesize, const int fileIdx);
     19class GrepEngine {
    2020public:
    2121
     
    4343};
    4444
    45 void icgrep_Linking(llvm::Module * m, llvm::ExecutionEngine * e);
    46 
    4745
    4846re::CC * getParsedCodePointSet();
  • icGREP/icgrep-devel/icgrep/preprocess.cpp

    r5402 r5406  
    3838}
    3939
    40 void preprocess_Linking(Module * m, ExecutionEngine * e) {
    41     Module::FunctionListType & fns = m->getFunctionList();
    42     for (Module::FunctionListType::iterator it = fns.begin(), it_end = fns.end(); it != it_end; ++it) {
    43         std::string fnName = it->getName().str();
    44         if (fnName == "wrapped_report_pos") {
    45             e->addGlobalMapping(cast<GlobalValue>(it), (void *)&wrapped_report_pos);
    46         }
    47     }
    48 }
    49 
    50 
    51 Function * preprocessPipeline(Module * m, IDISA::IDISA_Builder * iBuilder){
     40void preprocessPipeline(ParabixDriver & pxDriver){
     41    IDISA::IDISA_Builder * iBuilder = pxDriver.getIDISA_Builder();
     42    Module * m = iBuilder->getModule();
    5243    Type * const size_ty = iBuilder->getSizeTy();
    5344    Type * const inputType = PointerType::get(ArrayType::get(iBuilder->getBitBlockType(), 1), 0);
     
    7364
    7465    kernel::MMapSourceKernel mmapK(iBuilder, segmentSize);
    75     mmapK.generateKernel({}, {&ByteStream});
    7666    mmapK.setInitialArguments({fileSize});
     67    pxDriver.addKernelCall(mmapK, {}, {&ByteStream});
    7768
    7869    kernel::DirectCharacterClassKernelBuilder linefeedK(iBuilder, "linefeed", {re::makeCC(0x0A)}, 1);
    79     linefeedK.generateKernel({&ByteStream}, {&MatchResults});
     70    pxDriver.addKernelCall(linefeedK, {&ByteStream}, {&MatchResults});
    8071   
    8172    kernel::CCScanKernel scanMatchK(iBuilder, 1);
    82     scanMatchK.generateKernel({&MatchResults}, {});
     73    pxDriver.addKernelCall(scanMatchK, {&MatchResults}, {});
    8374   
    84     generatePipelineLoop(iBuilder, {&mmapK, &linefeedK, &scanMatchK});
     75    pxDriver.generatePipelineIR();
    8576    iBuilder->CreateRetVoid();
    8677
    87     return mainFn;
     78    pxDriver.addExternalLink(scanMatchK, "wrapped_report_pos", &wrapped_report_pos);
     79    pxDriver.linkAndFinalize();
    8880
    8981}
     
    9688    Module * M = new Module("preprocess", TheContext);
    9789    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
     90    ParabixDriver pxDriver(idb);
    9891
    99     llvm::Function * main_IR = preprocessPipeline(M, idb);
    100 
    101     ExecutionEngine * preprocessEngine = JIT_to_ExecutionEngine(M);
    102     ApplyObjectCache(preprocessEngine);
    103 
    104     preprocess_Linking(M, preprocessEngine);
     92    preprocessPipeline(pxDriver);
    10593   
    106     preprocessEngine->finalizeObject();
     94    preprocessFunctionType main = reinterpret_cast<preprocessFunctionType>(pxDriver.getPointerToMain());
    10795
    10896    delete idb;
    109     return reinterpret_cast<preprocessFunctionType>(preprocessEngine->getPointerToFunction(main_IR));
     97    return main;
    11098}
    11199
Note: See TracChangeset for help on using the changeset viewer.