Changeset 5755 for icGREP/icgrepdevel/icgrep/kernels/processing_rate.h
 Timestamp:
 Dec 3, 2017, 12:40:40 PM (18 months ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

icGREP/icgrepdevel/icgrep/kernels/processing_rate.h
r5706 r5755 4 4 #include <string> 5 5 #include <assert.h> 6 #include <boost/rational.hpp> 6 7 7 8 namespace kernel { … … 27 28 struct ProcessingRate { 28 29 30 friend struct Binding; 31 29 32 enum class KindId { 30 Fixed, Bounded, Unknown, DirectlyRelative, PopCountRelative33 Fixed, Bounded, Unknown, Relative, PopCount 31 34 }; 35 36 using RateValue = boost::rational<unsigned>; 32 37 33 38 KindId getKind() const { return mKind; } 34 39 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; 39 43 } 40 44 41 unsignedgetLowerBound() const {45 RateValue getLowerBound() const { 42 46 assert (isFixed()  isBounded()  isUnknown()); 43 return m N;47 return mLowerBound; 44 48 } 45 49 46 unsignedgetUpperBound() const {50 RateValue getUpperBound() const { 47 51 assert (isFixed()  isBounded()); 48 assert (isFixed() ? m M == mN : mM > mN);49 return m M;52 assert (isFixed() ? mUpperBound == mLowerBound : mUpperBound > mLowerBound); 53 return mUpperBound; 50 54 } 51 55 52 56 const std::string & getReference() const { 53 assert (is ExactlyRelative());57 assert (isRelative()); 54 58 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;67 59 } 68 60 … … 75 67 } 76 68 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; 79 75 } 80 76 … … 84 80 85 81 bool isDerived() const { 86 return is ExactlyRelative(); // isFixed() 82 return isRelative(); // isFixed()  87 83 } 88 84 89 85 bool operator == (const ProcessingRate & other) const { 90 return mKind == other.mKind && m N == other.mN && mM == other.mM&& mReference == other.mReference;86 return mKind == other.mKind && mLowerBound == other.mLowerBound && mUpperBound == other.mUpperBound && mReference == other.mReference; 91 87 } 92 88 … … 95 91 } 96 92 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 105 93 friend ProcessingRate FixedRate(const unsigned); 106 94 friend ProcessingRate BoundedRate(const unsigned, const unsigned); 107 95 friend ProcessingRate UnknownRate(const unsigned); 108 96 friend ProcessingRate RateEqualTo(std::string); 97 friend ProcessingRate PopcountOf(std::string, const ProcessingRate::RateValue); 109 98 110 protected: 99 ProcessingRate(ProcessingRate &&) = default; 100 ProcessingRate(const ProcessingRate &) = default; 101 ProcessingRate & operator = (const ProcessingRate & other) = default; 111 102 112 ProcessingRate(const KindId k, const unsigned n, const unsigned m, const std::string && ref = "") : mKind(k), mN(n), mM(m), mReference(ref) {} 103 protected: 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) {} 113 106 private: 114 107 KindId mKind; 115 unsigned mN;116 unsigned mM;108 RateValue mLowerBound; 109 RateValue mUpperBound; 117 110 std::string mReference; 118 111 }; … … 126 119 return FixedRate(lower); 127 120 } else { 128 return ProcessingRate(ProcessingRate::KindId::Bounded, lower, upper);121 return ProcessingRate(ProcessingRate::KindId::Bounded, {lower}, {upper}); 129 122 } 130 123 } 131 124 125 /** 126 * @brief UnknownRate 127 * 128 * The produced item count per stride should never be dependent on an unknown rate input stream. 129 */ 132 130 inline ProcessingRate UnknownRate(const unsigned lower = 0) { 133 131 return ProcessingRate(ProcessingRate::KindId::Unknown, lower, 0); … … 135 133 136 134 inline 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)); 138 136 } 137 138 inline 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 142 ProcessingRate::RateValue lcm(const ProcessingRate::RateValue & x, const ProcessingRate::RateValue & y); 143 144 ProcessingRate::RateValue gcd(const ProcessingRate::RateValue & x, const ProcessingRate::RateValue & y); 139 145 140 146 }
Note: See TracChangeset
for help on using the changeset viewer.