Changeset 5370 for icGREP/icgrep-devel


Ignore:
Timestamp:
Mar 21, 2017, 11:55:00 AM (2 years ago)
Author:
xuedongx
Message:

Add1 processing rate; pablo Count only up to EOFbit

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

Legend:

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

    r5351 r5370  
    3434}
    3535
     36ProcessingRate Add1() {
     37    return ProcessingRate(ProcessingRate::ProcessingRateKind::Add1, 0, 0);
     38}
     39
    3640ProcessingRate UnknownRate() {
    3741    return ProcessingRate(ProcessingRate::ProcessingRateKind::Unknown, 0, 0);
     42}
     43
     44Value * ProcessingRate::CreateRatioCalculation(IDISA::IDISA_Builder * b, Value * principalInputItems, Value * doFinal) const {
     45    Type * T = principalInputItems->getType();
     46    if (mKind == ProcessingRate::ProcessingRateKind::Fixed || mKind == ProcessingRate::ProcessingRateKind::Max) {
     47        Value * strmItems = (ratio_numerator == 1) ? principalInputItems : b->CreateMul(principalInputItems, ConstantInt::get(T, ratio_numerator));
     48        if (ratio_denominator == 1) return strmItems;
     49        return b->CreateUDiv(b->CreateAdd(ConstantInt::get(T, ratio_denominator - 1), strmItems), ConstantInt::get(T, ratio_denominator));
     50    }
     51    if (mKind == ProcessingRate::ProcessingRateKind::RoundUp) {
     52        Constant * multiple = ConstantInt::get(T, ratio_denominator);
     53        Constant * multipleLess1 = ConstantInt::get(T, ratio_denominator - 1);
     54        return b->CreateMul(b->CreateUDiv(b->CreateAdd(principalInputItems, multipleLess1), multiple), multiple);
     55    }
     56    if (mKind == ProcessingRate::ProcessingRateKind::Add1) {
     57        return b->CreateAdd(principalInputItems, b->CreateZExt(doFinal, principalInputItems->getType()));
     58    }
     59    return nullptr;
    3860}
    3961
     
    4971        Constant * multipleLess1 = ConstantInt::get(T, ratio_denominator - 1);
    5072        return b->CreateMul(b->CreateUDiv(b->CreateAdd(principalInputItems, multipleLess1), multiple), multiple);
     73    }
     74    if (mKind == ProcessingRate::ProcessingRateKind::Add1) {
     75        return principalInputItems;
    5176    }
    5277    return nullptr;
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5347 r5370  
    1010#include <vector>  // for vector
    1111namespace IDISA { class IDISA_Builder; }
    12 namespace llvm { class ConstantInt; }
     12//namespace llvm { class ConstantInt; }
     13#include <llvm/IR/Constants.h>
    1314namespace llvm { class Function; }
    1415namespace llvm { class Module; }
     
    3839
    3940struct ProcessingRate  {
    40     enum ProcessingRateKind : uint8_t {Fixed, RoundUp, Max, Unknown};
     41    enum ProcessingRateKind : uint8_t {Fixed, RoundUp, Max, Add1, Unknown};
    4142    ProcessingRate() {}
    4243    ProcessingRateKind getKind() const {return mKind;}
    43     bool isExact() const {return (mKind == Fixed)||(mKind == RoundUp) ;}
     44    bool isExact() const {return (mKind == Fixed)||(mKind == RoundUp)||(mKind == Add1) ;}
     45    llvm::Value * CreateRatioCalculation(IDISA::IDISA_Builder * b, llvm::Value * principalInputItems, llvm::Value * doFinal) const;
    4446    llvm::Value * CreateRatioCalculation(IDISA::IDISA_Builder * b, llvm::Value * principalInputItems) const;
    4547    friend ProcessingRate FixedRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems);
    4648    friend ProcessingRate MaxRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems);
    47     friend ProcessingRate RoundUpToMultiple(unsigned itemMultiple);
     49    friend ProcessingRate RoundUpToMultiple(unsigned itemMultiple);   
     50    friend ProcessingRate Add1();
    4851    friend ProcessingRate UnknownRate();
    4952   
     
    6063ProcessingRate MaxRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems = 1);
    6164ProcessingRate RoundUpToMultiple(unsigned itemMultiple);
     65ProcessingRate Add1();
    6266ProcessingRate UnknownRate();
    6367
     
    115119    virtual void setProcessedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const = 0;
    116120
    117     virtual llvm::Value * getProducedItemCount(llvm::Value * instance, const std::string & name) const = 0;
     121
    118122
    119123    virtual void setProducedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const = 0;
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5361 r5370  
    247247    }
    248248    return getScalarField(instance, name + PROCESSED_ITEM_COUNT_SUFFIX);
     249}
     250
     251Value * KernelBuilder::getProducedItemCount(Value * instance, const std::string & name, Value * doFinal) const {
     252    unsigned ssIdx = getStreamSetIndex(name);
     253    if (mStreamSetOutputs[ssIdx].rate.isExact()) {
     254        std::string principalField = mStreamSetInputs.empty() ? mStreamSetOutputs[0].name + PRODUCED_ITEM_COUNT_SUFFIX : mStreamSetInputs[0].name + PROCESSED_ITEM_COUNT_SUFFIX;
     255        Value * principalItemsProcessed = getScalarField(instance, principalField);
     256        return mStreamSetOutputs[ssIdx].rate.CreateRatioCalculation(iBuilder, principalItemsProcessed, doFinal);
     257    }
     258    return getScalarField(instance, name + PRODUCED_ITEM_COUNT_SUFFIX);
    249259}
    250260
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5356 r5370  
    1313#include <IR_Gen/idisa_builder.h>
    1414
    15 namespace llvm { class ConstantInt; }
     15//namespace llvm { class ConstantInt; }
     16#include <llvm/IR/Constants.h>
    1617namespace llvm { class Function; }
    1718namespace llvm { class IntegerType; }
     
    4142    virtual void setProcessedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const;
    4243
    43     virtual llvm::Value * getProducedItemCount(llvm::Value * instance, const std::string & name) const override;
     44    llvm::Value * getProducedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * doFinal) const;
     45
     46    llvm::Value * getProducedItemCount(llvm::Value * instance, const std::string & name) const;
    4447
    4548    virtual void setProducedItemCount(llvm::Value * instance, const std::string & name, llvm::Value * value) const;
  • icGREP/icgrep-devel/icgrep/kernels/linebreak_kernel.cpp

    r5366 r5370  
    2828, std::string linebreak
    2929, unsigned basisBitsCount)
    30 : PabloKernel(iBuilder, linebreak +"_kernel", {Binding{iBuilder->getStreamSetTy(basisBitsCount), "basis"}}) {
     30: PabloKernel(iBuilder, linebreak +"_kernel", {Binding{iBuilder->getStreamSetTy(basisBitsCount), "basis"}}, {Binding{iBuilder->getStreamSetTy(1), "linebreak", Add1()}}) {
    3131
    3232    CC_Compiler ccc(this, getInput(0));
    3333    auto & builder = ccc.getBuilder();
    3434   
     35    PabloAST * LineBreak = nullptr;
    3536    PabloAST * LF = ccc.compileCC("LF", makeCC(0x0A), builder);
    3637    PabloAST * CR = ccc.compileCC(makeCC(0x0D));
     
    7576    PabloAST * lb = UNICODE_LINE_BREAK ? UnicodeLineBreak : LF;
    7677    PabloAST * unterminatedLineAtEOF = builder.createAtEOF(builder.createAdvance(builder.createNot(LB_chars), 1));
    77     PabloAST * LineBreak = builder.createOr(lb, unterminatedLineAtEOF);
    78     Var * const r = addOutput("linebreak", getStreamTy());
     78    LineBreak = builder.createOr(lb, unterminatedLineAtEOF);
     79    PabloAST * const r = builder.createExtract(getOutput(0), builder.getInteger(0));
    7980    builder.createAssign(r, LineBreak);
    8081}
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r5366 r5370  
    191191        }
    192192        kernels[k]->createDoSegmentCall(doSegmentArgs);
    193         std::vector<Value *> produced;
    194         for (unsigned i = 0; i < kernels[k]->getStreamOutputs().size(); i++) {
    195             produced.push_back(kernels[k]->getProducedItemCount(instancePtrs[k], kernels[k]->getStreamOutputs()[i].name));
    196         }
    197         ProducerPos.push_back(produced);
    198         if (! (kernels[k]->hasNoTerminateAttribute())) {
     193         if (! (kernels[k]->hasNoTerminateAttribute())) {
    199194            Value * terminated = kernels[k]->getTerminationSignal(instancePtrs[k]);
    200195            doFinal = iBuilder->CreateOr(doFinal, terminated);
    201196        }
     197       std::vector<Value *> produced;
     198        for (unsigned i = 0; i < kernels[k]->getStreamOutputs().size(); i++) {
     199            produced.push_back(kernels[k]->getProducedItemCount(instancePtrs[k], kernels[k]->getStreamOutputs()[i].name, doFinal));
     200        }
     201        ProducerPos.push_back(produced);
    202202
    203203        kernels[k]->releaseLogicalSegmentNo(instancePtrs[k], nextSegNo);
     
    515515        std::vector<Value *> produced;
    516516        for (unsigned i = 0; i < kernels[k]->getStreamOutputs().size(); i++) {
    517             produced.push_back(kernels[k]->getProducedItemCount(instance, kernels[k]->getStreamOutputs()[i].name));
     517            produced.push_back(kernels[k]->getProducedItemCount(instance, kernels[k]->getStreamOutputs()[i].name, terminationFound));
    518518        }
    519519        ProducerPos.push_back(produced);
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5368 r5370  
    478478            value = iBuilder->simd_and(compileExpression(e->getExpr()), EOFbit);
    479479        } else if (const Count * c = dyn_cast<Count>(stmt)) {
    480             Value * const to_count = compileExpression(c->getExpr());
     480            Value * EOFbit = mKernel->getScalarField("EOFbit");
     481            Value * EOFmask = mKernel->getScalarField("EOFmask");
     482            Value * const to_count = iBuilder->simd_and(iBuilder->simd_or(iBuilder->simd_not(EOFmask), EOFbit), compileExpression(c->getExpr()));
    481483            const unsigned counterSize = iBuilder->getSizeTy()->getBitWidth();
    482484            const auto f = mAccumulator.find(c);
Note: See TracChangeset for help on using the changeset viewer.