Changeset 5433 for icGREP/icgrep-devel


Ignore:
Timestamp:
May 3, 2017, 7:56:21 PM (2 years ago)
Author:
cameron
Message:

MaxReferenceItemsCalculation? initial check-in

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

Legend:

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

    r5431 r5433  
    2020using namespace llvm;
    2121
    22 ProcessingRate FixedRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems, std::string && referenceStreamSet) {
    23     return ProcessingRate(ProcessingRate::ProcessingRateKind::Fixed, strmItemsPer, perPrincipalInputItems, std::move(referenceStreamSet));
     22ProcessingRate FixedRatio(unsigned strmItems, unsigned referenceItems, std::string && referenceStreamSet) {
     23    return ProcessingRate(ProcessingRate::ProcessingRateKind::FixedRatio, strmItems, referenceItems, std::move(referenceStreamSet));
    2424}
    2525
    26 ProcessingRate MaxRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems, std::string && referenceStreamSet) {
    27     return ProcessingRate(ProcessingRate::ProcessingRateKind::Max, strmItemsPer, perPrincipalInputItems, std::move(referenceStreamSet));
     26ProcessingRate MaxRatio(unsigned strmItems, unsigned referenceItems, std::string && referenceStreamSet) {
     27    return ProcessingRate(ProcessingRate::ProcessingRateKind::MaxRatio, strmItems, referenceItems, std::move(referenceStreamSet));
    2828}
    2929
     
    4040}
    4141
    42 Value * ProcessingRate::CreateRatioCalculation(IDISA::IDISA_Builder * b, Value * principalInputItems, Value * doFinal) const {
    43     if (mKind == ProcessingRate::ProcessingRateKind::Fixed || mKind == ProcessingRate::ProcessingRateKind::Max) {
    44         if (mRatioNumerator == 1) {
    45             return principalInputItems;
     42Value * ProcessingRate::CreateRatioCalculation(IDISA::IDISA_Builder * b, Value * referenceItems, Value * doFinal) const {
     43    if (mKind == ProcessingRate::ProcessingRateKind::FixedRatio || mKind == ProcessingRate::ProcessingRateKind::MaxRatio) {
     44        if (mRatioNumerator == mRatioDenominator) {
     45            return referenceItems;
    4646        }
    47         Type * const T = principalInputItems->getType();
     47        Type * const T = referenceItems->getType();
    4848        Constant * const numerator = ConstantInt::get(T, mRatioNumerator);
    4949        Constant * const denominator = ConstantInt::get(T, mRatioDenominator);
    5050        Constant * const denominatorLess1 = ConstantInt::get(T, mRatioDenominator - 1);
    51         Value * strmItems = b->CreateMul(principalInputItems, numerator);
     51        Value * strmItems = b->CreateMul(referenceItems, numerator);
    5252        return b->CreateUDiv(b->CreateAdd(denominatorLess1, strmItems), denominator);
    5353    }
    5454    if (mKind == ProcessingRate::ProcessingRateKind::RoundUp) {
    55         Type * const T = principalInputItems->getType();
     55        Type * const T = referenceItems->getType();
    5656        Constant * const denominator = ConstantInt::get(T, mRatioDenominator);
    5757        Constant * const denominatorLess1 = ConstantInt::get(T, mRatioDenominator - 1);
    58         return b->CreateMul(b->CreateUDiv(b->CreateAdd(principalInputItems, denominatorLess1), denominator), denominator);
     58        return b->CreateMul(b->CreateUDiv(b->CreateAdd(referenceItems, denominatorLess1), denominator), denominator);
    5959    }
    6060    if (mKind == ProcessingRate::ProcessingRateKind::Add1) {
    6161        if (doFinal) {
    62             Type * const T = principalInputItems->getType();
    63             principalInputItems = b->CreateAdd(principalInputItems, b->CreateZExt(doFinal, T));
     62            Type * const T = referenceItems->getType();
     63            referenceItems = b->CreateAdd(referenceItems, b->CreateZExt(doFinal, T));
    6464        }
    65         return principalInputItems;
     65        return referenceItems;
     66    }
     67    return nullptr;
     68}
     69
     70Value * ProcessingRate::CreateMaxReferenceItemsCalculation(IDISA::IDISA_Builder * b, Value * outputItems, Value * doFinal) const {
     71    if (mKind == ProcessingRate::ProcessingRateKind::FixedRatio) {
     72        if (mRatioNumerator == mRatioDenominator) {
     73            return outputItems;
     74        }
     75        Type * const T = outputItems->getType();
     76        Constant * const numerator = ConstantInt::get(T, mRatioNumerator);
     77        Constant * const denominator = ConstantInt::get(T, mRatioDenominator);
     78        return b->CreateMul(b->CreateUDiv(outputItems, numerator), denominator);
     79    }
     80    if (mKind == ProcessingRate::ProcessingRateKind::RoundUp) {
     81        Type * const T = outputItems->getType();
     82        Constant * const denominator = ConstantInt::get(T, mRatioDenominator);
     83        return b->CreateMul(b->CreateUDiv(outputItems, denominator), denominator);
     84    }
     85    if (mKind == ProcessingRate::ProcessingRateKind::Add1) {
     86        Type * const T = outputItems->getType();
     87        if (doFinal) {
     88            return b->CreateSub(outputItems, b->CreateZExt(doFinal, T));
     89        }
     90        return b->CreateSub(outputItems, ConstantInt::get(T, 1));
    6691    }
    6792    return nullptr;
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5431 r5433  
    3232
    3333struct ProcessingRate  {
    34     enum class ProcessingRateKind : uint8_t { Fixed, RoundUp, Add1, Max, Unknown };
     34    enum class ProcessingRateKind : uint8_t { FixedRatio, RoundUp, Add1, MaxRatio, Unknown };
    3535    ProcessingRateKind getKind() const {return mKind;}
    36     bool isExact() const {return (mKind == ProcessingRateKind::Fixed)||(mKind == ProcessingRateKind::RoundUp)||(mKind == ProcessingRateKind::Add1) ;}
     36    bool isExact() const {return (mKind == ProcessingRateKind::FixedRatio)||(mKind == ProcessingRateKind::RoundUp)||(mKind == ProcessingRateKind::Add1) ;}
    3737    bool isUnknown() const { return !isExact(); }
    3838    llvm::Value * CreateRatioCalculation(IDISA::IDISA_Builder * b, llvm::Value * principalInputItems, llvm::Value * doFinal = nullptr) const;
     39    llvm::Value * CreateMaxReferenceItemsCalculation(IDISA::IDISA_Builder * b, llvm::Value * outputItems, llvm::Value * doFinal) const;
    3940    friend ProcessingRate FixedRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems, std::string && referenceStreamSet);
    4041    friend ProcessingRate MaxRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems, std::string && referenceStreamSet);
Note: See TracChangeset for help on using the changeset viewer.