Ignore:
Timestamp:
Dec 3, 2017, 12:40:40 PM (18 months ago)
Author:
nmedfort
Message:

Bug fixes and simplified MultiBlockKernel? logic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/processing_rate.h

    r5706 r5755  
    44#include <string>
    55#include <assert.h>
     6#include <boost/rational.hpp>
    67
    78namespace kernel {
     
    2728struct ProcessingRate  {
    2829
     30    friend struct Binding;
     31
    2932    enum class KindId {
    30         Fixed, Bounded, Unknown, DirectlyRelative, PopCountRelative
     33        Fixed, Bounded, Unknown, Relative, PopCount
    3134    };
     35
     36    using RateValue = boost::rational<unsigned>;
    3237
    3338    KindId getKind() const { return mKind; }
    3439
    35     unsigned getRate() const {
    36         assert (isFixed());
    37         assert (mN > 0 && mN == mM);
    38         return mN;
     40    RateValue getRate() const {
     41        assert (isFixed() || isRelative());
     42        return mLowerBound;
    3943    }
    4044
    41     unsigned getLowerBound() const {
     45    RateValue getLowerBound() const {
    4246        assert (isFixed() || isBounded() || isUnknown());
    43         return mN;
     47        return mLowerBound;
    4448    }
    4549
    46     unsigned getUpperBound() const {
     50    RateValue getUpperBound() const {
    4751        assert (isFixed() || isBounded());
    48         assert (isFixed() ? mM == mN : mM > mN);
    49         return mM;
     52        assert (isFixed() ? mUpperBound == mLowerBound : mUpperBound > mLowerBound);
     53        return mUpperBound;
    5054    }
    5155
    5256    const std::string & getReference() const {
    53         assert (isExactlyRelative());
     57        assert (isRelative());
    5458        return mReference;
    55     }
    56 
    57     const unsigned getNumerator() const {
    58         assert (isExactlyRelative());
    59         assert (mM > 0);
    60         return mM;
    61     }
    62 
    63     const unsigned getDenominator() const {
    64         assert (isExactlyRelative());
    65         assert (mN > 0);
    66         return mN;
    6759    }
    6860
     
    7567    }
    7668
    77     bool isExactlyRelative() const {
    78         return mKind == KindId::DirectlyRelative;
     69    bool isRelative() const {
     70        return mKind == KindId::Relative;
     71    }
     72
     73    bool isPopCount() const {
     74        return mKind == KindId::PopCount;
    7975    }
    8076
     
    8480
    8581    bool isDerived() const {
    86         return isExactlyRelative(); // isFixed() ||
     82        return isRelative(); // isFixed() ||
    8783    }
    8884
    8985    bool operator == (const ProcessingRate & other) const {
    90         return mKind == other.mKind && mN == other.mN && mM == other.mM && mReference == other.mReference;
     86        return mKind == other.mKind && mLowerBound == other.mLowerBound && mUpperBound == other.mUpperBound && mReference == other.mReference;
    9187    }
    9288
     
    9591    }
    9692
    97     ProcessingRate & operator = (const ProcessingRate & other) {
    98         mKind = other.mKind;
    99         mN = other.mN;
    100         mM = other.mM;
    101         mReference = other.mReference;
    102         return *this;
    103     }
    104 
    10593    friend ProcessingRate FixedRate(const unsigned);
    10694    friend ProcessingRate BoundedRate(const unsigned, const unsigned);
    10795    friend ProcessingRate UnknownRate(const unsigned);
    10896    friend ProcessingRate RateEqualTo(std::string);
     97    friend ProcessingRate PopcountOf(std::string, const ProcessingRate::RateValue);
    10998
    110 protected:
     99    ProcessingRate(ProcessingRate &&) = default;
     100    ProcessingRate(const ProcessingRate &) = default;
     101    ProcessingRate & operator = (const ProcessingRate & other) = default;
    111102
    112     ProcessingRate(const KindId k, const unsigned n, const unsigned m, const std::string && ref = "") : mKind(k), mN(n), mM(m), mReference(ref) {}
     103protected:   
     104    ProcessingRate(const KindId k, const unsigned n, const unsigned m, const std::string && ref = "") : mKind(k), mLowerBound(n), mUpperBound(m), mReference(ref) {}
     105    ProcessingRate(const KindId k, const RateValue n, const RateValue m, const std::string && ref = "") : mKind(k), mLowerBound(n), mUpperBound(m), mReference(ref) {}
    113106private:
    114107    KindId mKind;
    115     unsigned mN;
    116     unsigned mM;
     108    RateValue mLowerBound;
     109    RateValue mUpperBound;
    117110    std::string mReference;
    118111};
     
    126119        return FixedRate(lower);
    127120    } else {
    128         return ProcessingRate(ProcessingRate::KindId::Bounded, lower, upper);
     121        return ProcessingRate(ProcessingRate::KindId::Bounded, {lower}, {upper});
    129122    }
    130123}
    131124
     125/**
     126 * @brief UnknownRate
     127 *
     128 * The produced item count per stride should never be dependent on an unknown rate input stream.
     129 */
    132130inline ProcessingRate UnknownRate(const unsigned lower = 0) {
    133131    return ProcessingRate(ProcessingRate::KindId::Unknown, lower, 0);
     
    135133
    136134inline ProcessingRate RateEqualTo(std::string ref) {
    137     return ProcessingRate(ProcessingRate::KindId::DirectlyRelative, 1, 1, std::move(ref));
     135    return ProcessingRate(ProcessingRate::KindId::Relative, 1, 0, std::move(ref));
    138136}
     137
     138inline ProcessingRate PopcountOf(std::string ref, const ProcessingRate::RateValue ratio = ProcessingRate::RateValue{1}) {
     139    return ProcessingRate(ProcessingRate::KindId::PopCount, ratio, ProcessingRate::RateValue{0}, std::move(ref));
     140}
     141
     142ProcessingRate::RateValue lcm(const ProcessingRate::RateValue & x, const ProcessingRate::RateValue & y);
     143
     144ProcessingRate::RateValue gcd(const ProcessingRate::RateValue & x, const ProcessingRate::RateValue & y);
    139145
    140146}
Note: See TracChangeset for help on using the changeset viewer.