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

static ratio calculations

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.