Ignore:
Timestamp:
May 9, 2017, 9:57:18 AM (2 years ago)
Author:
cameron
Message:

static ratio calculations

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

Legend:

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

    r5436 r5438  
    4040}
    4141
     42unsigned ProcessingRate::calculateRatio(unsigned referenceItems, bool doFinal) const {
     43    if (mKind == ProcessingRate::ProcessingRateKind::FixedRatio || mKind == ProcessingRate::ProcessingRateKind::MaxRatio) {
     44        if (mRatioNumerator == mRatioDenominator) {
     45            return referenceItems;
     46        }
     47        unsigned strmItems = referenceItems * mRatioNumerator;
     48        return (strmItems + mRatioDenominator - 1) / mRatioDenominator;
     49    }
     50    if (mKind == ProcessingRate::ProcessingRateKind::RoundUp) {
     51        return ((referenceItems + mRatioDenominator - 1) / mRatioDenominator) * mRatioDenominator;
     52    }
     53    if (mKind == ProcessingRate::ProcessingRateKind::Add1) {
     54        return doFinal ? referenceItems + 1 : referenceItems;
     55    }
     56    report_fatal_error("Processing rate calculation attempted for variable or unknown rate.");
     57}
     58
    4259Value * ProcessingRate::CreateRatioCalculation(IDISA::IDISA_Builder * const b, Value * referenceItems, Value * doFinal) const {
    4360    if (mKind == ProcessingRate::ProcessingRateKind::FixedRatio || mKind == ProcessingRate::ProcessingRateKind::MaxRatio) {
     
    6582        return referenceItems;
    6683    }
    67     return nullptr;
     84    report_fatal_error("Processing rate calculation attempted for variable or unknown rate.");
     85}
     86
     87unsigned ProcessingRate::calculateMaxReferenceItems(unsigned outputItems, bool doFinal) const {
     88    if (mKind == ProcessingRate::ProcessingRateKind::FixedRatio) {
     89        if (mRatioNumerator == mRatioDenominator) {
     90            return outputItems;
     91        }
     92        return (outputItems / mRatioNumerator) * mRatioDenominator;
     93    }
     94    if (mKind == ProcessingRate::ProcessingRateKind::RoundUp) {
     95        return (outputItems / mRatioDenominator) * mRatioDenominator;
     96    }
     97    if (mKind == ProcessingRate::ProcessingRateKind::Add1) {
     98        return doFinal ? outputItems - 1 : outputItems;
     99    }
     100    report_fatal_error("Inverse processing rate calculation attempted for variable or unknown rate.");
    68101}
    69102
     
    90123        return b->CreateSub(outputItems, ConstantInt::get(T, 1));
    91124    }
    92     return nullptr;
     125    report_fatal_error("Inverse processing rate calculation attempted for variable or unknown rate.");
    93126}
    94127
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5436 r5438  
    1616// Processing rate attributes are required for all stream set bindings for a kernel.
    1717// These attributes describe the number of items that are processed or produced as
    18 // a ratio in comparison to the principal input stream set (or the principal output
    19 // stream set if there is no input.
     18// a ratio in comparison to a reference stream set, normally the principal input stream set
     19// by default (or the principal output stream set if there is no input).
    2020//
    2121// The default ratio is FixedRatio(1) which means that there is one item processed or
    22 // produced for every item of the principal input or output stream.
    23 // FixedRatio(m, n) means that for every group of n items of the principal stream,
     22// produced for every item of the reference stream.
     23// FixedRatio(m, n) means that for every group of n items of the refrence stream,
    2424// there are m items in the output stream (rounding up).
    2525//
    2626// Kernels which produce a variable number of items use MaxRatio(n), for a maximum
    2727// of n items produced or consumed per principal input or output item.  MaxRatio(m, n)
    28 // means there are at most m items for every n items of the principal stream.
     28// means there are at most m items for every n items of the reference stream.
    2929//
    3030// RoundUpToMultiple(n) means that number of items produced is the same as the
    31 // number of input items, rounded up to an exact multiple of n.
     31// number of reference items, rounded up to an exact multiple of n.
    3232//
    3333
     
    3939    bool isExact() const {return (mKind == ProcessingRateKind::FixedRatio)||(mKind == ProcessingRateKind::RoundUp)||(mKind == ProcessingRateKind::Add1) ;}
    4040    bool isUnknownRate() const { return mKind == ProcessingRateKind::Unknown; }
    41     llvm::Value * CreateRatioCalculation(IDISA::IDISA_Builder * const b, llvm::Value * principalInputItems, llvm::Value * doFinal = nullptr) const;
    42     llvm::Value * CreateMaxReferenceItemsCalculation(IDISA::IDISA_Builder * const b, llvm::Value * outputItems, llvm::Value * doFinal) const;
    43     friend ProcessingRate FixedRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems, std::string && referenceStreamSet);
    44     friend ProcessingRate MaxRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems, std::string && referenceStreamSet);
     41    unsigned calculateRatio(unsigned referenceItems, bool doFinal = false) const;
     42    unsigned calculateMaxReferenceItems(unsigned outputItems, bool doFinal = false) const;
     43    llvm::Value * CreateRatioCalculation(IDISA::IDISA_Builder * const b, llvm::Value * referenceItems, llvm::Value * doFinal = nullptr) const;
     44    llvm::Value * CreateMaxReferenceItemsCalculation(IDISA::IDISA_Builder * const b, llvm::Value * outputItems, llvm::Value * doFinal = nullptr) const;
     45    friend ProcessingRate FixedRatio(unsigned strmItems, unsigned referenceItems, std::string && referenceStreamSet);
     46    friend ProcessingRate MaxRatio(unsigned strmItems, unsigned referenceItems, std::string && referenceStreamSet);
    4547    friend ProcessingRate RoundUpToMultiple(unsigned itemMultiple, std::string && referenceStreamSet);
    4648    friend ProcessingRate Add1(std::string && referenceStreamSet);
     
    5961};
    6062
    61 ProcessingRate FixedRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems = 1, std::string && referenceStreamSet = "");
    62 ProcessingRate MaxRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems = 1, std::string && referenceStreamSet = "");
     63ProcessingRate FixedRatio(unsigned strmItems, unsigned referenceItems = 1, std::string && referenceStreamSet = "");
     64ProcessingRate MaxRatio(unsigned strmItems, unsigned referenceItems = 1, std::string && referenceStreamSet = "");
    6365ProcessingRate RoundUpToMultiple(unsigned itemMultiple, std::string &&referenceStreamSet = "");
    6466ProcessingRate Add1(std::string && referenceStreamSet = "");
Note: See TracChangeset for help on using the changeset viewer.