Ignore:
Timestamp:
Apr 7, 2017, 4:59:04 PM (2 years ago)
Author:
nmedfort
Message:

Continued work on processing stdin input. Partial integration of ParabixDriver? methods into icgrep and editd. Object cache does not currently work for recursive REs.

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/alignedprint.cpp

    r5362 r5398  
    127127        Value * output = iBuilder->CreateAlloca(iBuilder->getInt8Ty(), streamLength);
    128128
    129         Value * outputName = iBuilder->CreateGlobalStringPtr(name.c_str());
     129        Value * outputName = iBuilder->GetString(name.c_str());
    130130        ConstantInt * const length = iBuilder->getInt32(name.length());
    131131        iBuilder->CreateMemCpy(output, outputName, length, 1);
  • icGREP/icgrep-devel/icgrep/kernels/interface.cpp

    r5390 r5398  
    4444Value * ProcessingRate::CreateRatioCalculation(IDISA::IDISA_Builder * b, Value * principalInputItems, Value * doFinal) const {
    4545    if (mKind == ProcessingRate::ProcessingRateKind::Fixed || mKind == ProcessingRate::ProcessingRateKind::Max) {
    46         if (ratio_numerator == 1) {
     46        if (mRatioNumerator == 1) {
    4747            return principalInputItems;
    4848        }
    4949        Type * const T = principalInputItems->getType();
    50         Constant * const numerator = ConstantInt::get(T, ratio_numerator);
    51         Constant * const denominator = ConstantInt::get(T, ratio_denominator);
    52         Constant * const denominatorLess1 = ConstantInt::get(T, ratio_denominator - 1);
     50        Constant * const numerator = ConstantInt::get(T, mRatioNumerator);
     51        Constant * const denominator = ConstantInt::get(T, mRatioDenominator);
     52        Constant * const denominatorLess1 = ConstantInt::get(T, mRatioDenominator - 1);
    5353        Value * strmItems = b->CreateMul(principalInputItems, numerator);
    5454        return b->CreateUDiv(b->CreateAdd(denominatorLess1, strmItems), denominator);
     
    5656    if (mKind == ProcessingRate::ProcessingRateKind::RoundUp) {
    5757        Type * const T = principalInputItems->getType();
    58         Constant * const denominator = ConstantInt::get(T, ratio_denominator);
    59         Constant * const denominatorLess1 = ConstantInt::get(T, ratio_denominator - 1);
     58        Constant * const denominator = ConstantInt::get(T, mRatioDenominator);
     59        Constant * const denominatorLess1 = ConstantInt::get(T, mRatioDenominator - 1);
    6060        return b->CreateMul(b->CreateUDiv(b->CreateAdd(principalInputItems, denominatorLess1), denominator), denominator);
    6161    }
     
    9595
    9696    // Create the doSegment function prototype.
    97     std::vector<Type *> doSegmentParameters = {selfType, iBuilder->getInt1Ty()};
     97    std::vector<Type *> params = {selfType, iBuilder->getInt1Ty()};
     98    // const auto count = mStreamSetInputs.size() + mStreamSetOutputs.size();
    9899    for (unsigned i = 0; i < mStreamSetInputs.size(); ++i) {
    99         doSegmentParameters.push_back(iBuilder->getSizeTy());
     100        params.push_back(iBuilder->getSizeTy());
    100101    }
    101     FunctionType * doSegmentType = FunctionType::get(iBuilder->getVoidTy(), doSegmentParameters, false);
     102
     103    FunctionType * doSegmentType = FunctionType::get(iBuilder->getVoidTy(), params, false);
    102104    Function * doSegment = Function::Create(doSegmentType, GlobalValue::ExternalLinkage, getName() + DO_SEGMENT_SUFFIX, client);
    103105    doSegment->setCallingConv(CallingConv::C);
     
    107109    args->setName("self");
    108110    (++args)->setName("doFinal");
    109     for (auto ss : mStreamSetInputs) {
    110         (++args)->setName(ss.name + "_availableItems");
     111    for (const Binding & input : mStreamSetInputs) {
     112        (++args)->setName(input.name + "_availableItems");
    111113    }
     114//    for (const Binding & output : mStreamSetOutputs) {
     115//        (++args)->setName(output.name + "_consumedItems");
     116//    }
    112117
    113118    // Create the accumulator get function prototypes
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5391 r5398  
    4343    ProcessingRateKind getKind() const {return mKind;}
    4444    bool isExact() const {return (mKind == Fixed)||(mKind == RoundUp)||(mKind == Add1) ;}
     45    bool isUnknown() const { return !isExact(); }
    4546    llvm::Value * CreateRatioCalculation(IDISA::IDISA_Builder * b, llvm::Value * principalInputItems, llvm::Value * doFinal = nullptr) const;
    4647    friend ProcessingRate FixedRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems, std::string referenceStreamSet);
     
    5051    friend ProcessingRate UnknownRate();
    5152    std::string referenceStreamSet() const { return mReferenceStreamSet;}
    52    
    5353protected:
    5454    ProcessingRate(ProcessingRateKind k, unsigned numerator, unsigned denominator, std::string referenceStreamSet)
    55     : mKind(k), ratio_numerator(numerator), ratio_denominator(denominator), mReferenceStreamSet(referenceStreamSet) {}
     55    : mKind(k), mRatioNumerator(numerator), mRatioDenominator(denominator), mReferenceStreamSet(referenceStreamSet) {}
     56private:
    5657    ProcessingRateKind mKind;
    57     uint16_t ratio_numerator;
    58     uint16_t ratio_denominator;
     58    uint16_t mRatioNumerator;
     59    uint16_t mRatioDenominator;
    5960    std::string mReferenceStreamSet;
    60     bool isVariableRate();
    6161};
    6262
     
    120120    virtual void setProducedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const = 0;
    121121
    122     virtual llvm::Value * getConsumedItemCount(llvm::Value * instance, const std::string & name) const = 0;
    123 
    124     virtual void setConsumedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const = 0;
    125 
    126122    virtual llvm::Value * getProcessedItemCount(llvm::Value * instance, const std::string & name) const = 0;
    127123
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5395 r5398  
    6262void KernelBuilder::prepareStreamSetNameMap() {
    6363    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
    64         mStreamSetNameMap.emplace(mStreamSetInputs[i].name, i);
     64        mStreamMap.emplace(mStreamSetInputs[i].name, std::make_pair(Port::Input, i));
    6565    }
    6666    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    67         mStreamSetNameMap.emplace(mStreamSetOutputs[i].name, i);
     67        mStreamMap.emplace(mStreamSetOutputs[i].name, std::make_pair(Port::Output, i));
    6868    }
    6969}
     
    9595        if ((i == 0) || !mStreamSetInputs[i].rate.isExact()) {
    9696            addScalar(iBuilder->getSizeTy(), mStreamSetInputs[i].name + PROCESSED_ITEM_COUNT_SUFFIX);
    97         }
    98        
     97        }       
    9998    }
    10099    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
     
    110109        addScalar(binding.type, binding.name);
    111110    }
    112     if (mStreamSetNameMap.empty()) {
     111    if (mStreamMap.empty()) {
    113112        prepareStreamSetNameMap();
    114113    }
     
    278277Value * KernelBuilder::getProducedItemCount(Value * instance, const std::string & name, Value * doFinal) const {
    279278    assert ("instance cannot be null!" && instance);
    280     unsigned ssIdx = getStreamSetIndex(name);
     279    Port port; unsigned ssIdx;
     280    std::tie(port, ssIdx) = getStreamPort(name);
     281    assert (port == Port::Output);
    281282    if (mStreamSetOutputs[ssIdx].rate.isExact()) {
    282283        std::string refSet = mStreamSetOutputs[ssIdx].rate.referenceStreamSet();
     
    289290            }
    290291        } else {
    291             unsigned pfIndex = getStreamSetIndex(refSet);
    292             if (mStreamSetInputs.size() > pfIndex && mStreamSetInputs[pfIndex].name == refSet) {
     292            Port port; unsigned pfIndex;
     293            std::tie(port, pfIndex) = getStreamPort(refSet);
     294            if (port == Port::Input) {
    293295               principalField = refSet + PROCESSED_ITEM_COUNT_SUFFIX;
    294296            } else {
     
    302304}
    303305
    304 llvm::Value * KernelBuilder::getConsumedItemCount(llvm::Value * instance, const std::string & name) const {
    305     assert ("instance cannot be null!" && instance);
    306     return getScalarField(instance, name + CONSUMED_ITEM_COUNT_SUFFIX);
    307 }
    308 
    309306Value * KernelBuilder::getProcessedItemCount(Value * instance, const std::string & name) const {
    310307    assert ("instance cannot be null!" && instance);
    311     unsigned ssIdx = getStreamSetIndex(name);
     308    Port port; unsigned ssIdx;
     309    std::tie(port, ssIdx) = getStreamPort(name);
     310    assert (port == Port::Input);
    312311    if (mStreamSetInputs[ssIdx].rate.isExact()) {
    313312        std::string refSet = mStreamSetInputs[ssIdx].rate.referenceStreamSet();
     
    326325}
    327326
    328 void KernelBuilder::setConsumedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const {
    329     assert ("instance cannot be null!" && instance);
    330     setScalarField(instance, name + CONSUMED_ITEM_COUNT_SUFFIX, value);
    331 }
    332 
    333327void KernelBuilder::setProcessedItemCount(Value * instance, const std::string & name, Value * value) const {
    334328    assert ("instance cannot be null!" && instance);
    335329    setScalarField(instance, name + PROCESSED_ITEM_COUNT_SUFFIX, value);
    336 }
    337 
    338 void KernelBuilder::reserveBytes(llvm::Value * instance, const std::string & name, llvm::Value * value) const {
    339     assert ("instance cannot be null!" && instance);
    340     Value * itemCount = getProducedItemCount(instance, name);
    341     const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    342     buf->reserveBytes(getStreamSetBufferPtr(name), iBuilder->CreateAdd(itemCount, value));
    343330}
    344331
     
    440427}
    441428
    442 unsigned KernelBuilder::getStreamSetIndex(const std::string & name) const {
    443     const auto f = mStreamSetNameMap.find(name);
    444     if (LLVM_UNLIKELY(f == mStreamSetNameMap.end())) {
     429void KernelBuilder::setBaseAddress(const std::string & name, llvm::Value * addr) const {
     430    unsigned index; Port port;
     431    std::tie(port, index) = getStreamPort(name);
     432    const StreamSetBuffer * buf = nullptr;
     433    if (port == Port::Input) {
     434        assert (index < mStreamSetInputBuffers.size());
     435        buf = mStreamSetInputBuffers[index];
     436    } else {
     437        assert (index < mStreamSetOutputBuffers.size());
     438        buf = mStreamSetOutputBuffers[index];
     439    }
     440    return buf->setBaseAddress(getStreamSetBufferPtr(name), addr);
     441}
     442
     443Value * KernelBuilder::getBufferedSize(const std::string & name) const {
     444    unsigned index; Port port;
     445    std::tie(port, index) = getStreamPort(name);
     446    const StreamSetBuffer * buf = nullptr;
     447    if (port == Port::Input) {
     448        assert (index < mStreamSetInputBuffers.size());
     449        buf = mStreamSetInputBuffers[index];
     450    } else {
     451        assert (index < mStreamSetOutputBuffers.size());
     452        buf = mStreamSetOutputBuffers[index];
     453    }
     454    return buf->getBufferedSize(getStreamSetBufferPtr(name));
     455}
     456
     457void KernelBuilder::setBufferedSize(const std::string & name, Value * size) const {
     458    unsigned index; Port port;
     459    std::tie(port, index) = getStreamPort(name);
     460    const StreamSetBuffer * buf = nullptr;
     461    if (port == Port::Input) {
     462        assert (index < mStreamSetInputBuffers.size());
     463        buf = mStreamSetInputBuffers[index];
     464    } else {
     465        assert (index < mStreamSetOutputBuffers.size());
     466        buf = mStreamSetOutputBuffers[index];
     467    }
     468    buf->setBufferedSize(getStreamSetBufferPtr(name), size);
     469}
     470
     471void KernelBuilder::reserveBytes(const std::string & name, llvm::Value * value) const {
     472    Value * itemCount = getProducedItemCount(name);
     473    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
     474    buf->reserveBytes(getStreamSetBufferPtr(name), iBuilder->CreateAdd(itemCount, value));
     475}
     476
     477KernelBuilder::StreamPort KernelBuilder::getStreamPort(const std::string & name) const {
     478    const auto f = mStreamMap.find(name);
     479    if (LLVM_UNLIKELY(f == mStreamMap.end())) {
    445480        report_fatal_error(getName() + " does not contain stream set: " + name);
    446481    }
     
    630665    if (!useIndirectBr()) {
    631666        FunctionType * const type = FunctionType::get(iBuilder->getVoidTy(), {mSelf->getType()}, false);
    632         mCurrentMethod = Function::Create(type, GlobalValue::ExternalLinkage, getName() + DO_BLOCK_SUFFIX, iBuilder->getModule());
     667        mCurrentMethod = Function::Create(type, GlobalValue::InternalLinkage, getName() + DO_BLOCK_SUFFIX, iBuilder->getModule());
    633668        mCurrentMethod->setCallingConv(CallingConv::C);
    634669        mCurrentMethod->setDoesNotThrow();
     
    709744    if (!useIndirectBr()) {
    710745        FunctionType * const type = FunctionType::get(iBuilder->getVoidTy(), {mSelf->getType(), iBuilder->getSizeTy()}, false);
    711         mCurrentMethod = Function::Create(type, GlobalValue::ExternalLinkage, getName() + FINAL_BLOCK_SUFFIX, iBuilder->getModule());
     746        mCurrentMethod = Function::Create(type, GlobalValue::InternalLinkage, getName() + FINAL_BLOCK_SUFFIX, iBuilder->getModule());
    712747        mCurrentMethod->setCallingConv(CallingConv::C);
    713748        mCurrentMethod->setDoesNotThrow();
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5395 r5398  
    2525   
    2626class KernelBuilder : public KernelInterface {
    27     using NameMap = boost::container::flat_map<std::string, unsigned>;
     27protected:
     28    using KernelMap = boost::container::flat_map<std::string, unsigned>;
     29    enum class Port { Input, Output };
     30    using StreamPort = std::pair<Port, unsigned>;
     31    using StreamMap = boost::container::flat_map<std::string, StreamPort>;
    2832public:
    2933   
     
    8084    void setProducedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const final;
    8185
    82     llvm::Value * getConsumedItemCount(llvm::Value * instance, const std::string & name) const final;
    83 
    84     void setConsumedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const final;
    85 
    8686    llvm::Value * getProcessedItemCount(llvm::Value * instance, const std::string & name) const final;
    8787
    8888    void setProcessedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const final;
    89 
    90     virtual void reserveBytes(llvm::Value * instance, const std::string & name, llvm::Value * requested) const;
    9189
    9290    bool hasNoTerminateAttribute() { return mNoTerminateAttribute;}
     
    236234    llvm::Value * getRawOutputPointer(const std::string & name, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
    237235
    238     void reserveBytes(const std::string & name, llvm::Value * requested) const {
    239         reserveBytes(getSelf(), name, requested);
    240     }
     236    void setBaseAddress(const std::string & name, llvm::Value * addr) const;
     237
     238    llvm::Value * getBufferedSize(const std::string & name) const;
     239
     240    void setBufferedSize(const std::string & name, llvm::Value * size) const;
     241
     242    void reserveBytes(const std::string & name, llvm::Value * requested) const;
    241243
    242244    llvm::Value * getScalarFieldPtr(const std::string & name) const {
     
    256258    }
    257259
    258     inline llvm::Value * getConsumedItemCount(const std::string & name) const {
    259         return getConsumedItemCount(getSelf(), name);
    260     }
    261 
    262     inline void setConsumedItemCount(const std::string & name, llvm::Value * value) const {
    263         setConsumedItemCount(getSelf(), name, value);
    264     }
    265 
    266260    inline llvm::Value * getProcessedItemCount(const std::string & name) const {
    267261        return getProcessedItemCount(getSelf(), name);
     
    294288    llvm::Value * getScalarFieldPtr(llvm::Value * instance, llvm::Value * index) const;
    295289
    296     unsigned getStreamSetIndex(const std::string & name) const;
     290    StreamPort getStreamPort(const std::string & name) const;
    297291
    298292    const parabix::StreamSetBuffer * getInputStreamSetBuffer(const std::string & name) const {
    299         const auto index = getStreamSetIndex(name);
    300         assert (index < mStreamSetInputBuffers.size());
    301         return mStreamSetInputBuffers[index];
     293        const auto port = getStreamPort(name);
     294        assert (port.first == Port::Input);
     295        assert (port.second < mStreamSetInputBuffers.size());
     296        return mStreamSetInputBuffers[port.second];
    302297    }
    303298
    304299    const parabix::StreamSetBuffer * getOutputStreamSetBuffer(const std::string & name) const {
    305         const auto index = getStreamSetIndex(name);
    306         assert (index < mStreamSetOutputBuffers.size());
    307         return mStreamSetOutputBuffers[index];
     300        const auto port = getStreamPort(name);
     301        assert (port.first == Port::Output);
     302        assert (port.second < mStreamSetOutputBuffers.size());
     303        return mStreamSetOutputBuffers[port.second];
    308304    }
    309305
     
    322318
    323319    std::vector<llvm::Type *>                       mKernelFields;
    324     NameMap                                         mKernelMap;
    325     NameMap                                         mStreamSetNameMap;
     320    KernelMap                                       mKernelMap;
     321    StreamMap                                       mStreamMap;
    326322    std::vector<const parabix::StreamSetBuffer *>   mStreamSetInputBuffers;
    327323    std::vector<const parabix::StreamSetBuffer *>   mStreamSetOutputBuffers;
  • icGREP/icgrep-devel/icgrep/kernels/linebreak_kernel.h

    r5358 r5398  
    1616public:
    1717    LineBreakKernelBuilder(IDISA::IDISA_Builder * iBuilder, std::string linebreak, unsigned basisBitsCount);
     18    bool moduleIDisSignature() override {return true;}
    1819};
    1920
  • icGREP/icgrep-devel/icgrep/kernels/mmap_kernel.cpp

    r5391 r5398  
    4343}
    4444
    45 void MMapSourceKernel::generateInitMethod() {
    46 //    Value * fileSize = getScalarField("fileSize");
    47 //    fileSize = iBuilder->CreateUDiv(fileSize, iBuilder->getSize(mCodeUnitWidth / 8));
    48 //    setProducedItemCount("sourceBuffer", fileSize);
    49 }
    50 
    5145MMapSourceKernel::MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment, unsigned codeUnitWidth)
    5246: SegmentOrientedKernel(iBuilder, "Parabix:mmap_source",
  • icGREP/icgrep-devel/icgrep/kernels/mmap_kernel.h

    r5392 r5398  
    2020    bool moduleIDisSignature() override {return true;}
    2121private:
    22     void generateInitMethod() override;
    2322    void generateDoSegmentMethod(llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) override;
    2423private:
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r5390 r5398  
    162162        }
    163163        iBuilder->SetInsertPoint(segmentLoopBody[k]);
    164         std::vector<Value *> doSegmentArgs = {instancePtrs[k], doFinal};
     164        std::vector<Value *> args = {instancePtrs[k], doFinal};
    165165        for (unsigned j = 0; j < K->getStreamInputs().size(); j++) {
    166166            unsigned producerKernel, outputIndex;
    167167            std::tie(producerKernel, outputIndex) = producerTable[k][j];
    168             doSegmentArgs.push_back(ProducerPos[producerKernel][outputIndex]);
    169         }
    170         K->createDoSegmentCall(doSegmentArgs);
     168            args.push_back(ProducerPos[producerKernel][outputIndex]);
     169        }
     170        K->createDoSegmentCall(args);
    171171         if (! (K->hasNoTerminateAttribute())) {
    172172            Value * terminated = K->getTerminationSignal(instancePtrs[k]);
    173173            doFinal = iBuilder->CreateOr(doFinal, terminated);
    174174        }
    175        std::vector<Value *> produced;
     175        std::vector<Value *> produced;
    176176        for (unsigned i = 0; i < K->getStreamOutputs().size(); i++) {
    177177            produced.push_back(K->getProducedItemCount(instancePtrs[k], K->getStreamOutputs()[i].name, doFinal));
     
    438438    const auto ip = iBuilder->saveIP();
    439439    for (unsigned i = 0; i < threadNum; i++) {
    440         thread_functions.push_back(generateParallelPipelineThreadFunction("thread"+std::to_string(i), iBuilder, kernels, sharedStructType, producerTable, consumerTable, i));
     440        thread_functions.push_back(generateParallelPipelineThreadFunction("thread" + std::to_string(i), iBuilder, kernels, sharedStructType, producerTable, consumerTable, i));
    441441    }
    442442    iBuilder->restoreIP(ip);
     
    470470    const ProducerTable producer = createProducerTable(kernels);
    471471
    472 //    const ConsumerTable consumer = createConsumerTable(kernels);
     472 //   const ConsumerTable consumer = createConsumerTable(kernels);
    473473   
    474474    // ProducerPos[k][i] will hold the producedItemCount of the i^th output stream
     
    484484    Value * terminated = ConstantInt::getFalse(iBuilder->getContext());
    485485    for (unsigned k = 0; k < kernels.size(); k++) {
    486         KernelBuilder * const K = kernels[k];
    487         Value * const instance = K->getInstance();
     486        KernelBuilder * const kernel = kernels[k];
     487        Value * const instance = kernel->getInstance();
    488488        std::vector<Value *> args = {instance, terminated};
    489         for (unsigned j = 0; j < K->getStreamInputs().size(); j++) {
     489        for (unsigned j = 0; j < kernel->getStreamInputs().size(); j++) {
    490490            unsigned producerKernel, outputIndex;
    491491            std::tie(producerKernel, outputIndex) = producer[k][j];
    492492            args.push_back(ProducerPos[producerKernel][outputIndex]);
    493493        }
    494         K->createDoSegmentCall(args);
    495         if (!K->hasNoTerminateAttribute()) {
    496             terminated = iBuilder->CreateOr(terminated, K->getTerminationSignal(instance));
     494        kernel->createDoSegmentCall(args);
     495        if (!kernel->hasNoTerminateAttribute()) {
     496            terminated = iBuilder->CreateOr(terminated, kernel->getTerminationSignal(instance));
    497497        }
    498498        std::vector<Value *> produced;
    499         const auto & streamOutputs = K->getStreamOutputs();
     499        const auto & streamOutputs = kernel->getStreamOutputs();
    500500        for (unsigned i = 0; i < streamOutputs.size(); i++) {
    501             produced.push_back(K->getProducedItemCount(instance, streamOutputs[i].name, terminated));
     501            produced.push_back(kernel->getProducedItemCount(instance, streamOutputs[i].name, terminated));
    502502        }
    503503        ProducerPos.push_back(produced);
    504         Value * segNo = K->acquireLogicalSegmentNo(instance);
    505         K->releaseLogicalSegmentNo(instance, iBuilder->CreateAdd(segNo, iBuilder->getSize(1)));
     504        Value * segNo = kernel->acquireLogicalSegmentNo(instance);
     505        kernel->releaseLogicalSegmentNo(instance, iBuilder->CreateAdd(segNo, iBuilder->getSize(1)));
    506506    }
    507507
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5391 r5398  
    1111using namespace llvm;
    1212
     13inline static unsigned floor_log2(const unsigned v) {
     14    assert ("log2(0) is undefined!" && v != 0);
     15    return 31 - __builtin_clz(v);
     16}
     17
    1318namespace kernel {
    1419
    15 Value * generateForwardZeroesMask(IDISA::IDISA_Builder * iBuilder, Value * bits) {
    16     Value * bits_minus1 = iBuilder->CreateSub(bits, ConstantInt::get(bits->getType(), 1));
    17     return iBuilder->CreateAnd(bits_minus1, iBuilder->CreateNot(bits));
    18 }
    19 
    20 Value * generatePopcount(IDISA::IDISA_Builder * iBuilder, Value * bits) {
    21     Value * ctpopFunc = Intrinsic::getDeclaration(iBuilder->getModule(), Intrinsic::ctpop, bits->getType());
    22     return iBuilder->CreateCall(ctpopFunc, std::vector<Value *>({bits}));
    23 }
    24 
    25 Value * generateCountForwardZeroes(IDISA::IDISA_Builder * iBuilder, Value * bits) {
    26     Value * cttzFunc = Intrinsic::getDeclaration(iBuilder->getModule(), Intrinsic::cttz, bits->getType());
    27     return iBuilder->CreateCall(cttzFunc, std::vector<Value *>({bits, ConstantInt::get(iBuilder->getInt1Ty(), 0)}));
    28 }
    29 
    30 Value * generateCountReverseZeroes(IDISA::IDISA_Builder * iBuilder, Value * bits) {
    31     Value * ctlzFunc = Intrinsic::getDeclaration(iBuilder->getModule(), Intrinsic::ctlz, bits->getType());
    32     return iBuilder->CreateCall(ctlzFunc, std::vector<Value *>({bits, ConstantInt::get(iBuilder->getInt1Ty(), 0)}));
    33 }
    34 
    35 Value * generateResetLowestBit(IDISA::IDISA_Builder * iBuilder, Value * bits) {
    36     Value * bits_minus1 = iBuilder->CreateSub(bits, ConstantInt::get(bits->getType(), 1));
    37     return iBuilder->CreateAnd(bits_minus1, bits);
     20inline std::string getGrepTypeId(const GrepType grepType) {
     21    switch (grepType) {
     22        case GrepType::Normal:
     23            return "N";
     24        case GrepType::NameExpression:
     25            return "E";
     26        case GrepType::PropertyValue:
     27            return "P";
     28        default:
     29            llvm_unreachable("unknown grep type!");
     30    }
    3831}
    3932
     
    5649    VectorType * const scanwordVectorType =  VectorType::get(sizeTy, fieldCount);
    5750    Value * const blockNo = getScalarField("BlockNo");
    58     Value * const scanwordPos = iBuilder->CreateMul(blockNo, ConstantInt::get(blockNo->getType(), iBuilder->getBitBlockWidth()));
    59     Value * const lastRecordStart = getScalarField("LineStart");
     51    Value * const scanwordPos = iBuilder->CreateShl(blockNo, floor_log2(iBuilder->getBitBlockWidth()));
     52    Value * const lastRecordStart = getProcessedItemCount("InputStream");
    6053    Value * const lastRecordNum = getScalarField("LineNum");
    6154    Value * const inputStream = iBuilder->CreatePointerCast(getRawInputPointer("InputStream", iBuilder->getInt32(0), iBuilder->getInt32(0)), codeUnitTy);
    62 
    63     Value * const fileSize = iBuilder->CreateAdd(getProcessedItemCount("InputStream"), getScalarField("PendingBytes"));
    64 
    65     Constant * matchProcessor = nullptr;
    66     Value * fileIdx = nullptr;
    67     switch (mGrepType) {
    68         case GrepType::Normal:
    69             fileIdx = getScalarField("FileIdx");
    70             matchProcessor = m->getOrInsertFunction("wrapped_report_match" + std::to_string(mCodeUnitWidth), iBuilder->getVoidTy(), sizeTy, sizeTy, sizeTy, codeUnitTy, sizeTy, sizeTy, nullptr);
    71             break;
    72         case GrepType::NameExpression:
    73             matchProcessor = m->getOrInsertFunction("insert_codepoints", iBuilder->getVoidTy(), sizeTy, sizeTy, sizeTy, codeUnitTy, nullptr);
    74             break;
    75         case GrepType::PropertyValue:
    76             matchProcessor = m->getOrInsertFunction("insert_property_values", iBuilder->getVoidTy(), sizeTy, sizeTy, sizeTy, codeUnitTy, nullptr);
    77             break;
    78         default: llvm_unreachable("unknown grep type");
    79     }
    8055
    8156    Value * const matches = iBuilder->CreateBitCast(loadInputStreamBlock("matchResult", iBuilder->getInt32(0)), scanwordVectorType);
     
    125100            // The loop body is entered if we have more matches to process.
    126101            iBuilder->SetInsertPoint(processMatchesEntry);
    127             Value * prior_breaks = iBuilder->CreateAnd(generateForwardZeroesMask(iBuilder, phiMatchWord), phiRecordBreaks);
     102            Value * prior_breaks = iBuilder->CreateAnd(makeForwardZeroesMask(phiMatchWord), phiRecordBreaks);
    128103            // Within the loop we have a conditional block that is executed if there are any prior record breaks.
    129104            Value * prior_breaks_cond = iBuilder->CreateICmpNE(prior_breaks, ConstantInt::getNullValue(sizeTy));
     
    132107                // PRIOR_BREAKS_BLOCK
    133108                // If there are prior breaks, we count them and compute the record start position.
    134                 iBuilder->SetInsertPoint(prior_breaks_block);
    135                 Value * matchedRecordNum = iBuilder->CreateAdd(generatePopcount(iBuilder, prior_breaks), phiRecordNum);
    136                 Value * reverseDistance = generateCountReverseZeroes(iBuilder, prior_breaks);
     109                iBuilder->SetInsertPoint(prior_breaks_block);               
     110                Value * matchedRecordNum = iBuilder->CreateAdd(iBuilder->CreatePopcount(prior_breaks), phiRecordNum);
     111                Value * reverseDistance = iBuilder->CreateCountReverseZeroes(prior_breaks);
    137112                Value * width = ConstantInt::get(sizeTy, sizeTy->getBitWidth());
    138113                Value * priorRecordStart = iBuilder->CreateAdd(phiScanwordPos, iBuilder->CreateSub(width, reverseDistance));
     
    153128            phiRecordStart->addIncoming(matchRecordStart, loop_final_block);
    154129
    155             Value * matchRecordEnd = iBuilder->CreateAdd(phiScanwordPos, generateCountForwardZeroes(iBuilder, phiMatchWord));
     130            Value * matchRecordEnd = iBuilder->CreateAdd(phiScanwordPos, iBuilder->CreateCountForwardZeroes(phiMatchWord));
     131            Function * const matcher = m->getFunction("matcher");
     132            assert (matcher);
    156133            switch (mGrepType) {
    157134                case GrepType::Normal:
    158                     iBuilder->CreateCall(matchProcessor, {matchRecordNum, matchRecordStart, matchRecordEnd, inputStream, fileSize, fileIdx});
     135                    iBuilder->CreateCall(matcher, {matchRecordNum, matchRecordStart, matchRecordEnd, inputStream, getBufferedSize("InputStream"), getScalarField("FileIdx")});
    159136                    break;
    160137                case GrepType::NameExpression:
    161138                case GrepType::PropertyValue:
    162                     iBuilder->CreateCall(matchProcessor, {matchRecordNum, matchRecordStart, matchRecordEnd, inputStream});
     139                    iBuilder->CreateCall(matcher, {matchRecordNum, matchRecordStart, matchRecordEnd, inputStream});
    163140                    break;
    164141                default: break;
    165142            }
    166143
    167             Value * remaining_matches = generateResetLowestBit(iBuilder, phiMatchWord);
     144            Value * remaining_matches = resetLowestBit(phiMatchWord);
    168145            phiMatchWord->addIncoming(remaining_matches, loop_final_block);
    169146
     
    181158            // REMAINING_BREAKS_BLOCK: process remaining record breaks after all matches are processed
    182159            iBuilder->SetInsertPoint(remaining_breaks_block);
    183             Value * break_count = generatePopcount(iBuilder, phiRecordBreaks);
     160            Value * break_count = iBuilder->CreatePopcount(phiRecordBreaks);
    184161            Value * final_record_num = iBuilder->CreateAdd(phiRecordNum, break_count);
    185             Value * reverseZeroes = generateCountReverseZeroes(iBuilder, phiRecordBreaks);
     162            Value * reverseZeroes = iBuilder->CreateCountReverseZeroes(phiRecordBreaks);
    186163            Value * pendingLineStart = iBuilder->CreateAdd(phiScanwordPos, iBuilder->CreateSub(width, reverseZeroes));
    187164            iBuilder->CreateBr(return_block);
     
    208185    iBuilder->SetInsertPoint(scanWordExit);
    209186    setScalarField("BlockNo", iBuilder->CreateAdd(blockNo, ConstantInt::get(blockNo->getType(), 1)));
    210     setScalarField("LineStart", phiFinalRecordStart);
    211187    setScalarField("LineNum", phiFinalRecordNum);
    212 }
    213 
    214 void ScanMatchKernel::generateInitMethod() {
    215     setScalarField("PendingBytes", iBuilder->getSize(iBuilder->getBitBlockWidth() + 2));
    216 }
    217 
    218 void ScanMatchKernel::generateFinalBlockMethod(llvm::Value * remainingItems) {
    219     setScalarField("PendingBytes", remainingItems);
    220     CreateDoBlockMethodCall();
     188    setProcessedItemCount("InputStream", phiFinalRecordStart);
     189}
     190
     191inline Value * ScanMatchKernel::makeForwardZeroesMask(Value * const value) const {
     192    return iBuilder->CreateAnd(iBuilder->CreateSub(value, ConstantInt::get(value->getType(), 1)), iBuilder->CreateNot(value));
     193}
     194
     195inline Value * ScanMatchKernel::resetLowestBit(Value * const value) const {
     196    return iBuilder->CreateAnd(iBuilder->CreateSub(value, ConstantInt::get(value->getType(), 1)), value);
    221197}
    222198
    223199ScanMatchKernel::ScanMatchKernel(IDISA::IDISA_Builder * iBuilder, GrepType grepType, const unsigned codeUnitWidth)
    224 : BlockOrientedKernel(iBuilder, "Parabix:scanMatch" + std::to_string(codeUnitWidth),
    225     {Binding{iBuilder->getStreamSetTy(1, 8), "InputStream"}, Binding{iBuilder->getStreamSetTy(1, 1), "matchResult"}, Binding{iBuilder->getStreamSetTy(1, 1), "lineBreak"}},
     200: BlockOrientedKernel(iBuilder, "Parabix:scanMatch" + getGrepTypeId(grepType) + std::to_string(codeUnitWidth),
     201    {Binding{iBuilder->getStreamSetTy(1, 1), "matchResult"}, Binding{iBuilder->getStreamSetTy(1, 1), "lineBreak"}, Binding{iBuilder->getStreamSetTy(1, 8), "InputStream", UnknownRate()}},
    226202    {},
    227203    {Binding{iBuilder->getSizeTy(), "FileIdx"}},
    228204    {},
    229     {Binding{iBuilder->getSizeTy(), "BlockNo"}, Binding{iBuilder->getSizeTy(), "LineStart"}, Binding{iBuilder->getSizeTy(), "LineNum"}, Binding{iBuilder->getSizeTy(), "PendingBytes"}})
     205    {Binding{iBuilder->getSizeTy(), "BlockNo"}, Binding{iBuilder->getSizeTy(), "LineNum"}})
    230206, mGrepType(grepType)
    231207, mCodeUnitWidth(codeUnitWidth) {
    232 }
    233 
    234 }
     208
     209}
     210
     211}
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r5392 r5398  
    1919    bool moduleIDisSignature() override {return true;}
    2020protected:
    21     void generateInitMethod() override;
    2221    void generateDoBlockMethod() override;
    23     void generateFinalBlockMethod(llvm::Value * remainingItems) override;
    2422private:
    25     GrepType        mGrepType;
    26     const unsigned  mCodeUnitWidth;
     23    llvm::Value * makeForwardZeroesMask(llvm::Value * const value) const;
     24    llvm::Value * resetLowestBit(llvm::Value * const value) const;
     25private:
     26    const GrepType      mGrepType;
     27    const unsigned      mCodeUnitWidth;
    2728};
    2829}
  • icGREP/icgrep-devel/icgrep/kernels/stdin_kernel.cpp

    r5386 r5398  
    77#include <kernels/kernel.h>
    88#include <IR_Gen/idisa_builder.h>
     9#include <llvm/Support/raw_ostream.h>
    910
    1011using namespace llvm;
     
    2425
    2526    ConstantInt * const segmentSize = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
    26     Value * bufferedSize = getScalarField("BufferedSize");
    27     Value * const itemsAlreadyRead = getProducedItemCount("codeUnitBuffer");
     27    Value * bufferedSize = getBufferedSize("InputStream");
     28    Value * const itemsAlreadyRead = getProducedItemCount("InputStream");
    2829    Value * const bytesAlreadyRead = iBuilder->CreateMul(itemsAlreadyRead, iBuilder->getSize(mCodeUnitWidth / 8));
    2930    Value * unreadSize = iBuilder->CreateSub(bufferedSize, bytesAlreadyRead);
     31
    3032    Value * const exaustedBuffer = iBuilder->CreateICmpULT(unreadSize, segmentSize);
    3133    iBuilder->CreateUnlikelyCondBr(exaustedBuffer, readBlock, stdInExit);
     
    3537    const auto PageAlignedSegmentSize = round_up_to_nearest((mSegmentBlocks + 1) * iBuilder->getBitBlockWidth() * (mCodeUnitWidth / 8), getpagesize());
    3638    ConstantInt * const bytesToRead = iBuilder->getSize(PageAlignedSegmentSize);
    37     reserveBytes("codeUnitBuffer", bytesToRead);
     39    reserveBytes("InputStream", bytesToRead);
    3840    BasicBlock * const readExit = iBuilder->GetInsertBlock();
    3941
    40     Value * const ptr = getRawOutputPointer("codeUnitBuffer", iBuilder->getInt32(0), bufferedSize);
     42    Value * const ptr = getRawOutputPointer("InputStream", iBuilder->getInt32(0), bufferedSize);
    4143    Value * const bytePtr = iBuilder->CreatePointerCast(ptr, iBuilder->getInt8PtrTy());
    4244    Value * const bytesRead = iBuilder->CreateReadCall(iBuilder->getInt32(STDIN_FILENO), bytePtr, bytesToRead);
     
    4446    unreadSize = iBuilder->CreateAdd(unreadSize, bytesRead);
    4547    bufferedSize = iBuilder->CreateAdd(bufferedSize, bytesRead);
    46     setScalarField("BufferedSize", bufferedSize);
     48    setBufferedSize("InputStream", bufferedSize);
    4749    iBuilder->CreateUnlikelyCondBr(iBuilder->CreateICmpULT(unreadSize, segmentSize), setTermination, stdInExit);
    4850
     
    6264    Value * const itemsRead = iBuilder->CreateAdd(itemsAlreadyRead, produced);
    6365
    64     setProducedItemCount("codeUnitBuffer", itemsRead);
     66    setProducedItemCount("InputStream", itemsRead);
    6567}
    6668
    6769StdInKernel::StdInKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment, unsigned codeUnitWidth)
    68 : SegmentOrientedKernel(iBuilder, "stdin_source", {}, {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "codeUnitBuffer"}}, {}, {}, {Binding{iBuilder->getSizeTy(), "BufferedSize"}})
     70: SegmentOrientedKernel(iBuilder, "stdin_source", {}, {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "InputStream"}}, {}, {}, {})
    6971, mSegmentBlocks(blocksPerSegment)
    7072, mCodeUnitWidth(codeUnitWidth) {
     
    7274}
    7375
    74 void FileSource::generateInitMethod() {
    75     BasicBlock * setTerminationOnFailure = CreateBasicBlock("setTerminationOnFailure");
    76     BasicBlock * fileSourceInitExit = CreateBasicBlock("fileSourceInitExit");
    77     Value * handle = iBuilder->CreateFOpenCall(getScalarField("fileName"), iBuilder->CreateGlobalStringPtr("r"));
    78     setScalarField("IOstreamPtr", handle);
    79     Value * failure = iBuilder->CreateICmpEQ(iBuilder->CreatePtrToInt(handle, iBuilder->getSizeTy()), iBuilder->getSize(0));
    80     iBuilder->CreateCondBr(failure, setTerminationOnFailure, fileSourceInitExit);
    81     iBuilder->SetInsertPoint(setTerminationOnFailure);
     76void FileSourceKernel::generateDoSegmentMethod(Value *doFinal, const std::vector<Value *> &producerPos) {
     77
     78    BasicBlock * entryBlock = iBuilder->GetInsertBlock();
     79    BasicBlock * setTermination = CreateBasicBlock("setTermination");
     80    BasicBlock * mmapSourceExit = CreateBasicBlock("mmapSourceExit");
     81    ConstantInt * segmentItems = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
     82    Value * fileItems = getScalarField("fileSize");
     83    if (mCodeUnitWidth > 8) {
     84        fileItems = iBuilder->CreateUDiv(fileItems, iBuilder->getSize(mCodeUnitWidth / 8));
     85    }
     86    Value * produced = getProducedItemCount("sourceBuffer");
     87    produced = iBuilder->CreateAdd(produced, segmentItems);
     88    Value * lessThanFullSegment = iBuilder->CreateICmpULT(fileItems, produced);
     89    iBuilder->CreateCondBr(lessThanFullSegment, setTermination, mmapSourceExit);
     90    iBuilder->SetInsertPoint(setTermination);
    8291    setTerminationSignal();
    83     iBuilder->CreateBr(fileSourceInitExit);
    84     iBuilder->SetInsertPoint(fileSourceInitExit);
     92    iBuilder->CreateBr(mmapSourceExit);
     93
     94    iBuilder->SetInsertPoint(mmapSourceExit);
     95
     96    PHINode * itemsRead = iBuilder->CreatePHI(produced->getType(), 2);
     97    itemsRead->addIncoming(produced, entryBlock);
     98    itemsRead->addIncoming(fileItems, setTermination);
     99    setProducedItemCount("sourceBuffer", itemsRead);
    85100}
    86    
    87 void FileSource::generateDoSegmentMethod(Value * /* doFinal */, const std::vector<Value *> & /* producerPos */) {
    88101
    89     BasicBlock * closeFile = CreateBasicBlock("closeFile");
    90     BasicBlock * fileSourceExit = CreateBasicBlock("fileSourceExit");
    91     Constant * itemBytes = iBuilder->getSize(mCodeUnitWidth/8);
    92    
    93     Value * produced = getProducedItemCount("codeUnitBuffer");
    94     Value * bytePtr = getOutputStreamBlockPtr("codeUnitBuffer", iBuilder->getInt32(0));
    95     bytePtr = iBuilder->CreatePointerCast(bytePtr, iBuilder->getInt8PtrTy());
     102void FileSourceKernel::generateInitMethod() {
     103    setBaseAddress("sourceBuffer", getScalarField("fileSource"));
     104    setBufferedSize("sourceBuffer", getScalarField("fileSize"));
     105}
    96106
    97     Value * IOstreamPtr = getScalarField("IOstreamPtr");
    98     Value * itemsToDo = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
    99     Value * nRead = iBuilder->CreateFReadCall(bytePtr, itemsToDo, itemBytes, IOstreamPtr);
    100     produced = iBuilder->CreateAdd(produced, nRead);
    101     setProducedItemCount("codeUnitBuffer", produced);
    102     Value * lessThanFullSegment = iBuilder->CreateICmpULT(nRead, itemsToDo);
    103     iBuilder->CreateCondBr(lessThanFullSegment, closeFile, fileSourceExit);
    104 
    105     iBuilder->SetInsertPoint(closeFile);
    106     iBuilder->CreateFCloseCall(IOstreamPtr);
    107     setTerminationSignal();
    108     iBuilder->CreateBr(fileSourceExit);
    109    
    110     iBuilder->SetInsertPoint(fileSourceExit);
    111    
    112 }
    113    
    114 FileSource::FileSource(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment, unsigned codeUnitWidth)
    115 : SegmentOrientedKernel(iBuilder, "filesink", {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "codeUnitBuffer"}}, {},
    116                 {Binding{iBuilder->getInt8PtrTy(), "fileName"}}, {}, {Binding{iBuilder->getFILEptrTy(), "IOstreamPtr"}})
     107FileSourceKernel::FileSourceKernel(IDISA::IDISA_Builder * iBuilder, Type * fileSourceTy, unsigned blocksPerSegment, unsigned codeUnitWidth)
     108: SegmentOrientedKernel(iBuilder, "Parabix:file_source",
     109    {},
     110    {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}},
     111    {Binding{fileSourceTy, "fileSource"}, Binding{iBuilder->getSizeTy(), "fileSize"}}, {}, {})
    117112, mSegmentBlocks(blocksPerSegment)
    118113, mCodeUnitWidth(codeUnitWidth) {
     114
    119115}
    120116
     117
     118
    121119}
  • icGREP/icgrep-devel/icgrep/kernels/stdin_kernel.h

    r5377 r5398  
    1717public:
    1818    StdInKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
     19    bool moduleIDisSignature() override { return true; }
    1920protected:
    2021    void generateDoSegmentMethod(llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) override;
     
    2324    unsigned mCodeUnitWidth;
    2425};
    25    
    2626
    27 class FileSource final : public SegmentOrientedKernel {
     27class FileSourceKernel final : public SegmentOrientedKernel {
    2828public:
    29     FileSource(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
     29    FileSourceKernel(IDISA::IDISA_Builder * iBuilder, llvm::Type * fileSourceTy, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
     30    bool moduleIDisSignature() override { return true; }
    3031protected:
    3132    void generateInitMethod() override;
     
    3435    unsigned mSegmentBlocks;
    3536    unsigned mCodeUnitWidth;
    36  
    37 };
     37  };
    3838
    3939}
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5397 r5398  
    4444}
    4545
     46void StreamSetBuffer::setBaseAddress(Value * /* self */, Value * /* addr */) const {
     47    report_fatal_error("setBaseAddress is not supported by this buffer type");
     48}
     49
     50Value * StreamSetBuffer::getBufferedSize(Value * /* self */) const {
     51    report_fatal_error("getBufferedSize is not supported by this buffer type");
     52}
     53
     54void StreamSetBuffer::setBufferedSize(Value * /* self */, llvm::Value * /* size */) const {
     55    report_fatal_error("setBufferedSize is not supported by this buffer type");
     56}
     57
    4658inline bool StreamSetBuffer::isCapacityGuaranteed(const Value * const index, const size_t capacity) const {
    4759    if (LLVM_UNLIKELY(isa<ConstantInt>(index))) {
     
    8395Value * StreamSetBuffer::getRawItemPointer(Value * self, Value * streamIndex, Value * absolutePosition) const {
    8496    Value * ptr = getBaseAddress(self);
    85     if (isa<ConstantInt>(streamIndex) && cast<ConstantInt>(streamIndex)->isZero()) {
     97    if (!isa<ConstantInt>(streamIndex) || !cast<ConstantInt>(streamIndex)->isZero()) {
    8698        ptr = iBuilder->CreateGEP(ptr, {iBuilder->getInt32(0), streamIndex});
    8799    }
     
    148160
    149161Value * ExternalFileBuffer::getLinearlyAccessibleItems(Value * self, Value *) const {
     162    report_fatal_error("External buffers: getLinearlyAccessibleItems is not supported.");
     163}
     164
     165// Source File Buffer
     166Value * SourceFileBuffer::getBufferedSize(Value * self) const {
     167    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
     168    return iBuilder->CreateLoad(ptr);
     169}
     170
     171void SourceFileBuffer::setBufferedSize(Value * self, llvm::Value * size) const {
     172    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
     173    iBuilder->CreateStore(size, ptr);
     174}
     175
     176void SourceFileBuffer::setBaseAddress(Value * self, Value * addr) const {
     177    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     178    iBuilder->CreateStore(addr, ptr);
     179}
     180
     181Value * SourceFileBuffer::getBaseAddress(Value * const self) const {
     182    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     183    return iBuilder->CreateLoad(ptr);
     184}
     185
     186Value * SourceFileBuffer::getStreamSetBlockPtr(Value * self, Value * blockIndex) const {
     187    return iBuilder->CreateGEP(self, blockIndex);
     188}
     189
     190Value * SourceFileBuffer::getLinearlyAccessibleItems(Value * self, Value *) const {
    150191    report_fatal_error("External buffers: getLinearlyAccessibleItems is not supported.");
    151192}
     
    170211    addr = iBuilder->CreatePointerCast(addr, addrPtr->getType()->getPointerElementType());
    171212    iBuilder->CreateStore(addr, addrPtr);
     213    Value * const bufferSizePtr = iBuilder->CreateGEP(instance, {iBuilder->getInt32(0), iBuilder->getInt32(2)});
     214    iBuilder->CreateStore(ConstantInt::getNullValue(bufferSizePtr->getType()->getPointerElementType()), bufferSizePtr);
    172215    mStreamSetBufferPtr = instance;
    173216}
     
    205248    iBuilder->CreateBr(resume);
    206249    iBuilder->SetInsertPoint(resume);
     250}
     251
     252Value * ExtensibleBuffer::getBufferedSize(Value * self) const {
     253    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(2)});
     254    return iBuilder->CreateLoad(ptr);
     255}
     256
     257void ExtensibleBuffer::setBufferedSize(Value * self, llvm::Value * size) const {
     258    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(2)});
     259    iBuilder->CreateStore(size, ptr);
    207260}
    208261
     
    485538}
    486539
     540SourceFileBuffer::SourceFileBuffer(IDISA::IDISA_Builder * b, Type * type, unsigned AddressSpace)
     541: StreamSetBuffer(BufferKind::SourceFileBuffer, b, type, StructType::get(resolveStreamSetType(b, type)->getPointerTo(), b->getSizeTy(), nullptr), 0, AddressSpace) {
     542
     543}
     544
    487545ExtensibleBuffer::ExtensibleBuffer(IDISA::IDISA_Builder * b, Type * type, size_t bufferBlocks, unsigned AddressSpace)
    488 : StreamSetBuffer(BufferKind::ExtensibleBuffer, b, type, StructType::get(b->getSizeTy(), resolveStreamSetType(b, type)->getPointerTo(), nullptr), bufferBlocks, AddressSpace) {
     546: StreamSetBuffer(BufferKind::ExtensibleBuffer, b, type, StructType::get(b->getSizeTy(), resolveStreamSetType(b, type)->getPointerTo(), b->getSizeTy(), nullptr), bufferBlocks, AddressSpace) {
    489547    mUniqueID = "XT" + std::to_string(bufferBlocks);
    490548    if (AddressSpace > 0) mUniqueID += "@" + std::to_string(AddressSpace);
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5395 r5398  
    1919public:
    2020
    21     enum class BufferKind : unsigned {BlockBuffer, ExternalFileBuffer, CircularBuffer, CircularCopybackBuffer, SwizzledCopybackBuffer, ExpandableBuffer, ExtensibleBuffer};
     21    enum class BufferKind : unsigned {
     22        BlockBuffer
     23        , ExternalFileBuffer
     24        , SourceFileBuffer
     25        , CircularBuffer
     26        , CircularCopybackBuffer
     27        , SwizzledCopybackBuffer
     28        , ExpandableBuffer
     29        , ExtensibleBuffer
     30    };
    2231
    2332    BufferKind getBufferKind() const {
     
    6170    llvm::Value * getRawItemPointer(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
    6271
     72
     73    virtual void setBaseAddress(llvm::Value * self, llvm::Value * addr) const;
     74
     75    virtual void setBufferedSize(llvm::Value * self, llvm::Value * size) const;
     76
     77    virtual llvm::Value * getBufferedSize(llvm::Value * self) const;
     78
    6379    // The number of items that cam be linearly accessed from a given logical stream position.
    6480    virtual llvm::Value * getLinearlyAccessibleItems(llvm::Value * self, llvm::Value * fromPosition) const;
     81
    6582    virtual llvm::Value * getLinearlyAccessibleBlocks(llvm::Value * self, llvm::Value * fromBlock) const;
    6683
     
    102119
    103120protected:
     121
    104122    llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockNo) const override;
    105123};
     
    110128        return b->getBufferKind() == BufferKind::ExternalFileBuffer;
    111129    }
    112    
     130
    113131    ExternalFileBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0);
    114132
     
    119137
    120138    llvm::Value * getLinearlyAccessibleItems(llvm::Value * self, llvm::Value * fromPosition) const override;
    121    
    122 protected:
     139
     140protected:
     141    llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockNo) const override;
     142};
     143
     144class SourceFileBuffer final : public StreamSetBuffer {
     145public:
     146    static inline bool classof(const StreamSetBuffer * b) {
     147        return b->getBufferKind() == BufferKind::SourceFileBuffer;
     148    }
     149
     150    SourceFileBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0);
     151
     152    void setBaseAddress(llvm::Value * self, llvm::Value * addr) const override;
     153
     154    void setBufferedSize(llvm::Value * self, llvm::Value * size) const override;
     155
     156    llvm::Value * getBufferedSize(llvm::Value * self) const override;
     157
     158    llvm::Value * getLinearlyAccessibleItems(llvm::Value * self, llvm::Value * fromPosition) const override;
     159
     160protected:
     161
     162    llvm::Value * getBaseAddress(llvm::Value * self) const override;
     163
    123164    llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockNo) const override;
    124165};
     
    137178
    138179    void reserveBytes(llvm::Value * self, llvm::Value * required) const override;
     180
     181    void setBufferedSize(llvm::Value * self, llvm::Value * size) const override;
     182
     183    llvm::Value * getBufferedSize(llvm::Value * self) const override;
    139184
    140185    void releaseBuffer(llvm::Value * self) const override;
Note: See TracChangeset for help on using the changeset viewer.