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

File:
1 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());
Note: See TracChangeset for help on using the changeset viewer.