Ignore:
Timestamp:
Oct 25, 2017, 4:57:58 PM (21 months ago)
Author:
nmedfort
Message:

First stage of MultiBlockKernel? and pipeline restructuring

File:
1 edited

Legend:

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

    r5646 r5706  
    77#define KERNEL_INTERFACE_H
    88
    9 #include <llvm/IR/Constants.h>
     9#include <kernels/processing_rate.h>
     10#include <kernels/attributes.h>
     11#include <memory>
    1012#include <string>
    1113#include <vector>
     
    1416namespace kernel { class Kernel; }
    1517namespace kernel { class KernelBuilder; }
    16 
    17 // Processing rate attributes are required for all stream set bindings for a kernel.
    18 // These attributes describe the number of items that are processed or produced as
    19 // a ratio in comparison to a reference stream set, normally the principal input stream set
    20 // by default (or the principal output stream set if there is no input).
    21 //
    22 // The default ratio is FixedRatio(1) which means that there is one item processed or
    23 // produced for every item of the reference stream.
    24 // FixedRatio(m, n) means that for every group of n items of the refrence stream,
    25 // there are m items in the output stream (rounding up).
    26 //
    27 // Kernels which produce a variable number of items use MaxRatio(n), for a maximum
    28 // of n items produced or consumed per principal input or output item.  MaxRatio(m, n)
    29 // means there are at most m items for every n items of the reference stream.
    30 //
    31 // RoundUpToMultiple(n) means that number of items produced is the same as the
    32 // number of reference items, rounded up to an exact multiple of n.
    33 //
    34 
    35 struct ProcessingRate  {
    36     friend class kernel::Kernel;
    37     enum class ProcessingRateKind : uint8_t { FixedRatio, RoundUp, Add1, MaxRatio, Unknown };
    38     ProcessingRateKind getKind() const {return mKind;}
    39     bool isFixedRatio() const {return mKind == ProcessingRateKind::FixedRatio;}
    40     bool isMaxRatio() const {return mKind == ProcessingRateKind::MaxRatio;}
    41     bool isExact() const {return (mKind == ProcessingRateKind::FixedRatio)||(mKind == ProcessingRateKind::RoundUp)||(mKind == ProcessingRateKind::Add1) ;}
    42     bool isUnknownRate() const { return mKind == ProcessingRateKind::Unknown; }
    43     unsigned calculateRatio(unsigned referenceItems, bool doFinal = false) const;
    44     // Calculate the max number of reference items that can be processed without exceeding/exhausting outputItems
    45     unsigned calculateMaxReferenceItems(unsigned outputItems, bool doFinal = false) const;
    46     llvm::Value * CreateRatioCalculation(IDISA::IDISA_Builder * const b, llvm::Value * referenceItems, llvm::Value * doFinal = nullptr) const;
    47     llvm::Value * CreateMaxReferenceItemsCalculation(IDISA::IDISA_Builder * const b, llvm::Value * outputItems, llvm::Value * doFinal = nullptr) const;
    48     friend ProcessingRate FixedRatio(unsigned strmItems, unsigned referenceItems, std::string && referenceStreamSet);
    49     friend ProcessingRate MaxRatio(unsigned strmItems, unsigned referenceItems, std::string && referenceStreamSet);
    50     friend ProcessingRate RoundUpToMultiple(unsigned itemMultiple, std::string && referenceStreamSet);
    51     friend ProcessingRate Add1(std::string && referenceStreamSet);
    52     friend ProcessingRate UnknownRate();
    53     uint16_t getRatioNumerator() const { return mRatioNumerator;}
    54     uint16_t getRatioDenominator() const { return mRatioDenominator;}
    55     const std::string & referenceStreamSet() const { return mReferenceStreamSet;}
    56 protected:
    57     ProcessingRate(ProcessingRateKind k, unsigned numerator, unsigned denominator, std::string && referenceStreamSet)
    58     : mKind(k), mRatioNumerator(numerator), mRatioDenominator(denominator), mReferenceStreamSet(referenceStreamSet) {}
    59     void setReferenceStreamSet(const std::string & s) {mReferenceStreamSet = s;}
     18namespace llvm { class CallInst; }
     19namespace llvm { class Function; }
     20namespace llvm { class Value; }
     21namespace llvm { class Module; }
     22namespace llvm { class StructType; }
     23namespace llvm { class Type; }
     24
     25namespace kernel {
     26
     27struct Binding {
     28
     29    friend class KernelInterface;
     30
     31    Binding(llvm::Type * type, const std::string & name, ProcessingRate r = FixedRate(1))
     32    : type(type), name(name), rate(r), attributes() { }
     33
     34
     35    Binding(llvm::Type * type, const std::string & name, ProcessingRate r, Attribute && attribute)
     36    : type(type), name(name), rate(r), attributes({std::move(attribute)}) { }
     37
     38
     39    Binding(llvm::Type * type, const std::string & name, ProcessingRate r, std::initializer_list<Attribute> attributes)
     40    : type(type), name(name), rate(r), attributes(attributes) { }
     41
     42    llvm::Type * getType() const {
     43        return type;
     44    }
     45
     46    const std::string & getName() const {
     47        return name;
     48    }
     49
     50    const ProcessingRate & getRate() const {
     51        return rate;
     52    }
     53
     54    const Attribute & getAttribute(const unsigned i) const {
     55        return attributes[i];
     56    }
     57
     58    const std::vector<Attribute> & getAttributes() const {
     59        return attributes;
     60    }
     61
     62    void addAttribute(Attribute attribute);
     63
     64    bool hasAttributes() const {
     65        return !attributes.empty();
     66    }
     67
    6068private:
    61     const ProcessingRateKind mKind;
    62     const uint16_t mRatioNumerator;
    63     const uint16_t mRatioDenominator;
    64     std::string mReferenceStreamSet;
    65 };
    66 
    67 ProcessingRate FixedRatio(unsigned strmItems, unsigned referenceItems = 1, std::string && referenceStreamSet = "");
    68 ProcessingRate MaxRatio(unsigned strmItems, unsigned referenceItems = 1, std::string && referenceStreamSet = "");
    69 ProcessingRate RoundUpToMultiple(unsigned itemMultiple, std::string &&referenceStreamSet = "");
    70 ProcessingRate Add1(std::string && referenceStreamSet = "");
    71 ProcessingRate UnknownRate();
    72 
    73 struct Binding {
    74     Binding(llvm::Type * type, const std::string & name, ProcessingRate r = FixedRatio(1))
    75     : type(type), name(name), rate(r) { }
    76     llvm::Type * const        type;
    77     const std::string         name;
    78     ProcessingRate      rate;
     69    llvm::Type * const          type;
     70    const std::string           name;
     71    ProcessingRate              rate;
     72    std::vector<Attribute>      attributes;
    7973};
    8074
     
    157151    }
    158152
    159     void setInstance(llvm::Value * const instance) {
    160         assert ("kernel instance cannot be null!" && instance);
    161         assert ("kernel instance must point to a valid kernel state type!" && (instance->getType()->getPointerElementType() == mKernelStateType));
    162         mKernelInstance = instance;
     153    void setInstance(llvm::Value * const instance);
     154
     155    bool hasPrincipleItemCount() const {
     156        return mHasPrincipleItemCount;
    163157    }
    164158
    165159    unsigned getLookAhead(const unsigned i) const {
    166         assert (i < mStreamSetInputLookahead.size());
    167         return mStreamSetInputLookahead[i];
     160        return 0;
    168161    }
    169162
    170163    void setLookAhead(const unsigned i, const unsigned lookAheadPositions) {
    171         assert (i < mStreamSetInputLookahead.size());
    172         mStreamSetInputLookahead[i] = lookAheadPositions;
     164
    173165    }
    174166
     
    180172
    181173    llvm::Function * getTerminateFunction(llvm::Module * const module) const;
     174
     175    llvm::CallInst * makeDoSegmentCall(KernelBuilder & idb, const std::vector<llvm::Value *> & args) const;
    182176
    183177    KernelInterface(const std::string && kernelName,
     
    190184    , mModule(nullptr)
    191185    , mKernelStateType(nullptr)
     186    , mHasPrincipleItemCount(false)
    192187    , mKernelName(kernelName)
    193188    , mStreamSetInputs(stream_inputs)
    194     , mStreamSetInputLookahead(mStreamSetInputs.size(), 0)
    195189    , mStreamSetOutputs(stream_outputs)
    196190    , mScalarInputs(scalar_inputs)
    197191    , mScalarOutputs(scalar_outputs)
    198192    , mInternalScalars(internal_scalars) {
    199 
     193        normalizeStreamProcessingRates();
    200194    }
    201195   
     196private:
     197
     198    void normalizeStreamProcessingRates();
     199
    202200protected:
    203201
     
    205203    llvm::Module *                          mModule;
    206204    llvm::StructType *                      mKernelStateType;
     205    bool                                    mHasPrincipleItemCount;
    207206    const std::string                       mKernelName;
    208207    std::vector<llvm::Value *>              mInitialArguments;
    209208    std::vector<Binding>                    mStreamSetInputs;
    210     std::vector<unsigned>                   mStreamSetInputLookahead;
    211209    std::vector<Binding>                    mStreamSetOutputs;
    212210    std::vector<Binding>                    mScalarInputs;
    213211    std::vector<Binding>                    mScalarOutputs;
    214212    std::vector<Binding>                    mInternalScalars;
     213
    215214};
    216215
     216}
     217
    217218#endif
Note: See TracChangeset for help on using the changeset viewer.