Changeset 5692 for icGREP


Ignore:
Timestamp:
Oct 16, 2017, 6:43:14 AM (18 months ago)
Author:
cameron
Message:

Cleaning up icgrep - removing experimental nvptx and incomplete UTF-16 modes

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

Legend:

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

    r5679 r5692  
    3939#include <errno.h>
    4040#include <mutex>
    41 #ifdef CUDA_ENABLED
    42 #include <preprocess.cpp>
    43 #include <IR_Gen/CudaDriver.h>
    44 #endif
    4541
    4642using namespace parabix;
     
    9793}
    9894   
    99 void GrepEngine::doGrep(const std::string & fileName, std::string & PTXFilename) const{
    100 #ifdef CUDA_ENABLED
    101     const bool CountOnly = true;
    102     boost::filesystem::path file(fileName);
    103     if (exists(file)) {
    104         if (is_directory(file)) {
    105             return;
    106         }
    107     } else {
    108         if (!NoMessagesFlag) {
    109             std::cerr << "Error: cannot open " << fileName << " for processing. Skipped.\n";
    110             return;
    111         }
    112     }
    113 
    114     const auto fileSize = file_size(file);
    115    
    116     if (fileSize > 0) {
    117         try {
    118             boost::iostreams::mapped_file_source source(fileName, fileSize, 0);
    119             char * fileBuffer = const_cast<char *>(source.data());
    120            
    121             codegen::BlockSize = 128;
    122             std::vector<size_t> LFPositions = preprocess(fileBuffer, fileSize);
    123            
    124             const unsigned numOfGroups = codegen::GroupNum;
    125             if (posix_memalign((void**)&startPoints, 8, (numOfGroups+1)*sizeof(size_t)) ||
    126                 posix_memalign((void**)&accumBytes, 8, (numOfGroups+1)*sizeof(size_t))) {
    127                 std::cerr << "Cannot allocate memory for startPoints or accumBytes.\n";
    128                 exit(-1);
    129             }
    130             if(PTXFilename=="")
    131                 PTXFilename = mGrepDriver->getBuilder()->getModule()->getModuleIdentifier() + ".ptx";
    132             RunPTX(PTXFilename, fileBuffer, fileSize, CountOnly, LFPositions, startPoints, accumBytes);
    133             source.close();
    134         } catch (std::exception & e) {
    135             if (!NoMessagesFlag) {
    136                 std::cerr << "Boost mmap error: " + fileName + ": " + e.what() + " Skipped.\n";
    137                 return;
    138             }
    139         }
    140     } else {
    141         std::cout << 0 << std::endl;
    142     }
    143 #endif
    144 }
    145 
    14695uint64_t GrepEngine::doGrep(const std::string & fileName, const uint32_t fileIdx) const {
    14796    struct stat sb;
     
    378327}
    379328
    380 
    381    
    382 void GrepEngine::grepCodeGen_nvptx(std::vector<re::RE *> REs, const GrepModeType grepMode, const bool UTF_16) {
    383 
    384     assert (mGrepDriver == nullptr);
    385 
    386     mGrepDriver = new NVPTXDriver("engine");
    387     auto & idb = mGrepDriver->getBuilder();
    388     Module * M = idb->getModule();
    389 
    390     const unsigned segmentSize = codegen::SegmentSize;
    391     const unsigned encodingBits = UTF_16 ? 16 : 8;
    392 
    393     Type * const int64Ty = idb->getInt64Ty();
    394     Type * const int32Ty = idb->getInt32Ty();
    395     Type * const size_ty = idb->getSizeTy();
    396     Type * const sizeTyPtr = PointerType::get(size_ty, 1);
    397     Type * const int64tyPtr = PointerType::get(int64Ty, 1);
    398     Type * const voidTy = idb->getVoidTy();
    399    
    400     Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", voidTy, int64tyPtr, sizeTyPtr, sizeTyPtr, int64tyPtr, nullptr));
    401     mainFunc->setCallingConv(CallingConv::C);
    402     idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
    403     auto args = mainFunc->arg_begin();
    404 
    405     Value * const inputPtr = &*(args++);
    406     inputPtr->setName("inputPtr");
    407     Value * const startPointsPtr = &*(args++);
    408     startPointsPtr->setName("startPointsPtr");
    409     Value * const bufferSizesPtr = &*(args++);
    410     bufferSizesPtr->setName("bufferSizesPtr");
    411     Value * const outputPtr = &*(args++);
    412     outputPtr->setName("outputPtr");
    413 
    414     Function * tidFunc = M->getFunction("llvm.nvvm.read.ptx.sreg.tid.x");
    415     Value * tid = idb->CreateCall(tidFunc);
    416     Function * bidFunc = cast<Function>(M->getOrInsertFunction("llvm.nvvm.read.ptx.sreg.ctaid.x", int32Ty, nullptr));
    417     Value * bid = idb->CreateCall(bidFunc);
    418 
    419     Value * startPoint = idb->CreateLoad(idb->CreateGEP(startPointsPtr, bid));
    420     Value * startBlock = idb->CreateUDiv(startPoint, ConstantInt::get(int64Ty, idb->getBitBlockWidth()));
    421     Type * const inputStreamType = PointerType::get(ArrayType::get(ArrayType::get(idb->getBitBlockType(), 8), 1), 1);   
    422     Value * inputStreamPtr = idb->CreateGEP(idb->CreateBitCast(inputPtr, inputStreamType), startBlock);
    423     Value * inputStream = idb->CreateGEP(inputStreamPtr, tid);
    424     Value * bufferSize = idb->CreateLoad(idb->CreateGEP(bufferSizesPtr, bid));
    425 
    426     StreamSetBuffer * ByteStream = mGrepDriver->addBuffer(make_unique<SourceBuffer>(idb, idb->getStreamSetTy(1, 8), 1));
    427     kernel::Kernel * sourceK = mGrepDriver->addKernelInstance(make_unique<kernel::MemorySourceKernel>(idb, inputStreamType, segmentSize));
    428     sourceK->setInitialArguments({inputStream, bufferSize});
    429     mGrepDriver->makeKernelCall(sourceK, {}, {ByteStream});
    430 
    431     StreamSetBuffer * Matches = std::get<1>(grepPipeline(mGrepDriver, REs, grepMode, encodingBits, ByteStream));
    432    
    433     kernel::Kernel * matchCountK = mGrepDriver->addKernelInstance(make_unique<kernel::PopcountKernel>(idb));
    434     mGrepDriver->makeKernelCall(matchCountK, {Matches}, {});
    435     mGrepDriver->generatePipelineIR();
    436     idb->setKernel(matchCountK);
    437     Value * matchedLineCount = idb->getAccumulator("countResult");
    438     matchedLineCount = idb->CreateZExt(matchedLineCount, int64Ty);
    439    
    440     Value * strideBlocks = ConstantInt::get(int32Ty, idb->getStride() / idb->getBitBlockWidth());
    441     Value * outputThreadPtr = idb->CreateGEP(outputPtr, idb->CreateAdd(idb->CreateMul(bid, strideBlocks), tid));
    442     idb->CreateStore(matchedLineCount, outputThreadPtr);
    443     mGrepDriver->deallocateBuffers();
    444     idb->CreateRetVoid();
    445 
    446     mGrepDriver->finalizeObject();
    447 }
    448 
    449 void GrepEngine::grepCodeGen(std::vector<re::RE *> REs, const GrepModeType grepMode, const bool UTF_16, GrepSource grepSource) {
     329void GrepEngine::grepCodeGen(std::vector<re::RE *> REs, const GrepModeType grepMode, GrepSource grepSource) {
    450330
    451331    assert (mGrepDriver == nullptr);
     
    455335
    456336    const unsigned segmentSize = codegen::SegmentSize;
    457     const unsigned encodingBits = UTF_16 ? 16 : 8;
     337    const unsigned encodingBits = 8;
    458338
    459339    Type * const int64Ty = idb->getInt64Ty();
     
    491371        scanMatchK->setInitialArguments({fileIdx});
    492372        mGrepDriver->makeKernelCall(scanMatchK, {Matches, LineBreakStream, ByteStream}, {});
    493         if (UTF_16) {
    494             mGrepDriver->LinkFunction(*scanMatchK, "matcher", &wrapped_report_match<uint16_t>);
    495         } else {
    496             mGrepDriver->LinkFunction(*scanMatchK, "matcher", &wrapped_report_match<uint8_t>);
    497         }
     373        mGrepDriver->LinkFunction(*scanMatchK, "matcher", &wrapped_report_match<uint8_t>);
    498374        mGrepDriver->generatePipelineIR();
    499375        mGrepDriver->deallocateBuffers();
  • icGREP/icgrep-devel/icgrep/grep_engine.h

    r5679 r5692  
    3232    ~GrepEngine();
    3333
    34     void grepCodeGen(std::vector<re::RE *> REs, GrepModeType grepMode, bool UTF_16, GrepSource grepSource);
    35 
    36     void grepCodeGen_nvptx(std::vector<re::RE *> REs, GrepModeType grepMode, bool UTF_16);
     34    void grepCodeGen(std::vector<re::RE *> REs, GrepModeType grepMode, GrepSource grepSource);
    3735
    3836    void doGrep(const std::string & fileName, std::string & PTXFilename) const;
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r5620 r5692  
    11/*
    2  *  Copyright (c) 2016 International Characters.
     2 *  Copyright (c) 2014-7 International Characters.
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 *  icgrep is a trademark of International Characters.
     
    3535using namespace llvm;
    3636
    37 static cl::opt<bool> UTF_16("UTF-16", cl::desc("Regular expressions over the UTF-16 representation of Unicode."));
    38 
    3937static cl::list<std::string> inputFiles(cl::Positional, cl::desc("<regex> <input file ...>"), cl::OneOrMore);
    4038
     
    4543static cl::opt<bool> MultiGrepKernels("enable-multigrep-kernels", cl::desc("Construct separated kernels for each regular expression"));
    4644static cl::opt<int> REsPerGroup("re-num", cl::desc("Number of regular expressions processed by each kernel."), cl::init(1));
    47 
    48 static cl::opt<std::string> PTXFile("ptx", cl::desc("compiled PTX file."), cl::init(""));
    4945
    5046static std::vector<std::string> allFiles;
     
    182178
    183179    allFiles = getFullFileList(inputFiles);
     180    if ((allFiles.size() > 1) && !grep::NoFilenameFlag) {
     181        grep::WithFilenameFlag = true;
     182    }
    184183
    185184    grep::GrepEngine grepEngine;
     
    187186    if (allFiles.empty()) {
    188187
    189         grepEngine.grepCodeGen(REs, grep::Mode, UTF_16, GrepSource::StdIn);
     188        grepEngine.grepCodeGen(REs, grep::Mode, GrepSource::StdIn);
    190189        allFiles = { "-" };
    191190        grep::initFileResult(allFiles);
     
    194193    } else {
    195194               
    196         if (codegen::NVPTX) {
    197             if(PTXFile=="")
    198                 grepEngine.grepCodeGen_nvptx(REs, grep::Mode, UTF_16);
    199             for (unsigned i = 0; i != allFiles.size(); ++i) {
    200                 grepEngine.doGrep(allFiles[i], PTXFile);
    201             }
    202             return 0;
    203         } else {
    204             grepEngine.grepCodeGen(REs, grep::Mode, UTF_16, GrepSource::File);
    205         }
     195        grepEngine.grepCodeGen(REs, grep::Mode, GrepSource::File);
    206196
    207197        grep::initFileResult(allFiles);
Note: See TracChangeset for help on using the changeset viewer.