Ignore:
Timestamp:
Feb 18, 2017, 10:07:09 AM (2 years ago)
Author:
cameron
Message:

Refining the ProcessingRate? attribute

File:
1 edited

Legend:

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

    r5327 r5328  
    2525//
    2626// 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).
    2830//
    2931// 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
     39struct 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();
    3649   
    37     ProcessingRate(ClassTypeId t = ClassTypeId::Unknown) : mClassTypeId(t) {}
     50protected:
     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};
    3858
    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        
     59ProcessingRate FixedRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems);
     60ProcessingRate MaxRatio(unsigned strmItemsPer, unsigned perPrincipalInputItems);
     61ProcessingRate RoundUpToMultiple(unsigned itemMultiple);
     62ProcessingRate UnknownRate();
    7163
    7264struct 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) { }
    7867    llvm::Type *        type;
    7968    std::string         name;
    80     ProcessingRate *    rate;
     69    ProcessingRate      rate;
    8170};
    8271
Note: See TracChangeset for help on using the changeset viewer.