Changeset 5419 for icGREP


Ignore:
Timestamp:
Apr 23, 2017, 12:44:04 PM (2 years ago)
Author:
nmedfort
Message:

Bug fixes for 32-bit systems

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.cpp

    r5418 r5419  
    250250}
    251251
    252 /*
    253     MADV_NORMAL
    254         No special treatment. This is the default.
    255     MADV_RANDOM
    256         Expect page references in random order. (Hence, read ahead may be less useful than normally.)
    257     MADV_SEQUENTIAL
    258         Expect page references in sequential order. (Hence, pages in the given range can be aggressively read ahead, and may be freed
    259         soon after they are accessed.)
    260     MADV_WILLNEED
    261         Expect access in the near future. (Hence, it might be a good idea to read some pages ahead.)
    262     MADV_DONTNEED
    263         Do not expect access in the near future. (For the time being, the application is finished with the given range, so the kernel
    264         can free resources associated with it.) Subsequent accesses of pages in this range will succeed, but will result either in
    265         reloading of the memory contents from the underlying mapped file (see mmap(2)) or zero-fill-on-demand pages for mappings
    266         without an underlying file.
    267 */
    268 
    269 Value * CBuilder::CreateMAdvise(Value * addr, Value * length, std::initializer_list<MAdviceFlags> advice) {
     252/**
     253 * @brief CBuilder::CreateMAdvise
     254 * @param addr
     255 * @param length
     256 * @param advice
     257 *
     258 * Note: intermittent failures are possible. Test if this is more than a simple hint and handle accordingly.
     259 *
     260 *  ADVICE_NORMAL
     261 *      No special treatment. This is the default.
     262 *  ADVICE_RANDOM
     263 *      Expect page references in random order. (Hence, read ahead may be less useful than normally.)
     264 *  ADVICE_SEQUENTIAL
     265 *      Expect page references in sequential order. (Hence, pages in the given range can be aggressively read ahead, and may be freed
     266 *      soon after they are accessed.)
     267 *  ADVICE_WILLNEED
     268 *      Expect access in the near future. (Hence, it might be a good idea to read some pages ahead.)
     269 *  ADVICE_DONTNEED
     270 *      Do not expect access in the near future. (For the time being, the application is finished with the given range, so the kernel
     271 *      can free resources associated with it.) Subsequent accesses of pages in this range will succeed, but will result either in
     272 *      reloading of the memory contents from the underlying mapped file (see mmap(2)) or zero-fill-on-demand pages for mappings
     273 *      without an underlying file.
     274 *
     275 * @return Value indicating success (0) or failure (non-zero).
     276 */
     277Value * CBuilder::CreateMAdvise(Value * addr, Value * length, Advice advice) {
    270278    Triple T(mMod->getTargetTriple());
    271279    Value * result = nullptr;
    272     if (T.isOSLinux()) {
     280    if (T.isOSLinux() || T.isOSDarwin()) {
    273281        DataLayout DL(mMod);
    274282        IntegerType * const intTy = getIntPtrTy(DL);
     
    282290        addr = CreatePointerCast(addr, voidPtrTy);
    283291        length = CreateZExtOrTrunc(length, sizeTy);
    284         int adviceFlags = 0;
    285         for (const MAdviceFlags adv : advice) {
    286             switch (adv) {
    287                 case MAdviceFlags::MMAP_NORMAL: adviceFlags |= MADV_NORMAL; break;
    288                 case MAdviceFlags::MMAP_RANDOM: adviceFlags |= MADV_RANDOM; break;
    289                 case MAdviceFlags::MMAP_SEQUENTIAL: adviceFlags |= MADV_SEQUENTIAL; break;
    290                 case MAdviceFlags::MMAP_DONTNEED: adviceFlags |= MADV_DONTNEED; break;
    291                 case MAdviceFlags::MMAP_WILLNEED: adviceFlags |= MADV_WILLNEED; break;
    292 //                case MADV::REMOVE: adviceFlags |= MADV_REMOVE; break;
    293 //                case MADV::DONTFORK: adviceFlags |= MADV_DONTFORK; break;
    294 //                case MADV::DOFORK: adviceFlags |= MADV_DOFORK; break;
    295 //                case MADV::HWPOISON: adviceFlags |= MADV_HWPOISON; break;
    296 //                case MADV::MERGEABLE: adviceFlags |= MADV_MERGEABLE; break;
    297 //                case MADV::UNMERGEABLE: adviceFlags |= MADV_UNMERGEABLE; break;
    298 //                case MADV::HUGEPAGE: adviceFlags |= MADV_HUGEPAGE; break;
    299 //                case MADV::NOHUGEPAGE: adviceFlags |= MADV_NOHUGEPAGE; break;
    300 //                case MADV::DONTDUMP: adviceFlags |= MADV_DONTDUMP; break;
    301 //                case MADV::DODUMP: adviceFlags |= MADV_DODUMP; break;
    302             }
     292        int madv_flag = 0;
     293        switch (advice) {
     294            case Advice::ADVICE_NORMAL:
     295                madv_flag = MADV_NORMAL; break;
     296            case Advice::ADVICE_RANDOM:
     297                madv_flag = MADV_RANDOM; break;
     298            case Advice::ADVICE_SEQUENTIAL:
     299                madv_flag = MADV_SEQUENTIAL; break;
     300            case Advice::ADVICE_WILLNEED:
     301                madv_flag = MADV_WILLNEED; break;
     302            case Advice::ADVICE_DONTNEED:
     303                madv_flag = MADV_DONTNEED; break;
    303304        }
    304         result = CreateCall(MAdviseFunc, {addr, length, ConstantInt::get(intTy, adviceFlags)});
    305         if (codegen::EnableAsserts) {
    306             CreateAssert(CreateICmpEQ(result, ConstantInt::getNullValue(result->getType())), "CreateMMapAdvise: failed");
    307         }
     305        result = CreateCall(MAdviseFunc, {addr, length, ConstantInt::get(intTy, madv_flag)});
    308306    }
    309307    return result;
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5418 r5419  
    9797    llvm::Value * CreateFileSourceMMap(llvm::Value * fd, llvm::Value * size);
    9898
    99     enum MAdviceFlags {
    100         MMAP_NORMAL
    101         , MMAP_RANDOM
    102         , MMAP_SEQUENTIAL
    103         , MMAP_WILLNEED
    104         , MMAP_DONTNEED
     99    enum Advice {
     100        ADVICE_NORMAL
     101        , ADVICE_RANDOM
     102        , ADVICE_SEQUENTIAL
     103        , ADVICE_WILLNEED
     104        , ADVICE_DONTNEED
    105105    };
    106106
    107     llvm::Value * CreateMAdvise(llvm::Value * addr, llvm::Value * length, MAdviceFlags advice) {
    108         return CreateMAdvise(addr, length, { advice });
    109     }
    110 
    111     llvm::Value * CreateMAdvise(llvm::Value * addr, llvm::Value * length, std::initializer_list<MAdviceFlags> advice);
     107    llvm::Value * CreateMAdvise(llvm::Value * addr, llvm::Value * length, Advice advice);
    112108
    113109    llvm::Value * CreateMMap(llvm::Value * const addr, llvm::Value * size, llvm::Value * const prot, llvm::Value * const flags, llvm::Value * const fd, llvm::Value * const offset);
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5418 r5419  
    5858static std::vector<std::string> parsedPropertyValues;
    5959
    60 uint64_t GrepEngine::doGrep(const std::string & fileName, const int fileIdx) const {
    61     const int fd = open(fileName.c_str(), O_RDONLY);
     60uint64_t GrepEngine::doGrep(const std::string & fileName, const uint32_t fileIdx) const {
     61    const int32_t fd = open(fileName.c_str(), O_RDONLY);
    6262    if (LLVM_UNLIKELY(fd == -1)) {
    6363        return 0;
     
    6868}
    6969
    70 uint64_t GrepEngine::doGrep(const uint32_t fileDescriptor, const int fileIdx) const {
     70uint64_t GrepEngine::doGrep(const int32_t fileDescriptor, const uint32_t fileIdx) const {
    7171    assert (mGrepFunction);
    72     typedef uint64_t (*GrepFunctionType)(size_t fileDescriptor, const int fileIdx);
     72    typedef uint64_t (*GrepFunctionType)(int32_t fileDescriptor, const uint32_t fileIdx);
    7373    return reinterpret_cast<GrepFunctionType>(mGrepFunction)(fileDescriptor, fileIdx);
    7474}
    7575
    76 void GrepEngine::doGrep(const char * buffer, const uint64_t length, const int fileIdx) const {
     76void GrepEngine::doGrep(const char * buffer, const uint64_t length, const uint32_t fileIdx) const {
    7777    assert (mGrepFunction);
    78     typedef uint64_t (*GrepFunctionType)(const char * buffer, const uint64_t length, const int fileIdx);
     78    typedef uint64_t (*GrepFunctionType)(const char * buffer, const uint64_t length, const uint32_t fileIdx);
    7979    reinterpret_cast<GrepFunctionType>(mGrepFunction)(buffer, length, fileIdx);
    8080}
     
    223223
    224224    Type * const int64Ty = iBuilder->getInt64Ty();
     225    Type * const int32Ty = iBuilder->getInt32Ty();
    225226
    226227    Function * mainFunc = nullptr;
     
    231232    if (grepSource == GrepSource::Internal) {
    232233
    233         mainFunc = cast<Function>(M->getOrInsertFunction("Main", int64Ty, iBuilder->getInt8PtrTy(), int64Ty, int64Ty, nullptr));
     234        mainFunc = cast<Function>(M->getOrInsertFunction("Main", int64Ty, iBuilder->getInt8PtrTy(), int64Ty, int32Ty, nullptr));
    234235        mainFunc->setCallingConv(CallingConv::C);
    235236        iBuilder->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
     
    238239        Value * const buffer = &*(args++);
    239240        buffer->setName("buffer");
    240         Value * const length = &*(args++);
     241
     242        Value * length = &*(args++);
    241243        length->setName("length");
     244        length = iBuilder->CreateZExtOrTrunc(length, iBuilder->getSizeTy());
     245
    242246        fileIdx = &*(args++);
    243247        fileIdx->setName("fileIdx");
     
    250254    } else {
    251255
    252         mainFunc = cast<Function>(M->getOrInsertFunction("Main", int64Ty, iBuilder->getInt32Ty(), int64Ty, nullptr));
     256        mainFunc = cast<Function>(M->getOrInsertFunction("Main", int64Ty, iBuilder->getInt32Ty(), int32Ty, nullptr));
    253257        mainFunc->setCallingConv(CallingConv::C);
    254258        iBuilder->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
     
    307311        pxDriver.addKernelCall(matchCountK, {MergedResults}, {});
    308312        pxDriver.generatePipelineIR();
    309         iBuilder->CreateRet(matchCountK.getScalarField("matchedLineCount"));
     313        Value * matchedLineCount = matchCountK.getScalarField("matchedLineCount");
     314        matchedLineCount = iBuilder->CreateZExt(matchedLineCount, int64Ty);
     315        iBuilder->CreateRet(matchedLineCount);
    310316        pxDriver.linkAndFinalize();
    311317    } else {
  • icGREP/icgrep-devel/icgrep/grep_engine.h

    r5418 r5419  
    2121    void grepCodeGen(std::string moduleName, std::vector<re::RE *> REs, bool CountOnly, bool UTF_16, GrepSource grepSource, GrepType grepType = GrepType::Normal);
    2222
    23     uint64_t doGrep(const std::string & fileName, const int fileIdx) const;
     23    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) const;
    2424
    25     uint64_t doGrep(const uint32_t fileDescriptor, const int fileIdx) const;
     25    uint64_t doGrep(const int32_t fileDescriptor, const uint32_t fileIdx) const;
    2626   
    27     void doGrep(const char * buffer, const uint64_t length, const int fileIdx) const;
     27    void doGrep(const char * buffer, const uint64_t length, const uint32_t fileIdx) const;
    2828
    2929    re::CC * grepCodepoints();
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5418 r5419  
    117117
    118118    llvm::Value * getScalarField(const std::string & fieldName) const {
    119         return iBuilder->CreateLoad(getScalarFieldPtr(fieldName));
    120     }
    121 
    122     llvm::Value * getScalarField(llvm::Value * index) const {
    123         return iBuilder->CreateLoad(getScalarFieldPtr(index));
    124     }
     119        return iBuilder->CreateLoad(getScalarFieldPtr(fieldName), fieldName);
     120    }
     121
     122//    llvm::Value * getScalarField(llvm::Value * index) const {
     123//        return iBuilder->CreateLoad(getScalarFieldPtr(index));
     124//    }
    125125
    126126    // Set the value of a scalar field for the current instance.
     
    129129    }
    130130
    131     void setScalarField(llvm::Value * index, llvm::Value * value) const {
    132         iBuilder->CreateStore(value, getScalarFieldPtr(index));
    133     }
     131//    void setScalarField(llvm::Value * index, llvm::Value * value) const {
     132//        iBuilder->CreateStore(value, getScalarFieldPtr(index));
     133//    }
    134134
    135135    // Synchronization actions for executing a kernel for a particular logical segment.
  • icGREP/icgrep-devel/icgrep/kernels/mmap_kernel.cpp

    r5418 r5419  
    2323    setScalarField("readableBuffer", buffer);
    2424    setScalarField("fileSize", fileSize);
    25     iBuilder->CreateMAdvise(buffer, fileSize, CBuilder::MMAP_WILLNEED);
     25    iBuilder->CreateMAdvise(buffer, fileSize, CBuilder::ADVICE_WILLNEED);
    2626}
    2727
     
    5959
    6060    iBuilder->SetInsertPoint(dropPages);
    61     iBuilder->CreateMAdvise(iBuilder->CreateIntToPtr(readableBuffer, voidPtrTy), unnecessaryBytes, CBuilder::MMAP_DONTNEED);   
     61    iBuilder->CreateMAdvise(iBuilder->CreateIntToPtr(readableBuffer, voidPtrTy), unnecessaryBytes, CBuilder::ADVICE_DONTNEED);   
    6262    readableBuffer = iBuilder->CreateIntToPtr(iBuilder->CreateAdd(readableBuffer, unnecessaryBytes), voidPtrTy);
    6363    setScalarField("readableBuffer", readableBuffer);
     
    8787
    8888void MMapSourceKernel::generateFinalizeMethod() {
    89     Value * buffer = getBaseAddress("sourceBuffer");
    90     Value * fileSize = getBufferedSize("sourceBuffer");
    91     iBuilder->CreateMUnmap(buffer, fileSize);
     89    iBuilder->CreateMUnmap(getBaseAddress("sourceBuffer"), getBufferedSize("sourceBuffer"));
    9290}
    9391
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5411 r5419  
    201201    {Binding{iBuilder->getStreamSetTy(1, 1), "matchResult"}, Binding{iBuilder->getStreamSetTy(1, 1), "lineBreak"}, Binding{iBuilder->getStreamSetTy(1, 8), "InputStream", UnknownRate()}},
    202202    {},
    203     {Binding{iBuilder->getSizeTy(), "FileIdx"}},
     203    {Binding{iBuilder->getInt32Ty(), "FileIdx"}},
    204204    {},
    205205    {Binding{iBuilder->getSizeTy(), "BlockNo"}, Binding{iBuilder->getSizeTy(), "LineNum"}})
Note: See TracChangeset for help on using the changeset viewer.