Changeset 5328 for icGREP/icgrepdevel/icgrep/kernels/interface.h
 Timestamp:
 Feb 18, 2017, 10:07:09 AM (2 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

icGREP/icgrepdevel/icgrep/kernels/interface.h
r5327 r5328 25 25 // 26 26 // The default ratio is FixedRatio(1) which means that there is one item processed or 27 // produced for every item of the principal input or output item. 27 // produced for every item of the principal input or output stream. 28 // FixedRatio(m, n) means that for every group of n items of the principal stream, 29 // there are m items in the output stream (rounding up). 28 30 // 29 31 // Kernels which produce a variable number of items use MaxRatio(n), for a maximum 30 // of n items produced or consumed per principal input or output item. 31 struct ProcessingRate { 32 enum class ClassTypeId : unsigned {FixedRatio, MaxRatio, Unknown}; 33 inline ClassTypeId getClassTypeId() const noexcept { 34 return mClassTypeId; 35 } 32 // of n items produced or consumed per principal input or output item. MaxRatio(m, n) 33 // means there are at most m items for every n items of the principal stream. 34 // 35 // RoundUpToMultiple(n) means that number of items produced is the same as the 36 // number of input items, rounded up to an exact multiple of n. 37 // 38 39 struct ProcessingRate { 40 enum ProcessingRateKind : uint8_t {Fixed, RoundUp, Max, Unknown}; 41 ProcessingRate() {} 42 ProcessingRateKind getKind() const {return mKind;} 43 bool isExact() const {return (mKind == Fixed)(mKind == RoundUp) ;} 44 llvm::Value * CreateRatioCalculation(IDISA::IDISA_Builder * b, llvm::Value * principalInputItems) const; 45 friend ProcessingRate FixedRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems = 1); 46 friend ProcessingRate MaxRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems = 1); 47 friend ProcessingRate RoundUpToMultiple(unsigned itemMultiple); 48 friend ProcessingRate UnknownRate(); 36 49 37 ProcessingRate(ClassTypeId t = ClassTypeId::Unknown) : mClassTypeId(t) {} 50 protected: 51 ProcessingRate(ProcessingRateKind k, unsigned numerator, unsigned denominator) 52 : mKind(k), ratio_numerator(numerator), ratio_denominator(denominator) {} 53 ProcessingRateKind mKind; 54 uint16_t ratio_numerator; 55 uint16_t ratio_denominator; 56 bool isVariableRate(); 57 }; 38 58 39 const ClassTypeId mClassTypeId; 40 }; 41 42 // 43 // FixedRatio(m, n) means that the number of items processed or produced for a principal 44 // stream set of length L are ceiling(L*m/n) 45 // 46 struct FixedRatio : ProcessingRate { 47 FixedRatio(unsigned strmItems = 1, unsigned perPrincipalInputItems = 1) 48 : ProcessingRate(ClassTypeId::FixedRatio), thisStreamItems(strmItems), principalInputItems(perPrincipalInputItems) { 49 } 50 static inline bool classof(const ProcessingRate * e) { 51 return e>getClassTypeId() == ClassTypeId::FixedRatio; 52 } 53 54 unsigned thisStreamItems; 55 unsigned principalInputItems; 56 }; 57 58 struct MaxRatio : ProcessingRate { 59 MaxRatio(unsigned strmItems, unsigned perPrincipalInputItems = 1) 60 : ProcessingRate(ClassTypeId::MaxRatio), thisStreamItems(strmItems), principalInputItems(perPrincipalInputItems) { 61 } 62 static inline bool classof(const ProcessingRate * e) { 63 return e>getClassTypeId() == ClassTypeId::MaxRatio; 64 } 65 66 unsigned thisStreamItems; 67 unsigned principalInputItems; 68 }; 69 70 59 ProcessingRate FixedRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems); 60 ProcessingRate MaxRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems); 61 ProcessingRate RoundUpToMultiple(unsigned itemMultiple); 62 ProcessingRate UnknownRate(); 71 63 72 64 struct Binding { 73 Binding(llvm::Type * type, const std::string & name, ProcessingRate * r = nullptr) 74 : type(type), name(name) { 75 rate = (r == nullptr) ? new FixedRatio(1, 1) : r; 76 } 77 65 Binding(llvm::Type * type, const std::string & name, ProcessingRate r = FixedRatio(1)) 66 : type(type), name(name), rate(r) { } 78 67 llvm::Type * type; 79 68 std::string name; 80 ProcessingRate *rate;69 ProcessingRate rate; 81 70 }; 82 71
Note: See TracChangeset
for help on using the changeset viewer.