Ignore:
Timestamp:
Feb 16, 2017, 6:06:31 PM (2 years ago)
Author:
cameron
Message:

Processing rate attributes on stream set inputs and outputs; initial check-in

File:
1 edited

Legend:

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

    r5307 r5325  
    1919
    2020
     21// Processing rate attributes are required for all stream set bindings for a kernel.
     22// These attributes describe the number of items that are processed or produced as
     23// a ratio in comparison to the principal input stream set (or the principal output
     24// stream set if there is no input.
     25//
     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.
     28//
     29// 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.
     31struct ProcessingRate {
     32    enum class ClassTypeId : unsigned {FixedRatio, MaxRatio, Unknown};
     33    inline ClassTypeId getClassTypeId() const noexcept {
     34        return mClassTypeId;
     35    }
     36   
     37    ProcessingRate(ClassTypeId t = ClassTypeId::Unknown) : mClassTypeId(t) {}
     38
     39    const ClassTypeId       mClassTypeId;
     40};
     41
     42// FixedRatio(m, n) means that the number of items processed or produced for a principal
     43// stream set of length L are  m * L/n + L mod n
     44struct FixedRatio : ProcessingRate {
     45    FixedRatio(unsigned strmItems = 1, unsigned perPrincipalInputItems = 1)
     46    : ProcessingRate(ClassTypeId::FixedRatio), thisStreamItems(strmItems), principalInputItems(perPrincipalInputItems) {
     47    }
     48    static inline bool classof(const ProcessingRate * e) {
     49        return e->getClassTypeId() == ClassTypeId::FixedRatio;
     50    }
     51   
     52    unsigned thisStreamItems;
     53    unsigned principalInputItems;
     54};
     55
     56struct MaxRatio : ProcessingRate {
     57    MaxRatio(unsigned strmItems, unsigned perPrincipalInputItems = 1)
     58    : ProcessingRate(ClassTypeId::MaxRatio), thisStreamItems(strmItems), principalInputItems(perPrincipalInputItems) {
     59    }
     60    static inline bool classof(const ProcessingRate * e) {
     61        return e->getClassTypeId() == ClassTypeId::MaxRatio;
     62    }
     63   
     64    unsigned thisStreamItems;
     65    unsigned principalInputItems;
     66};
     67
     68       
     69
    2170struct Binding {
    22     Binding(llvm::Type * type, const std::string & name, const unsigned step = 0)
    23     : type(type), name(name), step(step) {
    24 
     71    Binding(llvm::Type * type, const std::string & name, ProcessingRate * r = nullptr)
     72    : type(type), name(name) {
     73        rate = (r == nullptr) ? new FixedRatio(1, 1) : r;
    2574    }
    2675
    2776    llvm::Type *        type;
    2877    std::string         name;
    29     const unsigned      step;
     78    ProcessingRate *    rate;
    3079};
    3180
Note: See TracChangeset for help on using the changeset viewer.